diff --git a/.coveragerc b/.coveragerc index 76a07db77c4..75f4cbd20fd 100644 --- a/.coveragerc +++ b/.coveragerc @@ -103,6 +103,7 @@ omit = homeassistant/components/notify/telegram.py homeassistant/components/notify/twitter.py homeassistant/components/notify/xmpp.py + homeassistant/components/notify/googlevoice.py homeassistant/components/sensor/arest.py homeassistant/components/sensor/bitcoin.py homeassistant/components/sensor/cpuspeed.py diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py new file mode 100644 index 00000000000..e37586c5cf6 --- /dev/null +++ b/homeassistant/components/notify/googlevoice.py @@ -0,0 +1,61 @@ +""" +homeassistant.components.notify.googlevoice +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Google Voice SMS platform for notify component. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.free_mobile/ +""" +import logging +from homeassistant.helpers import validate_config +from homeassistant.components.notify import ( + DOMAIN, ATTR_TARGET, BaseNotificationService) +from homeassistant.const import CONF_USERNAME, CONF_PASSWORD + +_LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/' + '7c5ee9969b97a7992fc86a753fe9f20e3ffa3f7c.zip#' + 'pygooglevoice-sms==0.0.1'] + + +def get_service(hass, config): + """ Get the Google Voice SMS notification service. """ + + if not validate_config({DOMAIN: config}, + {DOMAIN: [CONF_USERNAME, + CONF_PASSWORD]}, + _LOGGER): + return None + + return GoogleVoiceSMSNotificationService(config[CONF_USERNAME], + config[CONF_PASSWORD]) + + +# pylint: disable=too-few-public-methods +class GoogleVoiceSMSNotificationService(BaseNotificationService): + """ Implements notification service for the Google Voice SMS service. """ + + def __init__(self, username, password): + from googlevoicesms import Voice + self.voice = Voice() + self.username = username + self.password = password + + def send_message(self, message="", **kwargs): + """ Send SMS to specified target user cell. """ + + targets = kwargs.get(ATTR_TARGET) + + if not targets: + _LOGGER.info('At least 1 target is required') + return + + if not isinstance(targets, list): + targets = [targets] + + self.voice.login(self.username, self.password) + + for target in targets: + self.voice.send_sms(target, message) + + self.voice.logout() diff --git a/requirements_all.txt b/requirements_all.txt index 8c08df03d73..80369444496 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -110,6 +110,9 @@ python-nest==2.6.0 # homeassistant.components.notify.free_mobile freesms==0.1.0 +# homeassistant.components.notify.googlevoice +https://github.com/w1ll1am23/pygooglevoice-sms/archive/7c5ee9969b97a7992fc86a753fe9f20e3ffa3f7c.zip#pygooglevoice-sms==0.0.1 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0