mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 10:29:27 +00:00
* Shelly RPC sub-devices
* Better varaible name
* Add get_rpc_device_info helper
* Revert channel name changes
* Use get_rpc_device_info
* Add get_rpc_device_info helper
* Use get_block_device_info
* Use helpers in the button platform
* Fix channel name and roller mode for block devices
* Fix EM3 gen1
* Fix channel name for RPC devices
* Revert test changes
* Fix/improve test_block_get_block_channel_name
* Fix test_get_rpc_channel_name_multiple_components
* Fix tests
* Fix tests
* Fix tests
* Use key instead of index to generate sub-device identifier
* Improve logic for Pro RGBWW PM
* Split channels for em1
* Better channel name
* Cleaning
* has_entity_name is True
* Add get_block_sub_device_name() function
* Improve block functions
* Add get_rpc_sub_device_name() function
* Remove _attr_name
* Remove name for button with device class
* Fix names of virtual components
* Better Input name
* Fix get_rpc_channel_name()
* Fix names for Inputs
* get_rpc_channel_name() improvement
* Better variable name
* Clean RPC functions
* Fix input_name type
* Fix test
* Fix entity_ids for Blu Trv
* Fix get_block_channel_name()
* Fix for Blu Trv, once again
* Revert name for reboot button
* Fix button tests
* Fix tests
* Fix coordinator tests
* Fix tests for cover platform
* Fix tests for event platform
* Fix entity_ids in init tests
* Fix get_block_channel_name() for lights
* Fix tests for light platform
* Fix test for logbook
* Update snapshots for number platform
* Fix tests for sensor platform
* Fix tests for switch platform
* Fix tests for utils
* Uncomment
* Fix tests for flood
* Fix Valve entity name
* Fix climate tests
* Fix test for diagnostics
* Fix tests for init
* Remove old snapshots
* Add tests for 2PM Gen3
* Add comment
* More tests
* Cleaning
* Clean fixtures
* Update tests
* Anonymize coordinates in fixtures
* Split Pro 3EM entities into sub-devices
* Make sub-device names more unique
* 3EM (gen1) does not support sub-devices
* Coverage
* Rename "device temperature" sensor to the "relay temperature"
* Update tests after rebase
* Support sub-devices for 3EM (gen1)
* Mark has-entity-name rule as done 🎉
* Rename `relay temperature` to `temperature`
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
"""Describe Shelly logbook events."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
|
|
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
|
|
from homeassistant.const import ATTR_DEVICE_ID
|
|
from homeassistant.core import Event, HomeAssistant, callback
|
|
|
|
from .const import (
|
|
ATTR_CHANNEL,
|
|
ATTR_CLICK_TYPE,
|
|
ATTR_DEVICE,
|
|
BLOCK_INPUTS_EVENTS_TYPES,
|
|
DOMAIN,
|
|
EVENT_SHELLY_CLICK,
|
|
RPC_INPUTS_EVENTS_TYPES,
|
|
)
|
|
from .coordinator import (
|
|
get_block_coordinator_by_device_id,
|
|
get_rpc_coordinator_by_device_id,
|
|
)
|
|
from .utils import get_rpc_entity_name
|
|
|
|
|
|
@callback
|
|
def async_describe_events(
|
|
hass: HomeAssistant,
|
|
async_describe_event: Callable[[str, str, Callable[[Event], dict]], None],
|
|
) -> None:
|
|
"""Describe logbook events."""
|
|
|
|
@callback
|
|
def async_describe_shelly_click_event(event: Event) -> dict[str, str]:
|
|
"""Describe shelly.click logbook event (block device)."""
|
|
device_id = event.data[ATTR_DEVICE_ID]
|
|
click_type = event.data[ATTR_CLICK_TYPE]
|
|
channel = event.data[ATTR_CHANNEL]
|
|
input_name = f"{event.data[ATTR_DEVICE]} channel {channel}"
|
|
|
|
if click_type in RPC_INPUTS_EVENTS_TYPES:
|
|
rpc_coordinator = get_rpc_coordinator_by_device_id(hass, device_id)
|
|
if rpc_coordinator and rpc_coordinator.device.initialized:
|
|
key = f"input:{channel - 1}"
|
|
input_name = f"{rpc_coordinator.device.name} {get_rpc_entity_name(rpc_coordinator.device, key)}"
|
|
|
|
elif click_type in BLOCK_INPUTS_EVENTS_TYPES:
|
|
block_coordinator = get_block_coordinator_by_device_id(hass, device_id)
|
|
if block_coordinator and block_coordinator.device.initialized:
|
|
input_name = f"{block_coordinator.device.name} channel {channel}"
|
|
|
|
return {
|
|
LOGBOOK_ENTRY_NAME: "Shelly",
|
|
LOGBOOK_ENTRY_MESSAGE: (
|
|
f"'{click_type}' click event for {input_name} Input was fired"
|
|
),
|
|
}
|
|
|
|
async_describe_event(DOMAIN, EVENT_SHELLY_CLICK, async_describe_shelly_click_event)
|