mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Fix history stats count update immediately after change (#131856)
* Fix history stats count update immediately after change * rerun CI
This commit is contained in:
parent
2c1a754e5d
commit
9209e43e4c
@ -4,6 +4,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
from homeassistant.components.recorder import get_instance, history
|
from homeassistant.components.recorder import get_instance, history
|
||||||
from homeassistant.core import Event, EventStateChangedData, HomeAssistant, State
|
from homeassistant.core import Event, EventStateChangedData, HomeAssistant, State
|
||||||
@ -14,6 +16,8 @@ from .helpers import async_calculate_period, floored_timestamp
|
|||||||
|
|
||||||
MIN_TIME_UTC = datetime.datetime.min.replace(tzinfo=dt_util.UTC)
|
MIN_TIME_UTC = datetime.datetime.min.replace(tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HistoryStatsState:
|
class HistoryStatsState:
|
||||||
@ -186,8 +190,13 @@ class HistoryStats:
|
|||||||
current_state_matches = history_state.state in self._entity_states
|
current_state_matches = history_state.state in self._entity_states
|
||||||
state_change_timestamp = history_state.last_changed
|
state_change_timestamp = history_state.last_changed
|
||||||
|
|
||||||
if state_change_timestamp > now_timestamp:
|
if math.floor(state_change_timestamp) > now_timestamp:
|
||||||
# Shouldn't count states that are in the future
|
# Shouldn't count states that are in the future
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Skipping future timestamp %s (now %s)",
|
||||||
|
state_change_timestamp,
|
||||||
|
now_timestamp,
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if previous_state_matches:
|
if previous_state_matches:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user