mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve device tracker platform in Teslemetry (#145268)
This commit is contained in:
parent
2ef0a8557f
commit
db489a5069
@ -47,19 +47,25 @@ DESCRIPTIONS: tuple[TeslemetryDeviceTrackerEntityDescription, ...] = (
|
||||
TeslemetryDeviceTrackerEntityDescription(
|
||||
key="location",
|
||||
polling_prefix="drive_state",
|
||||
value_listener=lambda x, y: x.listen_Location(y),
|
||||
value_listener=lambda vehicle, callback: vehicle.listen_Location(callback),
|
||||
streaming_firmware="2024.26",
|
||||
),
|
||||
TeslemetryDeviceTrackerEntityDescription(
|
||||
key="route",
|
||||
polling_prefix="drive_state_active_route",
|
||||
value_listener=lambda x, y: x.listen_DestinationLocation(y),
|
||||
name_listener=lambda x, y: x.listen_DestinationName(y),
|
||||
value_listener=lambda vehicle, callback: vehicle.listen_DestinationLocation(
|
||||
callback
|
||||
),
|
||||
name_listener=lambda vehicle, callback: vehicle.listen_DestinationName(
|
||||
callback
|
||||
),
|
||||
streaming_firmware="2024.26",
|
||||
),
|
||||
TeslemetryDeviceTrackerEntityDescription(
|
||||
key="origin",
|
||||
value_listener=lambda x, y: x.listen_OriginLocation(y),
|
||||
value_listener=lambda vehicle, callback: vehicle.listen_OriginLocation(
|
||||
callback
|
||||
),
|
||||
streaming_firmware="2024.26",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
@ -152,7 +158,6 @@ class TeslemetryStreamingDeviceTrackerEntity(
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
if (state := await self.async_get_last_state()) is not None:
|
||||
self._attr_state = state.state
|
||||
self._attr_latitude = state.attributes.get("latitude")
|
||||
self._attr_longitude = state.attributes.get("longitude")
|
||||
self._attr_location_name = state.attributes.get("location_name")
|
||||
@ -170,12 +175,8 @@ class TeslemetryStreamingDeviceTrackerEntity(
|
||||
|
||||
def _location_callback(self, location: TeslaLocation | None) -> None:
|
||||
"""Update the value of the entity."""
|
||||
if location is None:
|
||||
self._attr_available = False
|
||||
else:
|
||||
self._attr_available = True
|
||||
self._attr_latitude = location.latitude
|
||||
self._attr_longitude = location.longitude
|
||||
self._attr_latitude = None if location is None else location.latitude
|
||||
self._attr_longitude = None if location is None else location.longitude
|
||||
self.async_write_ha_state()
|
||||
|
||||
def _name_callback(self, name: str | None) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user