History: Ignore insignificant domains

pull/1482/head
Paulus Schoutsen 2016-03-05 09:49:04 -08:00
parent d30fb7f04a
commit 605a572c86
2 changed files with 10 additions and 5 deletions

View File

@ -19,6 +19,7 @@ DOMAIN = 'history'
DEPENDENCIES = ['recorder', 'http']
SIGNIFICANT_DOMAINS = ('thermostat',)
IGNORE_DOMAINS = ('zone', 'scene',)
URL_HISTORY_PERIOD = re.compile(
r'/api/history/period(?:/(?P<date>\d{4}-\d{1,2}-\d{1,2})|)')
@ -46,9 +47,10 @@ def get_significant_states(start_time, end_time=None, entity_id=None):
"""
where = """
(domain in ({}) or last_changed=last_updated)
AND last_updated > ?
""".format(",".join(["'%s'" % x for x in SIGNIFICANT_DOMAINS]))
(domain IN ({}) OR last_changed=last_updated)
AND domain NOT IN ({}) AND last_updated > ?
""".format(",".join("'%s'" % x for x in SIGNIFICANT_DOMAINS),
",".join("'%s'" % x for x in IGNORE_DOMAINS))
data = [start_time]

View File

@ -148,7 +148,7 @@ class TestComponentHistory(unittest.TestCase):
"""test that only significant states are returned with
get_significant_states.
We inject a bunch of state updates from media player and
We inject a bunch of state updates from media player, zone and
thermostat. We should get back every thermostat change that
includes an attribute change, but only the state updates for
media player (attribute changes are not significant and not returned).
@ -157,6 +157,7 @@ class TestComponentHistory(unittest.TestCase):
self.init_recorder()
mp = 'media_player.test'
therm = 'thermostat.test'
zone = 'zone.home'
def set_state(entity_id, state, **kwargs):
self.hass.states.set(entity_id, state, **kwargs)
@ -186,6 +187,8 @@ class TestComponentHistory(unittest.TestCase):
# this state will be skipped only different in time
set_state(mp, 'YouTube',
attributes={'media_title': str(sentinel.mt3)})
# this state will be skipped because domain blacklisted
set_state(zone, 'zoning')
states[therm].append(
set_state(therm, 21, attributes={'current_temperature': 19.8}))
@ -199,4 +202,4 @@ class TestComponentHistory(unittest.TestCase):
set_state(therm, 21, attributes={'current_temperature': 20}))
hist = history.get_significant_states(zero, four)
self.assertEqual(states, hist)
assert states == hist