Switch async_track_state_change to the faster async_track_state_change_event part 4 (#37863)

* Switch async_track_state_change to the faster async_track_state_change_event part 4

Calling async_track_state_change_event directly is faster than async_track_state_change (see #37251) since async_track_state_change is a wrapper around async_track_state_change_event now

* pylint
This commit is contained in:
J. Nick Koston 2020-07-14 19:25:48 -10:00 committed by GitHub
parent aed98a830f
commit b430496b13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 24 deletions

View file

@ -184,7 +184,10 @@ class TestStatisticsSensor(unittest.TestCase):
def test_max_age(self):
"""Test value deprecation."""
mock_data = {"return_time": datetime(2017, 8, 2, 12, 23, tzinfo=dt_util.UTC)}
now = dt_util.utcnow()
mock_data = {
"return_time": datetime(now.year + 1, 8, 2, 12, 23, tzinfo=dt_util.UTC)
}
def mock_now():
return mock_data["return_time"]
@ -226,7 +229,10 @@ class TestStatisticsSensor(unittest.TestCase):
def test_max_age_without_sensor_change(self):
"""Test value deprecation."""
mock_data = {"return_time": datetime(2017, 8, 2, 12, 23, tzinfo=dt_util.UTC)}
now = dt_util.utcnow()
mock_data = {
"return_time": datetime(now.year + 1, 8, 2, 12, 23, tzinfo=dt_util.UTC)
}
def mock_now():
return mock_data["return_time"]
@ -279,8 +285,9 @@ class TestStatisticsSensor(unittest.TestCase):
def test_change_rate(self):
"""Test min_age/max_age and change_rate."""
now = dt_util.utcnow()
mock_data = {
"return_time": datetime(2017, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC)
"return_time": datetime(now.year + 1, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC)
}
def mock_now():
@ -318,10 +325,10 @@ class TestStatisticsSensor(unittest.TestCase):
state = self.hass.states.get("sensor.test")
assert datetime(
2017, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC
now.year + 1, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC
) == state.attributes.get("min_age")
assert datetime(
2017, 8, 2, 12, 23 + self.count - 1, 42, tzinfo=dt_util.UTC
now.year + 1, 8, 2, 12, 23 + self.count - 1, 42, tzinfo=dt_util.UTC
) == state.attributes.get("max_age")
assert self.change_rate == state.attributes.get("change_rate")
@ -364,8 +371,9 @@ class TestStatisticsSensor(unittest.TestCase):
def test_initialize_from_database_with_maxage(self):
"""Test initializing the statistics from the database."""
now = dt_util.utcnow()
mock_data = {
"return_time": datetime(2017, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC)
"return_time": datetime(now.year + 1, 8, 2, 12, 23, 42, tzinfo=dt_util.UTC)
}
def mock_now():