mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
fixes for pep and delay start
This commit is contained in:
parent
67b0365f62
commit
93fd6fa11b
@ -22,6 +22,7 @@ from homeassistant.const import (
|
||||
EVENT_TIME_CHANGED, MATCH_ALL)
|
||||
from homeassistant.core import Event, EventOrigin, State
|
||||
from homeassistant.remote import JSONEncoder
|
||||
from homeassistant.helpers.event import track_point_in_utc_time
|
||||
|
||||
DOMAIN = "recorder"
|
||||
|
||||
@ -33,8 +34,9 @@ RETURN_ONE_ROW = "one_row"
|
||||
|
||||
CONF_PURGE_DAYS = "purge_days"
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.All(dict, {
|
||||
CONF_PURGE_DAYS: int
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Optional(CONF_PURGE_DAYS): vol.All(vol.Coerce(int),
|
||||
vol.Range(min=1)),
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
@ -204,7 +206,10 @@ class Recorder(threading.Thread):
|
||||
"""Start processing events to save."""
|
||||
self._setup_connection()
|
||||
self._setup_run()
|
||||
self._purge_old_data()
|
||||
if self.purge_days is not None:
|
||||
track_point_in_utc_time(self.hass,
|
||||
lambda now: self._purge_old_data(),
|
||||
dt_util.utcnow() + timedelta(minutes=5))
|
||||
|
||||
while True:
|
||||
event = self.queue.get()
|
||||
|
@ -43,12 +43,13 @@ class TestRecorder(unittest.TestCase):
|
||||
timestamp = now
|
||||
state = 'dontpurgeme'
|
||||
recorder.query("INSERT INTO states ("
|
||||
"entity_id, domain, state, attributes, last_changed,"
|
||||
"last_updated, created, utc_offset, event_id)"
|
||||
"entity_id, domain, state, attributes,"
|
||||
"last_changed, last_updated, created,"
|
||||
"utc_offset, event_id)"
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
('test.recorder2', 'sensor', state,
|
||||
json.dumps(attributes), timestamp, timestamp,
|
||||
timestamp, -18000, event_id + 1000))
|
||||
json.dumps(attributes), timestamp, timestamp,
|
||||
timestamp, -18000, event_id + 1000))
|
||||
|
||||
def _add_test_events(self):
|
||||
"""Adds a few events for testing."""
|
||||
@ -155,7 +156,6 @@ class TestRecorder(unittest.TestCase):
|
||||
'event_type LIKE "EVENT_TEST%"')
|
||||
self.assertEqual(len(events), 3)
|
||||
|
||||
|
||||
def test_purge_disabled(self):
|
||||
"""Tests leaving purge_days disabled."""
|
||||
self._add_test_states()
|
||||
@ -167,7 +167,6 @@ class TestRecorder(unittest.TestCase):
|
||||
self.assertEqual(len(states), 5)
|
||||
self.assertEqual(len(events), 5)
|
||||
|
||||
|
||||
# run purge_old_data()
|
||||
recorder._INSTANCE.purge_days = None
|
||||
recorder._INSTANCE._purge_old_data()
|
||||
|
Loading…
x
Reference in New Issue
Block a user