From 542b640ef0f82eb5edd01245b12386da938f378e Mon Sep 17 00:00:00 2001 From: hydreliox Date: Mon, 11 Jan 2016 09:25:26 +0100 Subject: [PATCH 1/3] FreeMobile Notify First Commit for FreeSMS platform --- homeassistant/components/notify/freesms.py | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 homeassistant/components/notify/freesms.py diff --git a/homeassistant/components/notify/freesms.py b/homeassistant/components/notify/freesms.py new file mode 100644 index 00000000000..e1e813b0d60 --- /dev/null +++ b/homeassistant/components/notify/freesms.py @@ -0,0 +1,53 @@ +""" +homeassistant.components.notify.freesms +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FreeSMS platform for notify component. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify. ... / +""" +import logging +from homeassistant.helpers import validate_config +from homeassistant.components.notify import ( + DOMAIN, ATTR_TITLE, BaseNotificationService) +from homeassistant.const import CONF_USERNAME, CONF_ACCESS_TOKEN + +_LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['freesms==0.1.0'] + + +def get_service(hass, config): + """ Get the FreeSMS notification service. """ + + if not validate_config({DOMAIN: config}, + {DOMAIN: [CONF_USERNAME, + CONF_ACCESS_TOKEN]}, + _LOGGER): + return None + + return FreeSMSNotificationService(config[CONF_USERNAME], + config[CONF_ACCESS_TOKEN]) + + +# pylint: disable=too-few-public-methods +class FreeSMSNotificationService(BaseNotificationService): + """ Implements notification service for the Free SMS service. """ + + + + def __init__(self, username, access_token): + from freesms import FreeClient + self.free_client = FreeClient(username, access_token) + + def send_message(self, message="", **kwargs): + """ Send a message to the Free Mobile user cell. """ + resp = self.free_client.send_sms(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 bc73a6829def841c1649591d4c52d5e6d6773063 Mon Sep 17 00:00:00 2001 From: hydreliox Date: Mon, 11 Jan 2016 09:30:32 +0100 Subject: [PATCH 2/3] Code formatting Correct pylint errors --- homeassistant/components/notify/freesms.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/notify/freesms.py b/homeassistant/components/notify/freesms.py index e1e813b0d60..6e765ecfb74 100644 --- a/homeassistant/components/notify/freesms.py +++ b/homeassistant/components/notify/freesms.py @@ -9,7 +9,7 @@ https://home-assistant.io/components/notify. ... / import logging from homeassistant.helpers import validate_config from homeassistant.components.notify import ( - DOMAIN, ATTR_TITLE, BaseNotificationService) + DOMAIN, BaseNotificationService) from homeassistant.const import CONF_USERNAME, CONF_ACCESS_TOKEN _LOGGER = logging.getLogger(__name__) @@ -33,8 +33,6 @@ def get_service(hass, config): class FreeSMSNotificationService(BaseNotificationService): """ Implements notification service for the Free SMS service. """ - - def __init__(self, username, access_token): from freesms import FreeClient self.free_client = FreeClient(username, access_token) From 1bbecce5eb880f51f82ed15323718308345cff06 Mon Sep 17 00:00:00 2001 From: hydreliox Date: Mon, 11 Jan 2016 18:51:03 +0100 Subject: [PATCH 3/3] Add requirements and coverage exception --- .coveragerc | 1 + requirements_all.txt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.coveragerc b/.coveragerc index ea9f302fbb1..815a69cf513 100644 --- a/.coveragerc +++ b/.coveragerc @@ -73,6 +73,7 @@ omit = homeassistant/components/media_player/plex.py homeassistant/components/media_player/sonos.py homeassistant/components/media_player/squeezebox.py + homeassistant/components/notify/freesms.py homeassistant/components/notify/instapush.py homeassistant/components/notify/nma.py homeassistant/components/notify/pushbullet.py diff --git a/requirements_all.txt b/requirements_all.txt index f320408f138..5a6860e9284 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -89,6 +89,9 @@ https://github.com/bashwork/pymodbus/archive/d7fc4f1cc975631e0a9011390e8017f64b6 # homeassistant.components.mqtt paho-mqtt==1.1 +# homeassistant.components.notify.freesms +freesms==0.1.0 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0