Cleanup async_accept_signal in ZHA (#38009)
This commit is contained in:
parent
2a975db9cf
commit
d5a03b4d6a
10 changed files with 20 additions and 19 deletions
|
@ -80,7 +80,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
await self.get_device_class()
|
await self.get_device_class()
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,7 @@ class Thermostat(ZhaEntity, ClimateEntity):
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
self._thrm, SIGNAL_ATTR_UPDATED, self.async_attribute_updated
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ZhaCover(ZhaEntity, CoverEntity):
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
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):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
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
|
self._level_channel, SIGNAL_SET_LEVEL, self.async_set_level
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
if self._battery_channel:
|
if self._battery_channel:
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
self._battery_channel,
|
self._battery_channel,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
self.async_battery_percentage_remaining_updated,
|
self.async_battery_percentage_remaining_updated,
|
||||||
|
|
|
@ -114,7 +114,8 @@ class BaseZhaEntity(LogMixin, entity.Entity):
|
||||||
unsub()
|
unsub()
|
||||||
self._unsubs.remove(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
|
self, channel: ChannelType, signal: str, func: CALLABLE_T, signal_override=False
|
||||||
):
|
):
|
||||||
"""Accept a signal from a channel."""
|
"""Accept a signal from a channel."""
|
||||||
|
@ -162,7 +163,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
self.remove_future = asyncio.Future()
|
self.remove_future = asyncio.Future()
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
None,
|
None,
|
||||||
f"{SIGNAL_REMOVE}_{self.zha_device.ieee}",
|
f"{SIGNAL_REMOVE}_{self.zha_device.ieee}",
|
||||||
self.async_remove,
|
self.async_remove,
|
||||||
|
@ -175,7 +176,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
||||||
if last_state:
|
if last_state:
|
||||||
self.async_restore_last_state(last_state)
|
self.async_restore_last_state(last_state)
|
||||||
|
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
None,
|
None,
|
||||||
f"{self.zha_device.available_signal}_entity",
|
f"{self.zha_device.available_signal}_entity",
|
||||||
self.async_state_changed,
|
self.async_state_changed,
|
||||||
|
@ -231,14 +232,14 @@ class ZhaGroupEntity(BaseZhaEntity):
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
None,
|
None,
|
||||||
f"{SIGNAL_REMOVE_GROUP}_0x{self._group_id:04x}",
|
f"{SIGNAL_REMOVE_GROUP}_0x{self._group_id:04x}",
|
||||||
self.async_remove,
|
self.async_remove,
|
||||||
signal_override=True,
|
signal_override=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
None,
|
None,
|
||||||
f"{SIGNAL_GROUP_MEMBERSHIP_CHANGE}_0x{self._group_id:04x}",
|
f"{SIGNAL_GROUP_MEMBERSHIP_CHANGE}_0x{self._group_id:04x}",
|
||||||
self.async_remove,
|
self.async_remove,
|
||||||
|
|
|
@ -135,7 +135,7 @@ class ZhaFan(BaseFan, ZhaEntity):
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
self._fan_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -372,18 +372,18 @@ class Light(BaseLight, ZhaEntity):
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
)
|
)
|
||||||
if self._level_channel:
|
if self._level_channel:
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
self._level_channel, SIGNAL_SET_LEVEL, self.set_level
|
self._level_channel, SIGNAL_SET_LEVEL, self.set_level
|
||||||
)
|
)
|
||||||
refresh_interval = random.randint(*[x * 60 for x in self._REFRESH_INTERVAL])
|
refresh_interval = random.randint(*[x * 60 for x in self._REFRESH_INTERVAL])
|
||||||
self._cancel_refresh_handle = async_track_time_interval(
|
self._cancel_refresh_handle = async_track_time_interval(
|
||||||
self.hass, self._refresh, timedelta(seconds=refresh_interval)
|
self.hass, self._refresh, timedelta(seconds=refresh_interval)
|
||||||
)
|
)
|
||||||
await self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
None,
|
None,
|
||||||
SIGNAL_LIGHT_GROUP_STATE_CHANGED,
|
SIGNAL_LIGHT_GROUP_STATE_CHANGED,
|
||||||
self._maybe_force_refresh,
|
self._maybe_force_refresh,
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity):
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
self._doorlock_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -98,10 +98,10 @@ class Sensor(ZhaEntity):
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self._device_state_attributes.update(await self.async_state_attr_provider())
|
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
|
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
|
self._channel, SIGNAL_STATE_ATTR, self.async_update_state_attribute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ class Switch(BaseSwitch, ZhaEntity):
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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
|
self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue