Add typing of deconz_event (#67497)

This commit is contained in:
Robert Svensson 2022-03-14 17:40:58 +01:00 committed by GitHub
parent 1bb0f52814
commit 4506d45345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
"""Representation of a deCONZ remote or keypad."""
from __future__ import annotations
from pydeconz.sensor import (
ANCILLARY_CONTROL_EMERGENCY,
ANCILLARY_CONTROL_FIRE,
@ -23,6 +25,7 @@ from homeassistant.util import slugify
from .const import CONF_ANGLE, CONF_GESTURE, LOGGER
from .deconz_device import DeconzBase
from .gateway import DeconzGateway
CONF_DECONZ_EVENT = "deconz_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."""
@callback
def async_add_sensor(sensors=gateway.api.sensors.values()):
def async_add_sensor(
sensors: AncillaryControl | Switch = gateway.api.sensors.values(),
) -> None:
"""Create DeconzEvent."""
new_events = []
known_events = {event.unique_id for event in gateway.events}
@ -74,7 +79,7 @@ async def async_setup_events(gateway) -> None:
@callback
def async_unload_events(gateway) -> None:
def async_unload_events(gateway: DeconzGateway) -> None:
"""Unload all deCONZ events."""
for event in gateway.events:
event.async_will_remove_from_hass()
@ -89,18 +94,22 @@ class DeconzEvent(DeconzBase):
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."""
super().__init__(device, gateway)
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)
LOGGER.debug("deCONZ event created: %s", self.event_id)
@property
def device(self):
def device(self) -> AncillaryControl | Switch:
"""Return Event device."""
return self._device
@ -110,7 +119,7 @@ class DeconzEvent(DeconzBase):
self._device.remove_callback(self.async_update_callback)
@callback
def async_update_callback(self):
def async_update_callback(self) -> None:
"""Fire the event if reason is that state is updated."""
if (
self.gateway.ignore_state_updates
@ -154,8 +163,10 @@ class DeconzEvent(DeconzBase):
class DeconzAlarmEvent(DeconzEvent):
"""Alarm control panel companion event when user interacts with a keypad."""
_device: AncillaryControl
@callback
def async_update_callback(self):
def async_update_callback(self) -> None:
"""Fire the event if reason is new action is updated."""
if (
self.gateway.ignore_state_updates