Skip to content

Use last state attribute #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion custom_components/sensus_analytics/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "sensus_analytics",
"name": "Sensus Analytics Integration",
"version": "1.6.11",
"version": "1.6.12",
"documentation": "https://github.com/zestysoft/sensus_analytics_integration",
"dependencies": [],
"codeowners": ["@zestysoft"],
Expand Down
26 changes: 25 additions & 1 deletion custom_components/sensus_analytics/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Sensor platform for the Sensus Analytics Integration."""

from datetime import datetime
from datetime import datetime, timedelta

from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -118,6 +118,11 @@ def __init__(self, coordinator, entry):
self._attr_device_class = SensorDeviceClass.WATER
self._attr_state_class = SensorStateClass.TOTAL

@property
def last_reset(self):
"""Return the last reset time for the daily usage sensor."""
return dt_util.start_of_local_day()

@property
def native_value(self):
"""Return the state of the sensor."""
Expand Down Expand Up @@ -244,6 +249,11 @@ def __init__(self, coordinator, entry):
self._attr_device_class = SensorDeviceClass.WATER
self._attr_state_class = SensorStateClass.TOTAL_INCREASING

@property
def last_reset(self):
"""Return the last reset time for the meter odometer sensor."""
return None # Odometer typically does not reset

@property
def native_value(self):
"""Return the state of the sensor."""
Expand All @@ -263,6 +273,13 @@ def __init__(self, coordinator, entry):
self._attr_device_class = SensorDeviceClass.WATER
self._attr_state_class = SensorStateClass.TOTAL

@property
def last_reset(self):
"""Return the last reset time for the billing usage sensor."""
local_tz = dt_util.get_time_zone(self.hass.config.time_zone)
now = datetime.now(local_tz)
return now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)

@property
def native_value(self):
"""Return the state of the sensor."""
Expand Down Expand Up @@ -391,6 +408,13 @@ def __init__(self, coordinator, entry):
self._attr_device_class = SensorDeviceClass.WATER
self._attr_state_class = SensorStateClass.TOTAL

@property
def last_reset(self):
"""Return the last reset time for the last hour usage sensor."""
local_tz = dt_util.get_time_zone(self.hass.config.time_zone)
now = datetime.now(local_tz)
return now.replace(minute=0, second=0, microsecond=0) - timedelta(hours=1)

@property
def native_value(self):
"""Return the usage for the current hour from the previous day."""
Expand Down
Loading