From dd7d8d56bb7836db2dfa393e519fec4eff1494bf Mon Sep 17 00:00:00 2001 From: Florian Klien <flowolf@klienux.org> Date: Sun, 29 Oct 2017 01:05:56 +0200 Subject: [PATCH] added Yesss SMS platform (#10177) * added Yesss SMS component requires YesssSMS==0.1.1b * requirements_all * coveragerc * fix * docstring fix * added Exception handling * requirements_all * fixing lint error, version bump for YesssSMS --- .coveragerc | 1 + homeassistant/components/notify/yessssms.py | 51 +++++++++++++++++++++ requirements_all.txt | 3 ++ 3 files changed, 55 insertions(+) create mode 100644 homeassistant/components/notify/yessssms.py diff --git a/.coveragerc b/.coveragerc index ac8fef79e4b..0909ae12674 100644 --- a/.coveragerc +++ b/.coveragerc @@ -450,6 +450,7 @@ omit = homeassistant/components/notify/telstra.py homeassistant/components/notify/twitter.py homeassistant/components/notify/xmpp.py + homeassistant/components/notify/yessssms.py homeassistant/components/nuimo_controller.py homeassistant/components/prometheus.py homeassistant/components/remote/harmony.py diff --git a/homeassistant/components/notify/yessssms.py b/homeassistant/components/notify/yessssms.py new file mode 100644 index 00000000000..37a6a90a62e --- /dev/null +++ b/homeassistant/components/notify/yessssms.py @@ -0,0 +1,51 @@ +""" +Support for the YesssSMS platform. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.yessssms/ +""" +import logging + +import voluptuous as vol + +from homeassistant.components.notify import ( + PLATFORM_SCHEMA, BaseNotificationService) +from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_RECIPIENT +import homeassistant.helpers.config_validation as cv + +REQUIREMENTS = ['YesssSMS==0.1.1b3'] + +_LOGGER = logging.getLogger(__name__) + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_USERNAME): cv.string, + vol.Required(CONF_PASSWORD): cv.string, + vol.Required(CONF_RECIPIENT): cv.string, +}) + + +def get_service(hass, config, discovery_info=None): + """Get the YesssSMS notification service.""" + return YesssSMSNotificationService( + config[CONF_USERNAME], config[CONF_PASSWORD], config[CONF_RECIPIENT]) + + +class YesssSMSNotificationService(BaseNotificationService): + """Implement a notification service for the YesssSMS service.""" + + def __init__(self, username, password, recipient): + """Initialize the service.""" + from YesssSMS import YesssSMS + self.yesss = YesssSMS(username, password) + self._recipient = recipient + + def send_message(self, message="", **kwargs): + """Send a SMS message via Yesss.at's website.""" + try: + self.yesss.send(self._recipient, message) + except ValueError as ex: + if str(ex).startswith("YesssSMS:"): + _LOGGER.error(str(ex)) + except RuntimeError as ex: + if str(ex).startswith("YesssSMS:"): + _LOGGER.error(str(ex)) diff --git a/requirements_all.txt b/requirements_all.txt index ecd883b1835..b886d7e4016 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -51,6 +51,9 @@ TravisPy==0.3.5 # homeassistant.components.notify.twitter TwitterAPI==2.4.6 +# homeassistant.components.notify.yessssms +YesssSMS==0.1.1b3 + # homeassistant.components.abode abodepy==0.12.1 -- GitLab