@switchbot/homebridge-switchbot 5.0.0-beta.107 → 5.0.0-beta.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TODO.md +564 -0
- package/config.schema.json +100 -25
- package/dist/device-types.d.ts +15 -0
- package/dist/device-types.d.ts.map +1 -0
- package/dist/device-types.js +145 -0
- package/dist/device-types.js.map +1 -0
- package/dist/deviceFactory.d.ts +1 -1
- package/dist/deviceFactory.d.ts.map +1 -1
- package/dist/deviceFactory.js +55 -17
- package/dist/deviceFactory.js.map +1 -1
- package/dist/devices/genericDevice.d.ts +1 -1
- package/dist/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +4 -2
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/homebridge-ui/endpoints/config.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/config.js +73 -0
- package/dist/homebridge-ui/endpoints/config.js.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.js +65 -0
- package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.js +285 -0
- package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.js +171 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/index.html +144 -588
- package/dist/homebridge-ui/public/js/api.d.ts +15 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +164 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +189 -0
- package/dist/homebridge-ui/public/js/app.d.ts +2 -0
- package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/app.js +1069 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +21 -0
- package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
- package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/constants.js +2 -0
- package/dist/homebridge-ui/public/js/constants.js.map +1 -0
- package/dist/homebridge-ui/public/js/constants.ts +1 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.js +96 -0
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.ts +100 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts +2 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.js +99 -0
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.ts +113 -0
- package/dist/homebridge-ui/public/js/devices.d.ts +8 -0
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices.js +71 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +78 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +107 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +123 -0
- package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
- package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/logger.js +12 -0
- package/dist/homebridge-ui/public/js/logger.js.map +1 -0
- package/dist/homebridge-ui/public/js/logger.ts +11 -0
- package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
- package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modal.js +26 -0
- package/dist/homebridge-ui/public/js/modal.js.map +1 -0
- package/dist/homebridge-ui/public/js/modal.ts +28 -0
- package/dist/homebridge-ui/public/js/modals.d.ts +2 -0
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modals.js +132 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +153 -0
- package/dist/homebridge-ui/public/js/render.d.ts +6 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +166 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +190 -0
- package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
- package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/toast.js +29 -0
- package/dist/homebridge-ui/public/js/toast.js.map +1 -0
- package/dist/homebridge-ui/public/js/toast.ts +37 -0
- package/dist/homebridge-ui/public/js/types.d.ts +23 -0
- package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/types.js +2 -0
- package/dist/homebridge-ui/public/js/types.js.map +1 -0
- package/dist/homebridge-ui/public/js/types.ts +26 -0
- package/dist/homebridge-ui/server.d.ts +1 -3
- package/dist/homebridge-ui/server.d.ts.map +1 -1
- package/dist/homebridge-ui/server.js +10 -561
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.js +87 -0
- package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/utils/logger.d.ts +7 -0
- package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/logger.js +17 -0
- package/dist/homebridge-ui/utils/logger.js.map +1 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +6 -2
- package/dist/platform.js.map +1 -1
- package/dist/switchbotClient.d.ts.map +1 -1
- package/dist/switchbotClient.js +2 -0
- package/dist/switchbotClient.js.map +1 -1
- package/docs/variables/default.html +1 -1
- package/eslint.config.js +5 -0
- package/nodemon.json +2 -2
- package/package.json +20 -10
- package/scripts/build-ui.js +36 -0
- package/scripts/free-dev-ports.mjs +105 -0
- package/scripts/sync-device-types.mjs +28 -0
- package/src/device-types.ts +145 -0
- package/src/deviceFactory.ts +71 -31
- package/src/devices/genericDevice.ts +5 -2
- package/src/homebridge-ui/endpoints/config.ts +79 -0
- package/src/homebridge-ui/endpoints/credentials.ts +74 -0
- package/src/homebridge-ui/endpoints/devices.ts +321 -0
- package/src/homebridge-ui/endpoints/discovery.ts +191 -0
- package/src/homebridge-ui/public/index.html +144 -588
- package/src/homebridge-ui/public/js/api.ts +189 -0
- package/src/homebridge-ui/public/js/app.ts +21 -0
- package/src/homebridge-ui/public/js/constants.ts +1 -0
- package/src/homebridge-ui/public/js/credentials.ts +100 -0
- package/src/homebridge-ui/public/js/devices-delete.ts +113 -0
- package/src/homebridge-ui/public/js/devices.ts +78 -0
- package/src/homebridge-ui/public/js/discovery.ts +123 -0
- package/src/homebridge-ui/public/js/logger.ts +11 -0
- package/src/homebridge-ui/public/js/modal.ts +28 -0
- package/src/homebridge-ui/public/js/modals.ts +153 -0
- package/src/homebridge-ui/public/js/render.ts +190 -0
- package/src/homebridge-ui/public/js/toast.ts +37 -0
- package/src/homebridge-ui/public/js/types.ts +26 -0
- package/src/homebridge-ui/server.ts +11 -647
- package/src/homebridge-ui/utils/config-parser.ts +108 -0
- package/src/homebridge-ui/utils/logger.ts +17 -0
- package/src/platform.ts +6 -2
- package/src/switchbotClient.ts +2 -0
- package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
|
@@ -0,0 +1,1069 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/homebridge-ui/public/js/types.ts
|
|
12
|
+
var init_types = __esm({
|
|
13
|
+
"src/homebridge-ui/public/js/types.ts"() {
|
|
14
|
+
"use strict";
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// src/homebridge-ui/public/js/logger.ts
|
|
19
|
+
var uiLog;
|
|
20
|
+
var init_logger = __esm({
|
|
21
|
+
"src/homebridge-ui/public/js/logger.ts"() {
|
|
22
|
+
"use strict";
|
|
23
|
+
uiLog = {
|
|
24
|
+
info: (message, ...parameters) => {
|
|
25
|
+
console.warn("[SwitchBot UI]", message, ...parameters);
|
|
26
|
+
},
|
|
27
|
+
warn: (message, ...parameters) => {
|
|
28
|
+
console.warn("[SwitchBot UI]", message, ...parameters);
|
|
29
|
+
},
|
|
30
|
+
error: (message, ...parameters) => {
|
|
31
|
+
console.error("[SwitchBot UI]", message, ...parameters);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/homebridge-ui/public/js/api.ts
|
|
38
|
+
var api_exports = {};
|
|
39
|
+
__export(api_exports, {
|
|
40
|
+
addDevice: () => addDevice,
|
|
41
|
+
addDevicesInBulk: () => addDevicesInBulk,
|
|
42
|
+
deleteDevice: () => deleteDevice,
|
|
43
|
+
discoverDevices: () => discoverDevices,
|
|
44
|
+
fetchCredentialStatus: () => fetchCredentialStatus,
|
|
45
|
+
fetchDevices: () => fetchDevices,
|
|
46
|
+
saveCredentials: () => saveCredentials,
|
|
47
|
+
syncParentPluginConfigFromDisk: () => syncParentPluginConfigFromDisk,
|
|
48
|
+
updateDevice: () => updateDevice
|
|
49
|
+
});
|
|
50
|
+
function isSwitchBotPlatformConfig(block) {
|
|
51
|
+
const platformName = String(block?.platform || block?.name || "").toLowerCase();
|
|
52
|
+
return platformName === "switchbot" || platformName === "@switchbot/homebridge-switchbot" || platformName.includes("switchbot");
|
|
53
|
+
}
|
|
54
|
+
async function syncParentPluginConfigFromDisk(autoSave = false) {
|
|
55
|
+
try {
|
|
56
|
+
if (typeof homebridge.getPluginConfig !== "function" || typeof homebridge.updatePluginConfig !== "function") {
|
|
57
|
+
uiLog.warn("Parent config sync API not available");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const diskResp = await homebridge.request("/platform-config", {});
|
|
61
|
+
if (!diskResp || diskResp.success === false || !diskResp.data) {
|
|
62
|
+
uiLog.warn("Failed to fetch fresh platform config from disk");
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const pluginConfigBlocks = await homebridge.getPluginConfig();
|
|
66
|
+
if (!Array.isArray(pluginConfigBlocks) || !pluginConfigBlocks.length) {
|
|
67
|
+
uiLog.warn("No plugin config blocks returned from Homebridge");
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const index = pluginConfigBlocks.findIndex((block) => isSwitchBotPlatformConfig(block));
|
|
71
|
+
if (index < 0) {
|
|
72
|
+
uiLog.warn("SwitchBot platform block not found in Homebridge plugin config");
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
pluginConfigBlocks[index] = diskResp.data;
|
|
76
|
+
await homebridge.updatePluginConfig(pluginConfigBlocks);
|
|
77
|
+
if (autoSave && typeof homebridge.savePluginConfig === "function") {
|
|
78
|
+
uiLog.info("Auto-saving config to disk...");
|
|
79
|
+
await homebridge.savePluginConfig();
|
|
80
|
+
uiLog.info("Config saved successfully");
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
} catch (e) {
|
|
84
|
+
uiLog.warn("Failed to sync parent plugin config cache:", e);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function fetchCredentialStatus() {
|
|
89
|
+
try {
|
|
90
|
+
const resp = await homebridge.request("/credentials", {});
|
|
91
|
+
uiLog.info("Load credentials response:", resp);
|
|
92
|
+
if (!resp || resp.success === false) {
|
|
93
|
+
uiLog.error("Failed to load credentials:", resp);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return resp.data || {};
|
|
97
|
+
} catch (e) {
|
|
98
|
+
uiLog.error("Error loading credentials:", e);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function saveCredentials(token, secret) {
|
|
103
|
+
try {
|
|
104
|
+
uiLog.info("Saving credentials...");
|
|
105
|
+
const resp = await homebridge.request("/credentials", { token, secret });
|
|
106
|
+
uiLog.info("Save response:", resp);
|
|
107
|
+
if (!resp || resp.success === false) {
|
|
108
|
+
throw new Error(resp?.message || "Save failed");
|
|
109
|
+
}
|
|
110
|
+
return resp.data || resp;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function fetchDevices() {
|
|
116
|
+
try {
|
|
117
|
+
const resp = await homebridge.request("/devices", {});
|
|
118
|
+
if (!resp || resp.success === false) {
|
|
119
|
+
throw new Error(resp?.data?.message || "request failed");
|
|
120
|
+
}
|
|
121
|
+
return resp.data || [];
|
|
122
|
+
} catch (e) {
|
|
123
|
+
uiLog.error("Error fetching devices:", e);
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function discoverDevices() {
|
|
128
|
+
try {
|
|
129
|
+
const resp = await homebridge.request("/discover", {});
|
|
130
|
+
uiLog.info("Discover response:", resp);
|
|
131
|
+
if (!resp || resp.success === false) {
|
|
132
|
+
throw new Error(resp?.data?.message || "Discovery failed");
|
|
133
|
+
}
|
|
134
|
+
return resp.data || [];
|
|
135
|
+
} catch (e) {
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function addDevice(deviceId, name, type) {
|
|
140
|
+
try {
|
|
141
|
+
uiLog.info("Adding device to config:", { deviceId, name, type });
|
|
142
|
+
const resp = await homebridge.request("/add-device", { deviceId, name, type });
|
|
143
|
+
uiLog.info("Add device response:", resp);
|
|
144
|
+
if (!resp || resp.success === false) {
|
|
145
|
+
throw new Error(resp?.data?.message || "Failed to add device");
|
|
146
|
+
}
|
|
147
|
+
return resp.data || resp;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function addDevicesInBulk(devices) {
|
|
153
|
+
try {
|
|
154
|
+
const resp = await homebridge.request("/add-devices", { devices });
|
|
155
|
+
uiLog.info("Bulk add response:", resp);
|
|
156
|
+
if (!resp || resp.success === false) {
|
|
157
|
+
throw new Error(resp?.data?.message || "Bulk add failed");
|
|
158
|
+
}
|
|
159
|
+
return resp.data || resp;
|
|
160
|
+
} catch (e) {
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function updateDevice(deviceId, configDeviceName, configDeviceType) {
|
|
165
|
+
try {
|
|
166
|
+
const params = { deviceId };
|
|
167
|
+
if (configDeviceName) {
|
|
168
|
+
params.configDeviceName = configDeviceName;
|
|
169
|
+
}
|
|
170
|
+
if (configDeviceType) {
|
|
171
|
+
params.configDeviceType = configDeviceType;
|
|
172
|
+
}
|
|
173
|
+
uiLog.info("[Update Device] Sending update request with params:", params);
|
|
174
|
+
const resp = await homebridge.request("/update-device", params);
|
|
175
|
+
uiLog.info("[Update Device] Update response:", resp);
|
|
176
|
+
if (!resp || resp.success === false) {
|
|
177
|
+
throw new Error(resp?.data?.message || "Failed to update device");
|
|
178
|
+
}
|
|
179
|
+
return resp.data || resp;
|
|
180
|
+
} catch (e) {
|
|
181
|
+
throw e;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function deleteDevice(deviceId) {
|
|
185
|
+
try {
|
|
186
|
+
uiLog.info("Sending delete request for deviceId:", deviceId);
|
|
187
|
+
const resp = await homebridge.request("/delete-device", { deviceId });
|
|
188
|
+
uiLog.info("Delete response:", resp);
|
|
189
|
+
if (!resp || resp.success === false) {
|
|
190
|
+
throw new Error(resp?.data?.message || "Failed to delete device");
|
|
191
|
+
}
|
|
192
|
+
return resp.data || resp;
|
|
193
|
+
} catch (e) {
|
|
194
|
+
throw e;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
var init_api = __esm({
|
|
198
|
+
"src/homebridge-ui/public/js/api.ts"() {
|
|
199
|
+
"use strict";
|
|
200
|
+
init_types();
|
|
201
|
+
init_logger();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// src/homebridge-ui/public/js/modal.ts
|
|
206
|
+
function callUiMethod(name) {
|
|
207
|
+
try {
|
|
208
|
+
const value = homebridge?.[name];
|
|
209
|
+
if (typeof value === "function") {
|
|
210
|
+
const fn = value;
|
|
211
|
+
fn();
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
uiLog.warn(`Homebridge UI method ${String(name)} failed:`, e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function showBusyUi() {
|
|
218
|
+
callUiMethod("disableSaveButton");
|
|
219
|
+
callUiMethod("showSpinner");
|
|
220
|
+
}
|
|
221
|
+
function hideBusyUi() {
|
|
222
|
+
callUiMethod("hideSpinner");
|
|
223
|
+
callUiMethod("enableSaveButton");
|
|
224
|
+
}
|
|
225
|
+
var init_modal = __esm({
|
|
226
|
+
"src/homebridge-ui/public/js/modal.ts"() {
|
|
227
|
+
"use strict";
|
|
228
|
+
init_types();
|
|
229
|
+
init_logger();
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// src/homebridge-ui/public/js/toast.ts
|
|
234
|
+
function showToast(method, message, title = "SwitchBot") {
|
|
235
|
+
try {
|
|
236
|
+
const toast = homebridge?.toast;
|
|
237
|
+
const fn = toast?.[method];
|
|
238
|
+
if (typeof fn === "function") {
|
|
239
|
+
fn(message, title);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
uiLog.info(`[Toast:${method}] ${title} - ${message}`);
|
|
243
|
+
} catch (e) {
|
|
244
|
+
uiLog.warn(`Toast ${method} failed:`, e);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function toastSuccess(message, title) {
|
|
248
|
+
showToast("success", message, title);
|
|
249
|
+
}
|
|
250
|
+
function toastError(message, title) {
|
|
251
|
+
showToast("error", message, title);
|
|
252
|
+
}
|
|
253
|
+
function toastWarning(message, title) {
|
|
254
|
+
showToast("warning", message, title);
|
|
255
|
+
}
|
|
256
|
+
function toastInfo(message, title) {
|
|
257
|
+
showToast("info", message, title);
|
|
258
|
+
}
|
|
259
|
+
var init_toast = __esm({
|
|
260
|
+
"src/homebridge-ui/public/js/toast.ts"() {
|
|
261
|
+
"use strict";
|
|
262
|
+
init_types();
|
|
263
|
+
init_logger();
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// src/homebridge-ui/public/js/discovery.ts
|
|
268
|
+
var discovery_exports = {};
|
|
269
|
+
__export(discovery_exports, {
|
|
270
|
+
addDeviceToConfig: () => addDeviceToConfig,
|
|
271
|
+
discoverDevices: () => discoverDevices2
|
|
272
|
+
});
|
|
273
|
+
async function discoverDevices2() {
|
|
274
|
+
const btn = document.getElementById("discoverBtn");
|
|
275
|
+
const status = document.getElementById("discoverStatus");
|
|
276
|
+
const list = document.getElementById("discoveredList");
|
|
277
|
+
const autoAddAll = document.getElementById("autoAddAllCheckbox")?.checked;
|
|
278
|
+
if (!btn || !status || !list) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
showBusyUi();
|
|
283
|
+
btn.disabled = true;
|
|
284
|
+
btn.textContent = "\u{1F50D} Discovering...";
|
|
285
|
+
status.textContent = "Searching SwitchBot account...";
|
|
286
|
+
status.classList.remove("error");
|
|
287
|
+
const devicesRaw = await discoverDevices();
|
|
288
|
+
uiLog.info("Discover response:", devicesRaw);
|
|
289
|
+
const devices = devicesRaw.filter((d, index, arr) => !!d?.id && arr.findIndex((x) => x?.id === d.id) === index);
|
|
290
|
+
if (!devices.length) {
|
|
291
|
+
status.textContent = "No devices found in your SwitchBot account";
|
|
292
|
+
toastInfo("No devices found in your SwitchBot account");
|
|
293
|
+
list.style.display = "none";
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (autoAddAll) {
|
|
297
|
+
status.textContent = `Auto-adding ${devices.length} device(s)...`;
|
|
298
|
+
try {
|
|
299
|
+
const bulkResult = await addDevicesInBulk(
|
|
300
|
+
devices.map((d) => ({
|
|
301
|
+
deviceId: d.id,
|
|
302
|
+
name: d.name,
|
|
303
|
+
type: d.type
|
|
304
|
+
}))
|
|
305
|
+
);
|
|
306
|
+
uiLog.info("Bulk add response:", bulkResult);
|
|
307
|
+
if (!bulkResult || bulkResult.success === false) {
|
|
308
|
+
throw new Error(bulkResult?.data?.message || "Bulk add failed");
|
|
309
|
+
}
|
|
310
|
+
const addedCount = bulkResult?.addedCount ?? bulkResult?.data?.addedCount ?? 0;
|
|
311
|
+
const skippedCount = bulkResult?.skippedCount ?? bulkResult?.data?.skippedCount ?? 0;
|
|
312
|
+
status.textContent = `\u2713 Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`;
|
|
313
|
+
if (addedCount > 0) {
|
|
314
|
+
toastSuccess(`Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`);
|
|
315
|
+
} else if (skippedCount > 0) {
|
|
316
|
+
toastWarning(`No new devices were added (${skippedCount} skipped)`);
|
|
317
|
+
}
|
|
318
|
+
status.classList.remove("error");
|
|
319
|
+
list.style.display = "none";
|
|
320
|
+
if (devices.length > 0) {
|
|
321
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
322
|
+
status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
|
|
323
|
+
if (synced) {
|
|
324
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
325
|
+
} else {
|
|
326
|
+
toastWarning("Configuration sync failed; close and reopen settings before Save");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} catch (e) {
|
|
330
|
+
uiLog.error("Bulk add error:", e);
|
|
331
|
+
status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add devices"}`;
|
|
332
|
+
status.classList.add("error");
|
|
333
|
+
toastError(e instanceof Error ? e.message : "Failed to add devices");
|
|
334
|
+
}
|
|
335
|
+
await loadConfiguredDevices();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
status.textContent = `Found ${devices.length} device(s)`;
|
|
339
|
+
const ul = await renderDiscoveredDevices(devices);
|
|
340
|
+
document.getElementById("discoveredDevices")?.replaceWith(ul);
|
|
341
|
+
ul.id = "discoveredDevices";
|
|
342
|
+
list.style.display = "block";
|
|
343
|
+
} catch (e) {
|
|
344
|
+
uiLog.error("Discovery error:", e);
|
|
345
|
+
status.textContent = `Error: ${e instanceof Error ? e.message : "Discovery failed"}`;
|
|
346
|
+
status.classList.add("error");
|
|
347
|
+
toastError(e instanceof Error ? e.message : "Discovery failed");
|
|
348
|
+
list.style.display = "none";
|
|
349
|
+
} finally {
|
|
350
|
+
hideBusyUi();
|
|
351
|
+
btn.disabled = false;
|
|
352
|
+
btn.textContent = "\u{1F50D} Discover Devices";
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function addDeviceToConfig(device) {
|
|
356
|
+
const { addDeviceToConfig: addDevice2 } = await Promise.resolve().then(() => (init_devices(), devices_exports));
|
|
357
|
+
await addDevice2(device);
|
|
358
|
+
}
|
|
359
|
+
var init_discovery = __esm({
|
|
360
|
+
"src/homebridge-ui/public/js/discovery.ts"() {
|
|
361
|
+
"use strict";
|
|
362
|
+
init_api();
|
|
363
|
+
init_devices();
|
|
364
|
+
init_logger();
|
|
365
|
+
init_modal();
|
|
366
|
+
init_render();
|
|
367
|
+
init_toast();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// src/device-types.ts
|
|
372
|
+
var DEVICE_TYPES;
|
|
373
|
+
var init_device_types = __esm({
|
|
374
|
+
"src/device-types.ts"() {
|
|
375
|
+
"use strict";
|
|
376
|
+
DEVICE_TYPES = {
|
|
377
|
+
"Window Coverings": ["Blind Tilt", "Curtain", "Curtain3", "Roller Shade"],
|
|
378
|
+
"Locks & Access": [
|
|
379
|
+
"Keypad",
|
|
380
|
+
"Keypad Touch",
|
|
381
|
+
"Keypad Vision",
|
|
382
|
+
"Keypad Vision Pro",
|
|
383
|
+
"Lock Lite",
|
|
384
|
+
"Smart Lock",
|
|
385
|
+
"Smart Lock Pro",
|
|
386
|
+
"Smart Lock Ultra",
|
|
387
|
+
"Video Doorbell"
|
|
388
|
+
],
|
|
389
|
+
"Sensors": ["Contact Sensor", "Motion Sensor", "Presence Sensor", "Water Detector"],
|
|
390
|
+
"Lighting": [
|
|
391
|
+
"Candle Warmer Lamp",
|
|
392
|
+
"Ceiling Light",
|
|
393
|
+
"Ceiling Light Pro",
|
|
394
|
+
"Color Bulb",
|
|
395
|
+
"Floor Lamp",
|
|
396
|
+
"RGBIC Neon Rope Light",
|
|
397
|
+
"RGBIC Neon Wire Rope Light",
|
|
398
|
+
"RGBICWW Floor Lamp",
|
|
399
|
+
"RGBICWW Strip Light",
|
|
400
|
+
"Strip Light",
|
|
401
|
+
"Strip Light 3"
|
|
402
|
+
],
|
|
403
|
+
"Climate Control": [
|
|
404
|
+
"Air Purifier PM2.5",
|
|
405
|
+
"Air Purifier Table PM2.5",
|
|
406
|
+
"Air Purifier VOC",
|
|
407
|
+
"Air Purifier Table VOC",
|
|
408
|
+
"Battery Circulator Fan",
|
|
409
|
+
"Circulator Fan",
|
|
410
|
+
"Humidifier",
|
|
411
|
+
"Humidifier2",
|
|
412
|
+
"Meter",
|
|
413
|
+
"MeterPlus",
|
|
414
|
+
"MeterPro",
|
|
415
|
+
"MeterPro(CO2)",
|
|
416
|
+
"Smart Radiator Thermostat",
|
|
417
|
+
"Standing Circulator Fan",
|
|
418
|
+
"WoIOSensor"
|
|
419
|
+
],
|
|
420
|
+
"Plugs & Switches": [
|
|
421
|
+
"Garage Door Opener",
|
|
422
|
+
"Plug",
|
|
423
|
+
"Plug Mini (EU)",
|
|
424
|
+
"Plug Mini (JP)",
|
|
425
|
+
"Plug Mini (US)",
|
|
426
|
+
"Relay Switch 1",
|
|
427
|
+
"Relay Switch 1PM",
|
|
428
|
+
"Relay Switch 2PM"
|
|
429
|
+
],
|
|
430
|
+
"Robot Vacuums": [
|
|
431
|
+
"K10+",
|
|
432
|
+
"K10+ Pro",
|
|
433
|
+
"Robot Vacuum Cleaner K10+ Pro Combo",
|
|
434
|
+
"Robot Vacuum Cleaner K11+",
|
|
435
|
+
"Robot Vacuum Cleaner K20 Plus Pro",
|
|
436
|
+
"Robot Vacuum Cleaner S1",
|
|
437
|
+
"Robot Vacuum Cleaner S1 Plus",
|
|
438
|
+
"Robot Vacuum Cleaner S10",
|
|
439
|
+
"Robot Vacuum Cleaner S20"
|
|
440
|
+
],
|
|
441
|
+
"Hubs": ["AI Hub", "Hub", "Hub 2", "Hub 3", "Hub Mini", "Hub Plus"],
|
|
442
|
+
"Cameras": [
|
|
443
|
+
"Indoor Cam",
|
|
444
|
+
"Pan/Tilt Cam",
|
|
445
|
+
"Pan/Tilt Cam 2K",
|
|
446
|
+
"Pan/Tilt Cam Plus 2K",
|
|
447
|
+
"Pan/Tilt Cam Plus 3K"
|
|
448
|
+
],
|
|
449
|
+
"IR Devices": [
|
|
450
|
+
"Air Conditioner",
|
|
451
|
+
"Air Purifier",
|
|
452
|
+
"Camera",
|
|
453
|
+
"DVD",
|
|
454
|
+
"Fan",
|
|
455
|
+
"Light",
|
|
456
|
+
"Others",
|
|
457
|
+
"Projector",
|
|
458
|
+
"Set Top Box",
|
|
459
|
+
"Speaker",
|
|
460
|
+
"Streamer",
|
|
461
|
+
"TV",
|
|
462
|
+
"Vacuum Cleaner",
|
|
463
|
+
"Water Heater"
|
|
464
|
+
],
|
|
465
|
+
"Other Devices": ["AI Art Frame", "Bot", "Home Climate Panel", "Remote", "remote with screen"]
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// src/homebridge-ui/public/js/constants.ts
|
|
471
|
+
var init_constants = __esm({
|
|
472
|
+
"src/homebridge-ui/public/js/constants.ts"() {
|
|
473
|
+
"use strict";
|
|
474
|
+
init_device_types();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// src/homebridge-ui/public/js/modals.ts
|
|
479
|
+
var modals_exports = {};
|
|
480
|
+
__export(modals_exports, {
|
|
481
|
+
editDevice: () => editDevice
|
|
482
|
+
});
|
|
483
|
+
async function editDevice(device) {
|
|
484
|
+
const div = document.createElement("div");
|
|
485
|
+
div.style.position = "fixed";
|
|
486
|
+
div.style.top = "0";
|
|
487
|
+
div.style.left = "0";
|
|
488
|
+
div.style.width = "100%";
|
|
489
|
+
div.style.height = "100%";
|
|
490
|
+
div.style.background = "rgba(0,0,0,0.7)";
|
|
491
|
+
div.style.display = "flex";
|
|
492
|
+
div.style.alignItems = "center";
|
|
493
|
+
div.style.justifyContent = "center";
|
|
494
|
+
div.style.zIndex = "9999";
|
|
495
|
+
const modal = document.createElement("div");
|
|
496
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
497
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
498
|
+
modal.style.padding = "24px";
|
|
499
|
+
modal.style.borderRadius = "8px";
|
|
500
|
+
modal.style.minWidth = "400px";
|
|
501
|
+
modal.style.boxShadow = "0 10px 40px rgba(0,0,0,0.3)";
|
|
502
|
+
const title = document.createElement("h3");
|
|
503
|
+
title.textContent = "Edit Device";
|
|
504
|
+
title.style.marginTop = "0";
|
|
505
|
+
const nameLabel = document.createElement("label");
|
|
506
|
+
nameLabel.textContent = "Device Name";
|
|
507
|
+
nameLabel.style.display = "block";
|
|
508
|
+
nameLabel.style.marginBottom = "8px";
|
|
509
|
+
nameLabel.style.fontWeight = "500";
|
|
510
|
+
const nameInput = document.createElement("input");
|
|
511
|
+
nameInput.type = "text";
|
|
512
|
+
nameInput.value = device.name || device.id;
|
|
513
|
+
nameInput.style.width = "100%";
|
|
514
|
+
nameInput.style.marginBottom = "16px";
|
|
515
|
+
const apiTypeLabel = document.createElement("label");
|
|
516
|
+
apiTypeLabel.textContent = "Device Type (API - Read Only)";
|
|
517
|
+
apiTypeLabel.style.display = "block";
|
|
518
|
+
apiTypeLabel.style.marginBottom = "8px";
|
|
519
|
+
apiTypeLabel.style.fontWeight = "500";
|
|
520
|
+
const apiTypeInput = document.createElement("input");
|
|
521
|
+
apiTypeInput.type = "text";
|
|
522
|
+
apiTypeInput.value = device.deviceType || device.type || "Unknown";
|
|
523
|
+
apiTypeInput.readOnly = true;
|
|
524
|
+
apiTypeInput.style.width = "100%";
|
|
525
|
+
apiTypeInput.style.marginBottom = "16px";
|
|
526
|
+
apiTypeInput.style.opacity = "0.6";
|
|
527
|
+
apiTypeInput.style.cursor = "not-allowed";
|
|
528
|
+
const typeLabel = document.createElement("label");
|
|
529
|
+
typeLabel.textContent = "Config Device Type (Override)";
|
|
530
|
+
typeLabel.style.display = "block";
|
|
531
|
+
typeLabel.style.marginBottom = "8px";
|
|
532
|
+
typeLabel.style.fontWeight = "500";
|
|
533
|
+
const typeSelect = document.createElement("select");
|
|
534
|
+
typeSelect.style.width = "100%";
|
|
535
|
+
typeSelect.style.padding = "8px";
|
|
536
|
+
typeSelect.style.marginBottom = "16px";
|
|
537
|
+
typeSelect.style.borderRadius = "4px";
|
|
538
|
+
typeSelect.style.background = getComputedStyle(nameInput).background;
|
|
539
|
+
typeSelect.style.color = getComputedStyle(nameInput).color;
|
|
540
|
+
typeSelect.style.border = getComputedStyle(nameInput).border;
|
|
541
|
+
Object.keys(DEVICE_TYPES).forEach((categoryName) => {
|
|
542
|
+
const optgroup = document.createElement("optgroup");
|
|
543
|
+
optgroup.label = categoryName;
|
|
544
|
+
DEVICE_TYPES[categoryName].forEach((deviceType) => {
|
|
545
|
+
const opt = document.createElement("option");
|
|
546
|
+
opt.value = deviceType;
|
|
547
|
+
opt.text = deviceType;
|
|
548
|
+
const currentType = device.configDeviceType || device.deviceType || device.type || "";
|
|
549
|
+
opt.selected = currentType === deviceType;
|
|
550
|
+
optgroup.appendChild(opt);
|
|
551
|
+
});
|
|
552
|
+
typeSelect.appendChild(optgroup);
|
|
553
|
+
});
|
|
554
|
+
const buttons = document.createElement("div");
|
|
555
|
+
buttons.style.display = "flex";
|
|
556
|
+
buttons.style.gap = "8px";
|
|
557
|
+
buttons.style.justifyContent = "flex-end";
|
|
558
|
+
const errorMessage = document.createElement("div");
|
|
559
|
+
errorMessage.style.color = "#ef4444";
|
|
560
|
+
errorMessage.style.marginBottom = "12px";
|
|
561
|
+
errorMessage.style.fontSize = "12px";
|
|
562
|
+
errorMessage.style.display = "none";
|
|
563
|
+
const cancelBtn = document.createElement("button");
|
|
564
|
+
cancelBtn.textContent = "Cancel";
|
|
565
|
+
cancelBtn.style.background = "#666";
|
|
566
|
+
cancelBtn.onclick = () => div.remove();
|
|
567
|
+
const saveBtn = document.createElement("button");
|
|
568
|
+
saveBtn.textContent = "Save";
|
|
569
|
+
saveBtn.onclick = async () => {
|
|
570
|
+
try {
|
|
571
|
+
const { updateDevice: updateDevice2, syncParentPluginConfigFromDisk: syncParentPluginConfigFromDisk2, fetchDevices: fetchDevices3 } = await Promise.resolve().then(() => (init_api(), api_exports));
|
|
572
|
+
const { renderDeviceList: renderDeviceList2 } = await Promise.resolve().then(() => (init_render(), render_exports));
|
|
573
|
+
const params = {
|
|
574
|
+
deviceId: device.id,
|
|
575
|
+
configDeviceName: nameInput.value || void 0,
|
|
576
|
+
configDeviceType: typeSelect.value
|
|
577
|
+
};
|
|
578
|
+
await updateDevice2(params.deviceId, params.configDeviceName, params.configDeviceType);
|
|
579
|
+
await syncParentPluginConfigFromDisk2();
|
|
580
|
+
uiLog.info("[Edit Device] Refreshing device list after update");
|
|
581
|
+
const list = await fetchDevices3();
|
|
582
|
+
renderDeviceList2(list);
|
|
583
|
+
div.remove();
|
|
584
|
+
} catch (e) {
|
|
585
|
+
uiLog.error("Update error:", e);
|
|
586
|
+
errorMessage.textContent = `Error: ${e instanceof Error ? e.message : "Failed to update device"}`;
|
|
587
|
+
errorMessage.style.display = "block";
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
buttons.appendChild(cancelBtn);
|
|
591
|
+
buttons.appendChild(saveBtn);
|
|
592
|
+
modal.appendChild(title);
|
|
593
|
+
modal.appendChild(nameLabel);
|
|
594
|
+
modal.appendChild(nameInput);
|
|
595
|
+
modal.appendChild(apiTypeLabel);
|
|
596
|
+
modal.appendChild(apiTypeInput);
|
|
597
|
+
modal.appendChild(typeLabel);
|
|
598
|
+
modal.appendChild(typeSelect);
|
|
599
|
+
modal.appendChild(errorMessage);
|
|
600
|
+
modal.appendChild(buttons);
|
|
601
|
+
div.appendChild(modal);
|
|
602
|
+
document.body.appendChild(div);
|
|
603
|
+
nameInput.focus();
|
|
604
|
+
}
|
|
605
|
+
var init_modals = __esm({
|
|
606
|
+
"src/homebridge-ui/public/js/modals.ts"() {
|
|
607
|
+
"use strict";
|
|
608
|
+
init_constants();
|
|
609
|
+
init_logger();
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
// src/homebridge-ui/public/js/devices-delete.ts
|
|
614
|
+
var devices_delete_exports = {};
|
|
615
|
+
__export(devices_delete_exports, {
|
|
616
|
+
deleteDeviceFromConfig: () => deleteDeviceFromConfig
|
|
617
|
+
});
|
|
618
|
+
async function confirmDeleteDialog(deviceNameOrId) {
|
|
619
|
+
return new Promise((resolve) => {
|
|
620
|
+
const overlay = document.createElement("div");
|
|
621
|
+
overlay.style.position = "fixed";
|
|
622
|
+
overlay.style.top = "0";
|
|
623
|
+
overlay.style.left = "0";
|
|
624
|
+
overlay.style.width = "100%";
|
|
625
|
+
overlay.style.height = "100%";
|
|
626
|
+
overlay.style.background = "rgba(0,0,0,0.6)";
|
|
627
|
+
overlay.style.display = "flex";
|
|
628
|
+
overlay.style.alignItems = "center";
|
|
629
|
+
overlay.style.justifyContent = "center";
|
|
630
|
+
overlay.style.zIndex = "10000";
|
|
631
|
+
const modal = document.createElement("div");
|
|
632
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
633
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
634
|
+
modal.style.padding = "20px";
|
|
635
|
+
modal.style.borderRadius = "10px";
|
|
636
|
+
modal.style.minWidth = "340px";
|
|
637
|
+
modal.style.maxWidth = "90vw";
|
|
638
|
+
modal.style.boxShadow = "0 12px 40px rgba(0,0,0,0.35)";
|
|
639
|
+
const title = document.createElement("h3");
|
|
640
|
+
title.textContent = "Delete Device";
|
|
641
|
+
title.style.margin = "0 0 10px 0";
|
|
642
|
+
const message = document.createElement("p");
|
|
643
|
+
message.textContent = `Remove "${deviceNameOrId}" from configuration?`;
|
|
644
|
+
message.style.margin = "0 0 16px 0";
|
|
645
|
+
const actions = document.createElement("div");
|
|
646
|
+
actions.style.display = "flex";
|
|
647
|
+
actions.style.justifyContent = "flex-end";
|
|
648
|
+
actions.style.gap = "8px";
|
|
649
|
+
const cancelBtn = document.createElement("button");
|
|
650
|
+
cancelBtn.textContent = "Cancel";
|
|
651
|
+
cancelBtn.style.background = "#6b7280";
|
|
652
|
+
const deleteBtn = document.createElement("button");
|
|
653
|
+
deleteBtn.textContent = "Delete";
|
|
654
|
+
deleteBtn.style.background = "#ef4444";
|
|
655
|
+
const cleanup = (result) => {
|
|
656
|
+
overlay.remove();
|
|
657
|
+
resolve(result);
|
|
658
|
+
};
|
|
659
|
+
cancelBtn.onclick = () => cleanup(false);
|
|
660
|
+
deleteBtn.onclick = () => cleanup(true);
|
|
661
|
+
overlay.addEventListener("click", (event) => {
|
|
662
|
+
if (event.target === overlay) {
|
|
663
|
+
cleanup(false);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
actions.appendChild(cancelBtn);
|
|
667
|
+
actions.appendChild(deleteBtn);
|
|
668
|
+
modal.appendChild(title);
|
|
669
|
+
modal.appendChild(message);
|
|
670
|
+
modal.appendChild(actions);
|
|
671
|
+
overlay.appendChild(modal);
|
|
672
|
+
document.body.appendChild(overlay);
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
async function deleteDeviceFromConfig(deviceId, deviceName) {
|
|
676
|
+
uiLog.info("Delete button clicked for device:", deviceId, deviceName);
|
|
677
|
+
const confirmed = await confirmDeleteDialog(deviceName || deviceId);
|
|
678
|
+
if (!confirmed) {
|
|
679
|
+
uiLog.info("Delete cancelled by user");
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
try {
|
|
683
|
+
showBusyUi();
|
|
684
|
+
uiLog.info("Sending delete request for deviceId:", deviceId);
|
|
685
|
+
const resp = await deleteDevice(deviceId);
|
|
686
|
+
uiLog.info("Delete response:", resp);
|
|
687
|
+
if (!resp || resp.success === false) {
|
|
688
|
+
throw new Error(resp?.data?.message || "Failed to delete device");
|
|
689
|
+
}
|
|
690
|
+
uiLog.info("Syncing parent config from disk...");
|
|
691
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
692
|
+
if (!synced) {
|
|
693
|
+
toastWarning("Device deleted, but configuration sync failed");
|
|
694
|
+
}
|
|
695
|
+
uiLog.info("Refreshing device list...");
|
|
696
|
+
const list = await fetchDevices();
|
|
697
|
+
uiLog.info("Rendering devices:", list.length);
|
|
698
|
+
renderDeviceList(list);
|
|
699
|
+
uiLog.info("\u2713 Device deleted successfully");
|
|
700
|
+
toastSuccess(`Device "${deviceName || deviceId}" deleted successfully`);
|
|
701
|
+
} catch (e) {
|
|
702
|
+
uiLog.error("Delete error:", e);
|
|
703
|
+
toastError(e instanceof Error ? e.message : "Failed to delete device");
|
|
704
|
+
} finally {
|
|
705
|
+
hideBusyUi();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var init_devices_delete = __esm({
|
|
709
|
+
"src/homebridge-ui/public/js/devices-delete.ts"() {
|
|
710
|
+
"use strict";
|
|
711
|
+
init_api();
|
|
712
|
+
init_logger();
|
|
713
|
+
init_modal();
|
|
714
|
+
init_render();
|
|
715
|
+
init_toast();
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// src/homebridge-ui/public/js/render.ts
|
|
720
|
+
var render_exports = {};
|
|
721
|
+
__export(render_exports, {
|
|
722
|
+
renderBadge: () => renderBadge,
|
|
723
|
+
renderConnectionBadge: () => renderConnectionBadge,
|
|
724
|
+
renderDeviceList: () => renderDeviceList,
|
|
725
|
+
renderDiscoveredDevices: () => renderDiscoveredDevices,
|
|
726
|
+
renderIRBadge: () => renderIRBadge
|
|
727
|
+
});
|
|
728
|
+
function renderBadge(text, style) {
|
|
729
|
+
const badge = document.createElement("span");
|
|
730
|
+
badge.textContent = text;
|
|
731
|
+
badge.style.cssText = style;
|
|
732
|
+
return badge;
|
|
733
|
+
}
|
|
734
|
+
function renderConnectionBadge(connectionType) {
|
|
735
|
+
if (!connectionType) {
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
const badge = renderBadge(connectionType, "");
|
|
739
|
+
if (connectionType === "BLE") {
|
|
740
|
+
badge.style.cssText = "background: #4285f4; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
741
|
+
} else if (connectionType === "Both") {
|
|
742
|
+
badge.style.cssText = "background: #34a853; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
743
|
+
} else {
|
|
744
|
+
badge.style.cssText = "background: #9e9e9e; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
745
|
+
}
|
|
746
|
+
return badge;
|
|
747
|
+
}
|
|
748
|
+
function renderIRBadge() {
|
|
749
|
+
return renderBadge(
|
|
750
|
+
"IR",
|
|
751
|
+
"background: #ff6b35; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;"
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
async function renderDiscoveredDevices(devices) {
|
|
755
|
+
const ul = document.createElement("ul");
|
|
756
|
+
ul.style.maxHeight = "300px";
|
|
757
|
+
ul.style.overflowY = "auto";
|
|
758
|
+
const { addDeviceToConfig: addDeviceToConfig3 } = await Promise.resolve().then(() => (init_discovery(), discovery_exports));
|
|
759
|
+
for (const d of devices) {
|
|
760
|
+
const li = document.createElement("li");
|
|
761
|
+
li.className = "device-item";
|
|
762
|
+
const info = document.createElement("div");
|
|
763
|
+
info.style.flex = "1";
|
|
764
|
+
const name = document.createElement("div");
|
|
765
|
+
name.style.fontWeight = "500";
|
|
766
|
+
name.textContent = d.name || d.id;
|
|
767
|
+
if (d.connectionType) {
|
|
768
|
+
name.appendChild(document.createTextNode(" "));
|
|
769
|
+
const badge = renderConnectionBadge(d.connectionType);
|
|
770
|
+
if (badge) {
|
|
771
|
+
name.appendChild(badge);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
if (d.isIR) {
|
|
775
|
+
name.appendChild(document.createTextNode(" "));
|
|
776
|
+
name.appendChild(renderIRBadge());
|
|
777
|
+
}
|
|
778
|
+
const details = document.createElement("div");
|
|
779
|
+
details.style.fontSize = "12px";
|
|
780
|
+
details.style.opacity = "0.75";
|
|
781
|
+
let detailsText = `ID: ${d.id} | Type: ${d.type} | Model: ${d.model || "N/A"}`;
|
|
782
|
+
if (d.hubDeviceId) {
|
|
783
|
+
detailsText += ` | Hub: ${d.hubDeviceId}`;
|
|
784
|
+
}
|
|
785
|
+
if (d.rssi) {
|
|
786
|
+
detailsText += ` | Signal: ${d.rssi} dBm`;
|
|
787
|
+
}
|
|
788
|
+
if (d.address) {
|
|
789
|
+
detailsText += ` | MAC: ${d.address}`;
|
|
790
|
+
}
|
|
791
|
+
details.textContent = detailsText;
|
|
792
|
+
info.appendChild(name);
|
|
793
|
+
info.appendChild(details);
|
|
794
|
+
const addBtn = document.createElement("button");
|
|
795
|
+
addBtn.textContent = "+ Add";
|
|
796
|
+
addBtn.style.marginLeft = "8px";
|
|
797
|
+
addBtn.onclick = async () => {
|
|
798
|
+
await addDeviceToConfig3(d);
|
|
799
|
+
};
|
|
800
|
+
li.appendChild(info);
|
|
801
|
+
li.appendChild(addBtn);
|
|
802
|
+
ul.appendChild(li);
|
|
803
|
+
}
|
|
804
|
+
return ul;
|
|
805
|
+
}
|
|
806
|
+
function renderDeviceList(list) {
|
|
807
|
+
const ul = document.getElementById("devices");
|
|
808
|
+
const status = document.getElementById("status");
|
|
809
|
+
if (!ul || !status) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (!list.length) {
|
|
813
|
+
status.textContent = "No devices found in config.";
|
|
814
|
+
ul.innerHTML = "";
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
status.textContent = `Found ${list.length} device(s)`;
|
|
818
|
+
ul.innerHTML = "";
|
|
819
|
+
for (const d of list) {
|
|
820
|
+
const li = document.createElement("li");
|
|
821
|
+
li.className = "device-item";
|
|
822
|
+
const info = document.createElement("div");
|
|
823
|
+
info.style.flex = "1";
|
|
824
|
+
const name = document.createElement("div");
|
|
825
|
+
name.style.fontWeight = "500";
|
|
826
|
+
name.textContent = d.name || d.id;
|
|
827
|
+
const code = document.createElement("code");
|
|
828
|
+
code.textContent = d.id;
|
|
829
|
+
code.style.fontSize = "12px";
|
|
830
|
+
code.style.opacity = "0.75";
|
|
831
|
+
code.style.marginLeft = "8px";
|
|
832
|
+
const meta = document.createElement("div");
|
|
833
|
+
meta.style.opacity = "0.75";
|
|
834
|
+
meta.style.marginTop = "4px";
|
|
835
|
+
meta.style.fontSize = "12px";
|
|
836
|
+
const typeText = d.type ? `type: ${d.type}` : "";
|
|
837
|
+
const connText = d.connectionPreference ? `conn: ${d.connectionPreference}` : "";
|
|
838
|
+
const roomText = d.room ? `room: ${d.room}` : "";
|
|
839
|
+
meta.textContent = [typeText, connText, roomText].filter(Boolean).join(" | ");
|
|
840
|
+
info.appendChild(name);
|
|
841
|
+
info.appendChild(code);
|
|
842
|
+
info.appendChild(meta);
|
|
843
|
+
const buttons = document.createElement("div");
|
|
844
|
+
buttons.style.display = "flex";
|
|
845
|
+
buttons.style.gap = "8px";
|
|
846
|
+
const editBtn = document.createElement("button");
|
|
847
|
+
editBtn.textContent = "\u270F\uFE0F Edit";
|
|
848
|
+
editBtn.style.padding = "6px 12px";
|
|
849
|
+
editBtn.style.fontSize = "12px";
|
|
850
|
+
editBtn.onclick = async () => {
|
|
851
|
+
const { editDevice: editDevice2 } = await Promise.resolve().then(() => (init_modals(), modals_exports));
|
|
852
|
+
await editDevice2(d);
|
|
853
|
+
};
|
|
854
|
+
const copyBtn = document.createElement("button");
|
|
855
|
+
copyBtn.textContent = "Copy ID";
|
|
856
|
+
copyBtn.style.padding = "6px 12px";
|
|
857
|
+
copyBtn.style.fontSize = "12px";
|
|
858
|
+
copyBtn.addEventListener("click", async () => {
|
|
859
|
+
try {
|
|
860
|
+
await navigator.clipboard.writeText(d.id);
|
|
861
|
+
copyBtn.textContent = "Copied";
|
|
862
|
+
copyBtn.classList.add("success");
|
|
863
|
+
setTimeout(() => {
|
|
864
|
+
copyBtn.textContent = "Copy ID";
|
|
865
|
+
copyBtn.classList.remove("success");
|
|
866
|
+
}, 1200);
|
|
867
|
+
} catch (e) {
|
|
868
|
+
alert("Failed to copy");
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
const deleteBtn = document.createElement("button");
|
|
872
|
+
deleteBtn.textContent = "\u{1F5D1}\uFE0F Delete";
|
|
873
|
+
deleteBtn.style.padding = "6px 12px";
|
|
874
|
+
deleteBtn.style.fontSize = "12px";
|
|
875
|
+
deleteBtn.style.background = "#ef4444";
|
|
876
|
+
deleteBtn.onclick = async () => {
|
|
877
|
+
const { deleteDeviceFromConfig: deleteDeviceFromConfig2 } = await Promise.resolve().then(() => (init_devices_delete(), devices_delete_exports));
|
|
878
|
+
await deleteDeviceFromConfig2(d.id, d.name || d.id);
|
|
879
|
+
};
|
|
880
|
+
buttons.appendChild(editBtn);
|
|
881
|
+
buttons.appendChild(copyBtn);
|
|
882
|
+
buttons.appendChild(deleteBtn);
|
|
883
|
+
li.appendChild(info);
|
|
884
|
+
li.appendChild(buttons);
|
|
885
|
+
ul.appendChild(li);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
var init_render = __esm({
|
|
889
|
+
"src/homebridge-ui/public/js/render.ts"() {
|
|
890
|
+
"use strict";
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
// src/homebridge-ui/public/js/devices.ts
|
|
895
|
+
var devices_exports = {};
|
|
896
|
+
__export(devices_exports, {
|
|
897
|
+
addDeviceToConfig: () => addDeviceToConfig2,
|
|
898
|
+
loadConfiguredDevices: () => loadConfiguredDevices
|
|
899
|
+
});
|
|
900
|
+
async function addDeviceToConfig2(device, options = {}) {
|
|
901
|
+
const { refresh = true, showStatus = true } = options;
|
|
902
|
+
try {
|
|
903
|
+
showBusyUi();
|
|
904
|
+
uiLog.info("Adding device to config:", device);
|
|
905
|
+
const resp = await addDevice(device.id, device.name, device.type);
|
|
906
|
+
uiLog.info("Add device response:", resp);
|
|
907
|
+
if (!resp || resp.success === false) {
|
|
908
|
+
throw new Error(resp?.data?.message || "Failed to add device");
|
|
909
|
+
}
|
|
910
|
+
const alreadyExists = !!resp?.alreadyExists;
|
|
911
|
+
const message = resp?.message || (alreadyExists ? `Device "${device.name}" already in config` : `Device "${device.name}" added successfully!`);
|
|
912
|
+
if (alreadyExists) {
|
|
913
|
+
toastInfo(message);
|
|
914
|
+
} else {
|
|
915
|
+
toastSuccess(message);
|
|
916
|
+
}
|
|
917
|
+
if (showStatus) {
|
|
918
|
+
const status = document.getElementById("discoverStatus");
|
|
919
|
+
if (status) {
|
|
920
|
+
status.textContent = (alreadyExists ? "\u2022 " : "\u2713 ") + message;
|
|
921
|
+
status.classList.remove("error");
|
|
922
|
+
status.classList.add("success-msg");
|
|
923
|
+
if (!alreadyExists) {
|
|
924
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
925
|
+
status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
|
|
926
|
+
if (synced) {
|
|
927
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
928
|
+
} else {
|
|
929
|
+
toastWarning("Configuration sync failed; close and reopen settings before Save");
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (refresh) {
|
|
935
|
+
await loadConfiguredDevices();
|
|
936
|
+
}
|
|
937
|
+
return { added: !alreadyExists };
|
|
938
|
+
} catch (e) {
|
|
939
|
+
uiLog.error("Add device error:", e);
|
|
940
|
+
const status = document.getElementById("discoverStatus");
|
|
941
|
+
if (status) {
|
|
942
|
+
status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add device"}`;
|
|
943
|
+
status.classList.add("error");
|
|
944
|
+
}
|
|
945
|
+
toastError(e instanceof Error ? e.message : "Failed to add device");
|
|
946
|
+
return { added: false };
|
|
947
|
+
} finally {
|
|
948
|
+
hideBusyUi();
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
async function loadConfiguredDevices() {
|
|
952
|
+
const list = await fetchDevices();
|
|
953
|
+
renderDeviceList(list);
|
|
954
|
+
}
|
|
955
|
+
var init_devices = __esm({
|
|
956
|
+
"src/homebridge-ui/public/js/devices.ts"() {
|
|
957
|
+
"use strict";
|
|
958
|
+
init_api();
|
|
959
|
+
init_logger();
|
|
960
|
+
init_modal();
|
|
961
|
+
init_render();
|
|
962
|
+
init_toast();
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
// src/homebridge-ui/public/js/credentials.ts
|
|
967
|
+
init_api();
|
|
968
|
+
init_logger();
|
|
969
|
+
init_modal();
|
|
970
|
+
init_toast();
|
|
971
|
+
async function loadCredentialStatus() {
|
|
972
|
+
try {
|
|
973
|
+
const creds = await fetchCredentialStatus();
|
|
974
|
+
if (!creds) {
|
|
975
|
+
uiLog.error("Failed to load credentials");
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
const tokenStatus = document.getElementById("tokenStatus");
|
|
979
|
+
const secretStatus = document.getElementById("secretStatus");
|
|
980
|
+
if (!tokenStatus || !secretStatus) {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (creds.hasToken) {
|
|
984
|
+
tokenStatus.textContent = `\u2713 Configured (${creds.tokenLength} characters)`;
|
|
985
|
+
tokenStatus.classList.add("ok");
|
|
986
|
+
} else {
|
|
987
|
+
tokenStatus.textContent = "Not configured";
|
|
988
|
+
tokenStatus.classList.remove("ok");
|
|
989
|
+
}
|
|
990
|
+
if (creds.hasSecret) {
|
|
991
|
+
secretStatus.textContent = `\u2713 Configured (${creds.secretLength} characters)`;
|
|
992
|
+
secretStatus.classList.add("ok");
|
|
993
|
+
} else {
|
|
994
|
+
secretStatus.textContent = "Not configured";
|
|
995
|
+
secretStatus.classList.remove("ok");
|
|
996
|
+
}
|
|
997
|
+
} catch (e) {
|
|
998
|
+
uiLog.error("Error loading credentials:", e);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
async function saveCredentials2() {
|
|
1002
|
+
const token = document.getElementById("token")?.value;
|
|
1003
|
+
const secret = document.getElementById("secret")?.value;
|
|
1004
|
+
const saveStatus = document.getElementById("saveStatus");
|
|
1005
|
+
const saveBtn = document.getElementById("saveBtn");
|
|
1006
|
+
if (!saveStatus || !saveBtn) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (!token || !secret) {
|
|
1010
|
+
saveStatus.textContent = "Please enter both token and secret";
|
|
1011
|
+
saveStatus.classList.add("error");
|
|
1012
|
+
toastWarning("Please enter both token and secret");
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
try {
|
|
1016
|
+
showBusyUi();
|
|
1017
|
+
saveBtn.disabled = true;
|
|
1018
|
+
saveBtn.textContent = "Saving...";
|
|
1019
|
+
uiLog.info("Saving credentials...");
|
|
1020
|
+
const result = await saveCredentials(token, secret);
|
|
1021
|
+
uiLog.info("Save response:", result);
|
|
1022
|
+
const message = result?.message || "Credentials saved successfully";
|
|
1023
|
+
saveStatus.textContent = `\u2713 ${message}`;
|
|
1024
|
+
saveStatus.classList.remove("error");
|
|
1025
|
+
saveStatus.classList.add("success-msg");
|
|
1026
|
+
toastSuccess(message);
|
|
1027
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
1028
|
+
if (synced) {
|
|
1029
|
+
saveStatus.textContent += " - Config saved automatically.";
|
|
1030
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
1031
|
+
} else {
|
|
1032
|
+
toastWarning("Credentials saved, but configuration sync failed");
|
|
1033
|
+
}
|
|
1034
|
+
;
|
|
1035
|
+
document.getElementById("token").value = "";
|
|
1036
|
+
document.getElementById("secret").value = "";
|
|
1037
|
+
setTimeout(() => loadCredentialStatus(), 500);
|
|
1038
|
+
setTimeout(() => {
|
|
1039
|
+
saveStatus.textContent = "";
|
|
1040
|
+
saveStatus.classList.remove("success-msg");
|
|
1041
|
+
}, 3e3);
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
uiLog.error("Save error:", e);
|
|
1044
|
+
saveStatus.textContent = `Error: ${e instanceof Error ? e.message : "Failed to save"}`;
|
|
1045
|
+
saveStatus.classList.add("error");
|
|
1046
|
+
toastError(e instanceof Error ? e.message : "Failed to save credentials");
|
|
1047
|
+
} finally {
|
|
1048
|
+
hideBusyUi();
|
|
1049
|
+
saveBtn.disabled = false;
|
|
1050
|
+
saveBtn.textContent = "Save Credentials";
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/homebridge-ui/public/js/app.ts
|
|
1055
|
+
init_devices();
|
|
1056
|
+
init_discovery();
|
|
1057
|
+
window.loadCredentialStatus = loadCredentialStatus;
|
|
1058
|
+
window.saveCredentials = saveCredentials2;
|
|
1059
|
+
window.discoverDevices = discoverDevices2;
|
|
1060
|
+
async function init() {
|
|
1061
|
+
await loadCredentialStatus();
|
|
1062
|
+
const list = await loadConfiguredDevices();
|
|
1063
|
+
}
|
|
1064
|
+
if (document.readyState === "loading") {
|
|
1065
|
+
document.addEventListener("DOMContentLoaded", init);
|
|
1066
|
+
} else {
|
|
1067
|
+
init();
|
|
1068
|
+
}
|
|
1069
|
+
//# sourceMappingURL=app.js.map
|