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
This commit is contained in:
Nolan Gilley 2016-07-12 11:10:33 -04:00 committed by Paulus Schoutsen
parent bef2f87ddc
commit e58615b2a5
4 changed files with 148 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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