Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/recorder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
})

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.All(vol.Coerce(int), vol.Range(min=1)),
vol.Optional(CONF_PURGE_INTERVAL, default=1):
Expand Down Expand Up @@ -95,7 +95,7 @@ def run_information(hass, point_in_time: Optional[datetime] = None):

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the recorder."""
conf = config.get(DOMAIN, {})
conf = config[DOMAIN]
keep_days = conf.get(CONF_PURGE_KEEP_DAYS)
purge_interval = conf.get(CONF_PURGE_INTERVAL)

Expand Down
20 changes: 20 additions & 0 deletions tests/components/recorder/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from homeassistant.core import callback
from homeassistant.const import MATCH_ALL
from homeassistant.setup import async_setup_component
from homeassistant.components.recorder import Recorder
from homeassistant.components.recorder.const import DATA_INSTANCE
from homeassistant.components.recorder.util import session_scope
Expand Down Expand Up @@ -202,3 +203,22 @@ def test_recorder_setup_failure():
rec.join()

hass.stop()


async def test_defaults_set(hass):
"""Test the config defaults are set."""
recorder_config = None

async def mock_setup(hass, config):
Comment thread
andrewsayre marked this conversation as resolved.
"""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