1 """Provides device automations for Tasmota."""
3 from __future__
import annotations
5 from hatasmota.const
import AUTOMATION_TYPE_TRIGGER
6 from hatasmota.models
import DiscoveryHashType
7 from hatasmota.trigger
import TasmotaTrigger
12 EVENT_DEVICE_REGISTRY_UPDATED,
13 EventDeviceRegistryUpdatedData,
17 from .
import device_trigger
18 from .const
import DATA_REMOVE_DISCOVER_COMPONENT, DATA_UNSUB
19 from .discovery
import TASMOTA_DISCOVERY_ENTITY_NEW
23 """Remove automations for a Tasmota device."""
24 await device_trigger.async_remove_triggers(hass, device_id)
28 """Set up Tasmota device automation dynamically through discovery."""
30 async
def async_device_removed(
31 event: Event[EventDeviceRegistryUpdatedData],
33 """Handle the removal of a device."""
37 def _async_device_removed_filter(
38 event_data: EventDeviceRegistryUpdatedData,
40 """Filter device registry events."""
41 return event_data[
"action"] ==
"remove"
44 tasmota_automation: TasmotaTrigger, discovery_hash: DiscoveryHashType
46 """Discover and add a Tasmota device automation."""
47 if tasmota_automation.automation_type == AUTOMATION_TYPE_TRIGGER:
48 await device_trigger.async_setup_trigger(
49 hass, tasmota_automation, config_entry, discovery_hash
52 hass.data[DATA_REMOVE_DISCOVER_COMPONENT.format(
"device_automation")] = (
55 TASMOTA_DISCOVERY_ENTITY_NEW.format(
"device_automation"),
59 hass.data[DATA_UNSUB].append(
60 hass.bus.async_listen(
61 EVENT_DEVICE_REGISTRY_UPDATED,
63 event_filter=_async_device_removed_filter,
None async_discover(DiscoveryInfo discovery_info)
None async_remove_automations(HomeAssistant hass, str device_id)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)