Make panel_custom backwards compatible (#36926)
This commit is contained in:
parent
212660330f
commit
263bdaa565
2 changed files with 26 additions and 23 deletions
|
@ -38,18 +38,8 @@ def url_validator(value):
|
|||
has_html_url = CONF_WEBCOMPONENT_PATH in value
|
||||
has_module_url = CONF_MODULE_URL in value
|
||||
|
||||
if has_html_url:
|
||||
if has_js_url or has_module_url:
|
||||
raise vol.Invalid(
|
||||
"You cannot specify other urls besides a webcomponent path"
|
||||
)
|
||||
|
||||
return value
|
||||
|
||||
if not has_js_url and not has_module_url:
|
||||
raise vol.Invalid(
|
||||
f"You need to specify either {CONF_MODULE_URL} or {CONF_JS_URL} or both."
|
||||
)
|
||||
if has_html_url and (has_js_url or has_module_url):
|
||||
raise vol.Invalid("You cannot specify other urls besides a webcomponent path")
|
||||
|
||||
return value
|
||||
|
||||
|
@ -165,6 +155,8 @@ async def async_setup(hass, config):
|
|||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
seen = set()
|
||||
|
||||
for panel in config[DOMAIN]:
|
||||
name = panel[CONF_COMPONENT_NAME]
|
||||
|
||||
|
@ -185,7 +177,14 @@ async def async_setup(hass, config):
|
|||
if CONF_MODULE_URL in panel:
|
||||
kwargs["module_url"] = panel[CONF_MODULE_URL]
|
||||
|
||||
if CONF_WEBCOMPONENT_PATH in panel:
|
||||
if CONF_MODULE_URL not in panel and CONF_JS_URL not in panel:
|
||||
if name in seen:
|
||||
_LOGGER.warning(
|
||||
"Got HTML panel with duplicate name %s. Not registering", name
|
||||
)
|
||||
continue
|
||||
|
||||
seen.add(name)
|
||||
panel_path = panel.get(CONF_WEBCOMPONENT_PATH)
|
||||
|
||||
if panel_path is None:
|
||||
|
|
|
@ -30,19 +30,22 @@ async def test_webcomponent_custom_path_not_found(hass):
|
|||
assert "nice_url" not in panels
|
||||
|
||||
|
||||
async def test_webcomponent_custom_path(hass):
|
||||
async def test_webcomponent_custom_path(hass, caplog):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
filename = "mock.file"
|
||||
|
||||
config = {
|
||||
"panel_custom": {
|
||||
"name": "todo-mvc",
|
||||
"webcomponent_path": filename,
|
||||
"sidebar_title": "Sidebar Title",
|
||||
"sidebar_icon": "mdi:iconicon",
|
||||
"url_path": "nice_url",
|
||||
"config": {"hello": "world"},
|
||||
}
|
||||
"panel_custom": [
|
||||
{
|
||||
"name": "todo-mvc",
|
||||
"webcomponent_path": filename,
|
||||
"sidebar_title": "Sidebar Title",
|
||||
"sidebar_icon": "mdi:iconicon",
|
||||
"url_path": "nice_url",
|
||||
"config": {"hello": "world"},
|
||||
},
|
||||
{"name": "todo-mvc"},
|
||||
]
|
||||
}
|
||||
|
||||
with patch("os.path.isfile", Mock(return_value=True)):
|
||||
|
@ -70,6 +73,8 @@ async def test_webcomponent_custom_path(hass):
|
|||
assert panel.sidebar_icon == "mdi:iconicon"
|
||||
assert panel.sidebar_title == "Sidebar Title"
|
||||
|
||||
assert "Got HTML panel with duplicate name todo-mvc. Not registering" in caplog.text
|
||||
|
||||
|
||||
async def test_js_webcomponent(hass):
|
||||
"""Test if a web component is found in config panels dir."""
|
||||
|
@ -186,7 +191,6 @@ async def test_latest_and_es5_build(hass):
|
|||
async def test_url_option_conflict(hass):
|
||||
"""Test config with multiple url options."""
|
||||
to_try = [
|
||||
{"panel_custom": {"name": "todo-mvc"}},
|
||||
{
|
||||
"panel_custom": {
|
||||
"name": "todo-mvc",
|
||||
|
|
Loading…
Add table
Reference in a new issue