Remove last_reset attribute and set state class to total_increasing for rainforest energy sensors (#54810)

This commit is contained in:
Erik Montnemery 2021-08-18 13:44:08 +02:00 committed by GitHub
parent 3c5ba1fcc3
commit d9bfb8fc58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import timedelta
import logging import logging
from eagle200_reader import EagleReader from eagle200_reader import EagleReader
@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
) )
from homeassistant.const import ( from homeassistant.const import (
@ -22,7 +23,7 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle, dt from homeassistant.util import Throttle
CONF_CLOUD_ID = "cloud_id" CONF_CLOUD_ID = "cloud_id"
CONF_INSTALL_CODE = "install_code" CONF_INSTALL_CODE = "install_code"
@ -41,7 +42,6 @@ class SensorType:
unit_of_measurement: str unit_of_measurement: str
device_class: str | None = None device_class: str | None = None
state_class: str | None = None state_class: str | None = None
last_reset: datetime | None = None
SENSORS = { SENSORS = {
@ -54,15 +54,13 @@ SENSORS = {
name="Eagle-200 Total Meter Energy Delivered", name="Eagle-200 Total Meter Energy Delivered",
unit_of_measurement=ENERGY_KILO_WATT_HOUR, unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_TOTAL_INCREASING,
last_reset=dt.utc_from_timestamp(0),
), ),
"summation_received": SensorType( "summation_received": SensorType(
name="Eagle-200 Total Meter Energy Received", name="Eagle-200 Total Meter Energy Received",
unit_of_measurement=ENERGY_KILO_WATT_HOUR, unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_TOTAL_INCREASING,
last_reset=dt.utc_from_timestamp(0),
), ),
"summation_total": SensorType( "summation_total": SensorType(
name="Eagle-200 Net Meter Energy (Delivered minus Received)", name="Eagle-200 Net Meter Energy (Delivered minus Received)",
@ -134,7 +132,6 @@ class EagleSensor(SensorEntity):
self._attr_native_unit_of_measurement = sensor_info.unit_of_measurement self._attr_native_unit_of_measurement = sensor_info.unit_of_measurement
self._attr_device_class = sensor_info.device_class self._attr_device_class = sensor_info.device_class
self._attr_state_class = sensor_info.state_class self._attr_state_class = sensor_info.state_class
self._attr_last_reset = sensor_info.last_reset
def update(self): def update(self):
"""Get the energy information from the Rainforest Eagle.""" """Get the energy information from the Rainforest Eagle."""