Fix identifying Plex schema when used in packages (#34651)
parent
c93c6a66e8
commit
a2fab264c4
|
@ -559,12 +559,23 @@ def _log_pkg_error(package: str, component: str, config: Dict, message: str) ->
|
|||
|
||||
def _identify_config_schema(module: ModuleType) -> Optional[str]:
|
||||
"""Extract the schema and identify list or dict based."""
|
||||
try:
|
||||
key = next(k for k in module.CONFIG_SCHEMA.schema if k == module.DOMAIN) # type: ignore
|
||||
except (AttributeError, StopIteration):
|
||||
return None
|
||||
schema = module.CONFIG_SCHEMA.schema # type: ignore
|
||||
|
||||
schema = module.CONFIG_SCHEMA.schema[key] # type: ignore
|
||||
if isinstance(schema, vol.All):
|
||||
for subschema in schema.validators:
|
||||
if isinstance(subschema, dict):
|
||||
schema = subschema
|
||||
break
|
||||
else:
|
||||
return None
|
||||
|
||||
try:
|
||||
key = next(k for k in schema if k == module.DOMAIN) # type: ignore
|
||||
except (TypeError, AttributeError, StopIteration):
|
||||
return None
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected error identifying config schema")
|
||||
return None
|
||||
|
||||
if hasattr(key, "default") and not isinstance(
|
||||
key.default, vol.schema_builder.Undefined
|
||||
|
@ -581,7 +592,9 @@ def _identify_config_schema(module: ModuleType) -> Optional[str]:
|
|||
|
||||
return None
|
||||
|
||||
t_schema = str(schema)
|
||||
domain_schema = schema[key]
|
||||
|
||||
t_schema = str(domain_schema)
|
||||
if t_schema.startswith("{") or "schema_with_slug_keys" in t_schema:
|
||||
return "dict"
|
||||
if t_schema.startswith(("[", "All(<function ensure_list")):
|
||||
|
|
|
@ -1012,6 +1012,7 @@ async def test_component_config_exceptions(hass, caplog):
|
|||
("not_existing", vol.Schema({vol.Optional("zone", default=dict): dict}), None,),
|
||||
("non_existing", vol.Schema({"zone": int}), None),
|
||||
("zone", vol.Schema({}), None),
|
||||
("plex", vol.Schema(vol.All({"plex": {"host": str}})), "dict"),
|
||||
],
|
||||
)
|
||||
def test_identify_config_schema(domain, schema, expected):
|
||||
|
|
Loading…
Reference in New Issue