@switchbot/homebridge-switchbot 5.0.0-beta.6 → 5.0.0-beta.61
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/CHANGELOG.md +15 -0
- package/README.md +45 -3
- package/config.schema.json +866 -13754
- package/dist/devices-hap/airpurifier.d.ts.map +1 -1
- package/dist/devices-hap/airpurifier.js +12 -6
- package/dist/devices-hap/airpurifier.js.map +1 -1
- package/dist/devices-hap/blindtilt.js +3 -3
- package/dist/devices-hap/bot.d.ts.map +1 -1
- package/dist/devices-hap/bot.js +16 -5
- package/dist/devices-hap/bot.js.map +1 -1
- package/dist/devices-hap/ceilinglight.d.ts.map +1 -1
- package/dist/devices-hap/ceilinglight.js +13 -7
- package/dist/devices-hap/ceilinglight.js.map +1 -1
- package/dist/devices-hap/colorbulb.d.ts.map +1 -1
- package/dist/devices-hap/colorbulb.js +49 -9
- package/dist/devices-hap/colorbulb.js.map +1 -1
- package/dist/devices-hap/contact.js +3 -3
- package/dist/devices-hap/curtain.js +2 -2
- package/dist/devices-hap/curtain.js.map +1 -1
- package/dist/devices-hap/device.d.ts +18 -8
- package/dist/devices-hap/device.d.ts.map +1 -1
- package/dist/devices-hap/device.js +141 -69
- package/dist/devices-hap/device.js.map +1 -1
- package/dist/devices-hap/fan.d.ts.map +1 -1
- package/dist/devices-hap/fan.js +12 -6
- package/dist/devices-hap/fan.js.map +1 -1
- package/dist/devices-hap/hub.d.ts.map +1 -1
- package/dist/devices-hap/hub.js +6 -5
- package/dist/devices-hap/hub.js.map +1 -1
- package/dist/devices-hap/humidifier.d.ts +5 -0
- package/dist/devices-hap/humidifier.d.ts.map +1 -1
- package/dist/devices-hap/humidifier.js +92 -4
- package/dist/devices-hap/humidifier.js.map +1 -1
- package/dist/devices-hap/iosensor.d.ts.map +1 -1
- package/dist/devices-hap/iosensor.js +36 -21
- package/dist/devices-hap/iosensor.js.map +1 -1
- package/dist/devices-hap/lightstrip.d.ts.map +1 -1
- package/dist/devices-hap/lightstrip.js +38 -8
- package/dist/devices-hap/lightstrip.js.map +1 -1
- package/dist/devices-hap/lock.d.ts.map +1 -1
- package/dist/devices-hap/lock.js +14 -6
- package/dist/devices-hap/lock.js.map +1 -1
- package/dist/devices-hap/meter.d.ts.map +1 -1
- package/dist/devices-hap/meter.js +6 -5
- package/dist/devices-hap/meter.js.map +1 -1
- package/dist/devices-hap/meterplus.d.ts.map +1 -1
- package/dist/devices-hap/meterplus.js +6 -5
- package/dist/devices-hap/meterplus.js.map +1 -1
- package/dist/devices-hap/meterpro.d.ts.map +1 -1
- package/dist/devices-hap/meterpro.js +7 -6
- package/dist/devices-hap/meterpro.js.map +1 -1
- package/dist/devices-hap/motion.js +3 -3
- package/dist/devices-hap/plug.d.ts.map +1 -1
- package/dist/devices-hap/plug.js +11 -6
- package/dist/devices-hap/plug.js.map +1 -1
- package/dist/devices-hap/relayswitch.js +3 -3
- package/dist/devices-hap/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/devices-hap/robotvacuumcleaner.js +13 -6
- package/dist/devices-hap/robotvacuumcleaner.js.map +1 -1
- package/dist/devices-hap/waterdetector.js +3 -3
- package/dist/devices-matter/BaseMatterAccessory.d.ts +27 -0
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.js +169 -5
- package/dist/devices-matter/BaseMatterAccessory.js.map +1 -1
- package/dist/devices-matter/ColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorLightAccessory.js +12 -12
- package/dist/devices-matter/ColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.js +5 -7
- package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +1 -1
- package/dist/devices-matter/DimmableLightAccessory.js +9 -9
- package/dist/devices-matter/DimmableLightAccessory.js.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.js +14 -15
- package/dist/devices-matter/ExtendedColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.js +8 -16
- package/dist/devices-matter/OnOffLightAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +2 -0
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +10 -7
- package/dist/devices-matter/OnOffOutletAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffSwitchAccessory.js +2 -2
- package/dist/devices-matter/OnOffSwitchAccessory.js.map +1 -1
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts +29 -43
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +1 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +287 -262
- package/dist/devices-matter/RoboticVacuumAccessory.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +200 -18
- package/dist/homebridge-ui/server.js +0 -31
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +76 -35
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/platform-hap.d.ts +26 -15
- package/dist/platform-hap.d.ts.map +1 -1
- package/dist/platform-hap.js +333 -153
- package/dist/platform-hap.js.map +1 -1
- package/dist/platform-matter.d.ts +93 -6
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +1822 -224
- package/dist/platform-matter.js.map +1 -1
- package/dist/settings.d.ts +58 -7
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/test/apiRequestTracker.test.d.ts +2 -0
- package/dist/test/apiRequestTracker.test.d.ts.map +1 -0
- package/dist/test/apiRequestTracker.test.js +392 -0
- package/dist/test/apiRequestTracker.test.js.map +1 -0
- package/dist/test/hap/device-webhook-context.test.d.ts +2 -0
- package/dist/test/hap/device-webhook-context.test.d.ts.map +1 -0
- package/dist/test/hap/device-webhook-context.test.js +128 -0
- package/dist/test/hap/device-webhook-context.test.js.map +1 -0
- package/dist/test/hap/platform-hap.logging.test.d.ts +2 -0
- package/dist/test/hap/platform-hap.logging.test.d.ts.map +1 -0
- package/dist/test/hap/platform-hap.logging.test.js +33 -0
- package/dist/test/hap/platform-hap.logging.test.js.map +1 -0
- package/dist/test/hap/platform-hap.test.d.ts +2 -0
- package/dist/test/hap/platform-hap.test.d.ts.map +1 -0
- package/dist/test/hap/platform-hap.test.js +62 -0
- package/dist/test/hap/platform-hap.test.js.map +1 -0
- package/dist/test/helpers/platform-fixtures.d.ts +9 -0
- package/dist/test/helpers/platform-fixtures.d.ts.map +1 -0
- package/dist/test/helpers/platform-fixtures.js +30 -0
- package/dist/test/helpers/platform-fixtures.js.map +1 -0
- package/dist/test/homebridge-ui/server.test.d.ts +2 -0
- package/dist/test/homebridge-ui/server.test.d.ts.map +1 -0
- package/dist/test/homebridge-ui/server.test.js +445 -0
- package/dist/test/homebridge-ui/server.test.js.map +1 -0
- package/dist/{index.test.d.ts.map → test/index.test.d.ts.map} +1 -1
- package/dist/test/index.test.js +19 -0
- package/dist/test/index.test.js.map +1 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts +2 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts.map +1 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js +71 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js.map +1 -0
- package/dist/test/matter/devices-matter/roboticVacuumAccessory.test.d.ts +2 -0
- package/dist/test/matter/devices-matter/roboticVacuumAccessory.test.d.ts.map +1 -0
- package/dist/test/matter/devices-matter/roboticVacuumAccessory.test.js +366 -0
- package/dist/test/matter/devices-matter/roboticVacuumAccessory.test.js.map +1 -0
- package/dist/test/matter/platform-matter.additional.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.additional.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.additional.test.js +35 -0
- package/dist/test/matter/platform-matter.additional.test.js.map +1 -0
- package/dist/test/matter/platform-matter.bleparse.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.bleparse.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.bleparse.test.js +43 -0
- package/dist/test/matter/platform-matter.bleparse.test.js.map +1 -0
- package/dist/test/matter/platform-matter.cleanup.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.cleanup.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.cleanup.test.js +70 -0
- package/dist/test/matter/platform-matter.cleanup.test.js.map +1 -0
- package/dist/test/matter/platform-matter.keepstale.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.keepstale.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.keepstale.test.js +27 -0
- package/dist/test/matter/platform-matter.keepstale.test.js.map +1 -0
- package/dist/test/matter/platform-matter.logging.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.logging.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.logging.test.js +29 -0
- package/dist/test/matter/platform-matter.logging.test.js.map +1 -0
- package/dist/test/matter/platform-matter.mapping.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.mapping.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.mapping.test.js +43 -0
- package/dist/test/matter/platform-matter.mapping.test.js.map +1 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.js +84 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.js.map +1 -0
- package/dist/test/matter/platform-matter.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.test.js +117 -0
- package/dist/test/matter/platform-matter.test.js.map +1 -0
- package/dist/test/matter/platform-matter.unregister.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.unregister.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.unregister.test.js +30 -0
- package/dist/test/matter/platform-matter.unregister.test.js.map +1 -0
- package/dist/test/matter/platform-matter.webhook.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.webhook.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.webhook.test.js +46 -0
- package/dist/test/matter/platform-matter.webhook.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +95 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/verifyconfig.test.d.ts.map +1 -0
- package/dist/{verifyconfig.test.js → test/verifyconfig.test.js} +2 -2
- package/dist/test/verifyconfig.test.js.map +1 -0
- package/dist/utils.d.ts +204 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +713 -33
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +14 -0
- package/docs/assets/main.js +2 -2
- package/docs/index.html +31 -2
- package/docs/variables/default.html +1 -1
- package/package.json +15 -15
- package/src/devices-hap/airpurifier.ts +11 -6
- package/src/devices-hap/blindtilt.ts +3 -3
- package/src/devices-hap/bot.ts +15 -5
- package/src/devices-hap/ceilinglight.ts +12 -7
- package/src/devices-hap/colorbulb.ts +46 -10
- package/src/devices-hap/contact.ts +3 -3
- package/src/devices-hap/curtain.ts +2 -2
- package/src/devices-hap/device.ts +149 -70
- package/src/devices-hap/fan.ts +11 -6
- package/src/devices-hap/hub.ts +6 -5
- package/src/devices-hap/humidifier.ts +97 -4
- package/src/devices-hap/iosensor.ts +36 -21
- package/src/devices-hap/lightstrip.ts +35 -8
- package/src/devices-hap/lock.ts +13 -6
- package/src/devices-hap/meter.ts +6 -5
- package/src/devices-hap/meterplus.ts +6 -5
- package/src/devices-hap/meterpro.ts +7 -6
- package/src/devices-hap/motion.ts +3 -3
- package/src/devices-hap/plug.ts +10 -6
- package/src/devices-hap/relayswitch.ts +3 -3
- package/src/devices-hap/robotvacuumcleaner.ts +12 -6
- package/src/devices-hap/waterdetector.ts +3 -3
- package/src/devices-matter/BaseMatterAccessory.ts +176 -5
- package/src/devices-matter/ColorLightAccessory.ts +12 -12
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +5 -7
- package/src/devices-matter/DimmableLightAccessory.ts +9 -9
- package/src/devices-matter/ExtendedColorLightAccessory.ts +14 -15
- package/src/devices-matter/OnOffLightAccessory.ts +8 -16
- package/src/devices-matter/OnOffOutletAccessory.ts +12 -7
- package/src/devices-matter/OnOffSwitchAccessory.ts +2 -2
- package/src/devices-matter/RoboticVacuumAccessory.ts +340 -313
- package/src/homebridge-ui/public/index.html +200 -18
- package/src/homebridge-ui/server.ts +0 -34
- package/src/index.ts +4 -7
- package/src/irdevice/irdevice.ts +74 -35
- package/src/platform-hap.ts +365 -169
- package/src/platform-matter.ts +1872 -229
- package/src/settings.ts +62 -3
- package/src/test/apiRequestTracker.test.ts +417 -0
- package/src/test/hap/device-webhook-context.test.ts +136 -0
- package/src/test/hap/platform-hap.logging.test.ts +36 -0
- package/src/test/hap/platform-hap.test.ts +70 -0
- package/src/test/helpers/platform-fixtures.ts +33 -0
- package/src/test/homebridge-ui/server.test.ts +486 -0
- package/src/test/index.test.ts +24 -0
- package/src/test/matter/devices-matter/baseMatterAccessory.test.ts +88 -0
- package/src/test/matter/devices-matter/roboticVacuumAccessory.test.ts +453 -0
- package/src/test/matter/platform-matter.additional.test.ts +44 -0
- package/src/test/matter/platform-matter.bleparse.test.ts +47 -0
- package/src/test/matter/platform-matter.cleanup.test.ts +86 -0
- package/src/test/matter/platform-matter.keepstale.test.ts +37 -0
- package/src/test/matter/platform-matter.logging.test.ts +33 -0
- package/src/test/matter/platform-matter.mapping.test.ts +57 -0
- package/src/test/matter/platform-matter.openapi-mapping.test.ts +109 -0
- package/src/test/matter/platform-matter.test.ts +144 -0
- package/src/test/matter/platform-matter.unregister.test.ts +39 -0
- package/src/test/matter/platform-matter.webhook.test.ts +54 -0
- package/src/test/utils.test.ts +96 -0
- package/src/{verifyconfig.test.ts → test/verifyconfig.test.ts} +12 -11
- package/src/utils.ts +777 -36
- package/dist/index.test.js +0 -14
- package/dist/index.test.js.map +0 -1
- package/dist/verifyconfig.test.d.ts.map +0 -1
- package/dist/verifyconfig.test.js.map +0 -1
- package/src/index.test.ts +0 -19
- /package/dist/{index.test.d.ts → test/index.test.d.ts} +0 -0
- /package/dist/{verifyconfig.test.d.ts → test/verifyconfig.test.d.ts} +0 -0
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
<div id="menuWrapper" class="btn-group w-100 mb-0" role="group" aria-label="UI Menu" style="display: none">
|
|
29
29
|
<button type="button" class="btn btn-primary" id="menuSettings">Settings</button>
|
|
30
30
|
<button type="button" class="btn btn-primary" id="menuDevices">Devices</button>
|
|
31
|
-
<button type="button" class="btn btn-primary
|
|
31
|
+
<button type="button" class="btn btn-primary" id="menuHome">Support</button>
|
|
32
|
+
<button type="button" class="btn btn-primary mr-0" id="dynamic-config-tab">Dynamic Config</button>
|
|
32
33
|
</div>
|
|
33
34
|
<div id="disabledBanner" class="alert alert-secondary mb-0 mt-3" role="alert" style="display: none">
|
|
34
35
|
Plugin is currently disabled
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
</form>
|
|
44
45
|
<table class="table w-100" id="deviceTable" style="display: none">
|
|
45
46
|
<thead>
|
|
46
|
-
<tr
|
|
47
|
+
<tr>
|
|
47
48
|
<th scope="col" style="width: 40%">Device Name</th>
|
|
48
49
|
<th scope="col" style="width: 60%" id="displayName"></th>
|
|
49
50
|
</tr>
|
|
@@ -69,6 +70,18 @@
|
|
|
69
70
|
<th scope="row">Connection Type</th>
|
|
70
71
|
<td id="connectionType"></td>
|
|
71
72
|
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<th scope="row">Refresh Rate</th>
|
|
75
|
+
<td id="refreshRate"></td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<th scope="row">Update Rate</th>
|
|
79
|
+
<td id="updateRate"></td>
|
|
80
|
+
</tr>
|
|
81
|
+
<tr>
|
|
82
|
+
<th scope="row">Push Rate</th>
|
|
83
|
+
<td id="pushRate"></td>
|
|
84
|
+
</tr>
|
|
72
85
|
</tbody>
|
|
73
86
|
</table>
|
|
74
87
|
<p class="text-center">External accessories will not be displayed here.</p>
|
|
@@ -109,7 +122,7 @@
|
|
|
109
122
|
<h5>Help/About</h5>
|
|
110
123
|
<ul>
|
|
111
124
|
<li>
|
|
112
|
-
<a href="https://
|
|
125
|
+
<a href="https://
|
|
113
126
|
Request</a>
|
|
114
127
|
</li>
|
|
115
128
|
<li>
|
|
@@ -118,10 +131,50 @@
|
|
|
118
131
|
</li>
|
|
119
132
|
</ul>
|
|
120
133
|
</div>
|
|
134
|
+
<div id="dynamic-config-content" class="tab-content" style="display: none;">
|
|
135
|
+
<h2>Dynamic Config</h2>
|
|
136
|
+
<p>Discover and configure devices dynamically.</p>
|
|
137
|
+
<!-- Placeholder for dynamic content -->
|
|
138
|
+
</div>
|
|
121
139
|
<script>
|
|
122
140
|
(async () => {
|
|
123
141
|
try {
|
|
124
142
|
const currentConfig = await homebridge.getPluginConfig();
|
|
143
|
+
|
|
144
|
+
// Defensive wrapper: ensure token/secret aren't accidentally cleared by
|
|
145
|
+
// the UI/schema form. Some versions of config UI can omit sensitive
|
|
146
|
+
// fields from the submitted payload; when that happens we copy the
|
|
147
|
+
// existing values from `currentConfig` into the outgoing payload so
|
|
148
|
+
// saved config does not inadvertently remove credentials.
|
|
149
|
+
try {
|
|
150
|
+
if (typeof homebridge.updatePluginConfig === 'function') {
|
|
151
|
+
const _origUpdatePluginConfig = homebridge.updatePluginConfig.bind(homebridge)
|
|
152
|
+
homebridge.updatePluginConfig = async (cfg) => {
|
|
153
|
+
try {
|
|
154
|
+
if (Array.isArray(cfg) && cfg.length > 0 && Array.isArray(currentConfig) && currentConfig.length > 0) {
|
|
155
|
+
const incoming = cfg[0] || {}
|
|
156
|
+
const existing = currentConfig[0] || {}
|
|
157
|
+
incoming.credentials = incoming.credentials || {}
|
|
158
|
+
// Preserve token/secret when incoming payload leaves them blank/undefined
|
|
159
|
+
if ((incoming.credentials.token === undefined || String(incoming.credentials.token).trim() === '') && existing.credentials && existing.credentials.token) {
|
|
160
|
+
incoming.credentials.token = existing.credentials.token
|
|
161
|
+
}
|
|
162
|
+
if ((incoming.credentials.secret === undefined || String(incoming.credentials.secret).trim() === '') && existing.credentials && existing.credentials.secret) {
|
|
163
|
+
incoming.credentials.secret = existing.credentials.secret
|
|
164
|
+
}
|
|
165
|
+
cfg[0] = incoming
|
|
166
|
+
}
|
|
167
|
+
} catch (e) {
|
|
168
|
+
// Swallow any wrapper errors but log to console for debugging
|
|
169
|
+
// (do not expose secrets).
|
|
170
|
+
console.error('updatePluginConfig wrapper error', e)
|
|
171
|
+
}
|
|
172
|
+
return await _origUpdatePluginConfig(cfg)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.error('Failed to attach updatePluginConfig wrapper', e)
|
|
177
|
+
}
|
|
125
178
|
showIntro = () => {
|
|
126
179
|
const introLink = document.getElementById('introLink');
|
|
127
180
|
introLink.addEventListener('click', () => {
|
|
@@ -144,10 +197,25 @@
|
|
|
144
197
|
document.getElementById('menuSettings').classList.add('btn-primary');
|
|
145
198
|
document.getElementById('pageSupport').style.display = 'none';
|
|
146
199
|
document.getElementById('pageDevices').style.display = 'block';
|
|
147
|
-
|
|
200
|
+
let cachedAccessories =
|
|
148
201
|
typeof homebridge.getCachedAccessories === 'function'
|
|
149
202
|
? await homebridge.getCachedAccessories()
|
|
150
203
|
: await homebridge.request('/getCachedAccessories');
|
|
204
|
+
|
|
205
|
+
// If no HAP cached accessories were returned, try the Matter cached list using the new native method
|
|
206
|
+
if ((!cachedAccessories || cachedAccessories.length === 0)) {
|
|
207
|
+
try {
|
|
208
|
+
// Use the new native getCachedMatterAccessories() method from @homebridge/plugin-ui-utils v2.1.1-beta.0+
|
|
209
|
+
const matter = typeof homebridge.getCachedMatterAccessories === 'function'
|
|
210
|
+
? await homebridge.getCachedMatterAccessories()
|
|
211
|
+
: await homebridge.request('/getCachedMatterAccessories'); // Fallback to custom handler for older UI versions
|
|
212
|
+
if (Array.isArray(matter) && matter.length > 0) {
|
|
213
|
+
cachedAccessories = matter
|
|
214
|
+
}
|
|
215
|
+
} catch (e) {
|
|
216
|
+
// ignore
|
|
217
|
+
}
|
|
218
|
+
}
|
|
151
219
|
if (cachedAccessories.length > 0) {
|
|
152
220
|
cachedAccessories.sort((a, b) => {
|
|
153
221
|
return a.displayName.toLowerCase() > b.displayName.toLowerCase() ? 1 : b.displayName.toLowerCase() > a.displayName.toLowerCase() ? -1 : 0;
|
|
@@ -161,21 +229,127 @@
|
|
|
161
229
|
option.value = a.UUID;
|
|
162
230
|
deviceSelect.add(option);
|
|
163
231
|
});
|
|
232
|
+
const validateConfig = (config) => {
|
|
233
|
+
const deviceIds = new Set();
|
|
234
|
+
const isValid = config[0].options.devices.every((device) => {
|
|
235
|
+
if (!device.deviceId || typeof device.deviceId !== 'string') {
|
|
236
|
+
homebridge.toast.error(`Invalid device ID: ${device.deviceId}`, 'Error');
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
if (deviceIds.has(device.deviceId)) {
|
|
240
|
+
homebridge.toast.error(`Duplicate device ID found: ${device.deviceId}`, 'Error');
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
deviceIds.add(device.deviceId);
|
|
244
|
+
return true;
|
|
245
|
+
});
|
|
246
|
+
return isValid;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const addDeviceToConfig = async (deviceId) => {
|
|
250
|
+
try {
|
|
251
|
+
homebridge.showSpinner();
|
|
252
|
+
const currentConfig = await homebridge.getPluginConfig();
|
|
253
|
+
if (!currentConfig[0].options.devices) {
|
|
254
|
+
currentConfig[0].options.devices = [];
|
|
255
|
+
}
|
|
256
|
+
currentConfig[0].options.devices.push({
|
|
257
|
+
deviceId,
|
|
258
|
+
hide_device: false,
|
|
259
|
+
disablePlatformBLE: false,
|
|
260
|
+
allowPush: false,
|
|
261
|
+
disableCaching: false,
|
|
262
|
+
});
|
|
263
|
+
if (!validateConfig(currentConfig)) {
|
|
264
|
+
homebridge.hideSpinner();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
await homebridge.updatePluginConfig(currentConfig);
|
|
268
|
+
await homebridge.savePluginConfig();
|
|
269
|
+
homebridge.toast.success('Device added to config successfully!', 'Success');
|
|
270
|
+
} catch (error) {
|
|
271
|
+
homebridge.toast.error('Failed to add device to config!', 'Error');
|
|
272
|
+
} finally {
|
|
273
|
+
homebridge.hideSpinner();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const addDeviceButton = document.createElement('button');
|
|
278
|
+
addDeviceButton.textContent = 'Add Device to Config';
|
|
279
|
+
addDeviceButton.className = 'btn btn-success';
|
|
280
|
+
addDeviceButton.style.marginTop = '10px';
|
|
281
|
+
addDeviceButton.addEventListener('click', () => {
|
|
282
|
+
const deviceId = document.getElementById('deviceId').textContent;
|
|
283
|
+
if (deviceId) {
|
|
284
|
+
addDeviceToConfig(deviceId);
|
|
285
|
+
} else {
|
|
286
|
+
homebridge.toast.error('No device ID found!', 'Error');
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
document.getElementById('deviceInfo').appendChild(addDeviceButton);
|
|
290
|
+
|
|
291
|
+
const protocolInfo = document.createElement('p');
|
|
292
|
+
protocolInfo.id = 'protocolInfo';
|
|
293
|
+
protocolInfo.style.marginTop = '10px';
|
|
294
|
+
document.getElementById('deviceInfo').appendChild(protocolInfo);
|
|
295
|
+
|
|
296
|
+
const updateTableWithDetails = (deviceContext) => {
|
|
297
|
+
const tableBody = document.querySelector('#deviceTable tbody');
|
|
298
|
+
tableBody.innerHTML = '';
|
|
299
|
+
|
|
300
|
+
Object.entries(deviceContext).forEach(([key, value]) => {
|
|
301
|
+
if (value !== undefined && value !== null && String(value).trim() !== '') {
|
|
302
|
+
const row = document.createElement('tr');
|
|
303
|
+
const keyCell = document.createElement('th');
|
|
304
|
+
keyCell.scope = 'row';
|
|
305
|
+
keyCell.textContent = key;
|
|
306
|
+
const valueCell = document.createElement('td');
|
|
307
|
+
valueCell.textContent = value;
|
|
308
|
+
row.appendChild(keyCell);
|
|
309
|
+
row.appendChild(valueCell);
|
|
310
|
+
tableBody.appendChild(row);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// Ensure the element exists before attempting to set its innerHTML
|
|
316
|
+
const safeSetInnerHTML = (id, value) => {
|
|
317
|
+
const element = document.getElementById(id);
|
|
318
|
+
if (element) {
|
|
319
|
+
element.innerHTML = value;
|
|
320
|
+
} else {
|
|
321
|
+
console.warn(`Element with id '${id}' not found.`);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
164
325
|
showDeviceInfo = async (UUID) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
326
|
+
try {
|
|
327
|
+
homebridge.showSpinner();
|
|
328
|
+
const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
|
|
329
|
+
if (!thisAcc) {
|
|
330
|
+
throw new Error('Device not found');
|
|
331
|
+
}
|
|
332
|
+
const context = thisAcc.context;
|
|
333
|
+
const protocol = thisAcc.isMatter ? 'Matter Protocol' : 'HAP Protocol';
|
|
334
|
+
safeSetInnerHTML('displayName', thisAcc.displayName);
|
|
335
|
+
safeSetInnerHTML('deviceId', context.deviceId);
|
|
336
|
+
safeSetInnerHTML('model', context.model);
|
|
337
|
+
safeSetInnerHTML('version', context.version);
|
|
338
|
+
safeSetInnerHTML('deviceType', context.deviceType);
|
|
339
|
+
safeSetInnerHTML('connectionType', context.connectionType);
|
|
340
|
+
safeSetInnerHTML('refreshRate', context.refreshRate);
|
|
341
|
+
safeSetInnerHTML('updateRate', context.updateRate);
|
|
342
|
+
safeSetInnerHTML('pushRate', context.pushRate);
|
|
343
|
+
safeSetInnerHTML('protocolInfo', protocol);
|
|
344
|
+
document.getElementById('deviceTable').style.display = 'inline-table';
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
updateTableWithDetails(context);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
homebridge.toast.error(error.message, 'Error');
|
|
350
|
+
} finally {
|
|
351
|
+
homebridge.hideSpinner();
|
|
352
|
+
}
|
|
179
353
|
};
|
|
180
354
|
deviceSelect.addEventListener('change', (event) => showDeviceInfo(event.target.value));
|
|
181
355
|
if (cachedAccessories.length > 0) {
|
|
@@ -246,4 +420,12 @@
|
|
|
246
420
|
homebridge.hideSpinner();
|
|
247
421
|
}
|
|
248
422
|
})();
|
|
423
|
+
|
|
424
|
+
document.getElementById('dynamic-config-tab').addEventListener('click', function() {
|
|
425
|
+
// Hide other tabs
|
|
426
|
+
document.querySelectorAll('.tab-content').forEach(tab => tab.style.display = 'none');
|
|
427
|
+
|
|
428
|
+
// Show Dynamic Config tab
|
|
429
|
+
document.getElementById('dynamic-config-content').style.display = 'block';
|
|
430
|
+
});
|
|
249
431
|
</script>
|
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
|
|
3
1
|
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
|
|
4
2
|
|
|
5
3
|
class PluginUiServer extends HomebridgePluginUiServer {
|
|
6
4
|
constructor() {
|
|
7
5
|
super()
|
|
8
|
-
/*
|
|
9
|
-
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
10
|
-
The following is for users who have a lower version of config-ui-x
|
|
11
|
-
*/
|
|
12
|
-
this.onRequest('getCachedAccessories', () => {
|
|
13
|
-
try {
|
|
14
|
-
const plugin = 'homebridge-switchbot'
|
|
15
|
-
const devicesToReturn = []
|
|
16
|
-
|
|
17
|
-
// The path and file of the cached accessories
|
|
18
|
-
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`
|
|
19
|
-
|
|
20
|
-
// Check the file exists
|
|
21
|
-
if (fs.existsSync(accFile)) {
|
|
22
|
-
// read the cached accessories file
|
|
23
|
-
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'))
|
|
24
|
-
|
|
25
|
-
cachedAccessories.forEach((accessory: any) => {
|
|
26
|
-
// Check the accessory is from this plugin
|
|
27
|
-
if (accessory.plugin === plugin) {
|
|
28
|
-
// Add the cached accessory to the array
|
|
29
|
-
devicesToReturn.push(accessory.accessory as never)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
// Return the array
|
|
34
|
-
return devicesToReturn
|
|
35
|
-
} catch {
|
|
36
|
-
// Just return an empty accessory list in case of any errors
|
|
37
|
-
return []
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
6
|
this.ready()
|
|
41
7
|
}
|
|
42
8
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,14 +7,11 @@ import type { API } from 'homebridge'
|
|
|
7
7
|
import { SwitchBotHAPPlatform } from './platform-hap.js'
|
|
8
8
|
import { SwitchBotMatterPlatform } from './platform-matter.js'
|
|
9
9
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
10
|
+
import { createPlatformProxy } from './utils.js'
|
|
10
11
|
|
|
11
12
|
// Register our platform with homebridge.
|
|
12
13
|
export default (api: API): void => {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const log = (api as any).logger ?? console
|
|
17
|
-
log.info?.(`Homebridge SwitchBot Plugin initializing in ${isMatter ? 'Matter' : 'HAP'} mode.`)
|
|
18
|
-
// If Matter is enabled register the Matter platform, otherwise use HAP platform.
|
|
19
|
-
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, isMatter ? SwitchBotMatterPlatform : SwitchBotHAPPlatform)
|
|
14
|
+
// Create and register a small proxy that selects the correct platform (HAP or Matter) at runtime.
|
|
15
|
+
const ProxyCtor = createPlatformProxy(SwitchBotHAPPlatform, SwitchBotMatterPlatform)
|
|
16
|
+
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor as any)
|
|
20
17
|
}
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -276,69 +276,108 @@ export abstract class irdeviceBase {
|
|
|
276
276
|
/**
|
|
277
277
|
* Logging for Device
|
|
278
278
|
*/
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
279
|
+
infoLog(...log: any[]): void {
|
|
280
|
+
if (!this.enablingDeviceLogging()) {
|
|
281
|
+
return
|
|
282
282
|
}
|
|
283
|
+
// Delegate to a single helper that prefers platform-provided loggers.
|
|
284
|
+
this.logWith('info', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
287
|
+
successLog(...log: any[]): void {
|
|
288
|
+
if (!this.enablingDeviceLogging()) {
|
|
289
|
+
return
|
|
288
290
|
}
|
|
291
|
+
this.logWith('success', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
289
292
|
}
|
|
290
293
|
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
debugSuccessLog(...log: any[]): void {
|
|
295
|
+
if (!this.enablingDeviceLogging()) {
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
if (!this.loggingIsDebug()) {
|
|
299
|
+
return
|
|
296
300
|
}
|
|
301
|
+
this.logWith('success', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugSuccessLog', String(...log))
|
|
297
302
|
}
|
|
298
303
|
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
304
|
+
warnLog(...log: any[]): void {
|
|
305
|
+
if (!this.enablingDeviceLogging()) {
|
|
306
|
+
return
|
|
302
307
|
}
|
|
308
|
+
this.logWith('warn', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
303
309
|
}
|
|
304
310
|
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
309
|
-
}
|
|
311
|
+
debugWarnLog(...log: any[]): void {
|
|
312
|
+
if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
|
|
313
|
+
return
|
|
310
314
|
}
|
|
315
|
+
this.logWith('warn', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugWarnLog', String(...log))
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
318
|
+
errorLog(...log: any[]): void {
|
|
319
|
+
if (!this.enablingDeviceLogging()) {
|
|
320
|
+
return
|
|
316
321
|
}
|
|
322
|
+
this.logWith('error', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
317
323
|
}
|
|
318
324
|
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
323
|
-
}
|
|
325
|
+
debugErrorLog(...log: any[]): void {
|
|
326
|
+
if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
|
|
327
|
+
return
|
|
324
328
|
}
|
|
329
|
+
this.logWith('error', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugErrorLog', String(...log))
|
|
325
330
|
}
|
|
326
331
|
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
debugLog(...log: any[]): void {
|
|
333
|
+
if (!this.enablingDeviceLogging()) {
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
if (this.deviceLogging === 'debug') {
|
|
337
|
+
this.logWith('debug', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugLog', String(...log))
|
|
338
|
+
} else if (this.deviceLogging === 'debugMode') {
|
|
339
|
+
this.logWith('debug', `${this.device.remoteType}: ${this.accessory.displayName}`, 'debugLog', String(...log))
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Generic platform/local logger delegate
|
|
344
|
+
protected logWith(level: string, message: string, platformMethodName?: string, payload?: string): void {
|
|
345
|
+
const method = platformMethodName ?? `${level}Log`
|
|
346
|
+
const pFn = (this.platform as any)?.[method]
|
|
347
|
+
if (typeof pFn === 'function') {
|
|
348
|
+
try {
|
|
349
|
+
if (payload !== undefined) {
|
|
350
|
+
pFn(message, payload)
|
|
351
|
+
} else {
|
|
352
|
+
pFn(message)
|
|
353
|
+
}
|
|
354
|
+
return
|
|
355
|
+
} catch (_err) {
|
|
356
|
+
// fallthrough to local logger
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const map: Record<string, string> = {
|
|
360
|
+
info: 'info',
|
|
361
|
+
success: 'success',
|
|
362
|
+
debug: 'debug',
|
|
363
|
+
warn: 'warn',
|
|
364
|
+
error: 'error',
|
|
365
|
+
}
|
|
366
|
+
const local = (this.log as any)[map[level] ?? level]
|
|
367
|
+
if (typeof local === 'function') {
|
|
368
|
+
if (payload !== undefined) {
|
|
369
|
+
local.call(this.log, message, payload)
|
|
370
|
+
} else {
|
|
371
|
+
local.call(this.log, message)
|
|
333
372
|
}
|
|
334
373
|
}
|
|
335
374
|
}
|
|
336
375
|
|
|
337
|
-
|
|
376
|
+
loggingIsDebug(): boolean {
|
|
338
377
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
|
|
339
378
|
}
|
|
340
379
|
|
|
341
|
-
|
|
380
|
+
enablingDeviceLogging(): boolean {
|
|
342
381
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
|
|
343
382
|
}
|
|
344
383
|
}
|