mirror of
https://github.com/home-assistant/core.git
synced 2025-08-15 18:41:44 +02:00
fix refactor
This commit is contained in:
@@ -494,7 +494,7 @@ def get_last_state_changes(
|
||||
)
|
||||
|
||||
|
||||
def _get_states_for_entities_stmt(
|
||||
def _get_start_time_state_for_entities_stmt(
|
||||
run_start_ts: float,
|
||||
epoch_time: float,
|
||||
metadata_ids: list[int],
|
||||
@@ -567,7 +567,7 @@ def _get_start_time_state_stmt(
|
||||
)
|
||||
# We have more than one entity to look at so we need to do a query on states
|
||||
# since the last recorder run started.
|
||||
return _get_states_for_entities_stmt(
|
||||
return _get_start_time_state_for_entities_stmt(
|
||||
run_start_ts, epoch_time, metadata_ids, no_attributes
|
||||
)
|
||||
|
||||
|
@@ -8,7 +8,7 @@ from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import py
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy import lambda_stmt, text
|
||||
from sqlalchemy.engine.result import ChunkedIteratorResult
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.sql.elements import TextClause
|
||||
@@ -19,7 +19,7 @@ from homeassistant.components.recorder import util
|
||||
from homeassistant.components.recorder.const import DOMAIN, SQLITE_URL_PREFIX
|
||||
from homeassistant.components.recorder.db_schema import RecorderRuns
|
||||
from homeassistant.components.recorder.history.modern import (
|
||||
_get_single_entity_states_stmt,
|
||||
_get_single_entity_start_time_stmt,
|
||||
)
|
||||
from homeassistant.components.recorder.models import (
|
||||
UnsupportedDialect,
|
||||
@@ -909,7 +909,12 @@ def test_execute_stmt_lambda_element(
|
||||
with session_scope(hass=hass) as session:
|
||||
# No time window, we always get a list
|
||||
metadata_id = instance.states_meta_manager.get("sensor.on", session, True)
|
||||
stmt = _get_single_entity_states_stmt(dt_util.utcnow(), metadata_id, False)
|
||||
start_time_ts = dt_util.utcnow().timestamp()
|
||||
stmt = lambda_stmt(
|
||||
lambda: _get_single_entity_start_time_stmt(
|
||||
start_time_ts, metadata_id, False
|
||||
)
|
||||
)
|
||||
rows = util.execute_stmt_lambda_element(session, stmt)
|
||||
assert isinstance(rows, list)
|
||||
assert rows[0].state == new_state.state
|
||||
|
Reference in New Issue
Block a user