1
0
mirror of https://github.com/home-assistant/core.git synced 2025-10-09 11:49:27 +00:00
Files
.devcontainer
.github
.vscode
homeassistant
machine
pylint
rootfs
script
hassfest
json_schemas
scaffold
translations
__init__.py
alexa_locales.py
amazon_polly.py
bootstrap
check_dirty
check_format
const.py
countries.py
currencies.py
gen_requirements_all.py
inspect_schemas.py
install_integration_requirements.py
languages.py
licenses.py
lint
lint_and_test.py
microsoft_tts.py
monkeytype
quality_scale_summary.py
ruff.toml
run-in-env.sh
server
setup
split_tests.py
update
util.py
version_bump.py
tests
.core_files.yaml
.dockerignore
.git-blame-ignore-revs
.gitattributes
.gitignore
.hadolint.yaml
.pre-commit-config.yaml
.prettierignore
.strict-typing
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
build.yaml
codecov.yml
mypy.ini
pyproject.toml
requirements.txt
requirements_all.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
core/script/inspect_schemas.py
Alberto Montes 28ece89272 Update string formatting to use f-string on core codebase ()
* Update string formatting to use f-string on core codebase

* Small change given review feedback
2024-09-19 14:31:13 +02:00

67 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""Inspect all component SCHEMAS."""
import importlib
from pathlib import Path
import pkgutil
from homeassistant.config import _identify_config_schema
from homeassistant.scripts.check_config import color
def explore_module(package):
"""Explore the modules."""
module = importlib.import_module(package)
if not hasattr(module, "__path__"):
return []
for _, name, _ in pkgutil.iter_modules(module.__path__, f"{package}."):
yield name
def main():
"""Run the script."""
if not Path("requirements_all.txt").is_file():
print("Run this from HA root dir")
return
msg = {}
def add_msg(key, item):
"""Add a message."""
if key not in msg:
msg[key] = []
msg[key].append(item)
for package in explore_module("homeassistant.components"):
module = importlib.import_module(package)
module_name = getattr(module, "DOMAIN", module.__name__)
if hasattr(module, "PLATFORM_SCHEMA"):
if hasattr(module, "CONFIG_SCHEMA"):
add_msg(
"WARNING",
f"Module {module_name} contains PLATFORM and CONFIG schemas",
)
add_msg("PLATFORM SCHEMA", module_name)
continue
if not hasattr(module, "CONFIG_SCHEMA"):
add_msg("NO SCHEMA", module_name)
continue
schema_type, schema = _identify_config_schema(module)
add_msg(
f"CONFIG_SCHEMA {schema_type}",
f"{module_name} {color('cyan', str(schema)[:60])}",
)
for key in sorted(msg):
print(f"\n{key}")
for val in msg[key]:
print(f" - {val}")
if __name__ == "__main__":
main()