Unsub dispatcher when removing entity from hass (#33510)

* Unsub dispatcher when removing entity from hass

* Update homeassistant/components/plaato/sensor.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/volvooncall/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Paulus SchoutsenandMartin Hjelmare authored and GitHub committed 2020-04-02 09:25:33 -07:00
1 parent 314bc07cee
commit 4ebbabcdd1
71 files changed
+355 -209

No files matched your search

+1 -7
View File
@@ -13,21 +13,15 @@ class AxisEntityBase(Entity):
def __init__(self, device):
"""Initialize the Axis event."""
self.device = device
self.unsub_dispatcher = []
async def async_added_to_hass(self):
"""Subscribe device events."""
self.unsub_dispatcher.append(
self.async_on_remove(
async_dispatcher_connect(
self.hass, self.device.event_reachable, self.update_callback
)
)
async def async_will_remove_from_hass(self) -> None:
"""Unsubscribe device events when removed."""
for unsub_dispatcher in self.unsub_dispatcher:
unsub_dispatcher()
@property
def available(self):
"""Return True if device is available."""