Make recorder execute avoid native conversion by default (#36938)
This commit is contained in:
1 parent
f4b8a95205
commit
edad387b12
9 files changed
+42
-35
No files matched your search
@@ -2,12 +2,14 @@
|
||||
from datetime import datetime
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
|
||||
from homeassistant.components.recorder.models import Base, Events, RecorderRuns, States
|
||||
from homeassistant.const import EVENT_STATE_CHANGED
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.exceptions import InvalidEntityFormatError
|
||||
from homeassistant.util import dt
|
||||
|
||||
ENGINE = None
|
||||
@@ -155,8 +157,11 @@ class TestRecorderRuns(unittest.TestCase):
|
||||
|
||||
def test_states_from_native_invalid_entity_id():
|
||||
"""Test loading a state from an invalid entity ID."""
|
||||
event = States()
|
||||
event.entity_id = "test.invalid__id"
|
||||
event.attributes = "{}"
|
||||
state = event.to_native()
|
||||
state = States()
|
||||
state.entity_id = "test.invalid__id"
|
||||
state.attributes = "{}"
|
||||
with pytest.raises(InvalidEntityFormatError):
|
||||
state = state.to_native()
|
||||
|
||||
state = state.to_native(validate_entity_id=False)
|
||||
assert state.entity_id == "test.invalid__id"
|
||||
@@ -47,7 +47,7 @@ def test_recorder_bad_execute(hass_recorder):
|
||||
|
||||
hass_recorder()
|
||||
|
||||
def to_native():
|
||||
def to_native(validate_entity_id=True):
|
||||
"""Rasie exception."""
|
||||
raise SQLAlchemyError()
|
||||
|
||||
@@ -57,6 +57,6 @@ def test_recorder_bad_execute(hass_recorder):
|
||||
with pytest.raises(SQLAlchemyError), patch(
|
||||
"homeassistant.components.recorder.time.sleep"
|
||||
) as e_mock:
|
||||
util.execute((mck1,))
|
||||
util.execute((mck1,), to_native=True)
|
||||
|
||||
assert e_mock.call_count == 2
|
||||
@@ -3,8 +3,6 @@ from datetime import datetime, timedelta
|
||||
import statistics
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import recorder
|
||||
from homeassistant.components.statistics.sensor import StatisticsSensor
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, STATE_UNKNOWN, TEMP_CELSIUS
|
||||
@@ -17,6 +15,7 @@ from tests.common import (
|
||||
get_test_home_assistant,
|
||||
init_recorder_component,
|
||||
)
|
||||
from tests.components.recorder.common import wait_recording_done
|
||||
|
||||
|
||||
class TestStatisticsSensor(unittest.TestCase):
|
||||
@@ -321,11 +320,12 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
) == state.attributes.get("max_age")
|
||||
assert self.change_rate == state.attributes.get("change_rate")
|
||||
|
||||
@pytest.mark.skip("Flaky in CI")
|
||||
def test_initialize_from_database(self):
|
||||
"""Test initializing the statistics from the database."""
|
||||
# enable the recorder
|
||||
init_recorder_component(self.hass)
|
||||
self.hass.block_till_done()
|
||||
self.hass.data[recorder.DATA_INSTANCE].block_till_done()
|
||||
# store some values
|
||||
for value in self.values:
|
||||
self.hass.states.set(
|
||||
@@ -333,7 +333,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
# wait for the recorder to really store the data
|
||||
self.hass.data[recorder.DATA_INSTANCE].block_till_done()
|
||||
wait_recording_done(self.hass)
|
||||
# only now create the statistics component, so that it must read the
|
||||
# data from the database
|
||||
assert setup_component(
|
||||
@@ -357,7 +357,6 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
state = self.hass.states.get("sensor.test")
|
||||
assert str(self.mean) == state.state
|
||||
|
||||
@pytest.mark.skip("Flaky in CI")
|
||||
def test_initialize_from_database_with_maxage(self):
|
||||
"""Test initializing the statistics from the database."""
|
||||
mock_data = {
|
||||
@@ -381,6 +380,8 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
|
||||
# enable the recorder
|
||||
init_recorder_component(self.hass)
|
||||
self.hass.block_till_done()
|
||||
self.hass.data[recorder.DATA_INSTANCE].block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.statistics.sensor.dt_util.utcnow", new=mock_now
|
||||
@@ -397,7 +398,7 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
mock_data["return_time"] += timedelta(hours=1)
|
||||
|
||||
# wait for the recorder to really store the data
|
||||
self.hass.data[recorder.DATA_INSTANCE].block_till_done()
|
||||
wait_recording_done(self.hass)
|
||||
# only now create the statistics component, so that it must read
|
||||
# the data from the database
|
||||
assert setup_component(
|
||||
|
||||
Reference in new issue
Block a user