1
1
"""Sensor platform for the Sensus Analytics Integration."""
2
2
3
- from datetime import datetime
3
+ from datetime import datetime , timedelta
4
4
5
5
from homeassistant .components .sensor import SensorDeviceClass , SensorEntity , SensorStateClass
6
6
from homeassistant .config_entries import ConfigEntry
@@ -118,6 +118,11 @@ def __init__(self, coordinator, entry):
118
118
self ._attr_device_class = SensorDeviceClass .WATER
119
119
self ._attr_state_class = SensorStateClass .TOTAL
120
120
121
+ @property
122
+ def last_reset (self ):
123
+ """Return the last reset time for the daily usage sensor."""
124
+ return dt_util .start_of_local_day ()
125
+
121
126
@property
122
127
def native_value (self ):
123
128
"""Return the state of the sensor."""
@@ -244,6 +249,11 @@ def __init__(self, coordinator, entry):
244
249
self ._attr_device_class = SensorDeviceClass .WATER
245
250
self ._attr_state_class = SensorStateClass .TOTAL_INCREASING
246
251
252
+ @property
253
+ def last_reset (self ):
254
+ """Return the last reset time for the meter odometer sensor."""
255
+ return None # Odometer typically does not reset
256
+
247
257
@property
248
258
def native_value (self ):
249
259
"""Return the state of the sensor."""
@@ -263,6 +273,13 @@ def __init__(self, coordinator, entry):
263
273
self ._attr_device_class = SensorDeviceClass .WATER
264
274
self ._attr_state_class = SensorStateClass .TOTAL
265
275
276
+ @property
277
+ def last_reset (self ):
278
+ """Return the last reset time for the billing usage sensor."""
279
+ local_tz = dt_util .get_time_zone (self .hass .config .time_zone )
280
+ now = datetime .now (local_tz )
281
+ return now .replace (day = 1 , hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
282
+
266
283
@property
267
284
def native_value (self ):
268
285
"""Return the state of the sensor."""
@@ -391,6 +408,13 @@ def __init__(self, coordinator, entry):
391
408
self ._attr_device_class = SensorDeviceClass .WATER
392
409
self ._attr_state_class = SensorStateClass .TOTAL
393
410
411
+ @property
412
+ def last_reset (self ):
413
+ """Return the last reset time for the last hour usage sensor."""
414
+ local_tz = dt_util .get_time_zone (self .hass .config .time_zone )
415
+ now = datetime .now (local_tz )
416
+ return now .replace (minute = 0 , second = 0 , microsecond = 0 ) - timedelta (hours = 1 )
417
+
394
418
@property
395
419
def native_value (self ):
396
420
"""Return the usage for the current hour from the previous day."""
0 commit comments