Use new DeviceClass and StateClass enums in efergy (#61377)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/61420/head
epenet 2021-12-10 08:59:24 +01:00 committed by GitHub
parent 347d1fc6bd
commit 393107c855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 25 deletions

View File

@ -10,19 +10,16 @@ import voluptuous as vol
from homeassistant.components.efergy import EfergyEntity from homeassistant.components.efergy import EfergyEntity
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_CURRENCY, CONF_CURRENCY,
CONF_MONITORED_VARIABLES, CONF_MONITORED_VARIABLES,
CONF_TYPE, CONF_TYPE,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_MONETARY,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
POWER_WATT, POWER_WATT,
) )
@ -40,39 +37,39 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="instant_readings", key="instant_readings",
name="Power Usage", name="Power Usage",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="energy_day", key="energy_day",
name="Daily Consumption", name="Daily Consumption",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="energy_week", key="energy_week",
name="Weekly Consumption", name="Weekly Consumption",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="energy_month", key="energy_month",
name="Monthly Consumption", name="Monthly Consumption",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SensorEntityDescription( SensorEntityDescription(
key="energy_year", key="energy_year",
name="Yearly Consumption", name="Yearly Consumption",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
@ -83,36 +80,36 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="cost_day", key="cost_day",
name="Daily Energy Cost", name="Daily Energy Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="cost_week", key="cost_week",
name="Weekly Energy Cost", name="Weekly Energy Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="cost_month", key="cost_month",
name="Monthly Energy Cost", name="Monthly Energy Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SensorEntityDescription( SensorEntityDescription(
key="cost_year", key="cost_year",
name="Yearly Energy Cost", name="Yearly Energy Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key=CONF_CURRENT_VALUES, key=CONF_CURRENT_VALUES,
name="Power Usage", name="Power Usage",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )