From f4a82c6f6be1b3f95c15d9b0f14128e9ff6b0824 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 10 Nov 2015 09:40:23 +0100 Subject: [PATCH 1/4] Add pushetta --- requirements_all.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index ca5be2e24a1..571708ab873 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -151,5 +151,8 @@ py-cpuinfo==0.1.6 # Radio Thermostat (thermostat.radiotherm) radiotherm==1.2 -# Honeywell Evo Home Client +# Honeywell Evo Home Client (thermostat.honeywell) evohomeclient==0.2.3 + +# Pushetta (notify.pushetta) +pushetta==1.0.15 From e8a0d54fddfbfe759c1e2b216c3a4ae0ec6fac8d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 10 Nov 2015 09:40:42 +0100 Subject: [PATCH 2/4] Add pushetta --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index 9dcbacc4b41..8fa465898af 100644 --- a/.coveragerc +++ b/.coveragerc @@ -66,6 +66,7 @@ omit = homeassistant/components/notify/instapush.py homeassistant/components/notify/nma.py homeassistant/components/notify/pushbullet.py + homeassistant/components/notify/pushetta.py homeassistant/components/notify/pushover.py homeassistant/components/notify/slack.py homeassistant/components/notify/smtp.py From 8371b086768f907c60d388372fb90f5eb29b0594 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 10 Nov 2015 14:12:03 +0100 Subject: [PATCH 3/4] Add pushetta notify platform --- homeassistant/components/notify/pushetta.py | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 homeassistant/components/notify/pushetta.py diff --git a/homeassistant/components/notify/pushetta.py b/homeassistant/components/notify/pushetta.py new file mode 100644 index 00000000000..b51461c13ae --- /dev/null +++ b/homeassistant/components/notify/pushetta.py @@ -0,0 +1,63 @@ +""" +homeassistant.components.notify.pushetta +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Pushetta platform for notify component. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.pushetta/ +""" +import logging + +from homeassistant.helpers import validate_config +from homeassistant.components.notify import ( + DOMAIN, ATTR_TITLE, BaseNotificationService) +from homeassistant.const import CONF_API_KEY + +_LOGGER = logging.getLogger(__name__) + +REQUIREMENTS = ['pushetta==1.0.15'] + + +def get_service(hass, config): + """ Get the Pushetta notification service. """ + + from pushetta import Pushetta, exceptions + + if not validate_config({DOMAIN: config}, + {DOMAIN: [CONF_API_KEY, 'channel_name']}, + _LOGGER): + return None + + try: + pushetta = Pushetta(config[CONF_API_KEY]) + pushetta.pushMessage(config['channel_name'], "Home Assistant started") + except exceptions.TokenValidationError: + _LOGGER.error("Please check your access token") + return None + except exceptions.ChannelNotFoundError: + _LOGGER.exception("Channel '%s' not found", config['channel_name']) + return None + + return PushettaNotificationService(config[CONF_API_KEY], + config['channel_name']) + + +# pylint: disable=too-few-public-methods +class PushettaNotificationService(BaseNotificationService): + """ Implements notification service for Pushetta. """ + + def __init__(self, api_key, channel_name): + + from pushetta import Pushetta + + self._api_key = api_key + self._channel_name = channel_name + self.pushetta = Pushetta(self._api_key) + + def send_message(self, message="", **kwargs): + """ Send a message to a user. """ + + title = kwargs.get(ATTR_TITLE) + + self.pushetta.pushMessage(self._channel_name, + "{} {}".format(title, message)) From bf2bcb6dcff632d4360dcd1683df62e52721549f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 10 Nov 2015 18:20:10 +0100 Subject: [PATCH 4/4] Use _LOGGER.error instead of _LOGGER.exception --- homeassistant/components/notify/pushetta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/notify/pushetta.py b/homeassistant/components/notify/pushetta.py index b51461c13ae..22bbd5175c6 100644 --- a/homeassistant/components/notify/pushetta.py +++ b/homeassistant/components/notify/pushetta.py @@ -35,7 +35,7 @@ def get_service(hass, config): _LOGGER.error("Please check your access token") return None except exceptions.ChannelNotFoundError: - _LOGGER.exception("Channel '%s' not found", config['channel_name']) + _LOGGER.error("Channel '%s' not found", config['channel_name']) return None return PushettaNotificationService(config[CONF_API_KEY],