@switchbot/homebridge-switchbot 3.5.0-beta.1 → 3.5.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/dist/device/waterdetector.d.ts +92 -0
- package/dist/device/waterdetector.d.ts.map +1 -0
- package/dist/device/waterdetector.js +846 -0
- package/dist/device/waterdetector.js.map +1 -0
- package/dist/platform.d.ts +1 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +62 -0
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +6 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/waterdetector.ts +884 -0
- package/src/platform.ts +65 -0
- package/src/settings.ts +7 -0
package/src/platform.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { Hub } from './device/hub.js';
|
|
|
13
13
|
import { Contact } from './device/contact.js';
|
|
14
14
|
import { Curtain } from './device/curtain.js';
|
|
15
15
|
import { IOSensor } from './device/iosensor.js';
|
|
16
|
+
import { WaterDetector } from './device/waterdetector.js';
|
|
16
17
|
import { MeterPlus } from './device/meterplus.js';
|
|
17
18
|
import { ColorBulb } from './device/colorbulb.js';
|
|
18
19
|
import { CeilingLight } from './device/ceilinglight.js';
|
|
@@ -654,6 +655,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
654
655
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
655
656
|
this.createIOSensor(device);
|
|
656
657
|
break;
|
|
658
|
+
case 'Water Detector':
|
|
659
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
660
|
+
this.createWaterDetector(device);
|
|
661
|
+
break;
|
|
657
662
|
case 'Motion Sensor':
|
|
658
663
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
659
664
|
this.createMotion(device);
|
|
@@ -1150,6 +1155,66 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1150
1155
|
}
|
|
1151
1156
|
}
|
|
1152
1157
|
|
|
1158
|
+
private async createWaterDetector(device: device & devicesConfig) {
|
|
1159
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1160
|
+
|
|
1161
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
1162
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
1163
|
+
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1164
|
+
|
|
1165
|
+
if (existingAccessory) {
|
|
1166
|
+
// the accessory already exists
|
|
1167
|
+
if (await this.registerDevice(device)) {
|
|
1168
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1169
|
+
existingAccessory.context.model = device.deviceType;
|
|
1170
|
+
existingAccessory.context.deviceID = device.deviceId;
|
|
1171
|
+
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1172
|
+
if (device.firmware) {
|
|
1173
|
+
existingAccessory.context.FirmwareRevision = device.firmware;
|
|
1174
|
+
}
|
|
1175
|
+
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1176
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1177
|
+
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1178
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1179
|
+
// create the accessory handler for the restored accessory
|
|
1180
|
+
// this is imported from `platformAccessory.ts`
|
|
1181
|
+
new WaterDetector(this, existingAccessory, device);
|
|
1182
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1183
|
+
} else {
|
|
1184
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
1185
|
+
}
|
|
1186
|
+
} else if (await this.registerDevice(device)) {
|
|
1187
|
+
// the accessory does not yet exist, so we need to create it
|
|
1188
|
+
if (!device.external) {
|
|
1189
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// create a new accessory
|
|
1193
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1194
|
+
|
|
1195
|
+
// store a copy of the device object in the `accessory.context`
|
|
1196
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
1197
|
+
accessory.context.device = device;
|
|
1198
|
+
accessory.context.model = device.deviceType;
|
|
1199
|
+
accessory.context.deviceID = device.deviceId;
|
|
1200
|
+
if (device.firmware) {
|
|
1201
|
+
accessory.context.FirmwareRevision = device.firmware;
|
|
1202
|
+
}
|
|
1203
|
+
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1204
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1205
|
+
// create the accessory handler for the newly create accessory
|
|
1206
|
+
// this is imported from `platformAccessory.ts`
|
|
1207
|
+
new WaterDetector(this, accessory, device);
|
|
1208
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1209
|
+
|
|
1210
|
+
// publish device externally or link the accessory to your platform
|
|
1211
|
+
this.externalOrPlatform(device, accessory);
|
|
1212
|
+
this.accessories.push(accessory);
|
|
1213
|
+
} else {
|
|
1214
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1153
1218
|
private async createMotion(device: device & devicesConfig) {
|
|
1154
1219
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1155
1220
|
|
package/src/settings.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface devicesConfig extends device {
|
|
|
72
72
|
blindTilt?: blindTilt;
|
|
73
73
|
contact?: contact;
|
|
74
74
|
motion?: motion;
|
|
75
|
+
waterdetector?: waterdetector;
|
|
75
76
|
colorbulb?: colorbulb;
|
|
76
77
|
striplight?: striplight;
|
|
77
78
|
ceilinglight?: ceilinglight;
|
|
@@ -138,6 +139,12 @@ export type motion = {
|
|
|
138
139
|
set_maxLux?: number;
|
|
139
140
|
};
|
|
140
141
|
|
|
142
|
+
export type waterdetector = {
|
|
143
|
+
hide_leak?: boolean;
|
|
144
|
+
hide_temperature?: boolean;
|
|
145
|
+
hide_humidity?: boolean;
|
|
146
|
+
};
|
|
147
|
+
|
|
141
148
|
export type colorbulb = {
|
|
142
149
|
set_minStep?: number;
|
|
143
150
|
adaptiveLightingShift?: number;
|