Use device/state class enums in DSMR (#60791)

This commit is contained in:
Franck Nijhof 2021-12-02 04:15:17 +01:00 committed by GitHub
parent 8e715064cc
commit 58fdcfb6b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 85 deletions

View file

@ -5,17 +5,7 @@ import logging
from dsmr_parser import obis_references
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.const import (
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE,
)
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from .models import DSMRSensorEntityDescription
@ -50,16 +40,16 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
DSMRSensorEntityDescription(
key=obis_references.CURRENT_ELECTRICITY_USAGE,
name="Power Consumption",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
force_update=True,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.CURRENT_ELECTRICITY_DELIVERY,
name="Power Production",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
force_update=True,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_ACTIVE_TARIFF,
@ -71,75 +61,75 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
key=obis_references.ELECTRICITY_USED_TARIFF_1,
name="Energy Consumption (tarif 1)",
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
device_class=DEVICE_CLASS_ENERGY,
device_class=SensorDeviceClass.ENERGY,
force_update=True,
state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_USED_TARIFF_2,
name="Energy Consumption (tarif 2)",
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_DELIVERED_TARIFF_1,
name="Energy Production (tarif 1)",
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_DELIVERED_TARIFF_2,
name="Energy Production (tarif 2)",
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE,
name="Power Consumption Phase L1",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE,
name="Power Consumption Phase L2",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE,
name="Power Consumption Phase L3",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE,
name="Power Production Phase L1",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE,
name="Power Production Phase L2",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE,
name="Power Production Phase L3",
device_class=DEVICE_CLASS_POWER,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.SHORT_POWER_FAILURE_COUNT,
@ -197,84 +187,84 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_VOLTAGE_L1,
name="Voltage Phase L1",
device_class=DEVICE_CLASS_VOLTAGE,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_VOLTAGE_L2,
name="Voltage Phase L2",
device_class=DEVICE_CLASS_VOLTAGE,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_VOLTAGE_L3,
name="Voltage Phase L3",
device_class=DEVICE_CLASS_VOLTAGE,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_CURRENT_L1,
name="Current Phase L1",
device_class=DEVICE_CLASS_CURRENT,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_CURRENT_L2,
name="Current Phase L2",
device_class=DEVICE_CLASS_CURRENT,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_CURRENT_L3,
name="Current Phase L3",
device_class=DEVICE_CLASS_CURRENT,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key=obis_references.LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL,
name="Energy Consumption (total)",
dsmr_versions={"5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL,
name="Energy Production (total)",
dsmr_versions={"5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.SWEDEN_ELECTRICITY_USED_TARIFF_GLOBAL,
name="Energy Consumption (total)",
dsmr_versions={"5S"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.SWEDEN_ELECTRICITY_DELIVERED_TARIFF_GLOBAL,
name="Energy Production (total)",
dsmr_versions={"5S"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_IMPORTED_TOTAL,
name="Energy Consumption (total)",
dsmr_versions={"2.2", "4", "5", "5B"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.HOURLY_GAS_METER_READING,
@ -282,8 +272,8 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"4", "5", "5L"},
is_gas=True,
force_update=True,
device_class=DEVICE_CLASS_GAS,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.BELGIUM_HOURLY_GAS_METER_READING,
@ -291,8 +281,8 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"5B"},
is_gas=True,
force_update=True,
device_class=DEVICE_CLASS_GAS,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING,
),
DSMRSensorEntityDescription(
key=obis_references.GAS_METER_READING,
@ -300,7 +290,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"2.2"},
is_gas=True,
force_update=True,
device_class=DEVICE_CLASS_GAS,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING,
),
)