@switchbot/homebridge-switchbot 2.6.0-beta.0 → 2.6.0-beta.2

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/README.md CHANGED
@@ -131,8 +131,6 @@
131
131
  - If using Bluetooth Low Energy (BLE) only:
132
132
  - Must supply `deviceId` & `deviceName` to Device Config
133
133
  - Check `Enable Bluetooth Low Energy (BLE) Connection` on Device Config
134
- - SwitchBot Plug
135
- - Supports OpenAPI Connection Only
136
134
 
137
135
  ## Supported IR Devices
138
136
 
@@ -96,6 +96,11 @@
96
96
  "title": "Motion Sensor",
97
97
  "enum": ["Motion Sensor"]
98
98
  },
99
+
100
+ {
101
+ "title": "Hub 2",
102
+ "enum": ["Hub 2"]
103
+ },
99
104
  {
100
105
  "title": "Contact Sensor",
101
106
  "enum": ["Contact Sensor"]
@@ -184,7 +189,7 @@
184
189
  ],
185
190
  "description": "Bluetooth (BLE) API is only available for the following Device Types: Humidifier, Meter, MeterPlus, Curtain, Bot, Motion Sensor, Contact Sensor, Plug Mini (US), Plug Mini (JP), & Color Bulb",
186
191
  "condition": {
187
- "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);"
192
+ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType !== 'Hub 2');"
188
193
  }
189
194
  },
190
195
  "customBLEaddress": {
@@ -203,6 +208,25 @@
203
208
  "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && (model.options.devices[arrayIndices].connectionType === 'BLE' || model.options.devices[arrayIndices].connectionType === 'BLE/OpenAPI'));"
204
209
  }
205
210
  },
