Coverage for custom_components/supernotify/transports/persistent.py: 100%
31 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-08 17:42 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-08 17:42 +0000
1from __future__ import annotations
3import logging
4from typing import TYPE_CHECKING, Any
6from homeassistant.helpers.typing import ConfigType
8from custom_components.supernotify.const import (
9 ATTR_NOTIFICATION_ID,
10 TRANSPORT_PERSISTENT,
11)
12from custom_components.supernotify.model import DebugTrace, TransportConfig, TransportFeature
13from custom_components.supernotify.transport import Transport
15if TYPE_CHECKING:
16 from custom_components.supernotify.envelope import Envelope
17 from custom_components.supernotify.hass_api import HomeAssistantAPI
19_LOGGER = logging.getLogger(__name__)
22class PersistentTransport(Transport):
23 name = TRANSPORT_PERSISTENT
25 def __init__(self, *args: Any, **kwargs: Any) -> None:
26 super().__init__(*args, **kwargs)
28 @property
29 def supported_features(self) -> TransportFeature:
30 return TransportFeature.MESSAGE | TransportFeature.TITLE
32 @property
33 def default_config(self) -> TransportConfig:
34 config = super().default_config
35 config.delivery_defaults.action = "persistent_notification.create"
36 return config
38 def is_viable(self, hass_api: HomeAssistantAPI) -> bool:
39 # persistent_notification is always available in HA core, no integration to discover -
40 # but a UI popup on every single notification would be intrusive, so require opt-in
41 return True
43 def build_standard_deliveries(self, hass_api: HomeAssistantAPI) -> dict[str, ConfigType]:
44 return {self.name: {}}
46 async def deliver(self, envelope: Envelope, debug_trace: DebugTrace | None = None) -> bool:
47 data = envelope.data or {}
49 notification_id = data.get(ATTR_NOTIFICATION_ID) or envelope.delivery.data.get(ATTR_NOTIFICATION_ID)
50 action_data = envelope.core_action_data()
51 if notification_id is not None:
52 action_data["notification_id"] = notification_id
54 return await self.call_action(envelope, action_data=action_data)