mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use simplepush module, enable event, and allow encrypted communication (#9568)
* Use simplepush module, enable event, and allow encrypted communication * Fix check
This commit is contained in:
parent
515d1bdbd3
commit
2486c9af35
@ -6,49 +6,54 @@ https://home-assistant.io/components/notify.simplepush/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
import homeassistant.helpers.config_validation as cv
|
from homeassistant.const import CONF_PASSWORD
|
||||||
|
|
||||||
|
REQUIREMENTS = ['simplepush==1.1.3']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_RESOURCE = 'https://api.simplepush.io/send'
|
|
||||||
|
ATTR_ENCRYPTED = 'encrypted'
|
||||||
|
|
||||||
CONF_DEVICE_KEY = 'device_key'
|
CONF_DEVICE_KEY = 'device_key'
|
||||||
|
CONF_EVENT = 'event'
|
||||||
DEFAULT_TIMEOUT = 10
|
CONF_SALT = 'salt'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_DEVICE_KEY): cv.string,
|
vol.Required(CONF_DEVICE_KEY): cv.string,
|
||||||
|
vol.Optional(CONF_EVENT): cv.string,
|
||||||
|
vol.Inclusive(CONF_PASSWORD, ATTR_ENCRYPTED): cv.string,
|
||||||
|
vol.Inclusive(CONF_SALT, ATTR_ENCRYPTED): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Simplepush notification service."""
|
"""Get the Simplepush notification service."""
|
||||||
return SimplePushNotificationService(config.get(CONF_DEVICE_KEY))
|
return SimplePushNotificationService(config)
|
||||||
|
|
||||||
|
|
||||||
class SimplePushNotificationService(BaseNotificationService):
|
class SimplePushNotificationService(BaseNotificationService):
|
||||||
"""Implementation of the notification service for SimplePush."""
|
"""Implementation of the notification service for Simplepush."""
|
||||||
|
|
||||||
def __init__(self, device_key):
|
def __init__(self, config):
|
||||||
"""Initialize the service."""
|
"""Initialize the Simplepush notification service."""
|
||||||
self._device_key = device_key
|
self._device_key = config.get(CONF_DEVICE_KEY)
|
||||||
|
self._event = config.get(CONF_EVENT)
|
||||||
|
self._password = config.get(CONF_PASSWORD)
|
||||||
|
self._salt = config.get(CONF_SALT)
|
||||||
|
|
||||||
def send_message(self, message='', **kwargs):
|
def send_message(self, message='', **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a Simplepush user."""
|
||||||
|
from simplepush import send, send_encrypted
|
||||||
|
|
||||||
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
|
|
||||||
# Upstream bug will be fixed soon, but no dead-line available.
|
if self._password:
|
||||||
# payload = 'key={}&title={}&msg={}'.format(
|
send_encrypted(self._device_key, self._password, self._salt, title,
|
||||||
# self._device_key, title, message).replace(' ', '%')
|
message, event=self._event)
|
||||||
# response = requests.get(
|
else:
|
||||||
# _RESOURCE, data=payload, timeout=DEFAULT_TIMEOUT)
|
send(self._device_key, title, message, event=self._event)
|
||||||
response = requests.get(
|
|
||||||
'{}/{}/{}/{}'.format(_RESOURCE, self._device_key, title, message),
|
|
||||||
timeout=DEFAULT_TIMEOUT)
|
|
||||||
|
|
||||||
if response.json()['status'] != 'OK':
|
|
||||||
_LOGGER.error("Not possible to send notification")
|
|
||||||
|
@ -909,6 +909,9 @@ sharp_aquos_rc==0.3.2
|
|||||||
# homeassistant.components.sensor.shodan
|
# homeassistant.components.sensor.shodan
|
||||||
shodan==1.7.5
|
shodan==1.7.5
|
||||||
|
|
||||||
|
# homeassistant.components.notify.simplepush
|
||||||
|
simplepush==1.1.3
|
||||||
|
|
||||||
# homeassistant.components.alarm_control_panel.simplisafe
|
# homeassistant.components.alarm_control_panel.simplisafe
|
||||||
simplisafe-python==1.0.5
|
simplisafe-python==1.0.5
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user