Fix "home" route in Tesla Fleet & Teslemetry (#129546)

* translate Home to home

* refactor for mypy

* Fix home state

* Revert key change

* Add testing
This commit is contained in:
Brett Adams 2024-10-31 17:56:03 +10:00 committed by GitHub
parent 39093fc2bc
commit 3656bcf752
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 16 additions and 4 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_HOME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
@ -84,4 +85,7 @@ class TeslaFleetDeviceTrackerRouteEntity(TeslaFleetDeviceTrackerEntity):
@property
def location_name(self) -> str | None:
"""Return a location name for the current location of the device."""
return self.get("drive_state_active_route_destination")
location = self.get("drive_state_active_route_destination")
if location == "Home":
return STATE_HOME
return location

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.const import STATE_HOME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -80,4 +81,7 @@ class TeslemetryDeviceTrackerRouteEntity(TeslemetryDeviceTrackerEntity):
@property
def location_name(self) -> str | None:
"""Return a location name for the current location of the device."""
return self.get("drive_state_active_route_destination")
location = self.get("drive_state_active_route_destination")
if location == "Home":
return STATE_HOME
return location

View File

@ -112,6 +112,7 @@
"wiper_blade_heater": false
},
"drive_state": {
"active_route_destination": "Home",
"active_route_latitude": 30.2226265,
"active_route_longitude": -97.6236871,
"active_route_miles_to_arrival": 0.039491,

View File

@ -96,6 +96,6 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'not_home',
'state': 'home',
})
# ---

View File

@ -269,6 +269,7 @@
'climate_state_timestamp': 1705707520649,
'climate_state_wiper_blade_heater': False,
'color': None,
'drive_state_active_route_destination': 'Home',
'drive_state_active_route_latitude': '**REDACTED**',
'drive_state_active_route_longitude': '**REDACTED**',
'drive_state_active_route_miles_to_arrival': 0.039491,

View File

@ -112,6 +112,7 @@
"wiper_blade_heater": false
},
"drive_state": {
"active_route_destination": "Home",
"active_route_latitude": 30.2226265,
"active_route_longitude": -97.6236871,
"active_route_miles_to_arrival": 0.039491,

View File

@ -96,6 +96,6 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'not_home',
'state': 'home',
})
# ---

View File

@ -270,6 +270,7 @@
'climate_state_timestamp': 1705707520649,
'climate_state_wiper_blade_heater': False,
'color': None,
'drive_state_active_route_destination': 'Home',
'drive_state_active_route_latitude': '**REDACTED**',
'drive_state_active_route_longitude': '**REDACTED**',
'drive_state_active_route_miles_to_arrival': 0.039491,