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 authored and GitHub committed 2020-07-14 22:25:48 -07:00
1 parent aed98a830f
commit b430496b13
5 files changed
+50 -24

No files matched your search

+14 -6
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():