diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index 3ac4cf4e53b..9cc4ea9c434 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -39,6 +39,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, + ENERGY_MEGA_WATT_HOUR, ENERGY_WATT_HOUR, POWER_KILO_WATT, POWER_WATT, @@ -95,6 +96,7 @@ UNIT_CONVERSIONS: dict[str, dict[str, Callable]] = { # Convert energy to kWh DEVICE_CLASS_ENERGY: { ENERGY_KILO_WATT_HOUR: lambda x: x, + ENERGY_MEGA_WATT_HOUR: lambda x: x * 1000, ENERGY_WATT_HOUR: lambda x: x / 1000, }, # Convert power W diff --git a/homeassistant/const.py b/homeassistant/const.py index 1c3029a9d34..6e9f8ee97d7 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -419,6 +419,7 @@ POWER_VOLT_AMPERE: Final = "VA" # Energy units ENERGY_WATT_HOUR: Final = "Wh" ENERGY_KILO_WATT_HOUR: Final = "kWh" +ENERGY_MEGA_WATT_HOUR: Final = "MWh" # Electric_current units ELECTRIC_CURRENT_MILLIAMPERE: Final = "mA"