diff --git a/.coveragerc b/.coveragerc index ac8fef79e4b4ccd6fb3652d46b851191a21c8578..0909ae12674cb033bf69d8f8d1fc8141686aec68 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 0000000000000000000000000000000000000000..37a6a90a62ed66899e2434dda09064543d11f872 --- /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 ecd883b1835cc0f1aad9277cf4ee4a69e2f35968..b886d7e40168760ce56233f9f522ffbc7d008d40 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