Coverage for custom_components/supernotify/methods/persistent.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-28 14:21 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-28 14:21 +0000
1import logging
3from custom_components.supernotify import ATTR_NOTIFICATION_ID, METHOD_PERSISTENT
4from custom_components.supernotify.delivery_method import DeliveryMethod
5from custom_components.supernotify.envelope import Envelope
7_LOGGER = logging.getLogger(__name__)
10class PersistentDeliveryMethod(DeliveryMethod):
11 method = METHOD_PERSISTENT
12 default_action = "notify.persistent_notification"
14 def __init__(self, *args, **kwargs) -> None:
15 super().__init__(*args, **kwargs)
17 def validate_action(self, action: str | None) -> bool:
18 return action is None
20 async def deliver(self, envelope: Envelope) -> bool:
21 data = envelope.data or {}
22 config = self.delivery_config(envelope.delivery_name)
24 notification_id = data.get(ATTR_NOTIFICATION_ID, config.get(ATTR_NOTIFICATION_ID))
25 action_data = envelope.core_action_data()
26 action_data["notification_id"] = notification_id
28 return await self.call_action(envelope, action_data=action_data)