Coverage for custom_components/supernotify/transports/alexa_devices.py: 52%
33 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-01-07 15:35 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-01-07 15:35 +0000
1import logging
2from typing import Any
4from homeassistant.components.notify.const import ATTR_MESSAGE
5from homeassistant.const import ATTR_ENTITY_ID
7from custom_components.supernotify 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.envelope import Envelope
17from custom_components.supernotify.model import (
18 DebugTrace,
19 MessageOnlyPolicy,
20 SelectionRank,
21 TargetRequired,
22 TransportConfig,
23 TransportFeature,
24)
25from custom_components.supernotify.transport import Transport
27_LOGGER = logging.getLogger(__name__)
30class AlexaDevicesTransport(Transport):
31 """Notify via Home Assistant's built-in Alexa Devices integration
33 options:
34 message_usage: standard | use_title | combine_title
36 """
38 name = TRANSPORT_ALEXA
40 def __init__(self, *args: Any, **kwargs: Any) -> None:
41 super().__init__(*args, **kwargs)
43 @property
44 def supported_features(self) -> TransportFeature:
45 return TransportFeature.MESSAGE
47 @property
48 def default_config(self) -> TransportConfig:
49 config = TransportConfig()
50 config.delivery_defaults.action = "notify.send_message"
51 config.delivery_defaults.target_required = TargetRequired.ALWAYS
52 config.delivery_defaults.selection_rank = SelectionRank.FIRST
53 config.delivery_defaults.options = {
54 OPTION_SIMPLIFY_TEXT: True,
55 OPTION_STRIP_URLS: True,
56 OPTION_MESSAGE_USAGE: MessageOnlyPolicy.STANDARD,
57 OPTION_UNIQUE_TARGETS: True,
58 OPTION_TARGET_CATEGORIES: [ATTR_ENTITY_ID],
59 OPTION_TARGET_SELECT: [r"notify\.[a-z0-9_]+\_(speak|announce)", r"group\.[a-z0-9_]+"],
60 }
61 return config
63 async def deliver(self, envelope: Envelope, debug_trace: DebugTrace | None = None) -> bool: # noqa: ARG002
64 _LOGGER.debug("SUPERNOTIFY notify_alexa_devices: %s", envelope.message)
66 targets = envelope.target.entity_ids or []
68 if not targets:
69 _LOGGER.debug("SUPERNOTIFY skipping alexa devices, no targets")
70 return False
72 action_data: dict[str, Any] = {ATTR_MESSAGE: envelope.message or ""}
73 target_data: dict[str, Any] = {ATTR_ENTITY_ID: targets}
75 return await self.call_action(envelope, action_data=action_data, target_data=target_data)