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