mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add number + sensor device class energy storage (#88310)
* Add number + sensor device class energy storage * Format code * Update device automations
This commit is contained in:
parent
c444e1c860
commit
69ce6980d6
@ -127,6 +127,15 @@ class NumberDeviceClass(StrEnum):
|
|||||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
ENERGY_STORAGE = "energy_storage"
|
||||||
|
"""Stored energy.
|
||||||
|
|
||||||
|
Use this device class for sensors measuring stored energy, for example the amount
|
||||||
|
of electric energy currently stored in a battery or the capacity of a battery.
|
||||||
|
|
||||||
|
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||||
|
"""
|
||||||
|
|
||||||
FREQUENCY = "frequency"
|
FREQUENCY = "frequency"
|
||||||
"""Frequency.
|
"""Frequency.
|
||||||
|
|
||||||
@ -365,6 +374,7 @@ DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
|
|||||||
NumberDeviceClass.DATA_SIZE: set(UnitOfInformation),
|
NumberDeviceClass.DATA_SIZE: set(UnitOfInformation),
|
||||||
NumberDeviceClass.DISTANCE: set(UnitOfLength),
|
NumberDeviceClass.DISTANCE: set(UnitOfLength),
|
||||||
NumberDeviceClass.ENERGY: set(UnitOfEnergy),
|
NumberDeviceClass.ENERGY: set(UnitOfEnergy),
|
||||||
|
NumberDeviceClass.ENERGY_STORAGE: set(UnitOfEnergy),
|
||||||
NumberDeviceClass.FREQUENCY: set(UnitOfFrequency),
|
NumberDeviceClass.FREQUENCY: set(UnitOfFrequency),
|
||||||
NumberDeviceClass.GAS: {
|
NumberDeviceClass.GAS: {
|
||||||
UnitOfVolume.CENTUM_CUBIC_FEET,
|
UnitOfVolume.CENTUM_CUBIC_FEET,
|
||||||
|
@ -160,6 +160,17 @@ class SensorDeviceClass(StrEnum):
|
|||||||
ENERGY = "energy"
|
ENERGY = "energy"
|
||||||
"""Energy.
|
"""Energy.
|
||||||
|
|
||||||
|
Use this device class for sensors measuring energy consumption, for example
|
||||||
|
electric energy consumption.
|
||||||
|
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||||
|
"""
|
||||||
|
|
||||||
|
ENERGY_STORAGE = "energy_storage"
|
||||||
|
"""Stored energy.
|
||||||
|
|
||||||
|
Use this device class for sensors measuring stored energy, for example the amount
|
||||||
|
of electric energy currently stored in a battery or the capacity of a battery.
|
||||||
|
|
||||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -429,6 +440,7 @@ UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] =
|
|||||||
SensorDeviceClass.DATA_SIZE: InformationConverter,
|
SensorDeviceClass.DATA_SIZE: InformationConverter,
|
||||||
SensorDeviceClass.DISTANCE: DistanceConverter,
|
SensorDeviceClass.DISTANCE: DistanceConverter,
|
||||||
SensorDeviceClass.ENERGY: EnergyConverter,
|
SensorDeviceClass.ENERGY: EnergyConverter,
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: EnergyConverter,
|
||||||
SensorDeviceClass.GAS: VolumeConverter,
|
SensorDeviceClass.GAS: VolumeConverter,
|
||||||
SensorDeviceClass.POWER: PowerConverter,
|
SensorDeviceClass.POWER: PowerConverter,
|
||||||
SensorDeviceClass.POWER_FACTOR: UnitlessRatioConverter,
|
SensorDeviceClass.POWER_FACTOR: UnitlessRatioConverter,
|
||||||
@ -462,6 +474,7 @@ DEVICE_CLASS_UNITS: dict[SensorDeviceClass, set[type[StrEnum] | str | None]] = {
|
|||||||
UnitOfTime.SECONDS,
|
UnitOfTime.SECONDS,
|
||||||
},
|
},
|
||||||
SensorDeviceClass.ENERGY: set(UnitOfEnergy),
|
SensorDeviceClass.ENERGY: set(UnitOfEnergy),
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: set(UnitOfEnergy),
|
||||||
SensorDeviceClass.FREQUENCY: set(UnitOfFrequency),
|
SensorDeviceClass.FREQUENCY: set(UnitOfFrequency),
|
||||||
SensorDeviceClass.GAS: {
|
SensorDeviceClass.GAS: {
|
||||||
UnitOfVolume.CENTUM_CUBIC_FEET,
|
UnitOfVolume.CENTUM_CUBIC_FEET,
|
||||||
@ -526,6 +539,7 @@ DEVICE_CLASS_STATE_CLASSES: dict[SensorDeviceClass, set[SensorStateClass]] = {
|
|||||||
SensorStateClass.TOTAL,
|
SensorStateClass.TOTAL,
|
||||||
SensorStateClass.TOTAL_INCREASING,
|
SensorStateClass.TOTAL_INCREASING,
|
||||||
},
|
},
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: {SensorStateClass.MEASUREMENT},
|
||||||
SensorDeviceClass.ENUM: set(),
|
SensorDeviceClass.ENUM: set(),
|
||||||
SensorDeviceClass.FREQUENCY: {SensorStateClass.MEASUREMENT},
|
SensorDeviceClass.FREQUENCY: {SensorStateClass.MEASUREMENT},
|
||||||
SensorDeviceClass.GAS: {SensorStateClass.TOTAL, SensorStateClass.TOTAL_INCREASING},
|
SensorDeviceClass.GAS: {SensorStateClass.TOTAL, SensorStateClass.TOTAL_INCREASING},
|
||||||
|
@ -89,6 +89,7 @@ ENTITY_CONDITIONS = {
|
|||||||
SensorDeviceClass.DISTANCE: [{CONF_TYPE: CONF_IS_DISTANCE}],
|
SensorDeviceClass.DISTANCE: [{CONF_TYPE: CONF_IS_DISTANCE}],
|
||||||
SensorDeviceClass.DURATION: [{CONF_TYPE: CONF_IS_DURATION}],
|
SensorDeviceClass.DURATION: [{CONF_TYPE: CONF_IS_DURATION}],
|
||||||
SensorDeviceClass.ENERGY: [{CONF_TYPE: CONF_IS_ENERGY}],
|
SensorDeviceClass.ENERGY: [{CONF_TYPE: CONF_IS_ENERGY}],
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: [{CONF_TYPE: CONF_IS_ENERGY}],
|
||||||
SensorDeviceClass.FREQUENCY: [{CONF_TYPE: CONF_IS_FREQUENCY}],
|
SensorDeviceClass.FREQUENCY: [{CONF_TYPE: CONF_IS_FREQUENCY}],
|
||||||
SensorDeviceClass.GAS: [{CONF_TYPE: CONF_IS_GAS}],
|
SensorDeviceClass.GAS: [{CONF_TYPE: CONF_IS_GAS}],
|
||||||
SensorDeviceClass.HUMIDITY: [{CONF_TYPE: CONF_IS_HUMIDITY}],
|
SensorDeviceClass.HUMIDITY: [{CONF_TYPE: CONF_IS_HUMIDITY}],
|
||||||
|
@ -88,6 +88,7 @@ ENTITY_TRIGGERS = {
|
|||||||
SensorDeviceClass.DISTANCE: [{CONF_TYPE: CONF_DISTANCE}],
|
SensorDeviceClass.DISTANCE: [{CONF_TYPE: CONF_DISTANCE}],
|
||||||
SensorDeviceClass.DURATION: [{CONF_TYPE: CONF_DURATION}],
|
SensorDeviceClass.DURATION: [{CONF_TYPE: CONF_DURATION}],
|
||||||
SensorDeviceClass.ENERGY: [{CONF_TYPE: CONF_ENERGY}],
|
SensorDeviceClass.ENERGY: [{CONF_TYPE: CONF_ENERGY}],
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: [{CONF_TYPE: CONF_ENERGY}],
|
||||||
SensorDeviceClass.FREQUENCY: [{CONF_TYPE: CONF_FREQUENCY}],
|
SensorDeviceClass.FREQUENCY: [{CONF_TYPE: CONF_FREQUENCY}],
|
||||||
SensorDeviceClass.GAS: [{CONF_TYPE: CONF_GAS}],
|
SensorDeviceClass.GAS: [{CONF_TYPE: CONF_GAS}],
|
||||||
SensorDeviceClass.HUMIDITY: [{CONF_TYPE: CONF_HUMIDITY}],
|
SensorDeviceClass.HUMIDITY: [{CONF_TYPE: CONF_HUMIDITY}],
|
||||||
|
@ -51,12 +51,14 @@ def test_matches_device_classes(device_class: SensorDeviceClass) -> None:
|
|||||||
SensorDeviceClass.BATTERY: "CONF_IS_BATTERY_LEVEL",
|
SensorDeviceClass.BATTERY: "CONF_IS_BATTERY_LEVEL",
|
||||||
SensorDeviceClass.CO: "CONF_IS_CO",
|
SensorDeviceClass.CO: "CONF_IS_CO",
|
||||||
SensorDeviceClass.CO2: "CONF_IS_CO2",
|
SensorDeviceClass.CO2: "CONF_IS_CO2",
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: "CONF_IS_ENERGY",
|
||||||
}.get(device_class, f"CONF_IS_{device_class.value.upper()}")
|
}.get(device_class, f"CONF_IS_{device_class.value.upper()}")
|
||||||
assert hasattr(device_condition, constant_name), f"Missing constant {constant_name}"
|
assert hasattr(device_condition, constant_name), f"Missing constant {constant_name}"
|
||||||
|
|
||||||
# Ensure it has correct value
|
# Ensure it has correct value
|
||||||
constant_value = {
|
constant_value = {
|
||||||
SensorDeviceClass.BATTERY: "is_battery_level",
|
SensorDeviceClass.BATTERY: "is_battery_level",
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: "is_energy",
|
||||||
}.get(device_class, f"is_{device_class.value}")
|
}.get(device_class, f"is_{device_class.value}")
|
||||||
assert getattr(device_condition, constant_name) == constant_value
|
assert getattr(device_condition, constant_name) == constant_value
|
||||||
|
|
||||||
|
@ -55,12 +55,14 @@ def test_matches_device_classes(device_class: SensorDeviceClass) -> None:
|
|||||||
SensorDeviceClass.BATTERY: "CONF_BATTERY_LEVEL",
|
SensorDeviceClass.BATTERY: "CONF_BATTERY_LEVEL",
|
||||||
SensorDeviceClass.CO: "CONF_CO",
|
SensorDeviceClass.CO: "CONF_CO",
|
||||||
SensorDeviceClass.CO2: "CONF_CO2",
|
SensorDeviceClass.CO2: "CONF_CO2",
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: "CONF_ENERGY",
|
||||||
}.get(device_class, f"CONF_{device_class.value.upper()}")
|
}.get(device_class, f"CONF_{device_class.value.upper()}")
|
||||||
assert hasattr(device_trigger, constant_name), f"Missing constant {constant_name}"
|
assert hasattr(device_trigger, constant_name), f"Missing constant {constant_name}"
|
||||||
|
|
||||||
# Ensure it has correct value
|
# Ensure it has correct value
|
||||||
constant_value = {
|
constant_value = {
|
||||||
SensorDeviceClass.BATTERY: "battery_level",
|
SensorDeviceClass.BATTERY: "battery_level",
|
||||||
|
SensorDeviceClass.ENERGY_STORAGE: "energy",
|
||||||
}.get(device_class, device_class.value)
|
}.get(device_class, device_class.value)
|
||||||
assert getattr(device_trigger, constant_name) == constant_value
|
assert getattr(device_trigger, constant_name) == constant_value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user