1 """Describe Shelly logbook events."""
3 from __future__
import annotations
5 from collections.abc
import Callable
15 BLOCK_INPUTS_EVENTS_TYPES,
18 RPC_INPUTS_EVENTS_TYPES,
20 from .coordinator
import (
21 get_block_coordinator_by_device_id,
22 get_rpc_coordinator_by_device_id,
24 from .utils
import get_rpc_entity_name
30 async_describe_event: Callable[[str, str, Callable[[Event], dict]],
None],
32 """Describe logbook events."""
35 def async_describe_shelly_click_event(event: Event) -> dict[str, str]:
36 """Describe shelly.click logbook event (block device)."""
37 device_id = event.data[ATTR_DEVICE_ID]
38 click_type = event.data[ATTR_CLICK_TYPE]
39 channel = event.data[ATTR_CHANNEL]
40 input_name = f
"{event.data[ATTR_DEVICE]} channel {channel}"
42 if click_type
in RPC_INPUTS_EVENTS_TYPES:
44 if rpc_coordinator
and rpc_coordinator.device.initialized:
45 key = f
"input:{channel-1}"
48 elif click_type
in BLOCK_INPUTS_EVENTS_TYPES:
50 if block_coordinator
and block_coordinator.device.initialized:
51 input_name = f
"{block_coordinator.device.name} channel {channel}"
54 LOGBOOK_ENTRY_NAME:
"Shelly",
55 LOGBOOK_ENTRY_MESSAGE: (
56 f
"'{click_type}' click event for {input_name} Input was fired"
60 async_describe_event(DOMAIN, EVENT_SHELLY_CLICK, async_describe_shelly_click_event)
ShellyRpcCoordinator|None get_rpc_coordinator_by_device_id(HomeAssistant hass, str device_id)
ShellyBlockCoordinator|None get_block_coordinator_by_device_id(HomeAssistant hass, str device_id)
None async_describe_events(HomeAssistant hass, Callable[[str, str, Callable[[Event], dict]], None] async_describe_event)
str get_rpc_entity_name(RpcDevice device, str key, str|None description=None)