fix: Add unit_of_measurement to time_to_full_charge MQTT sensor
The time_to_full_charge sensor was being published with device_class 'duration' but without a unit_of_measurement, causing Home Assistant to log an error.
This adds 'h' (hours) as the unit_of_measurement to comply with Home Assistant's requirements for duration sensors. The Tesla API returns time_to_full_charge in hours as a decimal value.
Fixes Home Assistant error: Entity is using native unit of measurement 'None' which is not a valid unit for the device class ('duration')
Problem
The time_to_full_charge sensor was being published with device_class: "duration" but without a unit_of_measurement, causing Home Assistant to log the following error:
Entity sensor.xxx_time_to_full_charge is using native unit of measurement 'None' which is not a valid unit for the device class ('duration'); expected one of ['h', 'μs', 's', 'min', 'd', 'ms']
Solution
Added unit_of_measurement: "h" to the MQTT auto-discovery configuration for the time_to_full_charge sensor.
Rationale
- Tesla API returns
time_to_full_chargein hours (as a decimal value) - TeslaLogger passes this value through without conversion
- Home Assistant requires a valid unit for sensors with
device_class: "duration"
Testing
- Verified the fix matches the pattern of other duration sensors in the codebase
- Confirmed the Tesla API documentation specifies hours as the unit
Files Changed
-
TeslaLogger/MQTTAutoDiscovery.cs- Added unit configuration on line 107
@Adminius could you please test it?
@Adminius could you please test it?
approved!