Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions homeassistant/components/binary_sensor/rainmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,8 @@ def update(self):
"""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."""
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/rainmachine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -280,3 +280,8 @@ def device_state_attributes(self) -> dict:
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()
9 changes: 2 additions & 7 deletions homeassistant/components/sensor/rainmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,8 @@ def update(self):
"""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."""
Expand Down
17 changes: 6 additions & 11 deletions homeassistant/components/switch/rainmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,8 @@ def zones(self) -> list:

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."""
Expand Down Expand Up @@ -256,10 +251,10 @@ def is_on(self) -> bool:

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."""
Expand Down