Allow input_* and timer component setup without config (#30772)

* Allow input_boolean setup without config.

* Allow input_number setup without config.

* Allow input_select setup without config.

* Allow input_text setup without config.

* Allow timer setup without config.
This commit is contained in:
Alexei Chetroi 2020-01-14 22:15:59 -05:00 committed by David F. Mulcahey
parent 8af946fba5
commit 5fa7d6f22a
10 changed files with 108 additions and 13 deletions

View file

@ -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()
@ -132,7 +132,10 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
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(

View file

@ -105,7 +105,6 @@ CONFIG_SCHEMA = vol.Schema(
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
@ -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()
@ -162,7 +161,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
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(

View file

@ -81,7 +81,6 @@ CONFIG_SCHEMA = vol.Schema(
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
@ -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()
@ -136,7 +135,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
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(

View file

@ -109,7 +109,6 @@ CONFIG_SCHEMA = vol.Schema(
)
)
},
required=True,
extra=vol.ALLOW_EXTRA,
)
RELOAD_SERVICE_SCHEMA = vol.Schema({})
@ -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()
@ -164,7 +163,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
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(

View file

@ -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()
@ -138,7 +138,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
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(

View file

@ -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())

View file

@ -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())

View file

@ -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())

View file

@ -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())

View file

@ -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())