From e58615b2a5d0dbbd657a3e42b21e4492d26dcd9b Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Tue, 12 Jul 2016 11:10:33 -0400 Subject: [PATCH] Join by joaoapps component & notify platform (#2315) * initial support for Join notifier add more functions for Join * rename to joaoapps_join add message default in schema move api_key check * move special join services to their own component update coveragerc and requirements_all add icon and smallicon --- .coveragerc | 2 + homeassistant/components/joaoapps_join.py | 80 +++++++++++++++++++ .../components/notify/joaoapps_join.py | 62 ++++++++++++++ requirements_all.txt | 4 + 4 files changed, 148 insertions(+) create mode 100644 homeassistant/components/joaoapps_join.py create mode 100644 homeassistant/components/notify/joaoapps_join.py diff --git a/.coveragerc b/.coveragerc index 93899cd78a9..62de8bcc4e1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -126,6 +126,7 @@ omit = homeassistant/components/garage_door/rpi_gpio.py homeassistant/components/hdmi_cec.py homeassistant/components/ifttt.py + homeassistant/components/joaoapps_join.py homeassistant/components/keyboard.py homeassistant/components/light/blinksticklight.py homeassistant/components/light/hue.py @@ -162,6 +163,7 @@ omit = homeassistant/components/notify/gntp.py homeassistant/components/notify/googlevoice.py homeassistant/components/notify/instapush.py + homeassistant/components/notify/joaoapps_join.py homeassistant/components/notify/message_bird.py homeassistant/components/notify/nma.py homeassistant/components/notify/pushbullet.py diff --git a/homeassistant/components/joaoapps_join.py b/homeassistant/components/joaoapps_join.py new file mode 100644 index 00000000000..284567b9061 --- /dev/null +++ b/homeassistant/components/joaoapps_join.py @@ -0,0 +1,80 @@ +""" +Component for Joaoapps Join services. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/join/ +""" +import logging +import voluptuous as vol +from homeassistant.const import CONF_NAME, CONF_API_KEY +import homeassistant.helpers.config_validation as cv + +REQUIREMENTS = [ + 'https://github.com/nkgilley/python-join-api/archive/' + '3e1e849f1af0b4080f551b62270c6d244d5fbcbd.zip#python-join-api==0.0.1'] + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'joaoapps_join' +CONF_DEVICE_ID = 'device_id' + +CONFIG_SCHEMA = vol.Schema({ + DOMAIN: vol.Schema({ + vol.Required(CONF_DEVICE_ID): cv.string, + vol.Optional(CONF_NAME): cv.string, + vol.Optional(CONF_API_KEY): cv.string + }) +}, extra=vol.ALLOW_EXTRA) + + +# pylint: disable=too-many-locals +def setup(hass, config): + """Setup Join services.""" + from pyjoin import (get_devices, ring_device, set_wallpaper, send_sms, + send_file, send_url, send_notification) + device_id = config[DOMAIN].get(CONF_DEVICE_ID) + api_key = config[DOMAIN].get(CONF_API_KEY) + name = config[DOMAIN].get(CONF_NAME) + if api_key: + if not get_devices(api_key): + _LOGGER.error("Error connecting to Join, check API key") + return False + + def ring_service(service): + """Service to ring devices.""" + ring_device(device_id, api_key=api_key) + + def set_wallpaper_service(service): + """Service to set wallpaper on devices.""" + set_wallpaper(device_id, url=service.data.get('url'), api_key=api_key) + + def send_file_service(service): + """Service to send files to devices.""" + send_file(device_id, url=service.data.get('url'), api_key=api_key) + + def send_url_service(service): + """Service to open url on devices.""" + send_url(device_id, url=service.data.get('url'), api_key=api_key) + + def send_tasker_service(service): + """Service to open url on devices.""" + send_notification(device_id=device_id, + text=service.data.get('command'), + api_key=api_key) + + def send_sms_service(service): + """Service to send sms from devices.""" + send_sms(device_id=device_id, + sms_number=service.data.get('number'), + sms_text=service.data.get('message'), + api_key=api_key) + + name = name.lower().replace(" ", "_") + "_" if name else "" + hass.services.register(DOMAIN, name + 'ring', ring_service) + hass.services.register(DOMAIN, name + 'set_wallpaper', + set_wallpaper_service) + hass.services.register(DOMAIN, name + 'send_sms', send_sms_service) + hass.services.register(DOMAIN, name + 'send_file', send_file_service) + hass.services.register(DOMAIN, name + 'send_url', send_url_service) + hass.services.register(DOMAIN, name + 'send_tasker', send_tasker_service) + return True diff --git a/homeassistant/components/notify/joaoapps_join.py b/homeassistant/components/notify/joaoapps_join.py new file mode 100644 index 00000000000..1958cf5a64a --- /dev/null +++ b/homeassistant/components/notify/joaoapps_join.py @@ -0,0 +1,62 @@ +""" +Join platform for notify component. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.Join/ +""" +import logging +import voluptuous as vol +from homeassistant.components.notify import ( + ATTR_DATA, ATTR_TITLE, BaseNotificationService) +from homeassistant.const import CONF_PLATFORM, CONF_NAME, CONF_API_KEY +import homeassistant.helpers.config_validation as cv + +REQUIREMENTS = [ + 'https://github.com/nkgilley/python-join-api/archive/' + '3e1e849f1af0b4080f551b62270c6d244d5fbcbd.zip#python-join-api==0.0.1'] + +_LOGGER = logging.getLogger(__name__) + +CONF_DEVICE_ID = 'device_id' + +PLATFORM_SCHEMA = vol.Schema({ + vol.Required(CONF_PLATFORM): 'joaoapps_join', + vol.Required(CONF_DEVICE_ID): cv.string, + vol.Optional(CONF_NAME): cv.string, + vol.Optional(CONF_API_KEY): cv.string +}) + + +# pylint: disable=unused-variable +def get_service(hass, config): + """Get the Join notification service.""" + device_id = config.get(CONF_DEVICE_ID) + api_key = config.get(CONF_API_KEY) + if api_key: + from pyjoin import get_devices + if not get_devices(api_key): + _LOGGER.error("Error connecting to Join, check API key") + return False + return JoinNotificationService(device_id, api_key) + + +# pylint: disable=too-few-public-methods +class JoinNotificationService(BaseNotificationService): + """Implement the notification service for Join.""" + + def __init__(self, device_id, api_key=None): + """Initialize the service.""" + self._device_id = device_id + self._api_key = api_key + + def send_message(self, message="", **kwargs): + """Send a message to a user.""" + from pyjoin import send_notification + title = kwargs.get(ATTR_TITLE) + data = kwargs.get(ATTR_DATA) or {} + send_notification(device_id=self._device_id, + text=message, + title=title, + icon=data.get('icon'), + smallicon=data.get('smallicon'), + api_key=self._api_key) diff --git a/requirements_all.txt b/requirements_all.txt index 9538966d1ac..60db9a98c9e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -143,6 +143,10 @@ https://github.com/kellerza/pyqwikswitch/archive/v0.4.zip#pyqwikswitch==0.4 # homeassistant.components.ecobee https://github.com/nkgilley/python-ecobee-api/archive/4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6 +# homeassistant.components.joaoapps_join +# homeassistant.components.notify.joaoapps_join +https://github.com/nkgilley/python-join-api/archive/3e1e849f1af0b4080f551b62270c6d244d5fbcbd.zip#python-join-api==0.0.1 + # homeassistant.components.switch.edimax https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1