From e74791083e2448697f8fbd887d639e6e19dfbc2f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 20 Mar 2024 09:14:17 -1000 Subject: [PATCH] Fix duplicate events in live history (#113896) --- homeassistant/components/history/websocket_api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py index 6eb1fec3416..27e490dd8d4 100644 --- a/homeassistant/components/history/websocket_api.py +++ b/homeassistant/components/history/websocket_api.py @@ -5,7 +5,7 @@ from __future__ import annotations import asyncio from collections.abc import Callable, Iterable, MutableMapping from dataclasses import dataclass -from datetime import datetime as dt +from datetime import datetime as dt, timedelta import logging from typing import Any, cast @@ -564,7 +564,10 @@ async def ws_stream( hass, connection, msg_id, - last_event_time or start_time, + # Add one microsecond so we are outside the window of + # the last event we got from the database since otherwise + # we could fetch the same event twice + (last_event_time or start_time) + timedelta(microseconds=1), subscriptions_setup_complete_time, entity_ids, False, # We don't want the start time state again