-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon_manager.py
More file actions
103 lines (94 loc) · 3.28 KB
/
addon_manager.py
File metadata and controls
103 lines (94 loc) · 3.28 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
import os
import json
from pathlib import Path
class AddonManager:
def __init__(self, addons_dir="addons"):
self.addons_dir = Path(addons_dir)
self.installed_addons = {}
def discover_available(self):
"""Find all available addons"""
available = []
for addon_path in self.addons_dir.iterdir():
if addon_path.is_dir() and (addon_path / "manifest.json").exists():
manifest = json.loads((addon_path / "manifest.json").read_text())
available.append({
"id": addon_path.name,
"name": manifest.get("name", addon_path.name),
"description": manifest.get("description", ""),
"installed": addon_path.name in self.installed_addons
})
return available
def install_addon(self, addon_id):
"""Install an addon by moving it to active"""
addon_path = self.addons_dir / addon_id
if addon_path.exists():
self.installed_addons[addon_id] = {
"path": addon_path,
"enabled": True
}
return True
return False
def uninstall_addon(self, addon_id):
"""Uninstall an addon"""
if addon_id in self.installed_addons:
del self.installed_addons[addon_id]
return True
return False
# Pre-built addon manifests
PREBUILT_ADDONS = {
"philips_hue": {
"name": "Philips Hue",
"description": "Control your Hue smart bulbs and bridges",
"version": "1.0.0",
"author": "HomeCore Team",
"requirements": ["requests"],
"config_flow": True
},
"sonoff": {
"name": "Sonoff",
"description": "Connect to Sonoff WiFi switches and sensors",
"version": "1.0.0",
"author": "HomeCore Team",
"requirements": ["requests"],
"config_flow": True
},
"mqtt": {
"name": "MQTT Broker",
"description": "Universal messaging for IoT devices",
"version": "1.0.0",
"author": "HomeCore Team",
"requirements": ["paho-mqtt"],
"config_flow": True
},
"zwave": {
"name": "Z-Wave",
"description": "Connect to Z-Wave mesh network devices",
"version": "1.0.0",
"author": "HomeCore Team",
"requirements": ["python-openzwave"],
"config_flow": True
},
"homebridge": {
"name": "Homebridge",
"description": "Bridge HomeKit accessories to HomeCore",
"version": "1.0.0",
"author": "HomeCore Team",
"requirements": ["pyhap"],
"config_flow": True
}
}
def create_manifest_files(addons_dir="addons"):
"""Create manifest files for all pre-built addons"""
addons_path = Path(addons_dir)
addons_path.mkdir(exist_ok=True)
for addon_id, manifest_data in PREBUILT_ADDONS.items():
addon_path = addons_path / addon_id
addon_path.mkdir(exist_ok=True)
manifest_file = addon_path / "manifest.json"
if not manifest_file.exists(): # Only create if doesn't exist
with open(manifest_file, 'w') as f:
json.dump(manifest_data, f, indent=2)
# Initialize the manager
addon_manager = AddonManager()
# Create initial manifests
create_manifest_files()