diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 694af903a3e..45d8c8b3c06 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -416,21 +416,12 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): """Return state attributes.""" if last_reset := self.last_reset: state_class = self.state_class - if state_class != SensorStateClass.TOTAL and not self._last_reset_reported: - self._last_reset_reported = True - report_issue = self._suggest_report_issue() - # This should raise in Home Assistant Core 2022.5 - _LOGGER.warning( - ( - "Entity %s (%s) with state_class %s has set last_reset. Setting" - " last_reset for entities with state_class other than 'total'" - " is not supported. Please update your configuration if" - " state_class is manually configured, otherwise %s" - ), - self.entity_id, - type(self), - state_class, - report_issue, + if state_class != SensorStateClass.TOTAL: + raise ValueError( + f"Entity {self.entity_id} ({type(self)}) with state_class {state_class}" + " has set last_reset. Setting last_reset for entities with state_class" + " other than 'total' is not supported. Please update your configuration" + " if state_class is manually configured." ) if state_class == SensorStateClass.TOTAL: diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 522afe3b992..8e28a4fe382 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -170,12 +170,11 @@ async def test_deprecated_last_reset( "Entity sensor.test () " f"with state_class {state_class} has set last_reset. Setting last_reset for " "entities with state_class other than 'total' is not supported. Please update " - "your configuration if state_class is manually configured, otherwise report it " - "to the author of the 'test' custom integration" + "your configuration if state_class is manually configured." ) in caplog.text state = hass.states.get("sensor.test") - assert "last_reset" not in state.attributes + assert state is None async def test_datetime_conversion(