From 9c7b2ce9fd2f7c6c2078685bcc2bc8587c7b158a Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Thu, 28 Jan 2016 21:07:16 -0500 Subject: [PATCH 1/9] pygooglevoice-sms support --- homeassistant/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/const.py b/homeassistant/const.py index 143704e1968..1bc7c044eb2 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -26,6 +26,7 @@ CONF_PASSWORD = "password" CONF_API_KEY = "api_key" CONF_ACCESS_TOKEN = "access_token" CONF_FILENAME = "filename" +CONF_PHONE_NUMBER = "phone_number" CONF_VALUE_TEMPLATE = "value_template" From ffc06e8bcbe633b98a9ca4ba238af75fe9560a23 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Thu, 28 Jan 2016 21:07:59 -0500 Subject: [PATCH 2/9] pygooglevoice-sms support --- .../components/notify/googlevoice.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 homeassistant/components/notify/googlevoice.py diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py new file mode 100644 index 00000000000..1bce62b2e96 --- /dev/null +++ b/homeassistant/components/notify/googlevoice.py @@ -0,0 +1,57 @@ +""" +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, BaseNotificationService) +from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_PHONE_NUMBER + +_LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/' + 'caddd98a4e1cdc4e0a3d1f382aa1dc52bbd9b690.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, + CONF_PHONE_NUMBER]}, + _LOGGER): + return None + + return GoogleVoiceSMSNotificationService(config[CONF_USERNAME], + config[CONF_PASSWORD], config[CONF_PHONE_NUMBER]) + + +# pylint: disable=too-few-public-methods +class GoogleVoiceSMSNotificationService(BaseNotificationService): + """ Implements notification service for the Google Voice SMS service. """ + + def __init__(self, username, password, phone_number): + from googlevoice import Voice + self.voice = Voice() + self.number = phone_number + self.username = username + self.password = password + + def send_message(self, message="", **kwargs): + """ Send a message to the Free Mobile user cell. """ + resp = self.voice.login(self.username, self.password) + resp = self.voice.send_sms(self.number, message) + + if resp.status_code == 400: + _LOGGER.error("At least one parameter is missing") + elif resp.status_code == 402: + _LOGGER.error("Too much SMS send in a few time") + elif resp.status_code == 403: + _LOGGER.error("Wrong Username/Password") + elif resp.status_code == 500: + _LOGGER.error("Server error, try later") From 9ec44fbe32082bb55aa2212875cb574c24a2969a Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Thu, 28 Jan 2016 21:19:15 -0500 Subject: [PATCH 3/9] Updated googlevoicesms version --- homeassistant/components/notify/googlevoice.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index 1bce62b2e96..908953476d4 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -14,8 +14,7 @@ from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_PHONE_NUMBER _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/' - 'caddd98a4e1cdc4e0a3d1f382aa1dc52bbd9b690.zip#pygooglevoice-sms==0.0.1'] - + '7c5ee9969b97a7992fc86a753fe9f20e3ffa3f7c.zip#pygooglevoice-sms==0.0.1'] def get_service(hass, config): """ Get the Google Voice SMS notification service. """ @@ -36,7 +35,7 @@ class GoogleVoiceSMSNotificationService(BaseNotificationService): """ Implements notification service for the Google Voice SMS service. """ def __init__(self, username, password, phone_number): - from googlevoice import Voice + from googlevoicesms import Voice self.voice = Voice() self.number = phone_number self.username = username From aaf75c7e45ccb1504363059a1b30e7d49b5c5e5e Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 14:14:27 -0500 Subject: [PATCH 4/9] Added target support for googlevoice --- .../components/notify/googlevoice.py | 32 ++++++++----------- homeassistant/const.py | 1 - 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index 908953476d4..09c1e368719 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -9,8 +9,8 @@ https://home-assistant.io/components/notify.free_mobile/ import logging from homeassistant.helpers import validate_config from homeassistant.components.notify import ( - DOMAIN, BaseNotificationService) -from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_PHONE_NUMBER + DOMAIN, ATTR_TARGET, BaseNotificationService) +from homeassistant.const import CONF_USERNAME, CONF_PASSWORD _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/' @@ -21,36 +21,32 @@ def get_service(hass, config): if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_USERNAME, - CONF_PASSWORD, - CONF_PHONE_NUMBER]}, + CONF_PASSWORD]}, _LOGGER): return None return GoogleVoiceSMSNotificationService(config[CONF_USERNAME], - config[CONF_PASSWORD], config[CONF_PHONE_NUMBER]) + 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, phone_number): + def __init__(self, username, password): from googlevoicesms import Voice self.voice = Voice() - self.number = phone_number self.username = username self.password = password def send_message(self, message="", **kwargs): - """ Send a message to the Free Mobile user cell. """ - resp = self.voice.login(self.username, self.password) - resp = self.voice.send_sms(self.number, message) + """ Send SMS to specified target user cell. """ + + targets = kwargs.get(ATTR_TARGET) + self.voice.login(self.username, self.password) + + for target in targets: + resp = self.voice.send_sms(target, message) + + self.voice.logout() - if resp.status_code == 400: - _LOGGER.error("At least one parameter is missing") - elif resp.status_code == 402: - _LOGGER.error("Too much SMS send in a few time") - elif resp.status_code == 403: - _LOGGER.error("Wrong Username/Password") - elif resp.status_code == 500: - _LOGGER.error("Server error, try later") diff --git a/homeassistant/const.py b/homeassistant/const.py index 1bc7c044eb2..143704e1968 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -26,7 +26,6 @@ CONF_PASSWORD = "password" CONF_API_KEY = "api_key" CONF_ACCESS_TOKEN = "access_token" CONF_FILENAME = "filename" -CONF_PHONE_NUMBER = "phone_number" CONF_VALUE_TEMPLATE = "value_template" From a6720f54b3830851add43750f68627120589a2bc Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 16:48:01 -0500 Subject: [PATCH 5/9] Fixed style errors --- homeassistant/components/notify/googlevoice.py | 12 ++++++------ requirements_all.txt | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index 09c1e368719..cc0a1e0d1cd 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -16,6 +16,7 @@ _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. """ @@ -26,7 +27,7 @@ def get_service(hass, config): return None return GoogleVoiceSMSNotificationService(config[CONF_USERNAME], - config[CONF_PASSWORD]) + config[CONF_PASSWORD]) # pylint: disable=too-few-public-methods @@ -44,9 +45,8 @@ class GoogleVoiceSMSNotificationService(BaseNotificationService): targets = kwargs.get(ATTR_TARGET) self.voice.login(self.username, self.password) - - for target in targets: - resp = self.voice.send_sms(target, message) - - self.voice.logout() + for target in targets: + self.voice.send_sms(target, message) + + self.voice.logout() diff --git a/requirements_all.txt b/requirements_all.txt index 70ebbfe6006..26d8480a676 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -107,6 +107,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 From ad57f27989d738969916bb4f978c04dd3f72b8f5 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 16:54:56 -0500 Subject: [PATCH 6/9] Added test exclude in .coveragerc --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index c2c3fc74d3b..9fdbbd41e78 100644 --- a/.coveragerc +++ b/.coveragerc @@ -101,6 +101,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 From 375faa9c91851547553ec754e3d29e533fa077a0 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 21:53:06 -0500 Subject: [PATCH 7/9] Fixed style error --- homeassistant/components/notify/googlevoice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index cc0a1e0d1cd..2e0cf205097 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -14,7 +14,8 @@ 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'] + '7c5ee9969b97a7992fc86a753fe9f20e3ffa3f7c.zip#' + 'pygooglevoice-sms==0.0.1'] def get_service(hass, config): From 28f4283b404894c964dea14ba4b4d3b34fc2c5ae Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 22:04:02 -0500 Subject: [PATCH 8/9] Validate target --- homeassistant/components/notify/googlevoice.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index 2e0cf205097..a1ce39a6129 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -45,6 +45,10 @@ class GoogleVoiceSMSNotificationService(BaseNotificationService): """ Send SMS to specified target user cell. """ targets = kwargs.get(ATTR_TARGET) + + if not isinstance(targets, list): + targets = [targets] + self.voice.login(self.username, self.password) for target in targets: From 01a743c7d497a61e26e9c7e73e6f0bdddd1d44f9 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 22:09:59 -0500 Subject: [PATCH 9/9] Log if target == NULL --- homeassistant/components/notify/googlevoice.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/notify/googlevoice.py b/homeassistant/components/notify/googlevoice.py index a1ce39a6129..e37586c5cf6 100644 --- a/homeassistant/components/notify/googlevoice.py +++ b/homeassistant/components/notify/googlevoice.py @@ -46,6 +46,10 @@ class GoogleVoiceSMSNotificationService(BaseNotificationService): targets = kwargs.get(ATTR_TARGET) + if not targets: + _LOGGER.info('At least 1 target is required') + return + if not isinstance(targets, list): targets = [targets]