Init statistics sensor upon HASS start (#18236)
* Update query to include maxAge Updated the query from recorded to include MaxAge if set; reducing the amount of records retrieved that would otherwise be purged anyway for the sensor. * Initialization upon HASS start Register the state listener and read previous information from recorder once HASS is started. * Updated test_statistics.py for HASS start Updated test_statistics.py to start HASS and wait it is completed before running test. * Added newline in docstring Added newline in docstring. * Added start of HASS to test_initialize_from_database_with_maxage Added start of HASS to new test test_initialize_from_database_with_maxage. * Updates based on review Following updates based on review: -) Removed self._hass and passing hass -) Changed async_add_job to async_create_task -) For state update, calling async_schedule_update_ha_state
This commit is contained in:
1 parent
d2907b8e53
commit
d2e102ee2f
2 files changed
+52
-13
No files matched your search
@@ -49,6 +49,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in values:
|
||||
self.hass.states.set('binary_sensor.test_monitored', value)
|
||||
self.hass.block_till_done()
|
||||
@@ -67,6 +70,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in self.values:
|
||||
self.hass.states.set('sensor.test_monitored', value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
|
||||
@@ -100,6 +106,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in self.values:
|
||||
self.hass.states.set('sensor.test_monitored', value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
|
||||
@@ -121,6 +130,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in self.values[-3:]: # just the last 3 will do
|
||||
self.hass.states.set('sensor.test_monitored', value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
|
||||
@@ -162,6 +174,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in self.values:
|
||||
self.hass.states.set('sensor.test_monitored', value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
|
||||
@@ -194,6 +209,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
for value in self.values:
|
||||
self.hass.states.set('sensor.test_monitored', value,
|
||||
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
|
||||
@@ -231,6 +249,10 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
'sampling_size': 100,
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
# check if the result is as in test_sensor_source()
|
||||
state = self.hass.states.get('sensor.test_mean')
|
||||
assert str(self.mean) == state.state
|
||||
@@ -284,6 +306,9 @@ class TestStatisticsSensor(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.start()
|
||||
self.hass.block_till_done()
|
||||
|
||||
# check if the result is as in test_sensor_source()
|
||||
state = self.hass.states.get('sensor.test_mean')
|
||||
|
||||
|
||||
Reference in new issue
Block a user