Ensure Tile timestamps are reported as UTC (#110773)

This commit is contained in:
Aaron Bach 2024-02-17 07:43:28 -07:00 committed by GitHub
parent 833c0ee723
commit 258f8bfed0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
) )
from homeassistant.util.dt import as_utc
from . import TileData from . import TileData
from .const import DOMAIN from .const import DOMAIN
@ -145,16 +146,23 @@ 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_extra_state_attributes.update( 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, ATTR_RING_STATE: self._tile.ring_state,
ATTR_LAST_LOST_TIMESTAMP: self._tile.lost_timestamp, ATTR_VOIP_STATE: self._tile.voip_state,
ATTR_LAST_TIMESTAMP: self._tile.last_timestamp, }
ATTR_RING_STATE: self._tile.ring_state, for timestamp_attr in (
ATTR_VOIP_STATE: self._tile.voip_state, (ATTR_LAST_LOST_TIMESTAMP, self._tile.lost_timestamp),
} (ATTR_LAST_TIMESTAMP, self._tile.last_timestamp),
) ):
if not timestamp_attr[1]:
# If the API doesn't return a value for a particular timestamp
# attribute, skip it:
continue
self._attr_extra_state_attributes[timestamp_attr[0]] = as_utc(
timestamp_attr[1]
)
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Handle entity which will be added.""" """Handle entity which will be added."""