Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/simplepush/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DEFAULT_NAME: Final = "simplepush"
DATA_HASS_CONFIG: Final = "simplepush_hass_config"

ATTR_ATTACHMENTS: Final = "attachments"
ATTR_ENCRYPTED: Final = "encrypted"
ATTR_EVENT: Final = "event"

Expand Down
34 changes: 32 additions & 2 deletions homeassistant/components/simplepush/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from .const import ATTR_EVENT, CONF_DEVICE_KEY, CONF_SALT, DOMAIN
from .const import ATTR_ATTACHMENTS, ATTR_EVENT, CONF_DEVICE_KEY, CONF_SALT, DOMAIN

# Configuring Simplepush under the notify has been removed in 2022.9.0
PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA
Expand Down Expand Up @@ -61,11 +61,34 @@ def send_message(self, message: str, **kwargs: Any) -> None:
"""Send a message to a Simplepush user."""
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

attachments = None
# event can now be passed in the service data
event = None
if data := kwargs.get(ATTR_DATA):
event = data.get(ATTR_EVENT)

attachments_data = data.get(ATTR_ATTACHMENTS)
if isinstance(attachments_data, list):
attachments = []
for attachment in attachments_data:
if not (
isinstance(attachment, dict)
and (
"image" in attachment
or "video" in attachment
or ("video" in attachment and "thumbnail" in attachment)
)
):
_LOGGER.error("Attachment format is incorrect")
return

if "video" in attachment and "thumbnail" in attachment:
attachments.append(attachment)
elif "video" in attachment:
attachments.append(attachment["video"])
elif "image" in attachment:
attachments.append(attachment["image"])

# use event from config until YAML config is removed
event = event or self._event

Expand All @@ -77,10 +100,17 @@ def send_message(self, message: str, **kwargs: Any) -> None:
salt=self._salt,
title=title,
message=message,
attachments=attachments,
event=event,
)
else:
send(key=self._device_key, title=title, message=message, event=event)
send(
key=self._device_key,
title=title,
message=message,
attachments=attachments,
event=event,
)

except BadRequest:
_LOGGER.error("Bad request. Title or message are too long")
Expand Down