-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_config.py
More file actions
executable file
Β·138 lines (109 loc) Β· 3.84 KB
/
validate_config.py
File metadata and controls
executable file
Β·138 lines (109 loc) Β· 3.84 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
"""
Config validator for Home Assistant TUI.
Checks configuration files and connection before starting the app.
"""
import sys
from pathlib import Path
def validate():
"""Validate configuration and dependencies."""
print("π Home Assistant TUI Configuration Validator\n")
errors = []
warnings = []
# Check .env.prod
env_file = Path(".env")
if not env_file.exists():
errors.append("β .env not found")
else:
print("β .env.prod exists")
# Try to load it
try:
from dotenv import load_dotenv
import os
load_dotenv(env_file)
hass_url = os.getenv("HASS_URL")
hass_token = os.getenv("HASS_TOKEN")
if not hass_url:
errors.append("β HASS_URL not set in .env.prod")
else:
print(f"β HASS_URL: {hass_url}")
if not hass_token:
errors.append("β HASS_TOKEN not set in .env.prod")
else:
print(f"β HASS_TOKEN: {'*' * 20}... (hidden)")
except Exception as e:
errors.append(f"β Error loading .env.prod: {e}")
# Check config.yaml
config_file = Path("config.yaml")
if not config_file.exists():
errors.append("β config.yaml not found")
else:
print("β config.yaml exists")
try:
import yaml
with open(config_file) as f:
config = yaml.safe_load(f)
print(f"β config.yaml is valid YAML")
if "favorites" in config:
print(f" - {len(config['favorites'])} favorites configured")
if "filters" in config and "domains" in config["filters"]:
print(f" - {len(config['filters']['domains'])} domains filtered")
except Exception as e:
errors.append(f"β Error parsing config.yaml: {e}")
# Check user config
user_config = Path.home() / ".config" / "hass_tui" / "config.yaml"
if user_config.exists():
print(f"β User config found: {user_config}")
try:
import yaml
with open(user_config) as f:
user_cfg = yaml.safe_load(f)
print(f"β User config is valid YAML")
except Exception as e:
warnings.append(f"β οΈ Error parsing user config: {e}")
else:
print(f"βΉοΈ No user config (will use defaults): {user_config}")
# Check dependencies
print("\nπ¦ Checking dependencies...")
deps = ["textual", "websockets", "pydantic", "yaml", "dotenv"]
for dep in deps:
try:
if dep == "dotenv":
__import__("dotenv")
elif dep == "yaml":
__import__("yaml")
else:
__import__(dep)
print(f"β {dep}")
except ImportError:
errors.append(f"β Missing dependency: {dep}")
# Try to import the app
print("\nπ§ Checking app modules...")
try:
sys.path.insert(0, str(Path(__file__).parent))
from src.hass_tui import config
print("β config module")
except Exception as e:
errors.append(f"β Failed to import config: {e}")
try:
from src.hass_tui import app
print("β app module")
except Exception as e:
errors.append(f"β Failed to import app: {e}")
# Summary
print("\n" + "=" * 60)
if errors:
print(f"β VALIDATION FAILED - {len(errors)} error(s)")
for err in errors:
print(f" {err}")
else:
print("β
VALIDATION PASSED - Ready to run!")
if warnings:
print(f"\nβ οΈ {len(warnings)} warning(s):")
for warn in warnings:
print(f" {warn}")
print("=" * 60)
return len(errors) == 0
if __name__ == "__main__":
success = validate()
sys.exit(0 if success else 1)