Skip to content

Commit 78e1649

Browse files
authored
Remove runtime support for recorder DB without States.last_reported_ts (home-assistant#153495)
1 parent 12085e6 commit 78e1649

File tree

5 files changed

+10
-1903
lines changed

5 files changed

+10
-1903
lines changed

homeassistant/components/recorder/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
CONTEXT_ID_AS_BINARY_SCHEMA_VERSION = 36
5454
EVENT_TYPE_IDS_SCHEMA_VERSION = 37
5555
STATES_META_SCHEMA_VERSION = 38
56-
LAST_REPORTED_SCHEMA_VERSION = 43
5756
CIRCULAR_MEAN_SCHEMA_VERSION = 49
5857

5958
LEGACY_STATES_EVENT_ID_INDEX_SCHEMA_VERSION = 28

homeassistant/components/recorder/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
DEFAULT_MAX_BIND_VARS,
5757
DOMAIN,
5858
KEEPALIVE_TIME,
59-
LAST_REPORTED_SCHEMA_VERSION,
6059
MARIADB_PYMYSQL_URL_PREFIX,
6160
MARIADB_URL_PREFIX,
6261
MAX_QUEUE_BACKLOG_MIN_VALUE,
@@ -1226,7 +1225,7 @@ def _commit_event_session(self) -> None:
12261225
if (
12271226
pending_last_reported
12281227
:= self.states_manager.get_pending_last_reported_timestamp()
1229-
) and self.schema_version >= LAST_REPORTED_SCHEMA_VERSION:
1228+
):
12301229
with session.no_autoflush:
12311230
session.execute(
12321231
update(States),

homeassistant/components/recorder/history/modern.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from homeassistant.util import dt as dt_util
3030
from homeassistant.util.collection import chunked_or_all
3131

32-
from ..const import LAST_REPORTED_SCHEMA_VERSION, MAX_IDS_FOR_INDEXED_GROUP_BY
32+
from ..const import MAX_IDS_FOR_INDEXED_GROUP_BY
3333
from ..db_schema import (
3434
SHARED_ATTR_OR_LEGACY_ATTRIBUTES,
3535
StateAttributes,
@@ -388,10 +388,9 @@ def _state_changed_during_period_stmt(
388388
limit: int | None,
389389
include_start_time_state: bool,
390390
run_start_ts: float | None,
391-
include_last_reported: bool,
392391
) -> Select | CompoundSelect:
393392
stmt = (
394-
_stmt_and_join_attributes(no_attributes, False, include_last_reported)
393+
_stmt_and_join_attributes(no_attributes, False, True)
395394
.filter(
396395
(
397396
(States.last_changed_ts == States.last_updated_ts)
@@ -424,22 +423,22 @@ def _state_changed_during_period_stmt(
424423
single_metadata_id,
425424
no_attributes,
426425
False,
427-
include_last_reported,
426+
True,
428427
).subquery(),
429428
no_attributes,
430429
False,
431-
include_last_reported,
430+
True,
432431
),
433432
_select_from_subquery(
434433
stmt.subquery(),
435434
no_attributes,
436435
False,
437-
include_last_reported,
436+
True,
438437
),
439438
).subquery(),
440439
no_attributes,
441440
False,
442-
include_last_reported,
441+
True,
443442
)
444443

445444

@@ -454,9 +453,6 @@ def state_changes_during_period(
454453
include_start_time_state: bool = True,
455454
) -> dict[str, list[State]]:
456455
"""Return states changes during UTC period start_time - end_time."""
457-
has_last_reported = (
458-
get_instance(hass).schema_version >= LAST_REPORTED_SCHEMA_VERSION
459-
)
460456
if not entity_id:
461457
raise ValueError("entity_id must be provided")
462458
entity_ids = [entity_id.lower()]
@@ -489,14 +485,12 @@ def state_changes_during_period(
489485
limit,
490486
include_start_time_state,
491487
oldest_ts,
492-
has_last_reported,
493488
),
494489
track_on=[
495490
bool(end_time_ts),
496491
no_attributes,
497492
bool(limit),
498493
include_start_time_state,
499-
has_last_reported,
500494
],
501495
)
502496
return cast(
@@ -543,10 +537,10 @@ def _get_last_state_changes_single_stmt(metadata_id: int) -> Select:
543537

544538

545539
def _get_last_state_changes_multiple_stmt(
546-
number_of_states: int, metadata_id: int, include_last_reported: bool
540+
number_of_states: int, metadata_id: int
547541
) -> Select:
548542
return (
549-
_stmt_and_join_attributes(False, False, include_last_reported)
543+
_stmt_and_join_attributes(False, False, True)
550544
.where(
551545
States.state_id
552546
== (
@@ -568,9 +562,6 @@ def get_last_state_changes(
568562
hass: HomeAssistant, number_of_states: int, entity_id: str
569563
) -> dict[str, list[State]]:
570564
"""Return the last number_of_states."""
571-
has_last_reported = (
572-
get_instance(hass).schema_version >= LAST_REPORTED_SCHEMA_VERSION
573-
)
574565
entity_id_lower = entity_id.lower()
575566
entity_ids = [entity_id_lower]
576567

@@ -595,9 +586,8 @@ def get_last_state_changes(
595586
else:
596587
stmt = lambda_stmt(
597588
lambda: _get_last_state_changes_multiple_stmt(
598-
number_of_states, metadata_id, has_last_reported
589+
number_of_states, metadata_id
599590
),
600-
track_on=[has_last_reported],
601591
)
602592
states = list(execute_stmt_lambda_element(session, stmt, orm_rows=False))
603593
return cast(

0 commit comments

Comments
 (0)