1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add support for MW/GW/TW and GWh/TWh (#130089)

This commit is contained in:
Jakob Schlyter
2024-11-08 22:12:16 +01:00
committed by GitHub
parent 742eca5927
commit cd11f01ace
8 changed files with 41 additions and 12 deletions

View File

@@ -222,6 +222,8 @@ class EnergyConverter(BaseUnitConverter):
UnitOfEnergy.WATT_HOUR: 1e3,
UnitOfEnergy.KILO_WATT_HOUR: 1,
UnitOfEnergy.MEGA_WATT_HOUR: 1 / 1e3,
UnitOfEnergy.GIGA_WATT_HOUR: 1 / 1e6,
UnitOfEnergy.TERA_WATT_HOUR: 1 / 1e9,
UnitOfEnergy.CALORIE: _WH_TO_CAL * 1e3,
UnitOfEnergy.KILO_CALORIE: _WH_TO_CAL,
UnitOfEnergy.MEGA_CALORIE: _WH_TO_CAL / 1e3,
@@ -292,10 +294,16 @@ class PowerConverter(BaseUnitConverter):
_UNIT_CONVERSION: dict[str | None, float] = {
UnitOfPower.WATT: 1,
UnitOfPower.KILO_WATT: 1 / 1000,
UnitOfPower.MEGA_WATT: 1 / 1e6,
UnitOfPower.GIGA_WATT: 1 / 1e9,
UnitOfPower.TERA_WATT: 1 / 1e12,
}
VALID_UNITS = {
UnitOfPower.WATT,
UnitOfPower.KILO_WATT,
UnitOfPower.MEGA_WATT,
UnitOfPower.GIGA_WATT,
UnitOfPower.TERA_WATT,
}