From 258f8bfed0e41ef392d9ace2acf0a0844ea6cc35 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sat, 17 Feb 2024 07:43:28 -0700 Subject: [PATCH] Ensure Tile timestamps are reported as UTC (#110773) --- .../components/tile/device_tracker.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/tile/device_tracker.py b/homeassistant/components/tile/device_tracker.py index 81d3fb00c6e..df166d17db5 100644 --- a/homeassistant/components/tile/device_tracker.py +++ b/homeassistant/components/tile/device_tracker.py @@ -20,6 +20,7 @@ from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, ) +from homeassistant.util.dt import as_utc from . import TileData from .const import DOMAIN @@ -145,16 +146,23 @@ class TileDeviceTracker(CoordinatorEntity[DataUpdateCoordinator[None]], TrackerE @callback def _update_from_latest_data(self) -> None: """Update the entity from the latest data.""" - self._attr_extra_state_attributes.update( - { - ATTR_ALTITUDE: self._tile.altitude, - ATTR_IS_LOST: self._tile.lost, - ATTR_LAST_LOST_TIMESTAMP: self._tile.lost_timestamp, - ATTR_LAST_TIMESTAMP: self._tile.last_timestamp, - ATTR_RING_STATE: self._tile.ring_state, - ATTR_VOIP_STATE: self._tile.voip_state, - } - ) + self._attr_extra_state_attributes = { + ATTR_ALTITUDE: self._tile.altitude, + ATTR_IS_LOST: self._tile.lost, + ATTR_RING_STATE: self._tile.ring_state, + ATTR_VOIP_STATE: self._tile.voip_state, + } + for timestamp_attr in ( + (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: """Handle entity which will be added."""