@switchbot/homebridge-switchbot 5.0.0-beta.147 → 5.0.0-beta.149
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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/manual-e2e.yml +3 -3
- package/config.schema.json +6 -0
- package/dist/SwitchBotHAPPlatform.d.ts +133 -0
- package/dist/SwitchBotHAPPlatform.d.ts.map +1 -0
- package/dist/SwitchBotHAPPlatform.js +555 -0
- package/dist/SwitchBotHAPPlatform.js.map +1 -0
- package/dist/SwitchBotMatterPlatform.d.ts +141 -0
- package/dist/SwitchBotMatterPlatform.d.ts.map +1 -0
- package/dist/SwitchBotMatterPlatform.js +536 -0
- package/dist/SwitchBotMatterPlatform.js.map +1 -0
- package/dist/deviceFactory.d.ts +2 -3
- package/dist/deviceFactory.d.ts.map +1 -1
- package/dist/deviceFactory.js +12 -3
- package/dist/deviceFactory.js.map +1 -1
- package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -1
- package/dist/homebridge-ui/endpoints/config.js +1 -18
- package/dist/homebridge-ui/endpoints/config.js.map +1 -1
- package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -1
- package/dist/homebridge-ui/endpoints/devices.js +1 -350
- package/dist/homebridge-ui/endpoints/devices.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +6 -0
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.js +22 -12
- package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -1
- package/dist/homebridge-ui/public/js/advanced-settings.ts +36 -25
- package/dist/homebridge-ui/public/js/api.d.ts +1 -1
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/api.js +111 -52
- package/dist/homebridge-ui/public/js/api.js.map +1 -1
- package/dist/homebridge-ui/public/js/api.ts +112 -53
- package/dist/homebridge-ui/public/js/app.js +234 -177
- package/dist/homebridge-ui/public/js/app.js.map +4 -4
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.js +26 -23
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -1
- package/dist/homebridge-ui/public/js/credentials.ts +26 -25
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.js +3 -10
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices-delete.ts +3 -12
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
- package/dist/homebridge-ui/public/js/devices.js +0 -3
- package/dist/homebridge-ui/public/js/devices.js.map +1 -1
- package/dist/homebridge-ui/public/js/devices.ts +5 -9
- package/dist/homebridge-ui/server.js +0 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -0
- package/dist/settings.js.map +1 -1
- package/dist/switchbotClient.js +1 -1
- package/dist/switchbotClient.js.map +1 -1
- package/dist/utils.d.ts +76 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1117 -2
- package/dist/utils.js.map +1 -1
- package/docs/variables/default.html +3 -1
- package/package.json +1 -1
- package/src/SwitchBotHAPPlatform.ts +558 -0
- package/src/SwitchBotMatterPlatform.ts +538 -0
- package/src/deviceFactory.ts +14 -6
- package/src/homebridge-ui/endpoints/config.ts +2 -18
- package/src/homebridge-ui/endpoints/devices.ts +1 -392
- package/src/homebridge-ui/public/index.html +6 -0
- package/src/homebridge-ui/public/js/advanced-settings.ts +36 -25
- package/src/homebridge-ui/public/js/api.ts +112 -53
- package/src/homebridge-ui/public/js/credentials.ts +26 -25
- package/src/homebridge-ui/public/js/devices-delete.ts +3 -12
- package/src/homebridge-ui/public/js/devices.ts +5 -9
- package/src/homebridge-ui/server.ts +0 -2
- package/src/index.ts +12 -2
- package/src/settings.ts +2 -0
- package/src/switchbotClient.ts +1 -1
- package/src/utils.ts +1128 -3
- package/test/platform/accessory-restore.spec.ts +2 -1
- package/test/platform/matter-childbridge.spec.ts +1 -1
- package/test/platform/matter-integration.spec.ts +1 -1
- package/test/platform/platform-edge.spec.ts +2 -1
- package/test/platform/platform.integration.spec.ts +1 -1
- package/dist/homebridge-ui/endpoints/credentials.d.ts +0 -6
- package/dist/homebridge-ui/endpoints/credentials.d.ts.map +0 -1
- package/dist/homebridge-ui/endpoints/credentials.js +0 -65
- package/dist/homebridge-ui/endpoints/credentials.js.map +0 -1
- package/dist/platform.d.ts +0 -48
- package/dist/platform.d.ts.map +0 -1
- package/dist/platform.js +0 -1733
- package/dist/platform.js.map +0 -1
- package/src/homebridge-ui/endpoints/credentials.ts +0 -74
- package/src/platform.ts +0 -1750
package/.github/workflows/ci.yml
CHANGED
|
@@ -43,12 +43,12 @@ jobs:
|
|
|
43
43
|
runs-on: ubuntu-latest
|
|
44
44
|
steps:
|
|
45
45
|
- name: Checkout
|
|
46
|
-
uses: actions/checkout@
|
|
46
|
+
uses: actions/checkout@v6
|
|
47
47
|
|
|
48
48
|
- name: Setup Node
|
|
49
|
-
uses: actions/setup-node@
|
|
49
|
+
uses: actions/setup-node@v6
|
|
50
50
|
with:
|
|
51
|
-
node-version: '
|
|
51
|
+
node-version: '22'
|
|
52
52
|
|
|
53
53
|
- name: Install dependencies
|
|
54
54
|
run: npm ci --prefer-offline --no-audit --progress=false
|
package/config.schema.json
CHANGED
|
@@ -27,6 +27,12 @@
|
|
|
27
27
|
"description": "Optional OpenAPI secret for certain account setups.",
|
|
28
28
|
"format": "password"
|
|
29
29
|
},
|
|
30
|
+
"enableBLE": {
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"title": "Enable BLE (Bluetooth)",
|
|
33
|
+
"description": "Enable or disable BLE (Bluetooth Low Energy) support. If disabled, only OpenAPI (cloud) will be used.",
|
|
34
|
+
"default": true
|
|
35
|
+
},
|
|
30
36
|
"devices": {
|
|
31
37
|
"type": "array",
|
|
32
38
|
"title": "Devices",
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { SwitchBotPluginConfig } from './settings.js';
|
|
2
|
+
import type { API, Logger, PlatformConfig } from 'homebridge';
|
|
3
|
+
/**
|
|
4
|
+
* Homebridge platform class for SwitchBot HAP (HomeKit Accessory Protocol) integration.
|
|
5
|
+
* Handles device discovery, registration, polling, and accessory lifecycle for HAP-enabled SwitchBot devices.
|
|
6
|
+
*
|
|
7
|
+
* @class SwitchBotHAPPlatform
|
|
8
|
+
* @param {Logger} log - Homebridge logger instance
|
|
9
|
+
* @param {PlatformConfig} config - Platform configuration object
|
|
10
|
+
* @param {API} [api] - Optional Homebridge API instance
|
|
11
|
+
* @property {API | undefined} api - Homebridge API instance
|
|
12
|
+
* @property {Logger} log - Homebridge logger instance
|
|
13
|
+
* @property {SwitchBotPluginConfig} config - Parsed plugin config
|
|
14
|
+
* @property {any[]} devices - All created device instances
|
|
15
|
+
* @property {Map<string, any>} accessories - Map of accessory UUID to accessory object
|
|
16
|
+
* @property {string} lastConfigHash - Hash of last loaded config for change detection
|
|
17
|
+
* @property {NodeJS.Timeout | null} configReloadInterval - Interval for periodic config reload
|
|
18
|
+
* @property {Map<string, NodeJS.Timeout>} openApiPollTimers - Timers for per-device OpenAPI polling
|
|
19
|
+
* @property {NodeJS.Timeout | null} openApiBatchTimer - Timer for batched OpenAPI polling
|
|
20
|
+
* @property {number} openApiRequestsToday - Count of OpenAPI requests made today
|
|
21
|
+
* @property {number} openApiLastReset - Timestamp (ms) of last OpenAPI daily counter reset
|
|
22
|
+
*/
|
|
23
|
+
export declare class SwitchBotHAPPlatform {
|
|
24
|
+
/** Homebridge API instance */
|
|
25
|
+
api: API | undefined;
|
|
26
|
+
/** Homebridge logger instance */
|
|
27
|
+
log: Logger;
|
|
28
|
+
/** Parsed plugin config */
|
|
29
|
+
config: SwitchBotPluginConfig;
|
|
30
|
+
/** All created device instances */
|
|
31
|
+
devices: any[];
|
|
32
|
+
/** Map of accessory UUID to accessory object */
|
|
33
|
+
accessories: Map<string, any>;
|
|
34
|
+
/** Hash of last loaded config for change detection */
|
|
35
|
+
private lastConfigHash;
|
|
36
|
+
/** Interval for periodic config reload */
|
|
37
|
+
private configReloadInterval;
|
|
38
|
+
/** Timers for per-device OpenAPI polling */
|
|
39
|
+
private openApiPollTimers;
|
|
40
|
+
/** Timer for batched OpenAPI polling */
|
|
41
|
+
private openApiBatchTimer;
|
|
42
|
+
/** Count of OpenAPI requests made today */
|
|
43
|
+
private openApiRequestsToday;
|
|
44
|
+
/** Timestamp (ms) of last OpenAPI daily counter reset */
|
|
45
|
+
private openApiLastReset;
|
|
46
|
+
/**
|
|
47
|
+
* Construct the SwitchBot HAP platform.
|
|
48
|
+
* @param log Homebridge logger
|
|
49
|
+
* @param config Platform config
|
|
50
|
+
* @param api Homebridge API instance
|
|
51
|
+
*/
|
|
52
|
+
constructor(log: Logger, config: PlatformConfig, api?: API);
|
|
53
|
+
/**
|
|
54
|
+
* Discover and create all device instances from config.
|
|
55
|
+
* Populates this.devices and registers HAP accessories for each device.
|
|
56
|
+
* Ensures Matter API is loaded before loading devices if available.
|
|
57
|
+
*
|
|
58
|
+
* @returns {Promise<void>} Resolves when all devices are loaded and registered
|
|
59
|
+
*/
|
|
60
|
+
loadDevices(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Registers all HAP accessories with the Homebridge HAP API.
|
|
63
|
+
*
|
|
64
|
+
* This method is called after all device instances have been created. It handles both new and restored
|
|
65
|
+
* accessories, updating their context and adding or updating HAP services and characteristics as needed.
|
|
66
|
+
* Accessories are registered with Homebridge using the HAP API, and the internal accessory map is updated accordingly.
|
|
67
|
+
*
|
|
68
|
+
* @param {Array<{created: any, d: any, type: string}>} createdDevices - Array of device descriptors:
|
|
69
|
+
* - created: The created device instance
|
|
70
|
+
* - d: The normalized device config object
|
|
71
|
+
* - type: The normalized device type string
|
|
72
|
+
* @returns {Promise<void>} Resolves when registration is complete
|
|
73
|
+
*
|
|
74
|
+
* Differences from Matter registration:
|
|
75
|
+
* - Uses the HAP API (not Matter API) for accessory registration.
|
|
76
|
+
* - Adds HAP services and characteristics to each accessory based on the device descriptor.
|
|
77
|
+
* - Does not require or check for Matter support or availability.
|
|
78
|
+
* - Accessory context and service wiring are HAP-specific.
|
|
79
|
+
*
|
|
80
|
+
* If the Homebridge HAP API is not available, registration is skipped and a log message is emitted.
|
|
81
|
+
*/
|
|
82
|
+
private registerHAPAccessories;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the timestamp (ms) of the last OpenAPI daily counter reset.
|
|
85
|
+
* @returns {number} Timestamp in ms
|
|
86
|
+
*/
|
|
87
|
+
getOpenApiLastReset(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Logs the last OpenAPI reset time in a human-readable format.
|
|
90
|
+
* @returns {void}
|
|
91
|
+
*/
|
|
92
|
+
logOpenApiLastReset(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Compute a hash of the current device config for change detection.
|
|
95
|
+
* @returns {string} JSON string hash of device config
|
|
96
|
+
*/
|
|
97
|
+
private getConfigHash;
|
|
98
|
+
/**
|
|
99
|
+
* Reload devices if config has changed since last load.
|
|
100
|
+
* Unregisters accessories and removes devices no longer in config.
|
|
101
|
+
* Calls loadDevices to repopulate devices and accessories.
|
|
102
|
+
*
|
|
103
|
+
* @returns {Promise<void>} Resolves when reload is complete
|
|
104
|
+
*/
|
|
105
|
+
private checkAndReloadDevices;
|
|
106
|
+
/**
|
|
107
|
+
* Cleanup method to clear config reload interval on shutdown.
|
|
108
|
+
* Called by Homebridge on shutdown event.
|
|
109
|
+
* @returns {void}
|
|
110
|
+
*/
|
|
111
|
+
shutdown(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Setup OpenAPI polling for all devices according to config (global, per-device, batch, rate limit).
|
|
114
|
+
* Handles daily request limits, per-device and batch polling, and resets.
|
|
115
|
+
*
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
118
|
+
private _setupOpenApiPolling;
|
|
119
|
+
/**
|
|
120
|
+
* Called by Homebridge to restore cached HAP accessories on startup.
|
|
121
|
+
* @param {any} accessory - The cached accessory object
|
|
122
|
+
* @returns {Promise<void>} Resolves when accessory is restored
|
|
123
|
+
*/
|
|
124
|
+
configureAccessory(accessory: any): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Called by Homebridge when a cached Matter accessory is restored (optional signature).
|
|
127
|
+
* @param {any} accessory - The cached accessory object
|
|
128
|
+
* @returns {void}
|
|
129
|
+
*/
|
|
130
|
+
configureMatterAccessory?(accessory: any): void;
|
|
131
|
+
}
|
|
132
|
+
export default SwitchBotHAPPlatform;
|
|
133
|
+
//# sourceMappingURL=SwitchBotHAPPlatform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwitchBotHAPPlatform.d.ts","sourceRoot":"","sources":["../src/SwitchBotHAPPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAO7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,oBAAoB;IAC/B,8BAA8B;IAC9B,GAAG,EAAE,GAAG,GAAG,SAAS,CAAA;IACpB,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,2BAA2B;IAC3B,MAAM,EAAE,qBAAqB,CAAA;IAC7B,mCAAmC;IACnC,OAAO,EAAE,GAAG,EAAE,CAAK;IACnB,gDAAgD;IAChD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,sDAAsD;IACtD,OAAO,CAAC,cAAc,CAAa;IACnC,0CAA0C;IAC1C,OAAO,CAAC,oBAAoB,CAA8B;IAC1D,4CAA4C;IAC5C,OAAO,CAAC,iBAAiB,CAAyC;IAClE,wCAAwC;IACxC,OAAO,CAAC,iBAAiB,CAA8B;IACvD,2CAA2C;IAC3C,OAAO,CAAC,oBAAoB,CAAI;IAChC,yDAAyD;IACzD,OAAO,CAAC,gBAAgB,CAAI;IAE5B;;;;;OAKG;gBACS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,GAAG;IA2C1D;;;;;;OAMG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DlC;;;;;;;;;;;;;;;;;;;;OAoBG;YACW,sBAAsB;IAgHpC;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAI7B;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAS3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAUrB;;;;;;OAMG;YACW,qBAAqB;IAiCnC;;;;OAIG;IACH,QAAQ,IAAI,IAAI;IAQhB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAkI5B;;;;OAIG;IACG,kBAAkB,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD;;;;OAIG;IACH,wBAAwB,CAAC,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;CAShD;AAED,eAAe,oBAAoB,CAAA"}
|