2019-04-03 15:40:03 +00:00
|
|
|
"""Simplepush notification service."""
|
2019-12-01 05:22:33 +00:00
|
|
|
from simplepush import send, send_encrypted
|
2018-05-31 21:58:03 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-03-28 03:36:13 +00:00
|
|
|
from homeassistant.components.notify import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_TITLE,
|
|
|
|
ATTR_TITLE_DEFAULT,
|
|
|
|
PLATFORM_SCHEMA,
|
|
|
|
BaseNotificationService,
|
|
|
|
)
|
2021-02-13 12:07:11 +00:00
|
|
|
from homeassistant.const import CONF_EVENT, CONF_PASSWORD
|
2019-12-01 05:22:33 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2018-05-31 21:58:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ENCRYPTED = "encrypted"
|
2018-05-31 21:58:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_DEVICE_KEY = "device_key"
|
|
|
|
CONF_SALT = "salt"
|
2018-05-31 21:58:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
)
|
2018-05-31 21:58:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_service(hass, config, discovery_info=None):
|
|
|
|
"""Get the Simplepush notification service."""
|
|
|
|
return SimplePushNotificationService(config)
|
|
|
|
|
|
|
|
|
|
|
|
class SimplePushNotificationService(BaseNotificationService):
|
|
|
|
"""Implementation of the notification service for Simplepush."""
|
|
|
|
|
|
|
|
def __init__(self, config):
|
|
|
|
"""Initialize the Simplepush notification service."""
|
|
|
|
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)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def send_message(self, message="", **kwargs):
|
2018-05-31 21:58:03 +00:00
|
|
|
"""Send a message to a Simplepush user."""
|
|
|
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
|
|
|
|
|
|
|
if self._password:
|
2019-07-31 19:25:30 +00:00
|
|
|
send_encrypted(
|
|
|
|
self._device_key,
|
|
|
|
self._password,
|
|
|
|
self._salt,
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
event=self._event,
|
|
|
|
)
|
2018-05-31 21:58:03 +00:00
|
|
|
else:
|
|
|
|
send(self._device_key, title, message, event=self._event)
|