Coverage for custom_components/supernotify/transports/persistent.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-21 23:31 +0000

1import logging 

2from typing import Any 

3 

4from custom_components.supernotify import ( 

5 ATTR_NOTIFICATION_ID, 

6 TRANSPORT_PERSISTENT, 

7) 

8from custom_components.supernotify.envelope import Envelope 

9from custom_components.supernotify.model import TargetRequired, TransportConfig 

10from custom_components.supernotify.transport import Transport 

11 

12_LOGGER = logging.getLogger(__name__) 

13 

14 

15class PersistentTransport(Transport): 

16 name = TRANSPORT_PERSISTENT 

17 

18 def __init__(self, *args: Any, **kwargs: Any) -> None: 

19 super().__init__(*args, **kwargs) 

20 

21 @property 

22 def default_config(self) -> TransportConfig: 

23 config = TransportConfig() 

24 config.delivery_defaults.action = "persistent_notification.create" 

25 config.delivery_defaults.target_required = TargetRequired.NEVER 

26 return config 

27 

28 async def deliver(self, envelope: Envelope) -> bool: 

29 data = envelope.data or {} 

30 

31 notification_id = data.get(ATTR_NOTIFICATION_ID) or envelope.delivery.data.get(ATTR_NOTIFICATION_ID) 

32 action_data = envelope.core_action_data() 

33 action_data["notification_id"] = notification_id 

34 

35 return await self.call_action(envelope, action_data=action_data)