Remove last_reset attribute from dsmr sensors (#54699)

This commit is contained in:
Erik Montnemery 2021-08-16 18:35:50 +02:00 committed by GitHub
parent 61ab2b0c60
commit 35389a6d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 34 deletions

View File

@ -5,7 +5,10 @@ import logging
from dsmr_parser import obis_references from dsmr_parser import obis_references
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
@ -13,7 +16,6 @@ from homeassistant.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
) )
from homeassistant.util import dt
from .models import DSMRSensorEntityDescription from .models import DSMRSensorEntityDescription
@ -67,32 +69,28 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
name="Energy Consumption (tarif 1)", name="Energy Consumption (tarif 1)",
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
force_update=True, force_update=True,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_USED_TARIFF_2, key=obis_references.ELECTRICITY_USED_TARIFF_2,
name="Energy Consumption (tarif 2)", name="Energy Consumption (tarif 2)",
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_DELIVERED_TARIFF_1, key=obis_references.ELECTRICITY_DELIVERED_TARIFF_1,
name="Energy Production (tarif 1)", name="Energy Production (tarif 1)",
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_DELIVERED_TARIFF_2, key=obis_references.ELECTRICITY_DELIVERED_TARIFF_2,
name="Energy Production (tarif 2)", name="Energy Production (tarif 2)",
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE, key=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE,
@ -229,8 +227,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"5L"}, dsmr_versions={"5L"},
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL, key=obis_references.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL,
@ -238,8 +235,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"5L"}, dsmr_versions={"5L"},
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.ELECTRICITY_IMPORTED_TOTAL, key=obis_references.ELECTRICITY_IMPORTED_TOTAL,
@ -247,8 +243,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
dsmr_versions={"2.2", "4", "5", "5B"}, dsmr_versions={"2.2", "4", "5", "5B"},
force_update=True, force_update=True,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.HOURLY_GAS_METER_READING, key=obis_references.HOURLY_GAS_METER_READING,
@ -258,8 +253,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
force_update=True, force_update=True,
icon="mdi:fire", icon="mdi:fire",
device_class=DEVICE_CLASS_GAS, device_class=DEVICE_CLASS_GAS,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.BELGIUM_HOURLY_GAS_METER_READING, key=obis_references.BELGIUM_HOURLY_GAS_METER_READING,
@ -269,8 +263,7 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
force_update=True, force_update=True,
icon="mdi:fire", icon="mdi:fire",
device_class=DEVICE_CLASS_GAS, device_class=DEVICE_CLASS_GAS,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
DSMRSensorEntityDescription( DSMRSensorEntityDescription(
key=obis_references.GAS_METER_READING, key=obis_references.GAS_METER_READING,
@ -280,7 +273,6 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
force_update=True, force_update=True,
icon="mdi:fire", icon="mdi:fire",
device_class=DEVICE_CLASS_GAS, device_class=DEVICE_CLASS_GAS,
last_reset=dt.utc_from_timestamp(0), state_class=STATE_CLASS_TOTAL_INCREASING,
state_class=STATE_CLASS_MEASUREMENT,
), ),
) )

View File

@ -18,6 +18,7 @@ from homeassistant.components.sensor import (
ATTR_STATE_CLASS, ATTR_STATE_CLASS,
DOMAIN as SENSOR_DOMAIN, DOMAIN as SENSOR_DOMAIN,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
@ -167,8 +168,10 @@ async def test_default_setup(hass, dsmr_connection_fixture):
assert gas_consumption.state == "745.695" assert gas_consumption.state == "745.695"
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire" assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None assert gas_consumption.attributes.get(ATTR_LAST_RESET) is None
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert (
gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
)
assert ( assert (
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
) )
@ -267,8 +270,10 @@ async def test_v4_meter(hass, dsmr_connection_fixture):
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire" assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None assert gas_consumption.attributes.get(ATTR_LAST_RESET) is None
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert (
gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
)
assert ( assert (
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
) )
@ -337,8 +342,10 @@ async def test_v5_meter(hass, dsmr_connection_fixture):
assert gas_consumption.state == "745.695" assert gas_consumption.state == "745.695"
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire" assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None assert gas_consumption.attributes.get(ATTR_LAST_RESET) is None
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert (
gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
)
assert ( assert (
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
) )
@ -403,8 +410,8 @@ async def test_luxembourg_meter(hass, dsmr_connection_fixture):
assert power_tariff.state == "123.456" assert power_tariff.state == "123.456"
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
assert power_tariff.attributes.get(ATTR_ICON) is None assert power_tariff.attributes.get(ATTR_ICON) is None
assert power_tariff.attributes.get(ATTR_LAST_RESET) is not None assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
assert power_tariff.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert power_tariff.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
assert ( assert (
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
) )
@ -418,8 +425,10 @@ async def test_luxembourg_meter(hass, dsmr_connection_fixture):
assert gas_consumption.state == "745.695" assert gas_consumption.state == "745.695"
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_GAS
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire" assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None assert gas_consumption.attributes.get(ATTR_LAST_RESET) is None
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert (
gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
)
assert ( assert (
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
) )
@ -488,8 +497,10 @@ async def test_belgian_meter(hass, dsmr_connection_fixture):
assert gas_consumption.state == "745.695" assert gas_consumption.state == "745.695"
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is DEVICE_CLASS_GAS assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is DEVICE_CLASS_GAS
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire" assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None assert gas_consumption.attributes.get(ATTR_LAST_RESET) is None
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT assert (
gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_TOTAL_INCREASING
)
assert ( assert (
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
) )