Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions homeassistant/components/smartthings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -554,8 +549,9 @@ 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_TOTAL_INCREASING

@property
def name(self) -> str:
Expand Down Expand Up @@ -590,10 +586,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