forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inspect_schemas.py
executable file
·66 lines (50 loc) · 1.73 KB
/
inspect_schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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()