Coverage for custom_components/supernotify/methods/persistent.py: 100%
21 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-10-18 09:29 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-10-18 09:29 +0000
1import logging
2from typing import Any
4from custom_components.supernotify import ATTR_NOTIFICATION_ID, METHOD_PERSISTENT
5from custom_components.supernotify.delivery_method import DeliveryMethod
6from custom_components.supernotify.envelope import Envelope
8_LOGGER = logging.getLogger(__name__)
9ACTION = "persistent_notification.create"
12class PersistentDeliveryMethod(DeliveryMethod):
13 method = METHOD_PERSISTENT
15 def __init__(self, *args: Any, **kwargs: Any) -> None:
16 kwargs["default_action"] = ACTION
17 super().__init__(*args, **kwargs)
19 def validate_action(self, action: str | None) -> bool:
20 return action is None or action == ACTION
22 async def deliver(self, envelope: Envelope) -> bool:
23 data = envelope.data or {}
24 config = self.delivery_config(envelope.delivery_name)
26 notification_id = data.get(ATTR_NOTIFICATION_ID, config.get(ATTR_NOTIFICATION_ID))
27 action_data = envelope.core_action_data()
28 action_data["notification_id"] = notification_id
30 return await self.call_action(envelope, action_data=action_data)