Switch myq to async_on_remove (#34473)

This commit is contained in:
J. Nick Koston 2020-04-20 13:31:50 -05:00 committed by GitHub
parent a5af746013
commit 01581ff92e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

View File

@ -5,7 +5,6 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_CONNECTIVITY,
BinarySensorDevice, BinarySensorDevice,
) )
from homeassistant.core import callback
from .const import ( from .const import (
DOMAIN, DOMAIN,
@ -95,14 +94,8 @@ class MyQBinarySensorDevice(BinarySensorDevice):
"""Return False, updates are controlled via coordinator.""" """Return False, updates are controlled via coordinator."""
return False return False
@callback
def _async_consume_update(self):
self.async_write_ha_state()
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Subscribe to updates.""" """Subscribe to updates."""
self._coordinator.async_add_listener(self._async_consume_update) self.async_on_remove(
self._coordinator.async_add_listener(self.async_write_ha_state)
async def async_will_remove_from_hass(self): )
"""Undo subscription."""
self._coordinator.async_remove_listener(self._async_consume_update)

View File

@ -209,10 +209,11 @@ class MyQDevice(CoverDevice):
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Subscribe to updates.""" """Subscribe to updates."""
self.async_on_remove(
self._coordinator.async_add_listener(self._async_consume_update) self._coordinator.async_add_listener(self._async_consume_update)
)
async def async_will_remove_from_hass(self): async def async_will_remove_from_hass(self):
"""Undo subscription.""" """Undo subscription."""
self._coordinator.async_remove_listener(self._async_consume_update)
if self._scheduled_transition_update: if self._scheduled_transition_update:
self._scheduled_transition_update() self._scheduled_transition_update()