Clean up left-behind dispatcher handlers when removing RainMachine (#18488)
* Clean up left-behind dispatcher handlers when removing RainMachine * Member commentspull/18535/head
parent
6b2f50b29e
commit
e73b9b9b8f
|
@ -78,13 +78,8 @@ class RainMachineBinarySensor(RainMachineEntity, BinarySensorDevice):
|
|||
"""Update the state."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, SENSOR_UPDATE_TOPIC, update)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
if self._async_unsub_dispatcher_connect:
|
||||
self._async_unsub_dispatcher_connect()
|
||||
self._dispatcher_handlers.append(async_dispatcher_connect(
|
||||
self.hass, SENSOR_UPDATE_TOPIC, update))
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the state."""
|
||||
|
|
|
@ -267,7 +267,7 @@ class RainMachineEntity(Entity):
|
|||
def __init__(self, rainmachine):
|
||||
"""Initialize."""
|
||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
self._async_unsub_dispatcher_connect = None
|
||||
self._dispatcher_handlers = []
|
||||
self._name = None
|
||||
self.rainmachine = rainmachine
|
||||
|
||||
|
@ -295,3 +295,8 @@ class RainMachineEntity(Entity):
|
|||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
for handler in self._dispatcher_handlers:
|
||||
handler()
|
||||
|
|
|
@ -81,13 +81,8 @@ class RainMachineSensor(RainMachineEntity):
|
|||
"""Update the state."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, SENSOR_UPDATE_TOPIC, update)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
if self._async_unsub_dispatcher_connect:
|
||||
self._async_unsub_dispatcher_connect()
|
||||
self._dispatcher_handlers.append(async_dispatcher_connect(
|
||||
self.hass, SENSOR_UPDATE_TOPIC, update))
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the sensor's state."""
|
||||
|
|
|
@ -186,13 +186,8 @@ class RainMachineProgram(RainMachineSwitch):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, PROGRAM_UPDATE_TOPIC, self._program_updated)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
if self._async_unsub_dispatcher_connect:
|
||||
self._async_unsub_dispatcher_connect()
|
||||
self._dispatcher_handlers.append(async_dispatcher_connect(
|
||||
self.hass, PROGRAM_UPDATE_TOPIC, self._program_updated))
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
"""Turn the program off."""
|
||||
|
@ -256,10 +251,10 @@ class RainMachineZone(RainMachineSwitch):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
async_dispatcher_connect(
|
||||
self.hass, PROGRAM_UPDATE_TOPIC, self._program_updated)
|
||||
async_dispatcher_connect(
|
||||
self.hass, ZONE_UPDATE_TOPIC, self._program_updated)
|
||||
self._dispatcher_handlers.append(async_dispatcher_connect(
|
||||
self.hass, PROGRAM_UPDATE_TOPIC, self._program_updated))
|
||||
self._dispatcher_handlers.append(async_dispatcher_connect(
|
||||
self.hass, ZONE_UPDATE_TOPIC, self._program_updated))
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
"""Turn the zone off."""
|
||||
|
|
Loading…
Reference in New Issue