Improve generic event typing [tasmota] (#114737)

pull/113914/head
Marc Mueller 2024-04-06 14:16:25 +02:00 committed by GitHub
parent bf142aef5f
commit fa7da34298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,6 @@
"""Provides device automations for Tasmota."""
from collections.abc import Mapping
from typing import Any
from __future__ import annotations
from hatasmota.const import AUTOMATION_TYPE_TRIGGER
from hatasmota.models import DiscoveryHashType
@ -9,7 +8,10 @@ from hatasmota.trigger import TasmotaTrigger
from homeassistant.config_entries import ConfigEntry
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 . 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:
"""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."""
await async_remove_automations(hass, event.data["device_id"])
@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."""
return event_data["action"] == "remove"