mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add typing of deconz_event (#67497)
This commit is contained in:
parent
1bb0f52814
commit
4506d45345
@ -1,5 +1,7 @@
|
|||||||
"""Representation of a deCONZ remote or keypad."""
|
"""Representation of a deCONZ remote or keypad."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from pydeconz.sensor import (
|
from pydeconz.sensor import (
|
||||||
ANCILLARY_CONTROL_EMERGENCY,
|
ANCILLARY_CONTROL_EMERGENCY,
|
||||||
ANCILLARY_CONTROL_FIRE,
|
ANCILLARY_CONTROL_FIRE,
|
||||||
@ -23,6 +25,7 @@ from homeassistant.util import slugify
|
|||||||
|
|
||||||
from .const import CONF_ANGLE, CONF_GESTURE, LOGGER
|
from .const import CONF_ANGLE, CONF_GESTURE, LOGGER
|
||||||
from .deconz_device import DeconzBase
|
from .deconz_device import DeconzBase
|
||||||
|
from .gateway import DeconzGateway
|
||||||
|
|
||||||
CONF_DECONZ_EVENT = "deconz_event"
|
CONF_DECONZ_EVENT = "deconz_event"
|
||||||
CONF_DECONZ_ALARM_EVENT = "deconz_alarm_event"
|
CONF_DECONZ_ALARM_EVENT = "deconz_alarm_event"
|
||||||
@ -35,11 +38,13 @@ SUPPORTED_DECONZ_ALARM_EVENTS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_events(gateway) -> None:
|
async def async_setup_events(gateway: DeconzGateway) -> None:
|
||||||
"""Set up the deCONZ events."""
|
"""Set up the deCONZ events."""
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_sensor(sensors=gateway.api.sensors.values()):
|
def async_add_sensor(
|
||||||
|
sensors: AncillaryControl | Switch = gateway.api.sensors.values(),
|
||||||
|
) -> None:
|
||||||
"""Create DeconzEvent."""
|
"""Create DeconzEvent."""
|
||||||
new_events = []
|
new_events = []
|
||||||
known_events = {event.unique_id for event in gateway.events}
|
known_events = {event.unique_id for event in gateway.events}
|
||||||
@ -74,7 +79,7 @@ async def async_setup_events(gateway) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_unload_events(gateway) -> None:
|
def async_unload_events(gateway: DeconzGateway) -> None:
|
||||||
"""Unload all deCONZ events."""
|
"""Unload all deCONZ events."""
|
||||||
for event in gateway.events:
|
for event in gateway.events:
|
||||||
event.async_will_remove_from_hass()
|
event.async_will_remove_from_hass()
|
||||||
@ -89,18 +94,22 @@ class DeconzEvent(DeconzBase):
|
|||||||
instead of a sensor entity in hass.
|
instead of a sensor entity in hass.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, device, gateway):
|
def __init__(
|
||||||
|
self,
|
||||||
|
device: AncillaryControl | Switch,
|
||||||
|
gateway: DeconzGateway,
|
||||||
|
) -> None:
|
||||||
"""Register callback that will be used for signals."""
|
"""Register callback that will be used for signals."""
|
||||||
super().__init__(device, gateway)
|
super().__init__(device, gateway)
|
||||||
|
|
||||||
self._device.register_callback(self.async_update_callback)
|
self._device.register_callback(self.async_update_callback)
|
||||||
|
|
||||||
self.device_id = None
|
self.device_id: str | None = None
|
||||||
self.event_id = slugify(self._device.name)
|
self.event_id = slugify(self._device.name)
|
||||||
LOGGER.debug("deCONZ event created: %s", self.event_id)
|
LOGGER.debug("deCONZ event created: %s", self.event_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device(self):
|
def device(self) -> AncillaryControl | Switch:
|
||||||
"""Return Event device."""
|
"""Return Event device."""
|
||||||
return self._device
|
return self._device
|
||||||
|
|
||||||
@ -110,7 +119,7 @@ class DeconzEvent(DeconzBase):
|
|||||||
self._device.remove_callback(self.async_update_callback)
|
self._device.remove_callback(self.async_update_callback)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_callback(self):
|
def async_update_callback(self) -> None:
|
||||||
"""Fire the event if reason is that state is updated."""
|
"""Fire the event if reason is that state is updated."""
|
||||||
if (
|
if (
|
||||||
self.gateway.ignore_state_updates
|
self.gateway.ignore_state_updates
|
||||||
@ -154,8 +163,10 @@ class DeconzEvent(DeconzBase):
|
|||||||
class DeconzAlarmEvent(DeconzEvent):
|
class DeconzAlarmEvent(DeconzEvent):
|
||||||
"""Alarm control panel companion event when user interacts with a keypad."""
|
"""Alarm control panel companion event when user interacts with a keypad."""
|
||||||
|
|
||||||
|
_device: AncillaryControl
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_callback(self):
|
def async_update_callback(self) -> None:
|
||||||
"""Fire the event if reason is new action is updated."""
|
"""Fire the event if reason is new action is updated."""
|
||||||
if (
|
if (
|
||||||
self.gateway.ignore_state_updates
|
self.gateway.ignore_state_updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user