mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +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(
|
TeslemetryDeviceTrackerEntityDescription(
|
||||||
key="location",
|
key="location",
|
||||||
polling_prefix="drive_state",
|
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",
|
streaming_firmware="2024.26",
|
||||||
),
|
),
|
||||||
TeslemetryDeviceTrackerEntityDescription(
|
TeslemetryDeviceTrackerEntityDescription(
|
||||||
key="route",
|
key="route",
|
||||||
polling_prefix="drive_state_active_route",
|
polling_prefix="drive_state_active_route",
|
||||||
value_listener=lambda x, y: x.listen_DestinationLocation(y),
|
value_listener=lambda vehicle, callback: vehicle.listen_DestinationLocation(
|
||||||
name_listener=lambda x, y: x.listen_DestinationName(y),
|
callback
|
||||||
|
),
|
||||||
|
name_listener=lambda vehicle, callback: vehicle.listen_DestinationName(
|
||||||
|
callback
|
||||||
|
),
|
||||||
streaming_firmware="2024.26",
|
streaming_firmware="2024.26",
|
||||||
),
|
),
|
||||||
TeslemetryDeviceTrackerEntityDescription(
|
TeslemetryDeviceTrackerEntityDescription(
|
||||||
key="origin",
|
key="origin",
|
||||||
value_listener=lambda x, y: x.listen_OriginLocation(y),
|
value_listener=lambda vehicle, callback: vehicle.listen_OriginLocation(
|
||||||
|
callback
|
||||||
|
),
|
||||||
streaming_firmware="2024.26",
|
streaming_firmware="2024.26",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
@ -152,7 +158,6 @@ class TeslemetryStreamingDeviceTrackerEntity(
|
|||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
if (state := await self.async_get_last_state()) is not None:
|
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_latitude = state.attributes.get("latitude")
|
||||||
self._attr_longitude = state.attributes.get("longitude")
|
self._attr_longitude = state.attributes.get("longitude")
|
||||||
self._attr_location_name = state.attributes.get("location_name")
|
self._attr_location_name = state.attributes.get("location_name")
|
||||||
@ -170,12 +175,8 @@ class TeslemetryStreamingDeviceTrackerEntity(
|
|||||||
|
|
||||||
def _location_callback(self, location: TeslaLocation | None) -> None:
|
def _location_callback(self, location: TeslaLocation | None) -> None:
|
||||||
"""Update the value of the entity."""
|
"""Update the value of the entity."""
|
||||||
if location is None:
|
self._attr_latitude = None if location is None else location.latitude
|
||||||
self._attr_available = False
|
self._attr_longitude = None if location is None else location.longitude
|
||||||
else:
|
|
||||||
self._attr_available = True
|
|
||||||
self._attr_latitude = location.latitude
|
|
||||||
self._attr_longitude = location.longitude
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
def _name_callback(self, name: str | None) -> None:
|
def _name_callback(self, name: str | None) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user