Add route sensors to Tessie (#106530)

* keys may be missing at startup

* Add route sensors and tracker location

* Fix keys and add translation

* Allow a sensor to have no value

* Move attribute to sensor

* Remove state attribute string
pull/98438/head
Brett Adams 2024-01-14 17:08:54 +10:00 committed by GitHub
parent 07810926d0
commit 8b4d99f7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from homeassistant.const import (
UnitOfPressure, UnitOfPressure,
UnitOfSpeed, UnitOfSpeed,
UnitOfTemperature, UnitOfTemperature,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -181,6 +182,36 @@ DESCRIPTIONS: tuple[TessieSensorEntityDescription, ...] = (
suggested_display_precision=1, suggested_display_precision=1,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
TessieSensorEntityDescription(
key="drive_state_active_route_traffic_minutes_delay",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
device_class=SensorDeviceClass.DURATION,
),
TessieSensorEntityDescription(
key="drive_state_active_route_energy_at_arrival",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
),
TessieSensorEntityDescription(
key="drive_state_active_route_miles_to_arrival",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfLength.MILES,
device_class=SensorDeviceClass.DISTANCE,
),
TessieSensorEntityDescription(
key="drive_state_active_route_minutes_to_arrival",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
device_class=SensorDeviceClass.DURATION,
),
TessieSensorEntityDescription(
key="drive_state_active_route_destination",
icon="mdi:map-marker",
entity_category=EntityCategory.DIAGNOSTIC,
),
) )
@ -194,7 +225,6 @@ async def async_setup_entry(
TessieSensorEntity(vehicle.state_coordinator, description) TessieSensorEntity(vehicle.state_coordinator, description)
for vehicle in data for vehicle in data
for description in DESCRIPTIONS for description in DESCRIPTIONS
if description.key in vehicle.state_coordinator.data
) )
@ -215,4 +245,4 @@ class TessieSensorEntity(TessieEntity, SensorEntity):
@property @property
def native_value(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.entity_description.value_fn(self._value) return self.entity_description.value_fn(self.get())

View File

@ -129,6 +129,21 @@
}, },
"climate_state_passenger_temp_setting": { "climate_state_passenger_temp_setting": {
"name": "Passenger temperature setting" "name": "Passenger temperature setting"
},
"active_route_traffic_minutes_delay": {
"name": "Traffic delay"
},
"active_route_energy_at_arrival": {
"name": "State of charge at arrival"
},
"active_route_miles_to_arrival": {
"name": "Distance to arrival"
},
"active_route_time_to_arrival": {
"name": "Time to arrival"
},
"drive_state_active_route_destination": {
"name": "Destination"
} }
}, },
"cover": { "cover": {

View File

@ -127,6 +127,10 @@
"active_route_latitude": 30.2226265, "active_route_latitude": 30.2226265,
"active_route_longitude": -97.6236871, "active_route_longitude": -97.6236871,
"active_route_traffic_minutes_delay": 0, "active_route_traffic_minutes_delay": 0,
"active_route_destination": "Giga Texas",
"active_route_energy_at_arrival": 65,
"active_route_miles_to_arrival": 46.707353,
"active_route_minutes_to_arrival": 59.2,
"gps_as_of": 1701129612, "gps_as_of": 1701129612,
"heading": 185, "heading": 185,
"latitude": -30.222626, "latitude": -30.222626,