Remove last_reset
attribute and set state class to total_increasing
for smartthings energy sensors (#54824)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
e98d50f6d1
commit
a6ac55390a
1 changed files with 8 additions and 19 deletions
|
@ -3,12 +3,15 @@ from __future__ import annotations
|
|||
|
||||
from collections import namedtuple
|
||||
from collections.abc import Sequence
|
||||
from datetime import datetime
|
||||
|
||||
from pysmartthings import Attribute, Capability
|
||||
from pysmartthings.device import DeviceEntity
|
||||
|
||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
AREA_SQUARE_METERS,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
|
@ -33,7 +36,6 @@ from homeassistant.const import (
|
|||
TEMP_FAHRENHEIT,
|
||||
VOLUME_CUBIC_METERS,
|
||||
)
|
||||
from homeassistant.util.dt import utc_from_timestamp
|
||||
|
||||
from . import SmartThingsEntity
|
||||
from .const import DATA_BROKERS, DOMAIN
|
||||
|
@ -133,7 +135,7 @@ CAPABILITY_TO_SENSORS = {
|
|||
"Energy Meter",
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
)
|
||||
],
|
||||
Capability.equivalent_carbon_dioxide_measurement: [
|
||||
|
@ -507,13 +509,6 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity):
|
|||
unit = self._device.status.attributes[self._attribute].unit
|
||||
return UNITS.get(unit, unit) if unit else self._default_unit
|
||||
|
||||
@property
|
||||
def last_reset(self) -> datetime | None:
|
||||
"""Return the time when the sensor was last reset, if any."""
|
||||
if self._attribute == Attribute.energy:
|
||||
return utc_from_timestamp(0)
|
||||
return None
|
||||
|
||||
|
||||
class SmartThingsThreeAxisSensor(SmartThingsEntity, SensorEntity):
|
||||
"""Define a SmartThings Three Axis Sensor."""
|
||||
|
@ -554,8 +549,9 @@ class SmartThingsPowerConsumptionSensor(SmartThingsEntity, SensorEntity):
|
|||
"""Init the class."""
|
||||
super().__init__(device)
|
||||
self.report_name = report_name
|
||||
# This is an exception for STATE_CLASS_MEASUREMENT per @balloob
|
||||
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
if self.report_name != "power":
|
||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
@ -590,10 +586,3 @@ class SmartThingsPowerConsumptionSensor(SmartThingsEntity, SensorEntity):
|
|||
if self.report_name == "power":
|
||||
return POWER_WATT
|
||||
return ENERGY_KILO_WATT_HOUR
|
||||
|
||||
@property
|
||||
def last_reset(self) -> datetime | None:
|
||||
"""Return the time when the sensor was last reset, if any."""
|
||||
if self.report_name != "power":
|
||||
return utc_from_timestamp(0)
|
||||
return None
|
||||
|
|
Loading…
Add table
Reference in a new issue