From dc7e08642ddd52b87ea4eb5cf1d2fd6036ece1d4 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 18 Aug 2021 14:47:02 +0200 Subject: [PATCH 1/2] Remove last_reset attribute from smartthings energy sensors --- .../components/smartthings/sensor.py | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index a8e6c0472e93a..06e9d1a16bc39 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -3,12 +3,15 @@ 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 @@ 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 @@ "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 @@ def native_unit_of_measurement(self): 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,11 @@ def __init__( """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_MEASUREMENT + else: + self._attr_state_class = STATE_CLASS_TOTAL_INCREASING @property def name(self) -> str: @@ -590,10 +588,3 @@ def native_unit_of_measurement(self): 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 From 5022a9254202340812c5ce3eb40782997235b8ed Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 18 Aug 2021 15:28:46 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Franck Nijhof --- homeassistant/components/smartthings/sensor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index 06e9d1a16bc39..7c682486f0411 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -550,9 +550,7 @@ def __init__( super().__init__(device) self.report_name = report_name self._attr_state_class = STATE_CLASS_MEASUREMENT - if self.report_name == "power": - self._attr_state_class = STATE_CLASS_MEASUREMENT - else: + if self.report_name != "power": self._attr_state_class = STATE_CLASS_TOTAL_INCREASING @property