Return None to indicate no config found (#15147)
* Return None to indicate no config found * Fix tests
This commit is contained in:
parent
6e4fb7a937
commit
c79c94550f
4 changed files with 16 additions and 2 deletions
|
@ -323,6 +323,10 @@ class ConfigEntries:
|
||||||
old_conf_migrate_func=_old_conf_migrator
|
old_conf_migrate_func=_old_conf_migrator
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if config is None:
|
||||||
|
self._entries = []
|
||||||
|
return
|
||||||
|
|
||||||
self._entries = [ConfigEntry(**entry) for entry in config['entries']]
|
self._entries = [ConfigEntry(**entry) for entry in config['entries']]
|
||||||
|
|
||||||
async def async_forward_entry_setup(self, entry, component):
|
async def async_forward_entry_setup(self, entry, component):
|
||||||
|
|
|
@ -72,7 +72,7 @@ class Store:
|
||||||
json.load_json, self.path, None)
|
json.load_json, self.path, None)
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
return {}
|
return None
|
||||||
|
|
||||||
if data['version'] == self.version:
|
if data['version'] == self.version:
|
||||||
return data['data']
|
return data['data']
|
||||||
|
|
|
@ -52,7 +52,7 @@ async def test_loading_non_existing(hass, store):
|
||||||
"""Test we can save and load data."""
|
"""Test we can save and load data."""
|
||||||
with patch('homeassistant.util.json.open', side_effect=FileNotFoundError):
|
with patch('homeassistant.util.json.open', side_effect=FileNotFoundError):
|
||||||
data = await store.async_load()
|
data = await store.async_load()
|
||||||
assert data == {}
|
assert data is None
|
||||||
|
|
||||||
|
|
||||||
async def test_saving_with_delay(hass, store, mock_save):
|
async def test_saving_with_delay(hass, store, mock_save):
|
||||||
|
|
|
@ -309,3 +309,13 @@ async def test_discovery_notification_not_created(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get('persistent_notification.config_entry_discovery')
|
state = hass.states.get('persistent_notification.config_entry_discovery')
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_loading_default_config(hass):
|
||||||
|
"""Test loading the default config."""
|
||||||
|
manager = config_entries.ConfigEntries(hass, {})
|
||||||
|
|
||||||
|
with patch('homeassistant.util.json.open', side_effect=FileNotFoundError):
|
||||||
|
await manager.async_load()
|
||||||
|
|
||||||
|
assert len(manager.async_entries()) == 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue