mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Fix recorder defaults (#24399)
* Fix recorder defaults * Address comment
This commit is contained in:
parent
9235b52828
commit
848a2a95a8
@ -62,7 +62,7 @@ FILTER_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.All(vol.Coerce(int), vol.Range(min=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:
|
||||
"""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)
|
||||
|
||||
|
@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
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
|
||||
@ -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):
|
||||
"""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
|
||||
|
Loading…
x
Reference in New Issue
Block a user