Fix recorder defaults (#24399)

* Fix recorder defaults

* Address comment
This commit is contained in:
Paulus Schoutsen 2019-06-08 16:18:29 -07:00 committed by Andrew Sayre
parent 9235b52828
commit 848a2a95a8
2 changed files with 22 additions and 2 deletions

View File

@ -62,7 +62,7 @@ FILTER_SCHEMA = vol.Schema({
}) })
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
DOMAIN: FILTER_SCHEMA.extend({ vol.Optional(DOMAIN, default=dict): FILTER_SCHEMA.extend({
vol.Optional(CONF_PURGE_KEEP_DAYS, default=10): vol.Optional(CONF_PURGE_KEEP_DAYS, default=10):
vol.All(vol.Coerce(int), vol.Range(min=1)), vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Optional(CONF_PURGE_INTERVAL, default=1): vol.Optional(CONF_PURGE_INTERVAL, default=1):
@ -95,7 +95,7 @@ def run_information(hass, point_in_time: Optional[datetime] = None):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the recorder.""" """Set up the recorder."""
conf = config.get(DOMAIN, {}) conf = config[DOMAIN]
keep_days = conf.get(CONF_PURGE_KEEP_DAYS) keep_days = conf.get(CONF_PURGE_KEEP_DAYS)
purge_interval = conf.get(CONF_PURGE_INTERVAL) purge_interval = conf.get(CONF_PURGE_INTERVAL)

View File

@ -7,6 +7,7 @@ import pytest
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.const import MATCH_ALL from homeassistant.const import MATCH_ALL
from homeassistant.setup import async_setup_component
from homeassistant.components.recorder import Recorder from homeassistant.components.recorder import Recorder
from homeassistant.components.recorder.const import DATA_INSTANCE from homeassistant.components.recorder.const import DATA_INSTANCE
from homeassistant.components.recorder.util import session_scope from homeassistant.components.recorder.util import session_scope
@ -202,3 +203,22 @@ def test_recorder_setup_failure():
rec.join() rec.join()
hass.stop() hass.stop()
async def test_defaults_set(hass):
"""Test the config defaults are set."""
recorder_config = None
async def mock_setup(hass, config):
"""Mock setup."""
nonlocal recorder_config
recorder_config = config['recorder']
return True
with patch('homeassistant.components.recorder.async_setup',
side_effect=mock_setup):
assert await async_setup_component(hass, 'history', {})
assert recorder_config is not None
assert recorder_config['purge_keep_days'] == 10
assert recorder_config['purge_interval'] == 1