Fix utility meter reset without tarrifs (#102884)

* Fix utility meter reset without tarrifs

When using a utility_meter helper set up with a "Meter reset cycle" of
"No cycle" it is impossible to properly reset the meter to 0 and utilize
the "last reset" and "last period" attributes on the helper.

With these changes the service call can now directly reset a meter in
such a configuration and the UI selector has been updated to include
utility meters in the selection list.

Fixes #96920

* Undo UI target selection modes

As requested to not cause confusion by being able to reset individual
meters when using multiple tariffs.

* Adjust logic to only reset standalone sensors

The original logic would allow resetting meters with multiple tariffs
which was an unintended side effect.
This commit is contained in:
gibwar 2024-03-01 08:44:24 -07:00 committed by GitHub
parent c37f1c67f1
commit 52fe0a5e96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 93 additions and 1 deletions

View file

@ -570,7 +570,7 @@ class UtilityMeterSensor(RestoreSensor):
async def async_reset_meter(self, entity_id):
"""Reset meter."""
if self._tariff_entity != entity_id:
if self._tariff is not None and self._tariff_entity != entity_id:
return
_LOGGER.debug("Reset utility meter <%s>", self.entity_id)
self._last_reset = dt_util.utcnow()