1818from homeassistant .const import PERCENTAGE , EntityCategory , UnitOfMass
1919from homeassistant .core import HomeAssistant
2020from homeassistant .helpers .entity_platform import AddConfigEntryEntitiesCallback
21+ from homeassistant .util import dt as dt_util
2122
2223from .coordinator import LitterRobotConfigEntry
2324from .entity import LitterRobotEntity , _WhiskerEntityT
@@ -39,6 +40,7 @@ class RobotSensorEntityDescription(SensorEntityDescription, Generic[_WhiskerEnti
3940 """A class that describes robot sensor entities."""
4041
4142 icon_fn : Callable [[Any ], str | None ] = lambda _ : None
43+ last_reset_fn : Callable [[], datetime | None ] = lambda : None
4244 value_fn : Callable [[_WhiskerEntityT ], float | datetime | str | None ]
4345
4446
@@ -179,7 +181,14 @@ class RobotSensorEntityDescription(SensorEntityDescription, Generic[_WhiskerEnti
179181 native_unit_of_measurement = UnitOfMass .POUNDS ,
180182 state_class = SensorStateClass .MEASUREMENT ,
181183 value_fn = lambda pet : pet .weight ,
182- )
184+ ),
185+ RobotSensorEntityDescription [Pet ](
186+ key = "visits_today" ,
187+ translation_key = "visits_today" ,
188+ state_class = SensorStateClass .TOTAL ,
189+ last_reset_fn = dt_util .start_of_local_day ,
190+ value_fn = lambda pet : pet .get_visits_since (dt_util .start_of_local_day ()),
191+ ),
183192]
184193
185194
@@ -225,3 +234,8 @@ def icon(self) -> str | None:
225234 if (icon := self .entity_description .icon_fn (self .state )) is not None :
226235 return icon
227236 return super ().icon
237+
238+ @property
239+ def last_reset (self ) -> datetime | None :
240+ """Return the time when the sensor was last reset, if any."""
241+ return self .entity_description .last_reset_fn () or super ().last_reset
0 commit comments