mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Add Mega Joule as valid unit of energy (#86055)
* Add Mega joule * Reorder valid energy types Alphabetical * Add Mega Joule * Add Mega Joule as valid energy unit * Add Mega Joule * Add Mega Joule as a Unit of Measurement to Energy * Update tests * Update tests * Update number docstring Co-authored-by: Roving Ronin <108674933+Roving-Ronin@users.noreply.github.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
f182e314e5
commit
0ccab19d2c
@ -43,6 +43,7 @@ SUPPORTED_STATE_CLASSES = {
|
||||
VALID_ENERGY_UNITS: set[str] = {
|
||||
UnitOfEnergy.GIGA_JOULE,
|
||||
UnitOfEnergy.KILO_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_JOULE,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR,
|
||||
UnitOfEnergy.WATT_HOUR,
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ ENERGY_USAGE_UNITS = {
|
||||
sensor.SensorDeviceClass.ENERGY: (
|
||||
UnitOfEnergy.GIGA_JOULE,
|
||||
UnitOfEnergy.KILO_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_JOULE,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR,
|
||||
UnitOfEnergy.WATT_HOUR,
|
||||
)
|
||||
@ -40,6 +41,7 @@ GAS_USAGE_UNITS = {
|
||||
sensor.SensorDeviceClass.ENERGY: (
|
||||
UnitOfEnergy.GIGA_JOULE,
|
||||
UnitOfEnergy.KILO_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_JOULE,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR,
|
||||
UnitOfEnergy.WATT_HOUR,
|
||||
),
|
||||
|
@ -122,7 +122,7 @@ class NumberDeviceClass(StrEnum):
|
||||
ENERGY = "energy"
|
||||
"""Energy.
|
||||
|
||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `GJ`
|
||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||
"""
|
||||
|
||||
FREQUENCY = "frequency"
|
||||
|
@ -159,7 +159,7 @@ class SensorDeviceClass(StrEnum):
|
||||
ENERGY = "energy"
|
||||
"""Energy.
|
||||
|
||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `GJ`
|
||||
Unit of measurement: `Wh`, `kWh`, `MWh`, `MJ`, `GJ`
|
||||
"""
|
||||
|
||||
FREQUENCY = "frequency"
|
||||
|
@ -517,6 +517,7 @@ class UnitOfEnergy(StrEnum):
|
||||
|
||||
GIGA_JOULE = "GJ"
|
||||
KILO_WATT_HOUR = "kWh"
|
||||
MEGA_JOULE = "MJ"
|
||||
MEGA_WATT_HOUR = "MWh"
|
||||
WATT_HOUR = "Wh"
|
||||
|
||||
|
@ -176,12 +176,14 @@ class EnergyConverter(BaseUnitConverter):
|
||||
UnitOfEnergy.WATT_HOUR: 1 * 1000,
|
||||
UnitOfEnergy.KILO_WATT_HOUR: 1,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR: 1 / 1000,
|
||||
UnitOfEnergy.MEGA_JOULE: 3.6,
|
||||
UnitOfEnergy.GIGA_JOULE: 3.6 / 1000,
|
||||
}
|
||||
VALID_UNITS = {
|
||||
UnitOfEnergy.WATT_HOUR,
|
||||
UnitOfEnergy.KILO_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_JOULE,
|
||||
UnitOfEnergy.GIGA_JOULE,
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,9 @@ async def test_validation_device_consumption_entity_unexpected_unit(
|
||||
{
|
||||
"type": "entity_unexpected_unit_energy",
|
||||
"affected_entities": {("sensor.unexpected_unit", "beers")},
|
||||
"translation_placeholders": {"energy_units": "GJ, kWh, MWh, Wh"},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh"
|
||||
},
|
||||
}
|
||||
]
|
||||
],
|
||||
@ -306,7 +308,9 @@ async def test_validation_solar(hass, mock_energy_manager, mock_get_metadata):
|
||||
{
|
||||
"type": "entity_unexpected_unit_energy",
|
||||
"affected_entities": {("sensor.solar_production", "beers")},
|
||||
"translation_placeholders": {"energy_units": "GJ, kWh, MWh, Wh"},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh"
|
||||
},
|
||||
}
|
||||
]
|
||||
],
|
||||
@ -355,7 +359,9 @@ async def test_validation_battery(hass, mock_energy_manager, mock_get_metadata):
|
||||
("sensor.battery_import", "beers"),
|
||||
("sensor.battery_export", "beers"),
|
||||
},
|
||||
"translation_placeholders": {"energy_units": "GJ, kWh, MWh, Wh"},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh"
|
||||
},
|
||||
},
|
||||
]
|
||||
],
|
||||
@ -424,7 +430,9 @@ async def test_validation_grid(
|
||||
("sensor.grid_consumption_1", "beers"),
|
||||
("sensor.grid_production_1", "beers"),
|
||||
},
|
||||
"translation_placeholders": {"energy_units": "GJ, kWh, MWh, Wh"},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh"
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "statistics_not_defined",
|
||||
@ -511,7 +519,9 @@ async def test_validation_grid_external_cost_compensation(
|
||||
("sensor.grid_consumption_1", "beers"),
|
||||
("sensor.grid_production_1", "beers"),
|
||||
},
|
||||
"translation_placeholders": {"energy_units": "GJ, kWh, MWh, Wh"},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh"
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "statistics_not_defined",
|
||||
@ -678,7 +688,7 @@ async def test_validation_grid_auto_cost_entity_errors(
|
||||
"type": "entity_unexpected_unit_energy_price",
|
||||
"affected_entities": {("sensor.grid_price_1", "$/Ws")},
|
||||
"translation_placeholders": {
|
||||
"price_units": "EUR/GJ, EUR/kWh, EUR/MWh, EUR/Wh"
|
||||
"price_units": "EUR/GJ, EUR/kWh, EUR/MJ, EUR/MWh, EUR/Wh"
|
||||
},
|
||||
},
|
||||
),
|
||||
@ -822,7 +832,7 @@ async def test_validation_gas(
|
||||
"type": "entity_unexpected_unit_gas",
|
||||
"affected_entities": {("sensor.gas_consumption_1", "beers")},
|
||||
"translation_placeholders": {
|
||||
"energy_units": "GJ, kWh, MWh, Wh",
|
||||
"energy_units": "GJ, kWh, MJ, MWh, Wh",
|
||||
"gas_units": "CCF, ft³, m³",
|
||||
},
|
||||
},
|
||||
@ -852,7 +862,7 @@ async def test_validation_gas(
|
||||
"affected_entities": {("sensor.gas_price_2", "EUR/invalid")},
|
||||
"translation_placeholders": {
|
||||
"price_units": (
|
||||
"EUR/GJ, EUR/kWh, EUR/MWh, EUR/Wh, EUR/CCF, EUR/ft³, EUR/m³"
|
||||
"EUR/GJ, EUR/kWh, EUR/MJ, EUR/MWh, EUR/Wh, EUR/CCF, EUR/ft³, EUR/m³"
|
||||
)
|
||||
},
|
||||
},
|
||||
|
@ -208,6 +208,8 @@ _CONVERTED_VALUE: dict[
|
||||
(10, UnitOfEnergy.MEGA_WATT_HOUR, 10000, UnitOfEnergy.KILO_WATT_HOUR),
|
||||
(10, UnitOfEnergy.GIGA_JOULE, 10000 / 3.6, UnitOfEnergy.KILO_WATT_HOUR),
|
||||
(10, UnitOfEnergy.GIGA_JOULE, 10 / 3.6, UnitOfEnergy.MEGA_WATT_HOUR),
|
||||
(10, UnitOfEnergy.MEGA_JOULE, 10 / 3.6, UnitOfEnergy.KILO_WATT_HOUR),
|
||||
(10, UnitOfEnergy.MEGA_JOULE, 0.010 / 3.6, UnitOfEnergy.MEGA_WATT_HOUR),
|
||||
],
|
||||
InformationConverter: [
|
||||
(8e3, UnitOfInformation.BITS, 8, UnitOfInformation.KILOBITS),
|
||||
|
Loading…
x
Reference in New Issue
Block a user