Add Wh/km unit for energy distance (#145243)

This commit is contained in:
Franck Nijhof 2025-05-20 13:16:27 +02:00 committed by GitHub
parent a3c0b83dee
commit fb0cb7cad6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 2 deletions

View File

@ -176,7 +176,7 @@ class NumberDeviceClass(StrEnum):
Use this device class for sensors measuring energy by distance, for example the amount Use this device class for sensors measuring energy by distance, for example the amount
of electric energy consumed by an electric car. of electric energy consumed by an electric car.
Unit of measurement: `kWh/100km`, `mi/kWh`, `km/kWh` Unit of measurement: `kWh/100km`, `Wh/km`, `mi/kWh`, `km/kWh`
""" """
ENERGY_STORAGE = "energy_storage" ENERGY_STORAGE = "energy_storage"

View File

@ -205,7 +205,7 @@ class SensorDeviceClass(StrEnum):
Use this device class for sensors measuring energy by distance, for example the amount Use this device class for sensors measuring energy by distance, for example the amount
of electric energy consumed by an electric car. of electric energy consumed by an electric car.
Unit of measurement: `kWh/100km`, `mi/kWh`, `km/kWh` Unit of measurement: `kWh/100km`, `Wh/km`, `mi/kWh`, `km/kWh`
""" """
ENERGY_STORAGE = "energy_storage" ENERGY_STORAGE = "energy_storage"

View File

@ -647,6 +647,7 @@ class UnitOfEnergyDistance(StrEnum):
"""Energy Distance units.""" """Energy Distance units."""
KILO_WATT_HOUR_PER_100_KM = "kWh/100km" KILO_WATT_HOUR_PER_100_KM = "kWh/100km"
WATT_HOUR_PER_KM = "Wh/km"
MILES_PER_KILO_WATT_HOUR = "mi/kWh" MILES_PER_KILO_WATT_HOUR = "mi/kWh"
KM_PER_KILO_WATT_HOUR = "km/kWh" KM_PER_KILO_WATT_HOUR = "km/kWh"

View File

@ -313,6 +313,7 @@ class EnergyDistanceConverter(BaseUnitConverter):
UNIT_CLASS = "energy_distance" UNIT_CLASS = "energy_distance"
_UNIT_CONVERSION: dict[str | None, float] = { _UNIT_CONVERSION: dict[str | None, float] = {
UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM: 1, UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM: 1,
UnitOfEnergyDistance.WATT_HOUR_PER_KM: 10,
UnitOfEnergyDistance.MILES_PER_KILO_WATT_HOUR: 100 * _KM_TO_M / _MILE_TO_M, UnitOfEnergyDistance.MILES_PER_KILO_WATT_HOUR: 100 * _KM_TO_M / _MILE_TO_M,
UnitOfEnergyDistance.KM_PER_KILO_WATT_HOUR: 100, UnitOfEnergyDistance.KM_PER_KILO_WATT_HOUR: 100,
} }

View File

@ -509,6 +509,18 @@ _CONVERTED_VALUE: dict[
6.213712, 6.213712,
UnitOfEnergyDistance.MILES_PER_KILO_WATT_HOUR, UnitOfEnergyDistance.MILES_PER_KILO_WATT_HOUR,
), ),
(
10,
UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM,
100,
UnitOfEnergyDistance.WATT_HOUR_PER_KM,
),
(
15,
UnitOfEnergyDistance.WATT_HOUR_PER_KM,
1.5,
UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM,
),
( (
25, 25,
UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM, UnitOfEnergyDistance.KILO_WATT_HOUR_PER_100_KM,