mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Make panel_custom backwards compatible (#36926)
This commit is contained in:
parent
212660330f
commit
263bdaa565
@ -38,18 +38,8 @@ def url_validator(value):
|
|||||||
has_html_url = CONF_WEBCOMPONENT_PATH in value
|
has_html_url = CONF_WEBCOMPONENT_PATH in value
|
||||||
has_module_url = CONF_MODULE_URL in value
|
has_module_url = CONF_MODULE_URL in value
|
||||||
|
|
||||||
if has_html_url:
|
if has_html_url and (has_js_url or has_module_url):
|
||||||
if has_js_url or has_module_url:
|
raise vol.Invalid("You cannot specify other urls besides a webcomponent path")
|
||||||
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."
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -165,6 +155,8 @@ async def async_setup(hass, config):
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
seen = set()
|
||||||
|
|
||||||
for panel in config[DOMAIN]:
|
for panel in config[DOMAIN]:
|
||||||
name = panel[CONF_COMPONENT_NAME]
|
name = panel[CONF_COMPONENT_NAME]
|
||||||
|
|
||||||
@ -185,7 +177,14 @@ async def async_setup(hass, config):
|
|||||||
if CONF_MODULE_URL in panel:
|
if CONF_MODULE_URL in panel:
|
||||||
kwargs["module_url"] = panel[CONF_MODULE_URL]
|
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)
|
panel_path = panel.get(CONF_WEBCOMPONENT_PATH)
|
||||||
|
|
||||||
if panel_path is None:
|
if panel_path is None:
|
||||||
|
@ -30,19 +30,22 @@ async def test_webcomponent_custom_path_not_found(hass):
|
|||||||
assert "nice_url" not in panels
|
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."""
|
"""Test if a web component is found in config panels dir."""
|
||||||
filename = "mock.file"
|
filename = "mock.file"
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
"panel_custom": {
|
"panel_custom": [
|
||||||
"name": "todo-mvc",
|
{
|
||||||
"webcomponent_path": filename,
|
"name": "todo-mvc",
|
||||||
"sidebar_title": "Sidebar Title",
|
"webcomponent_path": filename,
|
||||||
"sidebar_icon": "mdi:iconicon",
|
"sidebar_title": "Sidebar Title",
|
||||||
"url_path": "nice_url",
|
"sidebar_icon": "mdi:iconicon",
|
||||||
"config": {"hello": "world"},
|
"url_path": "nice_url",
|
||||||
}
|
"config": {"hello": "world"},
|
||||||
|
},
|
||||||
|
{"name": "todo-mvc"},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch("os.path.isfile", Mock(return_value=True)):
|
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_icon == "mdi:iconicon"
|
||||||
assert panel.sidebar_title == "Sidebar Title"
|
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):
|
async def test_js_webcomponent(hass):
|
||||||
"""Test if a web component is found in config panels dir."""
|
"""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):
|
async def test_url_option_conflict(hass):
|
||||||
"""Test config with multiple url options."""
|
"""Test config with multiple url options."""
|
||||||
to_try = [
|
to_try = [
|
||||||
{"panel_custom": {"name": "todo-mvc"}},
|
|
||||||
{
|
{
|
||||||
"panel_custom": {
|
"panel_custom": {
|
||||||
"name": "todo-mvc",
|
"name": "todo-mvc",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user