diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index 43ae21fea50..06b26cce362 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -12,11 +12,7 @@ import voluptuous as vol from homeassistant.components import recorder from homeassistant.components.http import HomeAssistantView -from homeassistant.components.recorder.models import ( - DB_TIMEZONE, - States, - process_timestamp, -) +from homeassistant.components.recorder.models import States, process_timestamp from homeassistant.components.recorder.util import execute, session_scope from homeassistant.const import ( ATTR_HIDDEN, @@ -355,7 +351,9 @@ def _sorted_states_to_json( ent_results.append( { 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 diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index b47eca9f051..e7a03678835 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -223,11 +223,8 @@ class TestComponentHistory(unittest.TestCase): # will happen with encoding a native state input_state = states["media_player.test"][1] orig_last_changed = json.dumps( - process_timestamp(input_state.last_changed.replace(microsecond=0)), - cls=JSONEncoder, + process_timestamp(input_state.last_changed), cls=JSONEncoder, ).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 states["media_player.test"][1] = { "last_changed": orig_last_changed,