Skip to content

Commit 99a796d

Browse files
authored
Remove legacy history queries from recorder (home-assistant#153324)
1 parent 1cd1b1a commit 99a796d

File tree

17 files changed

+16
-2596
lines changed

17 files changed

+16
-2596
lines changed

homeassistant/components/recorder/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,6 @@ def _process_state_changed_event_into_session(
11271127
else:
11281128
states_manager.add_pending(entity_id, dbstate)
11291129

1130-
if states_meta_manager.active:
1131-
dbstate.entity_id = None
1132-
11331130
if entity_id is None or not (
11341131
shared_attrs_bytes := state_attributes_manager.serialize_from_event(event)
11351132
):
@@ -1140,7 +1137,7 @@ def _process_state_changed_event_into_session(
11401137
dbstate.states_meta_rel = pending_states_meta
11411138
elif metadata_id := states_meta_manager.get(entity_id, session, True):
11421139
dbstate.metadata_id = metadata_id
1143-
elif states_meta_manager.active and entity_removed:
1140+
elif entity_removed:
11441141
# If the entity was removed, we don't need to add it to the
11451142
# StatesMeta table or record it in the pending commit
11461143
# if it does not have a metadata_id allocated to it as

homeassistant/components/recorder/db_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def from_event(event: Event[EventStateChangedData]) -> States:
494494
context = event.context
495495
return States(
496496
state=state_value,
497-
entity_id=event.data["entity_id"],
497+
entity_id=None,
498498
attributes=None,
499499
context_id=None,
500500
context_id_bin=ulid_to_bytes_or_none(context.id),

homeassistant/components/recorder/entity_registry.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ def update_states_metadata(
6161
) -> None:
6262
"""Update the states metadata table when an entity is renamed."""
6363
states_meta_manager = instance.states_meta_manager
64-
if not states_meta_manager.active:
65-
_LOGGER.warning(
66-
"Cannot rename entity_id `%s` to `%s` "
67-
"because the states meta manager is not yet active",
68-
entity_id,
69-
new_entity_id,
70-
)
71-
return
72-
7364
with session_scope(
7465
session=instance.get_session(),
7566
exception_filter=filter_unique_constraint_integrity_error(instance, "state"),

homeassistant/components/recorder/history/__init__.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from sqlalchemy.orm.session import Session
99

1010
from homeassistant.core import HomeAssistant, State
11-
from homeassistant.helpers.recorder import get_instance
1211

1312
from ..filters import Filters
1413
from .const import NEED_ATTRIBUTE_DOMAINS, SIGNIFICANT_DOMAINS
@@ -44,15 +43,7 @@ def get_full_significant_states_with_session(
4443
no_attributes: bool = False,
4544
) -> dict[str, list[State]]:
4645
"""Return a dict of significant states during a time period."""
47-
if not get_instance(hass).states_meta_manager.active:
48-
from .legacy import ( # noqa: PLC0415
49-
get_full_significant_states_with_session as _legacy_get_full_significant_states_with_session,
50-
)
51-
52-
_target = _legacy_get_full_significant_states_with_session
53-
else:
54-
_target = _modern_get_full_significant_states_with_session
55-
return _target(
46+
return _modern_get_full_significant_states_with_session(
5647
hass,
5748
session,
5849
start_time,
@@ -69,15 +60,7 @@ def get_last_state_changes(
6960
hass: HomeAssistant, number_of_states: int, entity_id: str
7061
) -> dict[str, list[State]]:
7162
"""Return the last number_of_states."""
72-
if not get_instance(hass).states_meta_manager.active:
73-
from .legacy import ( # noqa: PLC0415
74-
get_last_state_changes as _legacy_get_last_state_changes,
75-
)
76-
77-
_target = _legacy_get_last_state_changes
78-
else:
79-
_target = _modern_get_last_state_changes
80-
return _target(hass, number_of_states, entity_id)
63+
return _modern_get_last_state_changes(hass, number_of_states, entity_id)
8164

8265

8366
def get_significant_states(
@@ -93,15 +76,7 @@ def get_significant_states(
9376
compressed_state_format: bool = False,
9477
) -> dict[str, list[State | dict[str, Any]]]:
9578
"""Return a dict of significant states during a time period."""
96-
if not get_instance(hass).states_meta_manager.active:
97-
from .legacy import ( # noqa: PLC0415
98-
get_significant_states as _legacy_get_significant_states,
99-
)
100-
101-
_target = _legacy_get_significant_states
102-
else:
103-
_target = _modern_get_significant_states
104-
return _target(
79+
return _modern_get_significant_states(
10580
hass,
10681
start_time,
10782
end_time,
@@ -129,15 +104,7 @@ def get_significant_states_with_session(
129104
compressed_state_format: bool = False,
130105
) -> dict[str, list[State | dict[str, Any]]]:
131106
"""Return a dict of significant states during a time period."""
132-
if not get_instance(hass).states_meta_manager.active:
133-
from .legacy import ( # noqa: PLC0415
134-
get_significant_states_with_session as _legacy_get_significant_states_with_session,
135-
)
136-
137-
_target = _legacy_get_significant_states_with_session
138-
else:
139-
_target = _modern_get_significant_states_with_session
140-
return _target(
107+
return _modern_get_significant_states_with_session(
141108
hass,
142109
session,
143110
start_time,
@@ -163,15 +130,7 @@ def state_changes_during_period(
163130
include_start_time_state: bool = True,
164131
) -> dict[str, list[State]]:
165132
"""Return a list of states that changed during a time period."""
166-
if not get_instance(hass).states_meta_manager.active:
167-
from .legacy import ( # noqa: PLC0415
168-
state_changes_during_period as _legacy_state_changes_during_period,
169-
)
170-
171-
_target = _legacy_state_changes_during_period
172-
else:
173-
_target = _modern_state_changes_during_period
174-
return _target(
133+
return _modern_state_changes_during_period(
175134
hass,
176135
start_time,
177136
end_time,

0 commit comments

Comments
 (0)