Coverage for custom_components/supernotify/transports/notify_entity.py: 97%
32 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-21 23:31 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-21 23:31 +0000
1import logging
2from typing import Any
4from homeassistant.const import ATTR_ENTITY_ID # ATTR_VARIABLES from script.const has import issues
6from custom_components.supernotify import (
7 OPTION_MESSAGE_USAGE,
8 OPTION_SIMPLIFY_TEXT,
9 OPTION_STRIP_URLS,
10 OPTION_TARGET_CATEGORIES,
11 OPTION_TARGET_INCLUDE_RE,
12 OPTION_UNIQUE_TARGETS,
13 TRANSPORT_NOTIFY_ENTITY,
14 SelectionRank,
15)
16from custom_components.supernotify.envelope import Envelope
17from custom_components.supernotify.model import MessageOnlyPolicy, TransportConfig
18from custom_components.supernotify.transport import (
19 Transport,
20)
22_LOGGER = logging.getLogger(__name__)
24RE_NOTIFY_ENTITY = r"notify\.[A-Za-z0-9_]+"
25FIXED_ACTION = "notify.send_message"
28class NotifyEntityTransport(Transport):
29 """Call any notify entity"""
31 name = TRANSPORT_NOTIFY_ENTITY
33 def __init__(self, *args: Any, **kwargs: Any) -> None:
34 super().__init__(*args, **kwargs)
36 @property
37 def default_config(self) -> TransportConfig:
38 config = TransportConfig()
39 config.delivery_defaults.action = FIXED_ACTION
40 config.delivery_defaults.selection_rank = SelectionRank.LAST
41 config.delivery_defaults.options = {
42 OPTION_SIMPLIFY_TEXT: False,
43 OPTION_STRIP_URLS: False,
44 OPTION_MESSAGE_USAGE: MessageOnlyPolicy.STANDARD,
45 OPTION_UNIQUE_TARGETS: True,
46 OPTION_TARGET_CATEGORIES: [ATTR_ENTITY_ID],
47 OPTION_TARGET_INCLUDE_RE: [RE_NOTIFY_ENTITY],
48 }
49 return config
51 @property
52 def auto_configure(self) -> bool:
53 return True
55 async def deliver(self, envelope: Envelope) -> bool:
56 action_data = envelope.core_action_data()
57 targets = envelope.target.entity_ids or []
58 if not targets:
59 raise ValueError("No targets for notify entity transport")
60 target_data: dict[str, Any] = {ATTR_ENTITY_ID: targets}
61 # area_id
62 # device_id
63 # label_id
64 action_data = envelope.core_action_data()
66 return await self.call_action(envelope, FIXED_ACTION, action_data=action_data, target_data=target_data)