mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Move single-use lovelace function (#136336)
This commit is contained in:
parent
dae4b53cb7
commit
8dba4affa9
@ -2,6 +2,7 @@
|
||||
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -17,6 +18,7 @@ from homeassistant.helpers import collection, config_validation as cv
|
||||
from homeassistant.helpers.service import async_register_admin_service
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import async_get_integration
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import dashboard, resources, websocket
|
||||
from .const import ( # noqa: F401
|
||||
@ -40,12 +42,25 @@ from .const import ( # noqa: F401
|
||||
SERVICE_RELOAD_RESOURCES,
|
||||
STORAGE_DASHBOARD_CREATE_FIELDS,
|
||||
STORAGE_DASHBOARD_UPDATE_FIELDS,
|
||||
url_slug,
|
||||
)
|
||||
from .system_health import system_health_info # noqa: F401
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _validate_url_slug(value: Any) -> str:
|
||||
"""Validate value is a valid url slug."""
|
||||
if value is None:
|
||||
raise vol.Invalid("Slug should not be None")
|
||||
if "-" not in value:
|
||||
raise vol.Invalid("Url path needs to contain a hyphen (-)")
|
||||
str_value = str(value)
|
||||
slg = slugify(str_value, separator="-")
|
||||
if str_value == slg:
|
||||
return str_value
|
||||
raise vol.Invalid(f"invalid slug {value} (try {slg})")
|
||||
|
||||
|
||||
CONF_DASHBOARDS = "dashboards"
|
||||
|
||||
YAML_DASHBOARD_SCHEMA = vol.Schema(
|
||||
@ -65,7 +80,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
),
|
||||
vol.Optional(CONF_DASHBOARDS): cv.schema_with_slug_keys(
|
||||
YAML_DASHBOARD_SCHEMA,
|
||||
slug_validator=url_slug,
|
||||
slug_validator=_validate_url_slug,
|
||||
),
|
||||
vol.Optional(CONF_RESOURCES): [RESOURCE_SCHEMA],
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -16,7 +16,6 @@ from homeassistant.const import (
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -91,18 +90,5 @@ STORAGE_DASHBOARD_CREATE_FIELDS: VolDictType = {
|
||||
STORAGE_DASHBOARD_UPDATE_FIELDS = DASHBOARD_BASE_UPDATE_FIELDS
|
||||
|
||||
|
||||
def url_slug(value: Any) -> str:
|
||||
"""Validate value is a valid url slug."""
|
||||
if value is None:
|
||||
raise vol.Invalid("Slug should not be None")
|
||||
if "-" not in value:
|
||||
raise vol.Invalid("Url path needs to contain a hyphen (-)")
|
||||
str_value = str(value)
|
||||
slg = slugify(str_value, separator="-")
|
||||
if str_value == slg:
|
||||
return str_value
|
||||
raise vol.Invalid(f"invalid slug {value} (try {slg})")
|
||||
|
||||
|
||||
class ConfigNotFound(HomeAssistantError):
|
||||
"""When no config available."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user