1 """Simplepush notification service."""
3 from __future__
import annotations
8 from simplepush
import BadRequest, UnknownError, send
14 BaseNotificationService,
20 from .const
import ATTR_ATTACHMENTS, ATTR_EVENT, CONF_DEVICE_KEY, CONF_SALT
22 _LOGGER = logging.getLogger(__name__)
28 discovery_info: DiscoveryInfoType |
None =
None,
29 ) -> SimplePushNotificationService |
None:
30 """Get the Simplepush notification service."""
37 """Implementation of the notification service for Simplepush."""
39 def __init__(self, config: dict[str, Any]) ->
None:
40 """Initialize the Simplepush notification service."""
41 self._device_key: str = config[CONF_DEVICE_KEY]
42 self._event: str |
None = config.get(CONF_EVENT)
43 self._password: str |
None = config.get(CONF_PASSWORD)
44 self._salt: str |
None = config.get(CONF_SALT)
47 """Send a message to a Simplepush user."""
48 title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
53 if data := kwargs.get(ATTR_DATA):
54 event = data.get(ATTR_EVENT)
56 attachments_data = data.get(ATTR_ATTACHMENTS)
57 if isinstance(attachments_data, list):
59 for attachment
in attachments_data:
61 isinstance(attachment, dict)
64 or "video" in attachment
65 or (
"video" in attachment
and "thumbnail" in attachment)
68 _LOGGER.error(
"Attachment format is incorrect")
71 if "video" in attachment
and "thumbnail" in attachment:
72 attachments.append(attachment)
73 elif "video" in attachment:
74 attachments.append(attachment[
"video"])
75 elif "image" in attachment:
76 attachments.append(attachment[
"image"])
79 event = event
or self._event
85 password=self._password,
89 attachments=attachments,
97 attachments=attachments,
102 _LOGGER.error(
"Bad request. Title or message are too long")
104 _LOGGER.error(
"Failed to send the notification")
None send_message(self, str message, **Any kwargs)
None __init__(self, dict[str, Any] config)
SimplePushNotificationService|None async_get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)