mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Fix history graphs with mysql/mariadb (#36769)
This commit is contained in:
parent
dd239661e7
commit
9cc20fc6b8
@ -12,11 +12,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components import recorder
|
from homeassistant.components import recorder
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.components.recorder.models import (
|
from homeassistant.components.recorder.models import States, process_timestamp
|
||||||
DB_TIMEZONE,
|
|
||||||
States,
|
|
||||||
process_timestamp,
|
|
||||||
)
|
|
||||||
from homeassistant.components.recorder.util import execute, session_scope
|
from homeassistant.components.recorder.util import execute, session_scope
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_HIDDEN,
|
ATTR_HIDDEN,
|
||||||
@ -355,7 +351,9 @@ def _sorted_states_to_json(
|
|||||||
ent_results.append(
|
ent_results.append(
|
||||||
{
|
{
|
||||||
STATE_KEY: db_state.state,
|
STATE_KEY: db_state.state,
|
||||||
LAST_CHANGED_KEY: f"{str(_process_timestamp(db_state.last_changed)).replace(' ','T').split('.')[0]}{DB_TIMEZONE}",
|
LAST_CHANGED_KEY: _process_timestamp(
|
||||||
|
db_state.last_changed
|
||||||
|
).isoformat(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
prev_state = db_state
|
prev_state = db_state
|
||||||
|
@ -223,11 +223,8 @@ class TestComponentHistory(unittest.TestCase):
|
|||||||
# will happen with encoding a native state
|
# will happen with encoding a native state
|
||||||
input_state = states["media_player.test"][1]
|
input_state = states["media_player.test"][1]
|
||||||
orig_last_changed = json.dumps(
|
orig_last_changed = json.dumps(
|
||||||
process_timestamp(input_state.last_changed.replace(microsecond=0)),
|
process_timestamp(input_state.last_changed), cls=JSONEncoder,
|
||||||
cls=JSONEncoder,
|
|
||||||
).replace('"', "")
|
).replace('"', "")
|
||||||
if orig_last_changed.endswith("+00:00"):
|
|
||||||
orig_last_changed = f"{orig_last_changed[:-6]}{recorder.models.DB_TIMEZONE}"
|
|
||||||
orig_state = input_state.state
|
orig_state = input_state.state
|
||||||
states["media_player.test"][1] = {
|
states["media_player.test"][1] = {
|
||||||
"last_changed": orig_last_changed,
|
"last_changed": orig_last_changed,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user