2021-01-04 22:10:42 +00:00
|
|
|
"""Describe Shelly logbook events."""
|
2021-07-21 17:11:44 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Callable
|
2021-01-04 22:10:42 +00:00
|
|
|
|
|
|
|
from homeassistant.const import ATTR_DEVICE_ID
|
2021-07-21 17:11:44 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
|
|
from homeassistant.helpers.typing import EventType
|
2021-01-04 22:10:42 +00:00
|
|
|
|
2021-07-21 17:11:44 +00:00
|
|
|
from . import get_device_wrapper
|
2021-01-04 22:10:42 +00:00
|
|
|
from .const import (
|
|
|
|
ATTR_CHANNEL,
|
|
|
|
ATTR_CLICK_TYPE,
|
|
|
|
ATTR_DEVICE,
|
|
|
|
DOMAIN,
|
|
|
|
EVENT_SHELLY_CLICK,
|
|
|
|
)
|
2021-09-11 20:28:33 +00:00
|
|
|
from .utils import get_block_device_name
|
2021-01-04 22:10:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
2021-07-21 17:11:44 +00:00
|
|
|
def async_describe_events(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
async_describe_event: Callable[[str, str, Callable[[EventType], dict]], None],
|
|
|
|
) -> None:
|
2021-01-04 22:10:42 +00:00
|
|
|
"""Describe logbook events."""
|
|
|
|
|
|
|
|
@callback
|
2021-07-21 17:11:44 +00:00
|
|
|
def async_describe_shelly_click_event(event: EventType) -> dict[str, str]:
|
2021-01-04 22:10:42 +00:00
|
|
|
"""Describe shelly.click logbook event."""
|
|
|
|
wrapper = get_device_wrapper(hass, event.data[ATTR_DEVICE_ID])
|
2021-08-03 18:16:00 +00:00
|
|
|
if wrapper and wrapper.device.initialized:
|
2021-09-11 20:28:33 +00:00
|
|
|
device_name = get_block_device_name(wrapper.device)
|
2021-01-04 22:10:42 +00:00
|
|
|
else:
|
|
|
|
device_name = event.data[ATTR_DEVICE]
|
|
|
|
|
|
|
|
channel = event.data[ATTR_CHANNEL]
|
|
|
|
click_type = event.data[ATTR_CLICK_TYPE]
|
|
|
|
|
|
|
|
return {
|
|
|
|
"name": "Shelly",
|
|
|
|
"message": f"'{click_type}' click event for {device_name} channel {channel} was fired.",
|
|
|
|
}
|
|
|
|
|
|
|
|
async_describe_event(DOMAIN, EVENT_SHELLY_CLICK, async_describe_shelly_click_event)
|