211
+ "hidHub": {
212
+ "type": "object",
213
+ "properties": {
214
+ "hide_temperature": {
215
+ "title": "Hide Hub 2's Temperature Sensor",
216
+ "type": "boolean",
217
+ "condition": {
218
+ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && (model.options.devices[arrayIndices].configDeviceType === 'Hub 2') && model.options.devices[arrayIndices].deviceId);"
219
+ }
220
+ },
221
+ "hide_humidity": {
222
+ "title": "Hide Hub 2's Humidity Sensor",
223
+ "type": "boolean",
224
+ "condition": {
225
+ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && (model.options.devices[arrayIndices].configDeviceType === 'Hub 2') && model.options.devices[arrayIndices].deviceId);"
226
+ }
227
+ }
228
+ }
229
+ },
206
230
  "bot": {
207
231
  "type": "object",
208
232
  "properties": {
@@ -1134,6 +1158,8 @@
1134
1158
  "options.devices[].hide_device",
1135
1159
  "options.devices[].configDeviceType",
1136
1160
  "options.devices[].connectionType",
1161
+ "options.devices[].hidHub.hide_temperature",
1162
+ "options.devices[].hidHub.hide_humidity",
1137
1163
  "options.devices[].scanDuration",
1138
1164
  "options.devices[].disableCaching",
1139
1165
  "options.devices[].maxRetry",
@@ -0,0 +1,65 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Context } from 'vm';
4
+ import { IncomingMessage } from 'http';
5
+ import { SwitchBotPlatform } from '../platform';
6
+ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
+ import { device, devicesConfig } from '../settings';
8
+ export declare class Hub {
9
+ private readonly platform;
10
+ private accessory;
11
+ device: device & devicesConfig;
12
+ hubTemperatureSensor: Service;
13
+ hubHumiditySensor: Service;
14
+ CurrentRelativeHumidity: number;
15
+ CurrentTemperature: number;
16
+ deviceStatus: any;
17
+ set_minStep: number;
18
+ updateRate: number;
19
+ set_minLux: number;
20
+ set_maxLux: number;
21
+ scanDuration: number;
22
+ deviceLogging: string;
23
+ deviceRefreshRate: number;
24
+ private readonly BLE;
25
+ private readonly OpenAPI;
26
+ constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device & devicesConfig);
27
+ /**
28
+ * Parse the device status from the SwitchBot api
29
+ */
30
+ parseStatus(): Promise<void>;
31
+ openAPIparseStatus(): Promise<void>;
32
+ refreshStatus(): Promise<void>;
33
+ openAPIRefreshStatus(): Promise<void>;
34
+ retry({ max, fn }: {
35
+ max: number;
36
+ fn: {
37
+ (): any;
38
+ (): Promise<any>;
39
+ };
40
+ }): Promise<null>;
41
+ maxRetry(): number;
42
+ /**
43
+ * Handle requests to set the value of the "Target Position" characteristic
44
+ */
45
+ updateHomeKitCharacteristics(): Promise<void>;
46
+ statusCode({ res }: {
47
+ res: IncomingMessage;
48
+ }): Promise<void>;
49
+ offlineOff(): Promise<void>;
50
+ apiError(e: any): Promise<void>;
51
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue;
52
+ refreshRate(device: device & devicesConfig): Promise<void>;
53
+ logs(device: device & devicesConfig): Promise<void>;
54
+ /**
55
+ * Logging for Device
56
+ */
57
+ infoLog(...log: any[]): void;
58
+ warnLog(...log: any[]): void;
59
+ debugWarnLog(...log: any[]): void;
60
+ errorLog(...log: any[]): void;
61
+ debugErrorLog(...log: any[]): void;
62
+ debugLog(...log: any[]): void;
63
+ enablingDeviceLogging(): boolean;
64
+ }
65
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/device/hub.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAC;AAG5E,qBAAa,GAAG;IAyBF,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAqB,OAAO,CAAC,SAAS;IA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AAC,IAAI,CAAC;IAM3B,QAAQ,CAAC,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrC,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,mBAAmB;IAiBtG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB1D,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBzD;;OAEG;IACH,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,YAAY,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAQjC,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7B,aAAa,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAQlC,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAU7B,qBAAqB,IAAI,OAAO;CAGjC"}
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Hub = void 0;
7
+ const https_1 = __importDefault(require("https"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const rxjs_1 = require("rxjs");
10
+ const super_stringify_1 = __importDefault(require("super-stringify"));
11
+ const settings_1 = require("../settings");
12
+ const utils_1 = require("../utils");
13
+ class Hub {
14
+ constructor(platform, accessory, device) {
15
+ this.platform = platform;
16
+ this.accessory = accessory;
17
+ this.device = device;
18
+ // Connection
19
+ this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
20
+ this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
21
+ // default placeholders
22
+ this.logs(device);
23
+ this.refreshRate(device);
24
+ this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
25
+ this.CurrentTemperature = accessory.context.CurrentTemperature;
26
+ // Retrieve initial values and updateHomekit
27
+ this.refreshStatus();
28
+ // set accessory information
29
+ accessory
30
+ .getService(this.platform.Service.AccessoryInformation)
31
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
32
+ .setCharacteristic(this.platform.Characteristic.Model, accessory.context.model)
33
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
34
+ .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
35
+ .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
36
+ .updateValue(this.FirmwareRevision(accessory, device));
37
+ // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
38
+ // you can create multiple services for each accessory
39
+ (this.hubTemperatureSensor =
40
+ accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
41
+ `${device.deviceName} ${device.deviceType}`;
42
+ (this.hubHumiditySensor =
43
+ accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
44
+ `${device.deviceName} ${device.deviceType}`;
45
+ // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
46
+ // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
47
+ // accessory.getService('NAME') ?? accessory.addService(this.platform.Service.WindowCovering, 'NAME', 'USER_DEFINED_SUBTYPE');
48
+ // set the service name, this is what is displayed as the default name on the Home app
49
+ // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
50
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
+ if (!this.hubTemperatureSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
52
+ this.hubTemperatureSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
53
+ }
54
+ this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
55
+ if (!this.hubHumiditySensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
56
+ this.hubHumiditySensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
57
+ }
58
+ // each service must implement at-minimum the "required characteristics" for the given service type
59
+ // see https://developers.homebridge.io/#/service/WindowCovering
60
+ // console.log(this.hubHumiditySensor);
61
+ // Humidity Sensor Service
62
+ if (device.hub?.hide_humidity) {
63
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
64
+ this.hubHumiditySensor = this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, false);
65
+ accessory.removeService(this.hubHumiditySensor);
66
+ }
67
+ else if (!this.hubHumiditySensor) {
68
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
69
+ (this.hubHumiditySensor =
70
+ accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
71
+ `${device.deviceName} ${device.deviceType}`;
72
+ this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
73
+ this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
74
+ }
75
+ else {
76
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
77
+ }
78
+ // Temperature Sensor Service
79
+ if (device.hub?.hide_temperature) {
80
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
81
+ this.hubTemperatureSensor = this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, false);
82
+ accessory.removeService(this.hubTemperatureSensor);
83
+ }
84
+ else if (!this.hubTemperatureSensor) {
85
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
86
+ (this.hubTemperatureSensor =
87
+ accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
88
+ `${device.deviceName} ${device.deviceType}`;
89
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
90
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
91
+ }
92
+ else {
93
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
94
+ }
95
+ // Update Homekit
96
+ this.updateHomeKitCharacteristics();
97
+ // Start an update interval
98
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000).subscribe(async () => {
99
+ await this.refreshStatus();
100
+ });
101
+ }
102
+ /**
103
+ * Parse the device status from the SwitchBot api
104
+ */
105
+ async parseStatus() {
106
+ if (this.OpenAPI && this.platform.config.credentials?.token) {
107
+ await this.openAPIparseStatus();
108
+ }
109
+ else {
110
+ await this.offlineOff();
111
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
112
+ }
113
+ }
114
+ async openAPIparseStatus() {
115
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
116
+ this.infoLog(`update temperature and humidity for ${this.accessory.displayName}`);
117
+ // this.infoLog(`temp: ${this.CurrentTemperature}, humidity: ${this.CurrentRelativeHumidity}`);
118
+ this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
119
+ this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
120
+ }
121
+ async refreshStatus() {
122
+ if (this.OpenAPI && this.platform.config.credentials?.token) {
123
+ await this.openAPIRefreshStatus();
124
+ }
125
+ else {
126
+ await this.offlineOff();
127
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type: OpenAPI, refreshStatus will not happen.`);
128
+ }
129
+ }
130
+ async openAPIRefreshStatus() {
131
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
132
+ try {
133
+ const t = Date.now();
134
+ const nonce = 'requestID';
135
+ const data = this.platform.config.credentials?.token + t + nonce;
136
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
137
+ const sign = signTerm.toString('base64');
138
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
139
+ const options = {
140
+ hostname: settings_1.HostDomain,
141
+ port: 443,
142
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
143
+ method: 'GET',
144
+ headers: {
145
+ Authorization: this.platform.config.credentials?.token,
146
+ sign: sign,
147
+ nonce: nonce,
148
+ t: t,
149
+ 'Content-Type': 'application/json',
150
+ },
151
+ };
152
+ const req = https_1.default.request(options, (res) => {
153
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
154
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}: ${res}`);
155
+ let rawData = '';
156
+ res.on('data', (d) => {
157
+ rawData += d;
158
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
159
+ });
160
+ res.on('end', () => {
161
+ try {
162
+ this.deviceStatus = JSON.parse(rawData);
163
+ this.CurrentTemperature = this.deviceStatus.body.temperature;
164
+ this.CurrentRelativeHumidity = this.deviceStatus.body.humidity;
165
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
166
+ this.openAPIparseStatus();
167
+ this.updateHomeKitCharacteristics();
168
+ }
169
+ catch (e) {
170
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
171
+ }
172
+ });
173
+ });
174
+ req.on('error', (e) => {
175
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
176
+ });
177
+ req.end();
178
+ }
179
+ catch (e) {
180
+ this.apiError(e);
181
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
182
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
183
+ }
184
+ }
185
+ async retry({ max, fn }) {
186
+ return fn().catch(async (e) => {
187
+ if (max === 0) {
188
+ throw e;
189
+ }
190
+ this.infoLog(e);
191
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
192
+ await (0, utils_1.sleep)(1000);
193
+ return this.retry({ max: max - 1, fn });
194
+ });
195
+ }
196
+ maxRetry() {
197
+ if (this.device.maxRetry) {
198
+ return this.device.maxRetry;
199
+ }
200
+ else {
201
+ return 5;
202
+ }
203
+ }
204
+ /**
205
+ * Handle requests to set the value of the "Target Position" characteristic
206
+ */
207
+ async updateHomeKitCharacteristics() {
208
+ this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
209
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
210
+ this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
211
+ }
212
+ async statusCode({ res }) {
213
+ switch (res.statusCode) {
214
+ case 151:
215
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
216
+ break;
217
+ case 152:
218
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
219
+ break;
220
+ case 160:
221
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
222
+ break;
223
+ case 161:
224
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
225
+ this.offlineOff();
226
+ break;
227
+ case 171:
228
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
229
+ this.offlineOff();
230
+ break;
231
+ case 190:
232
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
233
+ ` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
234
+ break;
235
+ case 100:
236
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
237
+ break;
238
+ default:
239
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
240
+ }
241
+ }
242
+ async offlineOff() {
243
+ if (this.device.offline) {
244
+ await this.updateHomeKitCharacteristics();
245
+ }
246
+ }
247
+ async apiError(e) {
248
+ this.hubTemperatureSensor?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
249
+ this.hubHumiditySensor?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
250
+ }
251
+ FirmwareRevision(accessory, device) {
252
+ let FirmwareRevision;
253
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
254
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
255
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
256
+ if (accessory.context.FirmwareRevision) {
257
+ FirmwareRevision = accessory.context.FirmwareRevision;
258
+ }
259
+ else if (device.firmware) {
260
+ FirmwareRevision = device.firmware;
261
+ }
262
+ else {
263
+ FirmwareRevision = this.platform.version;
264
+ }
265
+ return FirmwareRevision;
266
+ }
267
+ async refreshRate(device) {
268
+ // refreshRate
269
+ if (device.refreshRate) {
270
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
271
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
272
+ }
273
+ else if (this.platform.config.options.refreshRate) {
274
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
275
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
276
+ }
277
+ // updateRate
278
+ if (device?.curtain?.updateRate) {
279
+ this.updateRate = device?.curtain?.updateRate;
280
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Curtain updateRate: ${this.updateRate}`);
281
+ }
282
+ else {
283
+ this.updateRate = 7;
284
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Curtain updateRate: ${this.updateRate}`);
285
+ }
286
+ }
287
+ async logs(device) {
288
+ if (this.platform.debugMode) {
289
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
290
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
291
+ }
292
+ else if (device.logging) {
293
+ this.deviceLogging = this.accessory.context.logging = device.logging;
294
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
295
+ }
296
+ else if (this.platform.config.options?.logging) {
297
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
298
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
299
+ }
300
+ else {
301
+ this.deviceLogging = this.accessory.context.logging = 'standard';
302
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
303
+ }
304
+ }
305
+ /**
306
+ * Logging for Device
307
+ */
308
+ infoLog(...log) {
309
+ if (this.enablingDeviceLogging()) {
310
+ this.platform.log.info(String(...log));
311
+ }
312
+ }
313
+ warnLog(...log) {
314
+ if (this.enablingDeviceLogging()) {
315
+ this.platform.log.warn(String(...log));
316
+ }
317
+ }
318
+ debugWarnLog(...log) {
319
+ if (this.enablingDeviceLogging()) {
320
+ if (this.deviceLogging?.includes('debug')) {
321
+ this.platform.log.warn('[DEBUG]', String(...log));
322
+ }
323
+ }
324
+ }
325
+ errorLog(...log) {
326
+ if (this.enablingDeviceLogging()) {
327
+ this.platform.log.error(String(...log));
328
+ }
329
+ }
330
+ debugErrorLog(...log) {
331
+ if (this.enablingDeviceLogging()) {
332
+ if (this.deviceLogging?.includes('debug')) {
333
+ this.platform.log.error('[DEBUG]', String(...log));
334
+ }
335
+ }
336
+ }
337
+ debugLog(...log) {
338
+ if (this.enablingDeviceLogging()) {
339
+ if (this.deviceLogging === 'debug') {
340
+ this.platform.log.info('[DEBUG]', String(...log));
341
+ }
342
+ else {
343
+ this.platform.log.debug(String(...log));
344
+ }
345
+ }
346
+ }
347
+ enablingDeviceLogging() {
348
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
349
+ }
350
+ }
351
+ exports.Hub = Hub;
352
+ //# sourceMappingURL=hub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.js","sourceRoot":"","sources":["../../src/device/hub.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,oDAA4B;AAG5B,+BAAgC;AAChC,sEAA6C;AAG7C,0CAA4E;AAC5E,oCAAiC;AAEjC,MAAa,GAAG;IAyBd,YAA6B,QAA2B,EAAU,SAA4B,EAAS,MAA8B;QAAxG,aAAQ,GAAR,QAAQ,CAAmB;QAAU,cAAS,GAAT,SAAS,CAAmB;QAAS,WAAM,GAAN,MAAM,CAAwB;QAJrI,aAAa;QACI,QAAG,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,aAAa,CAAC;QAC3F,YAAO,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,IAAI,CAAC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CAAC,qBAAqB,EAAE,EAAE;YAChC,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,EAAE;gBAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;aACnD;iBAAM;gBACL,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;aACzC;SACF;IACH,CAAC;IAED,qBAAqB;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,aAAa,KAAK,UAAU,CAAC;IACnF,CAAC;CACF;AA/XD,kBA+XC"}
@@ -44,6 +44,7 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
44
44
  private createBot;
45
45
  private createMeter;
46
46
  private createMeterPlus;
47
+ private createHub2;
47
48
  private createIOSensor;
48
49
  private createMotion;
49
50
  private createContact;
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";AA+BA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACiC,MAAM,EAAE,uBAAuB,EAAE,aAAa,EAA0B,eAAe,EAAE,MAAM,YAAY,CAAC;AACpJ,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;aAajC,GAAG,EAAE,MAAM;aAAkB,MAAM,EAAE,uBAAuB;aAAkB,GAAG,EAAE,GAAG;IAZlH,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAE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I;IAM5B,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,YAAY,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAQjC,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7B,aAAa,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAQlC,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAU7B,uBAAuB,IAAI,OAAO;CAGnC"}
package/dist/platform.js CHANGED
@@ -9,6 +9,7 @@ const plug_1 = require("./device/plug");
9
9
  const lock_1 = require("./device/lock");
10
10
  const meter_1 = require("./device/meter");
11
11
  const motion_1 = require("./device/motion");
12
+ const hub_1 = require("./device/hub");
12
13
  const contact_1 = require("./device/contact");
13
14
  const curtain_1 = require("./device/curtain");
14
15
  const iosensor_1 = require("./device/iosensor");
@@ -390,6 +391,7 @@ class SwitchBotPlatform {
390
391
  break;
391
392
  case 'Hub 2':
392
393
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
394
+ this.createHub2(device);
393
395
  break;
394
396
  case 'Bot':
395
397
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
@@ -703,6 +705,7 @@ class SwitchBotPlatform {
703
705
  if (existingAccessory) {
704
706
  // the accessory already exists
705
707
  if (await this.registerDevice(device)) {
708
+ // console.log("existingAccessory", existingAccessory);
706
709
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
707
710
  existingAccessory.context.model = device.deviceType;
708
711
  existingAccessory.context.deviceID = device.deviceId;
@@ -748,6 +751,60 @@ class SwitchBotPlatform {
748
751
  this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
749
752
  }
750
753
  }
754
+ async createHub2(device) {
755
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
756
+ // see if an accessory with the same uuid has already been registered and restored from
757
+ // the cached devices we stored in the `configureAccessory` method above
758
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
759
+ if (existingAccessory) {
760
+ // the accessory already exists
761
+ if (await this.registerDevice(device)) {
762
+ // console.log("existingAccessory", existingAccessory);
763
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
764
+ existingAccessory.context.model = device.deviceType;
765
+ existingAccessory.context.deviceID = device.deviceId;
766
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
767
+ existingAccessory.context.firmwareRevision = device.firmware;
768
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
769
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
770
+ existingAccessory.context.connectionType = await this.connectionType(device);
771
+ this.api.updatePlatformAccessories([existingAccessory]);
772
+ // create the accessory handler for the restored accessory
773
+ // this is imported from `platformAccessory.ts`
774
+ new hub_1.Hub(this, existingAccessory, device);
775
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
776
+ }
777
+ else {
778
+ this.unregisterPlatformAccessories(existingAccessory);
779
+ }
780
+ }
781
+ else if (await this.registerDevice(device)) {
782
+ // the accessory does not yet exist, so we need to create it
783
+ if (!device.external) {
784
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
785
+ }
786
+ // create a new accessory
787
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
788
+ // store a copy of the device object in the `accessory.context`
789
+ // the `context` property can be used to store any data about the accessory you may need
790
+ accessory.context.device = device;
791
+ accessory.context.model = device.deviceType;
792
+ accessory.context.deviceID = device.deviceId;
793
+ accessory.context.firmwareRevision = device.firmware;
794
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
795
+ accessory.context.connectionType = await this.connectionType(device);
796
+ // create the accessory handler for the newly create accessory
797
+ // this is imported from `platformAccessory.ts`
798
+ new hub_1.Hub(this, accessory, device);
799
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
800
+ // publish device externally or link the accessory to your platform
801
+ this.externalOrPlatform(device, accessory);
802
+ this.accessories.push(accessory);
803
+ }
804
+ else {
805
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
806
+ }
807
+ }
751
808
  async createIOSensor(device) {
752
809
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
753
810
  // see if an accessory with the same uuid has already been registered and restored from