Skip to content

Commit

Permalink
Introduce base entity for Tile (#134109)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Dec 27, 2024
1 parent 263e0ac commit 375af6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
18 changes: 2 additions & 16 deletions homeassistant/components/tile/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_USERNAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import as_utc

from . import TileCoordinator, TileData
from .const import DOMAIN
from .entity import TileEntity

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,10 +42,9 @@ async def async_setup_entry(
)


class TileDeviceTracker(CoordinatorEntity[TileCoordinator], TrackerEntity):
class TileDeviceTracker(TileEntity, TrackerEntity):
"""Representation of a network infrastructure device."""

_attr_has_entity_name = True
_attr_name = None
_attr_translation_key = "tile"

Expand All @@ -55,19 +53,7 @@ def __init__(self, entry: ConfigEntry, coordinator: TileCoordinator) -> None:
super().__init__(coordinator)

self._attr_extra_state_attributes = {}
self._tile = coordinator.tile
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
def _handle_coordinator_update(self) -> None:
Expand Down
26 changes: 26 additions & 0 deletions homeassistant/components/tile/entity.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 375af6c

Please sign in to comment.