From bb9053e93de6d4d957832d7724a255abf8b99997 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 19 Oct 2021 20:08:44 +0200 Subject: [PATCH] Add MWh as an energy unit (#58034) --- homeassistant/components/sensor/recorder.py | 2 ++ homeassistant/const.py | 1 + 2 files changed, 3 insertions(+) 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"