From 652c666d143f680ca597ba8d4a16378f11743546 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Fri, 25 Mar 2016 18:39:08 -0700 Subject: [PATCH] Add GNTP notifier --- .coveragerc | 1 + homeassistant/components/notify/gntp.py | 58 +++++++++++++++++++++++++ requirements_all.txt | 3 ++ 3 files changed, 62 insertions(+) create mode 100644 homeassistant/components/notify/gntp.py diff --git a/.coveragerc b/.coveragerc index fa1eb376906..98f5eb89f82 100644 --- a/.coveragerc +++ b/.coveragerc @@ -109,6 +109,7 @@ omit = homeassistant/components/media_player/squeezebox.py homeassistant/components/notify/free_mobile.py homeassistant/components/notify/googlevoice.py + homeassistant/components/notify/gntp.py homeassistant/components/notify/instapush.py homeassistant/components/notify/message_bird.py homeassistant/components/notify/nma.py diff --git a/homeassistant/components/notify/gntp.py b/homeassistant/components/notify/gntp.py new file mode 100644 index 00000000000..67e80e2c424 --- /dev/null +++ b/homeassistant/components/notify/gntp.py @@ -0,0 +1,58 @@ +""" +GNTP (aka Growl) notification service. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.gntp/ +""" +import logging +import os + +from homeassistant.components.notify import ( + ATTR_TITLE, BaseNotificationService) + +REQUIREMENTS = ['gntp==1.0.3'] + +_LOGGER = logging.getLogger(__name__) + +_GNTP_LOGGER = logging.getLogger('gntp') +_GNTP_LOGGER.setLevel(logging.ERROR) + + +def get_service(hass, config): + """Get the GNTP notification service.""" + if config.get('app_icon') is None: + icon_file = os.path.join(os.path.dirname(__file__), "..", "frontend", + "www_static", "favicon-192x192.png") + app_icon = open(icon_file, 'rb').read() + else: + app_icon = config.get('app_icon') + + return GNTPNotificationService(config.get('app_name', 'HomeAssistant'), + config.get('app_icon', app_icon), + config.get('hostname', 'localhost'), + config.get('password'), + config.get('port', 23053)) + + +# pylint: disable=too-few-public-methods +class GNTPNotificationService(BaseNotificationService): + """Implement the notification service for GNTP.""" + + # pylint: disable=too-many-arguments + def __init__(self, app_name, app_icon, hostname, password, port): + """Initialize the service.""" + from gntp import notifier + self.gntp = notifier.GrowlNotifier( + applicationName=app_name, + notifications=["Notification"], + applicationIcon=app_icon, + hostname=hostname, + password=password, + port=port + ) + self.gntp.register() + + def send_message(self, message="", **kwargs): + """Send a message to a user.""" + self.gntp.notify(noteType="Notification", title=kwargs.get(ATTR_TITLE), + description=message) diff --git a/requirements_all.txt b/requirements_all.txt index 3e478e973bc..eac18de0419 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -54,6 +54,9 @@ freesms==0.1.0 # homeassistant.components.conversation fuzzywuzzy==0.8.0 +# homeassistant.components.notify.gntp +gntp==1.0.3 + # homeassistant.components.mqtt.server hbmqtt==0.6.3