Improve generic event typing [tasmota] (#114737)
This commit is contained in:
parent
bf142aef5f
commit
fa7da34298
1 changed files with 11 additions and 5 deletions
|
@ -1,7 +1,6 @@
|
||||||
"""Provides device automations for Tasmota."""
|
"""Provides device automations for Tasmota."""
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from __future__ import annotations
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from hatasmota.const import AUTOMATION_TYPE_TRIGGER
|
from hatasmota.const import AUTOMATION_TYPE_TRIGGER
|
||||||
from hatasmota.models import DiscoveryHashType
|
from hatasmota.models import DiscoveryHashType
|
||||||
|
@ -9,7 +8,10 @@ from hatasmota.trigger import TasmotaTrigger
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED
|
from homeassistant.helpers.device_registry import (
|
||||||
|
EVENT_DEVICE_REGISTRY_UPDATED,
|
||||||
|
EventDeviceRegistryUpdatedData,
|
||||||
|
)
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
from . import device_trigger
|
from . import device_trigger
|
||||||
|
@ -25,12 +27,16 @@ async def async_remove_automations(hass: HomeAssistant, device_id: str) -> None:
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||||
"""Set up Tasmota device automation dynamically through discovery."""
|
"""Set up Tasmota device automation dynamically through discovery."""
|
||||||
|
|
||||||
async def async_device_removed(event: Event) -> None:
|
async def async_device_removed(
|
||||||
|
event: Event[EventDeviceRegistryUpdatedData],
|
||||||
|
) -> None:
|
||||||
"""Handle the removal of a device."""
|
"""Handle the removal of a device."""
|
||||||
await async_remove_automations(hass, event.data["device_id"])
|
await async_remove_automations(hass, event.data["device_id"])
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_device_removed_filter(event_data: Mapping[str, Any]) -> bool:
|
def _async_device_removed_filter(
|
||||||
|
event_data: EventDeviceRegistryUpdatedData,
|
||||||
|
) -> bool:
|
||||||
"""Filter device registry events."""
|
"""Filter device registry events."""
|
||||||
return event_data["action"] == "remove"
|
return event_data["action"] == "remove"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue