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
7 changes: 5 additions & 2 deletions homeassistant/components/input_boolean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
)

await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in config[DOMAIN].items()]
[{CONF_ID: id_, **(conf or {})} for id_, conf in config.get(DOMAIN, {}).items()]
)
await storage_collection.async_load()

Expand All @@ -132,7 +132,10 @@ async def reload_service_handler(service_call: ServiceCallType) -> None:
if conf is None:
return
await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in conf[DOMAIN].items()]
[
{CONF_ID: id_, **(conf or {})}
for id_, conf in conf.get(DOMAIN, {}).items()
]
)

homeassistant.helpers.service.async_register_admin_service(
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/input_number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def _cv_input_number(cfg):
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
Expand Down Expand Up @@ -135,7 +134,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
)

await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in config[DOMAIN].items()]
[{CONF_ID: id_, **(conf or {})} for id_, conf in config.get(DOMAIN, {}).items()]
)
await storage_collection.async_load()

Expand All @@ -162,7 +161,7 @@ async def reload_service_handler(service_call: ServiceCallType) -> None:
if conf is None:
conf = {DOMAIN: {}}
await yaml_collection.async_load(
[{CONF_ID: id_, **conf} for id_, conf in conf[DOMAIN].items()]
[{CONF_ID: id_, **conf} for id_, conf in conf.get(DOMAIN, {}).items()]
)

homeassistant.helpers.service.async_register_admin_service(
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/input_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _cv_input_select(cfg):
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
Expand Down Expand Up @@ -109,7 +108,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
)

await yaml_collection.async_load(
[{CONF_ID: id_, **cfg} for id_, cfg in config[DOMAIN].items()]
[{CONF_ID: id_, **cfg} for id_, cfg in config.get(DOMAIN, {}).items()]
)
await storage_collection.async_load()

Expand All @@ -136,7 +135,7 @@ async def reload_service_handler(service_call: ServiceCallType) -> None:
if conf is None:
conf = {DOMAIN: {}}
await yaml_collection.async_load(
[{CONF_ID: id_, **cfg} for id_, cfg in conf[DOMAIN].items()]
[{CONF_ID: id_, **cfg} for id_, cfg in conf.get(DOMAIN, {}).items()]
)

homeassistant.helpers.service.async_register_admin_service(
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/input_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def _cv_input_text(cfg):
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
Expand Down Expand Up @@ -137,7 +136,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
)

await yaml_collection.async_load(
[{CONF_ID: id_, **(conf or {})} for id_, conf in config[DOMAIN].items()]
[{CONF_ID: id_, **(conf or {})} for id_, conf in config.get(DOMAIN, {}).items()]
)
await storage_collection.async_load()

Expand All @@ -164,7 +163,7 @@ async def reload_service_handler(service_call: ServiceCallType) -> None:
if conf is None:
conf = {DOMAIN: {}}
await yaml_collection.async_load(
[{CONF_ID: id_, **(cfg or {})} for id_, cfg in conf[DOMAIN].items()]
[{CONF_ID: id_, **(cfg or {})} for id_, cfg in conf.get(DOMAIN, {}).items()]
)

homeassistant.helpers.service.async_register_admin_service(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
collection.attach_entity_component_collection(component, storage_collection, Timer)

await yaml_collection.async_load(
[{CONF_ID: id_, **cfg} for id_, cfg in config[DOMAIN].items()]
[{CONF_ID: id_, **cfg} for id_, cfg in config.get(DOMAIN, {}).items()]
)
await storage_collection.async_load()

Expand All @@ -138,7 +138,7 @@ async def reload_service_handler(service_call: ServiceCallType) -> None:
if conf is None:
conf = {DOMAIN: {}}
await yaml_collection.async_load(
[{CONF_ID: id_, **cfg} for id_, cfg in conf[DOMAIN].items()]
[{CONF_ID: id_, **cfg} for id_, cfg in conf.get(DOMAIN, {}).items()]
)

homeassistant.helpers.service.async_register_admin_service(
Expand Down
19 changes: 19 additions & 0 deletions tests/components/input_boolean/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,22 @@ async def test_ws_delete(hass, hass_ws_client, storage_setup):
state = hass.states.get(input_entity_id)
assert state is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None


async def test_setup_no_config(hass, hass_admin_user):
"""Test component setup with no config."""
count_start = len(hass.states.async_entity_ids())
assert await async_setup_component(hass, DOMAIN, {})

with patch(
"homeassistant.config.load_yaml_config_file", autospec=True, return_value={}
):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
blocking=True,
context=Context(user_id=hass_admin_user.id),
)
await hass.async_block_till_done()

assert count_start == len(hass.states.async_entity_ids())
19 changes: 19 additions & 0 deletions tests/components/input_number/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,22 @@ async def test_ws_create(hass, hass_ws_client, storage_setup):

state = hass.states.get(input_entity_id)
assert float(state.state) == 10


async def test_setup_no_config(hass, hass_admin_user):
"""Test component setup with no config."""
count_start = len(hass.states.async_entity_ids())
assert await async_setup_component(hass, DOMAIN, {})

with patch(
"homeassistant.config.load_yaml_config_file", autospec=True, return_value={}
):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
blocking=True,
context=Context(user_id=hass_admin_user.id),
)
await hass.async_block_till_done()

assert count_start == len(hass.states.async_entity_ids())
19 changes: 19 additions & 0 deletions tests/components/input_select/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,22 @@ async def test_ws_create(hass, hass_ws_client, storage_setup):

state = hass.states.get(input_entity_id)
assert state.state == "even newer option"


async def test_setup_no_config(hass, hass_admin_user):
"""Test component setup with no config."""
count_start = len(hass.states.async_entity_ids())
assert await async_setup_component(hass, DOMAIN, {})

with patch(
"homeassistant.config.load_yaml_config_file", autospec=True, return_value={}
):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
blocking=True,
context=Context(user_id=hass_admin_user.id),
)
await hass.async_block_till_done()

assert count_start == len(hass.states.async_entity_ids())
19 changes: 19 additions & 0 deletions tests/components/input_text/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,22 @@ async def test_ws_create(hass, hass_ws_client, storage_setup):
assert state.attributes[ATTR_EDITABLE]
assert state.attributes[ATTR_MAX] == 44
assert state.attributes[ATTR_MIN] == 0


async def test_setup_no_config(hass, hass_admin_user):
"""Test component setup with no config."""
count_start = len(hass.states.async_entity_ids())
assert await async_setup_component(hass, DOMAIN, {})

with patch(
"homeassistant.config.load_yaml_config_file", autospec=True, return_value={}
):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
blocking=True,
context=Context(user_id=hass_admin_user.id),
)
await hass.async_block_till_done()

assert count_start == len(hass.states.async_entity_ids())
19 changes: 19 additions & 0 deletions tests/components/timer/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,22 @@ async def test_ws_create(hass, hass_ws_client, storage_setup):
assert state.state == STATUS_IDLE
assert state.attributes[ATTR_DURATION] == str(cv.time_period(42))
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, timer_id) == timer_entity_id


async def test_setup_no_config(hass, hass_admin_user):
"""Test component setup with no config."""
count_start = len(hass.states.async_entity_ids())
assert await async_setup_component(hass, DOMAIN, {})

with patch(
"homeassistant.config.load_yaml_config_file", autospec=True, return_value={}
):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
blocking=True,
context=Context(user_id=hass_admin_user.id),
)
await hass.async_block_till_done()

assert count_start == len(hass.states.async_entity_ids())