From ffc06e8bcbe633b98a9ca4ba238af75fe9560a23 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Thu, 28 Jan 2016 21:07:59 -0500 Subject: [PATCH] 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")