-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"domain": "greenapi", | ||
"name": "Whatsapp notifier basde on Green API", | ||
"codeowners": [ | ||
"@t0mer" | ||
], | ||
"documentation": "https://github.com/t0mer/green-api-custom-notifier", | ||
"iot_class": "local_polling", | ||
"issue_tracker": "https://github.com/t0mer/green-api-custom-notifier", | ||
"requirements": ["whatsapp-api-client-python"], | ||
"version": "0.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
import voluptuous as vol | ||
from whatsapp_api_client_python import API | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.components.notify import ( | ||
ATTR_TARGET, ATTR_TITLE, PLATFORM_SCHEMA, BaseNotificationService) | ||
|
||
ATTR_INSTANCE = "instance_id" | ||
ATTR_TOKEN = "token" | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Required(ATTR_TARGET): cv.string, | ||
vol.Required(ATTR_INSTANCE): cv.string, | ||
vol.Required(ATTR_TOKEN): cv.string, | ||
vol.Optional(ATTR_TITLE): cv.string, | ||
}) | ||
|
||
def get_service(hass, config, discovery_info=None): | ||
"""Get the custom notifier service.""" | ||
target = config.get(ATTR_TARGET) | ||
title = config.get(ATTR_TITLE) | ||
token = config.get(ATTR_TOKEN) | ||
instance_id = config.get(ATTR_INSTANCE) | ||
return GreenAPINotificationService(target, title, token, instance_id) | ||
|
||
class GreenAPINotificationService(BaseNotificationService): | ||
|
||
def __init__(self, target, title, token,instance_id): | ||
"""Initialize the service.""" | ||
self._targets = target.split(',') | ||
self._title = title | ||
self._token = token | ||
self._instance_id = instance_id | ||
self._greenAPI = API.GreenAPI(self._instance_id, self._token) | ||
|
||
def send_message(self, message="", **kwargs): | ||
"""Send a message to the target.""" | ||
try: | ||
for target in self._targets: | ||
_LOGGER.info("Sending message to %s: %s", target, message) | ||
self._greenAPI.sending.sendMessage(target, message) | ||
except Exception as e: | ||
_LOGGER.error("Sending message to %s: %s has failed with the following error %s", self._target, message, str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
notify: | ||
description: "Send a whatsapp notification using Green API" | ||
fields: | ||
message: | ||
description: The message to send | ||
example: "Hello World" | ||
|