1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-13 01:27:57 +01:00

Use state attribute enums in legacy device_tracker (#175854)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
epenet
2026-07-07 13:37:46 +02:00
committed by GitHub
parent 8683140348
commit 65edb1cfb2
@@ -77,7 +77,9 @@ from .const import (
LOGGER,
PLATFORM_TYPE_LEGACY,
SCAN_INTERVAL,
DeviceTrackerEntityStateAttribute,
SourceType,
TrackerEntityStateAttribute,
)
_LOGGER = logging.getLogger(__name__)
@@ -840,12 +842,14 @@ class Device(RestoreEntity):
@override
def state_attributes(self) -> dict[str, StateType]:
"""Return the device state attributes."""
attributes: dict[str, StateType] = {ATTR_SOURCE_TYPE: self.source_type}
attributes: dict[str, StateType] = {
DeviceTrackerEntityStateAttribute.SOURCE_TYPE: self.source_type
}
if self.gps is not None:
attributes[ATTR_LATITUDE] = self.gps[0]
attributes[ATTR_LONGITUDE] = self.gps[1]
attributes[ATTR_GPS_ACCURACY] = self.gps_accuracy
attributes[TrackerEntityStateAttribute.LATITUDE] = self.gps[0]
attributes[TrackerEntityStateAttribute.LONGITUDE] = self.gps[1]
attributes[TrackerEntityStateAttribute.GPS_ACCURACY] = self.gps_accuracy
if self.battery is not None:
attributes[ATTR_BATTERY] = self.battery
@@ -952,17 +956,17 @@ class Device(RestoreEntity):
self.last_seen = dt_util.utcnow()
for attribute, var in (
(ATTR_SOURCE_TYPE, "source_type"),
(ATTR_GPS_ACCURACY, "gps_accuracy"),
(DeviceTrackerEntityStateAttribute.SOURCE_TYPE, "source_type"),
(TrackerEntityStateAttribute.GPS_ACCURACY, "gps_accuracy"),
(ATTR_BATTERY, "battery"),
):
if attribute in state.attributes:
setattr(self, var, state.attributes[attribute])
if ATTR_LONGITUDE in state.attributes:
if TrackerEntityStateAttribute.LONGITUDE in state.attributes:
self.gps = (
state.attributes[ATTR_LATITUDE],
state.attributes[ATTR_LONGITUDE],
state.attributes[TrackerEntityStateAttribute.LATITUDE],
state.attributes[TrackerEntityStateAttribute.LONGITUDE],
)