From aaf75c7e45ccb1504363059a1b30e7d49b5c5e5e Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Fri, 29 Jan 2016 14:14:27 -0500 Subject: [PATCH] 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"