mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use shorthand attributes in tile device tracker (#126735)
This commit is contained in:
parent
83ebd601a9
commit
1d49c5056c
@ -98,35 +98,11 @@ class TileDeviceTracker(CoordinatorEntity[DataUpdateCoordinator[None]], TrackerE
|
|||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
return super().available and not self._tile.dead
|
return super().available and not self._tile.dead
|
||||||
|
|
||||||
@property
|
|
||||||
def location_accuracy(self) -> int:
|
|
||||||
"""Return the location accuracy of the device.
|
|
||||||
|
|
||||||
Value in meters.
|
|
||||||
"""
|
|
||||||
if not self._tile.accuracy:
|
|
||||||
return super().location_accuracy
|
|
||||||
return int(self._tile.accuracy)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return device info."""
|
"""Return device info."""
|
||||||
return DeviceInfo(identifiers={(DOMAIN, self._tile.uuid)}, name=self._tile.name)
|
return DeviceInfo(identifiers={(DOMAIN, self._tile.uuid)}, name=self._tile.name)
|
||||||
|
|
||||||
@property
|
|
||||||
def latitude(self) -> float | None:
|
|
||||||
"""Return latitude value of the device."""
|
|
||||||
if not self._tile.latitude:
|
|
||||||
return None
|
|
||||||
return self._tile.latitude
|
|
||||||
|
|
||||||
@property
|
|
||||||
def longitude(self) -> float | None:
|
|
||||||
"""Return longitude value of the device."""
|
|
||||||
if not self._tile.longitude:
|
|
||||||
return None
|
|
||||||
return self._tile.longitude
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Respond to a DataUpdateCoordinator update."""
|
"""Respond to a DataUpdateCoordinator update."""
|
||||||
@ -136,6 +112,14 @@ class TileDeviceTracker(CoordinatorEntity[DataUpdateCoordinator[None]], TrackerE
|
|||||||
@callback
|
@callback
|
||||||
def _update_from_latest_data(self) -> None:
|
def _update_from_latest_data(self) -> None:
|
||||||
"""Update the entity from the latest data."""
|
"""Update the entity from the latest data."""
|
||||||
|
self._attr_longitude = (
|
||||||
|
None if not self._tile.longitude else self._tile.longitude
|
||||||
|
)
|
||||||
|
self._attr_latitude = None if not self._tile.latitude else self._tile.latitude
|
||||||
|
self._attr_location_accuracy = (
|
||||||
|
0 if not self._tile.accuracy else int(self._tile.accuracy)
|
||||||
|
)
|
||||||
|
|
||||||
self._attr_extra_state_attributes = {
|
self._attr_extra_state_attributes = {
|
||||||
ATTR_ALTITUDE: self._tile.altitude,
|
ATTR_ALTITUDE: self._tile.altitude,
|
||||||
ATTR_IS_LOST: self._tile.lost,
|
ATTR_IS_LOST: self._tile.lost,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user