mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fix utility_meter wrong/old value on reset (#142951)
Co-authored-by: Erwin Douna <e.douna@gmail.com> Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
parent
51eb4770a7
commit
694c768666
@ -577,10 +577,10 @@ class UtilityMeterSensor(RestoreSensor):
|
||||
async def _async_reset_meter(self, event):
|
||||
"""Reset the utility meter status."""
|
||||
|
||||
await self._program_reset()
|
||||
|
||||
await self.async_reset_meter(self._tariff_entity)
|
||||
|
||||
await self._program_reset()
|
||||
|
||||
async def async_reset_meter(self, entity_id):
|
||||
"""Reset meter."""
|
||||
if self._tariff_entity is not None and self._tariff_entity != entity_id:
|
||||
|
@ -43,6 +43,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import CoreState, HomeAssistant, State
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
@ -1637,8 +1638,21 @@ async def _test_self_reset(
|
||||
|
||||
now += timedelta(seconds=30)
|
||||
with freeze_time(now):
|
||||
# Listen for events and check that state in the first event after reset is actually 0, issue #142053
|
||||
events = []
|
||||
|
||||
async def handle_energy_bill_event(event):
|
||||
events.append(event)
|
||||
|
||||
unsub = async_track_state_change_event(
|
||||
hass,
|
||||
"sensor.energy_bill",
|
||||
handle_energy_bill_event,
|
||||
)
|
||||
|
||||
async_fire_time_changed(hass, now)
|
||||
await hass.async_block_till_done()
|
||||
unsub()
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
@ -1654,6 +1668,10 @@ async def _test_self_reset(
|
||||
state.attributes.get("last_reset") == dt_util.as_utc(now).isoformat()
|
||||
) # last_reset is kept in UTC
|
||||
assert state.state == "3"
|
||||
# In first event state should be 0
|
||||
assert len(events) == 2
|
||||
assert events[0].data.get("new_state").state == "0"
|
||||
assert events[1].data.get("new_state").state == "0"
|
||||
else:
|
||||
assert state.attributes.get("last_period") == "0"
|
||||
assert state.state == "5"
|
||||
|
Loading…
x
Reference in New Issue
Block a user