Introduce base entity for Tile (#134109)
parent
263e0acd3a
commit
375af6cb1c
|
@ -8,13 +8,12 @@ from homeassistant.components.device_tracker import TrackerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_USERNAME
|
from homeassistant.const import CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
from homeassistant.util.dt import as_utc
|
from homeassistant.util.dt import as_utc
|
||||||
|
|
||||||
from . import TileCoordinator, TileData
|
from . import TileCoordinator, TileData
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import TileEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -43,10 +42,9 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TileDeviceTracker(CoordinatorEntity[TileCoordinator], TrackerEntity):
|
class TileDeviceTracker(TileEntity, TrackerEntity):
|
||||||
"""Representation of a network infrastructure device."""
|
"""Representation of a network infrastructure device."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
_attr_translation_key = "tile"
|
_attr_translation_key = "tile"
|
||||||
|
|
||||||
|
@ -55,19 +53,7 @@ class TileDeviceTracker(CoordinatorEntity[TileCoordinator], TrackerEntity):
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self._attr_extra_state_attributes = {}
|
self._attr_extra_state_attributes = {}
|
||||||
self._tile = coordinator.tile
|
|
||||||
self._attr_unique_id = f"{entry.data[CONF_USERNAME]}_{self._tile.uuid}"
|
self._attr_unique_id = f"{entry.data[CONF_USERNAME]}_{self._tile.uuid}"
|
||||||
self._entry = entry
|
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return if entity is available."""
|
|
||||||
return super().available and not self._tile.dead
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device info."""
|
|
||||||
return DeviceInfo(identifiers={(DOMAIN, self._tile.uuid)}, name=self._tile.name)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
"""Define a base Tile entity."""
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import TileCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class TileEntity(CoordinatorEntity[TileCoordinator]):
|
||||||
|
"""Define a base Tile entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(self, coordinator: TileCoordinator) -> None:
|
||||||
|
"""Initialize."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self._tile = coordinator.tile
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self._tile.uuid)}, name=self._tile.name
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return if entity is available."""
|
||||||
|
return super().available and not self._tile.dead
|
Loading…
Reference in New Issue