From d5a03b4d6a53878e0f3713c274376ba476682507 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Mon, 20 Jul 2020 10:04:57 -0400 Subject: [PATCH] Cleanup async_accept_signal in ZHA (#38009) --- homeassistant/components/zha/binary_sensor.py | 2 +- homeassistant/components/zha/climate.py | 2 +- homeassistant/components/zha/cover.py | 6 +++--- homeassistant/components/zha/device_tracker.py | 2 +- homeassistant/components/zha/entity.py | 11 ++++++----- homeassistant/components/zha/fan.py | 2 +- homeassistant/components/zha/light.py | 6 +++--- homeassistant/components/zha/lock.py | 2 +- homeassistant/components/zha/sensor.py | 4 ++-- homeassistant/components/zha/switch.py | 2 +- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 0ed931e92da..2548060c0fd 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -80,7 +80,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity): """Run when about to be added to hass.""" await super().async_added_to_hass() await self.get_device_class() - await self.async_accept_signal( + self.async_accept_signal( self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state ) diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index 7e2a0e147a7..7ffb727bacc 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -393,7 +393,7 @@ class Thermostat(ZhaEntity, ClimateEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._thrm, SIGNAL_ATTR_UPDATED, self.async_attribute_updated ) diff --git a/homeassistant/components/zha/cover.py b/homeassistant/components/zha/cover.py index 235368080f0..45114c677af 100644 --- a/homeassistant/components/zha/cover.py +++ b/homeassistant/components/zha/cover.py @@ -66,7 +66,7 @@ class ZhaCover(ZhaEntity, CoverEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._cover_channel, SIGNAL_ATTR_UPDATED, self.async_set_position ) @@ -213,10 +213,10 @@ class Shade(ZhaEntity, CoverEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_open_closed ) - await self.async_accept_signal( + self.async_accept_signal( self._level_channel, SIGNAL_SET_LEVEL, self.async_set_level ) diff --git a/homeassistant/components/zha/device_tracker.py b/homeassistant/components/zha/device_tracker.py index 2a53fc3bf3c..824435e6337 100644 --- a/homeassistant/components/zha/device_tracker.py +++ b/homeassistant/components/zha/device_tracker.py @@ -55,7 +55,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity): """Run when about to be added to hass.""" await super().async_added_to_hass() if self._battery_channel: - await self.async_accept_signal( + self.async_accept_signal( self._battery_channel, SIGNAL_ATTR_UPDATED, self.async_battery_percentage_remaining_updated, diff --git a/homeassistant/components/zha/entity.py b/homeassistant/components/zha/entity.py index 2deea13e08b..d583f89c9bc 100644 --- a/homeassistant/components/zha/entity.py +++ b/homeassistant/components/zha/entity.py @@ -114,7 +114,8 @@ class BaseZhaEntity(LogMixin, entity.Entity): unsub() self._unsubs.remove(unsub) - async def async_accept_signal( + @callback + def async_accept_signal( self, channel: ChannelType, signal: str, func: CALLABLE_T, signal_override=False ): """Accept a signal from a channel.""" @@ -162,7 +163,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity): async def async_added_to_hass(self) -> None: """Run when about to be added to hass.""" self.remove_future = asyncio.Future() - await self.async_accept_signal( + self.async_accept_signal( None, f"{SIGNAL_REMOVE}_{self.zha_device.ieee}", self.async_remove, @@ -175,7 +176,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity): if last_state: self.async_restore_last_state(last_state) - await self.async_accept_signal( + self.async_accept_signal( None, f"{self.zha_device.available_signal}_entity", self.async_state_changed, @@ -231,14 +232,14 @@ class ZhaGroupEntity(BaseZhaEntity): async def async_added_to_hass(self) -> None: """Register callbacks.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( None, f"{SIGNAL_REMOVE_GROUP}_0x{self._group_id:04x}", self.async_remove, signal_override=True, ) - await self.async_accept_signal( + self.async_accept_signal( None, f"{SIGNAL_GROUP_MEMBERSHIP_CHANGE}_0x{self._group_id:04x}", self.async_remove, diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index c7a13a4f34f..ac8edd10be5 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -135,7 +135,7 @@ class ZhaFan(BaseFan, ZhaEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._fan_channel, SIGNAL_ATTR_UPDATED, self.async_set_state ) diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 6fefc795460..51b0633ecf2 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -372,18 +372,18 @@ class Light(BaseLight, ZhaEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_state ) if self._level_channel: - await self.async_accept_signal( + self.async_accept_signal( self._level_channel, SIGNAL_SET_LEVEL, self.set_level ) refresh_interval = random.randint(*[x * 60 for x in self._REFRESH_INTERVAL]) self._cancel_refresh_handle = async_track_time_interval( self.hass, self._refresh, timedelta(seconds=refresh_interval) ) - await self.async_accept_signal( + self.async_accept_signal( None, SIGNAL_LIGHT_GROUP_STATE_CHANGED, self._maybe_force_refresh, diff --git a/homeassistant/components/zha/lock.py b/homeassistant/components/zha/lock.py index d70c1e2e7f3..d951e7ada19 100644 --- a/homeassistant/components/zha/lock.py +++ b/homeassistant/components/zha/lock.py @@ -60,7 +60,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity): async def async_added_to_hass(self): """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._doorlock_channel, SIGNAL_ATTR_UPDATED, self.async_set_state ) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 86969c5fe96..38a9f19dce2 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -98,10 +98,10 @@ class Sensor(ZhaEntity): await super().async_added_to_hass() self._device_state_attributes.update(await self.async_state_attr_provider()) - await self.async_accept_signal( + self.async_accept_signal( self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state ) - await self.async_accept_signal( + self.async_accept_signal( self._channel, SIGNAL_STATE_ATTR, self.async_update_state_attribute ) diff --git a/homeassistant/components/zha/switch.py b/homeassistant/components/zha/switch.py index 9a7fc7aa6b0..07c40c7175e 100644 --- a/homeassistant/components/zha/switch.py +++ b/homeassistant/components/zha/switch.py @@ -92,7 +92,7 @@ class Switch(BaseSwitch, ZhaEntity): async def async_added_to_hass(self) -> None: """Run when about to be added to hass.""" await super().async_added_to_hass() - await self.async_accept_signal( + self.async_accept_signal( self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_state )