From 237465998441077d85850a206841e5ff1a7a0269 Mon Sep 17 00:00:00 2001 From: David Lloyd Date: Sun, 29 Oct 2017 19:14:40 +1100 Subject: [PATCH] Added new Clickatell SMS messaging Notify Platform (#9775) * Added new Clickatell SMS messaging Notify Platform * Added new Clickatell SMS platform with layout corrections * Added new Clickatell platform with additional layout corrections * Added new Clickatell platform with exception handling removed * Added new Clickatell platform with poor reference removed * Reversed changes to dev_docker file * Minor changes --- homeassistant/components/notify/clickatell.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 homeassistant/components/notify/clickatell.py diff --git a/homeassistant/components/notify/clickatell.py b/homeassistant/components/notify/clickatell.py new file mode 100644 index 00000000000..6af2b455129 --- /dev/null +++ b/homeassistant/components/notify/clickatell.py @@ -0,0 +1,52 @@ +""" +Clickatell platform for notify component. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.clickatell/ +""" +import logging + +import requests +import voluptuous as vol + +import homeassistant.helpers.config_validation as cv +from homeassistant.const import (CONF_API_KEY, CONF_RECIPIENT) +from homeassistant.components.notify import ( + PLATFORM_SCHEMA, BaseNotificationService) + +_LOGGER = logging.getLogger(__name__) + +DEFAULT_NAME = 'clickatell' + +BASE_API_URL = 'https://platform.clickatell.com/messages/http/send' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_API_KEY): cv.string, + vol.Required(CONF_RECIPIENT): cv.string, +}) + + +def get_service(hass, config, discovery_info=None): + """Get the Clickatell notification service.""" + return ClickatellNotificationService(config) + + +class ClickatellNotificationService(BaseNotificationService): + """Implementation of a notification service for the Clickatell service.""" + + def __init__(self, config): + """Initialize the service.""" + self.api_key = config.get(CONF_API_KEY) + self.recipient = config.get(CONF_RECIPIENT) + + def send_message(self, message="", **kwargs): + """Send a message to a user.""" + data = { + 'apiKey': self.api_key, + 'to': self.recipient, + 'content': message, + } + + resp = requests.get(BASE_API_URL, params=data, timeout=5) + if (resp.status_code != 200) or (resp.status_code != 201): + _LOGGER.error("Error %s : %s", resp.status_code, resp.text)