Compile statistics for power sensors (#52299)

pull/52298/head^2
Erik Montnemery 2021-06-29 14:48:08 +02:00 committed by GitHub
parent e1797ea670
commit 6131ed09f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -19,8 +19,11 @@ from homeassistant.components.sensor import (
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
POWER_KILO_WATT,
POWER_WATT,
)
from homeassistant.core import HomeAssistant, State
import homeassistant.util.dt as dt_util
@ -33,16 +36,21 @@ DEVICE_CLASS_STATISTICS = {
DEVICE_CLASS_BATTERY: {"mean", "min", "max"},
DEVICE_CLASS_ENERGY: {"sum"},
DEVICE_CLASS_HUMIDITY: {"mean", "min", "max"},
DEVICE_CLASS_MONETARY: {"sum"},
DEVICE_CLASS_POWER: {"mean", "min", "max"},
DEVICE_CLASS_PRESSURE: {"mean", "min", "max"},
DEVICE_CLASS_TEMPERATURE: {"mean", "min", "max"},
DEVICE_CLASS_MONETARY: {"sum"},
}
UNIT_CONVERSIONS = {
DEVICE_CLASS_ENERGY: {
ENERGY_KILO_WATT_HOUR: lambda x: x,
ENERGY_WATT_HOUR: lambda x: x / 1000,
}
},
DEVICE_CLASS_POWER: {
POWER_WATT: lambda x: x,
POWER_KILO_WATT: lambda x: x * 1000,
},
}
WARN_UNSUPPORTED_UNIT = set()