mirror of
https://github.com/home-assistant/core.git
synced 2025-09-04 04:11:37 +02:00
Use lifecycle hook instead of storing callback in starline (#150707)
This commit is contained in:
committed by
GitHub
parent
db1707fd72
commit
b222cc5889
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
|
||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .account import StarlineAccount, StarlineDevice
|
from .account import StarlineAccount, StarlineDevice
|
||||||
@@ -24,7 +22,6 @@ class StarlineEntity(Entity):
|
|||||||
self._key = key
|
self._key = key
|
||||||
self._attr_unique_id = f"starline-{key}-{device.device_id}"
|
self._attr_unique_id = f"starline-{key}-{device.device_id}"
|
||||||
self._attr_device_info = account.device_info(device)
|
self._attr_device_info = account.device_info(device)
|
||||||
self._unsubscribe_api: Callable | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -38,11 +35,4 @@ class StarlineEntity(Entity):
|
|||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity about to be added to Home Assistant."""
|
"""Call when entity about to be added to Home Assistant."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self._unsubscribe_api = self._account.api.add_update_listener(self.update)
|
self.async_on_remove(self._account.api.add_update_listener(self.update))
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
|
||||||
"""Call when entity is being removed from Home Assistant."""
|
|
||||||
await super().async_will_remove_from_hass()
|
|
||||||
if self._unsubscribe_api is not None:
|
|
||||||
self._unsubscribe_api()
|
|
||||||
self._unsubscribe_api = None
|
|
||||||
|
Reference in New Issue
Block a user