Switch myq to async_on_remove (#34473)
This commit is contained in:
parent
a5af746013
commit
01581ff92e
2 changed files with 6 additions and 12 deletions
|
@ -5,7 +5,6 @@ from homeassistant.components.binary_sensor import (
|
|||
DEVICE_CLASS_CONNECTIVITY,
|
||||
BinarySensorDevice,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
|
@ -95,14 +94,8 @@ class MyQBinarySensorDevice(BinarySensorDevice):
|
|||
"""Return False, updates are controlled via coordinator."""
|
||||
return False
|
||||
|
||||
@callback
|
||||
def _async_consume_update(self):
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._coordinator.async_add_listener(self._async_consume_update)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
self._coordinator.async_remove_listener(self._async_consume_update)
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self.async_write_ha_state)
|
||||
)
|
||||
|
|
|
@ -209,10 +209,11 @@ class MyQDevice(CoverDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._coordinator.async_add_listener(self._async_consume_update)
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self._async_consume_update)
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
self._coordinator.async_remove_listener(self._async_consume_update)
|
||||
if self._scheduled_transition_update:
|
||||
self._scheduled_transition_update()
|
||||
|
|
Loading…
Add table
Reference in a new issue