mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Black
This commit is contained in:
@ -20,28 +20,27 @@ def exists(value):
|
||||
return value
|
||||
|
||||
|
||||
FIELD_SCHEMA = vol.Schema({
|
||||
vol.Required('description'): str,
|
||||
vol.Optional('example'): exists,
|
||||
vol.Optional('default'): exists,
|
||||
vol.Optional('values'): exists,
|
||||
vol.Optional('required'): bool,
|
||||
})
|
||||
FIELD_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("description"): str,
|
||||
vol.Optional("example"): exists,
|
||||
vol.Optional("default"): exists,
|
||||
vol.Optional("values"): exists,
|
||||
vol.Optional("required"): bool,
|
||||
}
|
||||
)
|
||||
|
||||
SERVICE_SCHEMA = vol.Schema({
|
||||
vol.Required('description'): str,
|
||||
vol.Optional('fields'): vol.Schema({
|
||||
str: FIELD_SCHEMA
|
||||
})
|
||||
})
|
||||
SERVICE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("description"): str,
|
||||
vol.Optional("fields"): vol.Schema({str: FIELD_SCHEMA}),
|
||||
}
|
||||
)
|
||||
|
||||
SERVICES_SCHEMA = vol.Schema({
|
||||
cv.slug: SERVICE_SCHEMA
|
||||
})
|
||||
SERVICES_SCHEMA = vol.Schema({cv.slug: SERVICE_SCHEMA})
|
||||
|
||||
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
-> bool:
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) -> bool:
|
||||
"""Recursively go through a dir and it's children and find the regex."""
|
||||
pattern = re.compile(search_pattern)
|
||||
|
||||
@ -58,29 +57,30 @@ def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
def validate_services(integration: Integration):
|
||||
"""Validate services."""
|
||||
# Find if integration uses services
|
||||
has_services = grep_dir(integration.path, "**/*.py",
|
||||
r"hass\.services\.(register|async_register)")
|
||||
has_services = grep_dir(
|
||||
integration.path, "**/*.py", r"hass\.services\.(register|async_register)"
|
||||
)
|
||||
|
||||
if not has_services:
|
||||
return
|
||||
|
||||
try:
|
||||
data = load_yaml(str(integration.path / 'services.yaml'))
|
||||
data = load_yaml(str(integration.path / "services.yaml"))
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
'services', 'Registers services but has no services.yaml')
|
||||
integration.add_error("services", "Registers services but has no services.yaml")
|
||||
return
|
||||
except HomeAssistantError:
|
||||
integration.add_error(
|
||||
'services', 'Registers services but unable to load services.yaml')
|
||||
"services", "Registers services but unable to load services.yaml"
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
SERVICES_SCHEMA(data)
|
||||
except vol.Invalid as err:
|
||||
integration.add_error(
|
||||
'services',
|
||||
"Invalid services.yaml: {}".format(humanize_error(data, err)))
|
||||
"services", "Invalid services.yaml: {}".format(humanize_error(data, err))
|
||||
)
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config):
|
||||
|
Reference in New Issue
Block a user