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

33 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2026-04-01 15:06 +0000

1import logging 

2from typing import TYPE_CHECKING, Any 

3 

4from homeassistant.components.notify.const import ATTR_MESSAGE 

5from homeassistant.const import ATTR_ENTITY_ID 

6 

7from custom_components.supernotify.const import ( 

8 OPTION_MESSAGE_USAGE, 

9 OPTION_SIMPLIFY_TEXT, 

10 OPTION_STRIP_URLS, 

11 OPTION_TARGET_CATEGORIES, 

12 OPTION_TARGET_SELECT, 

13 OPTION_UNIQUE_TARGETS, 

14 TRANSPORT_ALEXA, 

15) 

16from custom_components.supernotify.model import ( 

17 DebugTrace, 

18 MessageOnlyPolicy, 

19 TargetRequired, 

20 TransportConfig, 

21 TransportFeature, 

22) 

23from custom_components.supernotify.schema import SelectionRank 

24from custom_components.supernotify.transport import Transport 

25 

26if TYPE_CHECKING: 

27 from custom_components.supernotify.envelope import Envelope 

28 

29_LOGGER = logging.getLogger(__name__) 

30 

31 

32class AlexaDevicesTransport(Transport): 

33 """Notify via Home Assistant's built-in Alexa Devices integration 

34 

35 options: 

36 message_usage: standard | use_title | combine_title 

37 

38 """ 

39 

40 name = TRANSPORT_ALEXA 

41 

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

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

44 

45 @property 

46 def supported_features(self) -> TransportFeature: 

47 return TransportFeature.MESSAGE | TransportFeature.SPOKEN 

48 

49 @property 

50 def default_config(self) -> TransportConfig: 

51 config = TransportConfig() 

52 config.delivery_defaults.action = "notify.send_message" 

53 config.delivery_defaults.target_required = TargetRequired.ALWAYS 

54 config.delivery_defaults.selection_rank = SelectionRank.FIRST 

55 config.delivery_defaults.options = { 

56 OPTION_SIMPLIFY_TEXT: True, 

57 OPTION_STRIP_URLS: True, 

58 OPTION_MESSAGE_USAGE: MessageOnlyPolicy.STANDARD, 

59 OPTION_UNIQUE_TARGETS: True, 

60 OPTION_TARGET_CATEGORIES: [ATTR_ENTITY_ID], 

61 OPTION_TARGET_SELECT: [r"notify\.[a-z0-9_]+\_(speak|announce)", r"group\.[a-z0-9_]+"], 

62 } 

63 return config 

64 

65 async def deliver(self, envelope: Envelope, debug_trace: DebugTrace | None = None) -> bool: # noqa: ARG002 

66 _LOGGER.debug("SUPERNOTIFY notify_alexa_devices: %s", envelope.message) 

67 

68 targets = envelope.target.entity_ids or [] 

69 

70 if not targets: 

71 _LOGGER.debug("SUPERNOTIFY skipping alexa devices, no targets") 

72 return False 

73 

74 action_data: dict[str, Any] = {ATTR_MESSAGE: envelope.message or ""} 

75 target_data: dict[str, Any] = {ATTR_ENTITY_ID: targets} 

76 

77 return await self.call_action(envelope, action_data=action_data, target_data=target_data)