@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.11
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 +11 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +44 -17
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -2
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +220 -397
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -2
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +59 -31
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -2
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +57 -29
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +47 -18
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +16 -5
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +9 -0
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +30 -3
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +44 -18
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +46 -18
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +45 -20
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +46 -18
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +60 -31
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +48 -17
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +46 -18
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +46 -18
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +45 -17
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +40 -18
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -17
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +41 -16
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +8 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +6 -0
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +3 -0
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +3 -0
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +9 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +29 -2
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -0
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -0
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +216 -228
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +9 -0
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +3 -0
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +11 -2
- package/dist/platform.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +1 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/device/blindtilt.ts +44 -17
- package/src/device/bot.ts +224 -407
- package/src/device/ceilinglight.ts +57 -33
- package/src/device/colorbulb.ts +55 -31
- package/src/device/contact.ts +48 -19
- package/src/device/curtain.ts +19 -6
- package/src/device/device.ts +36 -3
- package/src/device/fan.ts +44 -19
- package/src/device/hub.ts +46 -18
- package/src/device/humidifier.ts +44 -20
- package/src/device/iosensor.ts +46 -18
- package/src/device/lightstrip.ts +60 -33
- package/src/device/lock.ts +49 -17
- package/src/device/meter.ts +46 -18
- package/src/device/meterplus.ts +46 -18
- package/src/device/motion.ts +46 -18
- package/src/device/plug.ts +38 -18
- package/src/device/robotvacuumcleaner.ts +41 -17
- package/src/device/waterdetector.ts +40 -16
- package/src/irdevice/airconditioner.ts +11 -2
- package/src/irdevice/airpurifier.ts +8 -0
- package/src/irdevice/camera.ts +4 -0
- package/src/irdevice/fan.ts +4 -0
- package/src/irdevice/irdevice.ts +35 -2
- package/src/irdevice/light.ts +12 -0
- package/src/irdevice/other.ts +254 -283
- package/src/irdevice/tv.ts +12 -0
- package/src/irdevice/vacuumcleaner.ts +4 -0
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +11 -2
- package/src/types/bledevicestatus.ts +1 -0
- package/src/utils.ts +15 -0
package/dist/device/bot.js
CHANGED
|
@@ -24,6 +24,7 @@ export class Bot extends deviceBase {
|
|
|
24
24
|
Fan;
|
|
25
25
|
StatefulProgrammableSwitch;
|
|
26
26
|
Outlet;
|
|
27
|
+
On;
|
|
27
28
|
// OpenAPI
|
|
28
29
|
deviceStatus;
|
|
29
30
|
//Webhook
|
|
@@ -48,8 +49,11 @@ export class Bot extends deviceBase {
|
|
|
48
49
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
49
50
|
this.doBotUpdate = new Subject();
|
|
50
51
|
this.botUpdateInProgress = false;
|
|
51
|
-
accessory.context.Battery = accessory.context.Battery ?? {};
|
|
52
52
|
// Initialize Battery property
|
|
53
|
+
accessory.context.Battery = accessory.context.Battery ?? {};
|
|
54
|
+
if (accessory.context.Battery.Name) {
|
|
55
|
+
accessory.context.Battery.Name = this.validateAndCleanString(accessory.context.Battery.Name, 'Battery Name', accessory.context.Battery.Name);
|
|
56
|
+
}
|
|
53
57
|
this.Battery = {
|
|
54
58
|
Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
|
|
55
59
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
|
|
@@ -68,21 +72,19 @@ export class Bot extends deviceBase {
|
|
|
68
72
|
accessory.category = 8 /* this.hap.Categories.SWITCH */;
|
|
69
73
|
// Initialize Switch Service
|
|
70
74
|
accessory.context.Switch = accessory.context.Switch ?? {};
|
|
75
|
+
if (accessory.context.Switch.Name) {
|
|
76
|
+
accessory.context.Switch.Name = this.validateAndCleanString(accessory.context.Switch.Name, 'Switch Name', accessory.context.Switch.Name);
|
|
77
|
+
}
|
|
71
78
|
this.Switch = {
|
|
72
79
|
Name: accessory.context.Switch.Name ?? accessory.displayName,
|
|
73
80
|
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch),
|
|
74
|
-
On: accessory.context.On ?? false,
|
|
75
81
|
};
|
|
76
82
|
accessory.context.Switch = this.Switch;
|
|
77
83
|
this.debugLog('Displaying as Switch');
|
|
78
84
|
// Initialize Switch Characteristics
|
|
79
85
|
this.Switch.Service
|
|
80
86
|
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
81
|
-
.setCharacteristic(this.hap.Characteristic.On, this.Switch.On)
|
|
82
87
|
.getCharacteristic(this.hap.Characteristic.On)
|
|
83
|
-
.onGet(() => {
|
|
84
|
-
return this.Switch.On;
|
|
85
|
-
})
|
|
86
88
|
.onSet(this.OnSet.bind(this));
|
|
87
89
|
// Remove other services
|
|
88
90
|
this.removeFanService(accessory);
|
|
@@ -100,10 +102,12 @@ export class Bot extends deviceBase {
|
|
|
100
102
|
accessory.category = 4 /* this.hap.Categories.GARAGE_DOOR_OPENER */;
|
|
101
103
|
// Initialize GarageDoor Service
|
|
102
104
|
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
|
|
105
|
+
if (accessory.context.GarageDoor.Name) {
|
|
106
|
+
accessory.context.GarageDoor.Name = this.validateAndCleanString(accessory.context.GarageDoor.Name, 'GarageDoor Name', accessory.context.GarageDoor.Name);
|
|
107
|
+
}
|
|
103
108
|
this.GarageDoor = {
|
|
104
109
|
Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
|
|
105
110
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener),
|
|
106
|
-
On: accessory.context.On ?? false,
|
|
107
111
|
};
|
|
108
112
|
accessory.context.GarageDoor = this.GarageDoor;
|
|
109
113
|
this.debugLog('Displaying as Garage Door Opener');
|
|
@@ -111,14 +115,12 @@ export class Bot extends deviceBase {
|
|
|
111
115
|
this.GarageDoor.Service
|
|
112
116
|
.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
|
|
113
117
|
.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
114
|
-
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
118
|
+
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
119
|
+
.setProps({
|
|
115
120
|
validValues: [0, 100],
|
|
116
121
|
minValue: 0,
|
|
117
122
|
maxValue: 100,
|
|
118
123
|
minStep: 100,
|
|
119
|
-
})
|
|
120
|
-
.onGet(() => {
|
|
121
|
-
return this.GarageDoor.On;
|
|
122
124
|
})
|
|
123
125
|
.onSet(this.OnSet.bind(this));
|
|
124
126
|
// Remove other services
|
|
@@ -137,10 +139,12 @@ export class Bot extends deviceBase {
|
|
|
137
139
|
accessory.category = 12 /* this.hap.Categories.DOOR */;
|
|
138
140
|
// Initialize Door Service
|
|
139
141
|
accessory.context.Door = accessory.context.Door ?? {};
|
|
142
|
+
if (accessory.context.Door.Name) {
|
|
143
|
+
accessory.context.Door.Name = this.validateAndCleanString(accessory.context.Door.Name, 'Door Name', accessory.context.Door.Name);
|
|
144
|
+
}
|
|
140
145
|
this.Door = {
|
|
141
146
|
Name: accessory.context.Door.Name ?? accessory.displayName,
|
|
142
147
|
Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door),
|
|
143
|
-
On: accessory.context.On ?? false,
|
|
144
148
|
};
|
|
145
149
|
accessory.context.Door = this.Door;
|
|
146
150
|
this.debugLog('Displaying as Door');
|
|
@@ -153,9 +157,6 @@ export class Bot extends deviceBase {
|
|
|
153
157
|
minValue: 0,
|
|
154
158
|
maxValue: 100,
|
|
155
159
|
minStep: 100,
|
|
156
|
-
})
|
|
157
|
-
.onGet(() => {
|
|
158
|
-
return this.Door.On;
|
|
159
160
|
})
|
|
160
161
|
.onSet(this.OnSet.bind(this));
|
|
161
162
|
// Remove other services
|
|
@@ -174,10 +175,12 @@ export class Bot extends deviceBase {
|
|
|
174
175
|
accessory.category = 13 /* this.hap.Categories.WINDOW */;
|
|
175
176
|
// Initialize Window Service
|
|
176
177
|
accessory.context.Window = accessory.context.Window ?? {};
|
|
178
|
+
if (accessory.context.Window.Name) {
|
|
179
|
+
accessory.context.Window.Name = this.validateAndCleanString(accessory.context.Window.Name, 'Window Name', accessory.context.Window.Name);
|
|
180
|
+
}
|
|
177
181
|
this.Window = {
|
|
178
182
|
Name: accessory.context.Window.Name ?? accessory.displayName,
|
|
179
183
|
Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window),
|
|
180
|
-
On: accessory.context.On ?? false,
|
|
181
184
|
};
|
|
182
185
|
accessory.context.Window = this.Window;
|
|
183
186
|
this.debugLog('Displaying as Window');
|
|
@@ -190,9 +193,6 @@ export class Bot extends deviceBase {
|
|
|
190
193
|
minValue: 0,
|
|
191
194
|
maxValue: 100,
|
|
192
195
|
minStep: 100,
|
|
193
|
-
})
|
|
194
|
-
.onGet(() => {
|
|
195
|
-
return this.Window.On;
|
|
196
196
|
})
|
|
197
197
|
.onSet(this.OnSet.bind(this));
|
|
198
198
|
// Remove other services
|
|
@@ -211,10 +211,12 @@ export class Bot extends deviceBase {
|
|
|
211
211
|
accessory.category = 14 /* this.hap.Categories.WINDOW_COVERING */;
|
|
212
212
|
// Initialize WindowCovering Service
|
|
213
213
|
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
|
|
214
|
+
if (accessory.context.WindowCovering.Name) {
|
|
215
|
+
accessory.context.WindowCovering.Name = this.validateAndCleanString(accessory.context.WindowCovering.Name, 'WindowCovering Name', accessory.context.WindowCovering.Name);
|
|
216
|
+
}
|
|
214
217
|
this.WindowCovering = {
|
|
215
218
|
Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
|
|
216
219
|
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering),
|
|
217
|
-
On: accessory.context.On ?? false,
|
|
218
220
|
};
|
|
219
221
|
accessory.context.WindowCovering = this.WindowCovering;
|
|
220
222
|
this.debugLog('Displaying as Window Covering');
|
|
@@ -222,14 +224,12 @@ export class Bot extends deviceBase {
|
|
|
222
224
|
this.WindowCovering.Service
|
|
223
225
|
.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
|
|
224
226
|
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
225
|
-
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
227
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
228
|
+
.setProps({
|
|
226
229
|
validValues: [0, 100],
|
|
227
230
|
minValue: 0,
|
|
228
231
|
maxValue: 100,
|
|
229
232
|
minStep: 100,
|
|
230
|
-
})
|
|
231
|
-
.onGet(() => {
|
|
232
|
-
return this.WindowCovering.On;
|
|
233
233
|
})
|
|
234
234
|
.onSet(this.OnSet.bind(this));
|
|
235
235
|
// Remove other services
|
|
@@ -248,20 +248,20 @@ export class Bot extends deviceBase {
|
|
|
248
248
|
accessory.category = 6 /* this.hap.Categories.DOOR_LOCK */;
|
|
249
249
|
// Initialize Lock Service
|
|
250
250
|
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
|
|
251
|
+
if (accessory.context.LockMechanism.Name) {
|
|
252
|
+
accessory.context.LockMechanism.Name = this.validateAndCleanString(accessory.context.LockMechanism.Name, 'LockMechanism Name', accessory.context.LockMechanism.Name);
|
|
253
|
+
}
|
|
251
254
|
this.LockMechanism = {
|
|
252
255
|
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
253
256
|
Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism),
|
|
254
|
-
On: accessory.context.On ?? false,
|
|
255
257
|
};
|
|
256
258
|
accessory.context.LockMechanism = this.LockMechanism;
|
|
257
259
|
this.debugLog('Displaying as Lock');
|
|
258
260
|
// Initialize Lock Characteristics
|
|
259
261
|
this.LockMechanism.Service
|
|
260
262
|
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
263
|
+
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
261
264
|
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
262
|
-
.onGet(() => {
|
|
263
|
-
return this.LockMechanism.On;
|
|
264
|
-
})
|
|
265
265
|
.onSet(this.OnSet.bind(this));
|
|
266
266
|
// Remove other services
|
|
267
267
|
this.removeFanService(accessory);
|
|
@@ -279,10 +279,12 @@ export class Bot extends deviceBase {
|
|
|
279
279
|
accessory.category = 29 /* this.hap.Categories.FAUCET */;
|
|
280
280
|
// Initialize Faucet Service
|
|
281
281
|
accessory.context.Faucet = accessory.context.Faucet ?? {};
|
|
282
|
+
if (accessory.context.Faucet.Name) {
|
|
283
|
+
accessory.context.Faucet.Name = this.validateAndCleanString(accessory.context.Faucet.Name, 'Faucet Name', accessory.context.Faucet.Name);
|
|
284
|
+
}
|
|
282
285
|
this.Faucet = {
|
|
283
286
|
Name: accessory.context.Faucet.Name ?? accessory.displayName,
|
|
284
287
|
Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet),
|
|
285
|
-
On: accessory.context.On ?? false,
|
|
286
288
|
};
|
|
287
289
|
accessory.context.Faucet = this.Faucet;
|
|
288
290
|
this.debugLog('Displaying as Faucet');
|
|
@@ -290,9 +292,6 @@ export class Bot extends deviceBase {
|
|
|
290
292
|
this.Faucet.Service
|
|
291
293
|
.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
|
|
292
294
|
.getCharacteristic(this.hap.Characteristic.Active)
|
|
293
|
-
.onGet(() => {
|
|
294
|
-
return this.Faucet.On;
|
|
295
|
-
})
|
|
296
295
|
.onSet(this.OnSet.bind(this));
|
|
297
296
|
// Remove other services
|
|
298
297
|
this.removeFanService(accessory);
|
|
@@ -310,20 +309,19 @@ export class Bot extends deviceBase {
|
|
|
310
309
|
accessory.category = 3 /* this.hap.Categories.FAN */;
|
|
311
310
|
// Initialize Fan Service
|
|
312
311
|
accessory.context.Fan = accessory.context.Fan ?? {};
|
|
312
|
+
if (accessory.context.Fan.Name) {
|
|
313
|
+
accessory.context.Fan.Name = this.validateAndCleanString(accessory.context.Fan.Name, 'Fan Name', accessory.context.Fan.Name);
|
|
314
|
+
}
|
|
313
315
|
this.Fan = {
|
|
314
316
|
Name: accessory.context.Fan.Name ?? accessory.displayName,
|
|
315
317
|
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2),
|
|
316
|
-
On: accessory.context.On ?? false,
|
|
317
318
|
};
|
|
318
319
|
accessory.context.Fan = this.Fan;
|
|
319
320
|
this.debugLog('Displaying as Fan');
|
|
320
321
|
// Initialize Fan Characteristics
|
|
321
322
|
this.Fan.Service
|
|
322
323
|
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
323
|
-
.getCharacteristic(this.hap.Characteristic.
|
|
324
|
-
.onGet(() => {
|
|
325
|
-
return this.Fan.On;
|
|
326
|
-
})
|
|
324
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
327
325
|
.onSet(this.OnSet.bind(this));
|
|
328
326
|
// Remove other services
|
|
329
327
|
this.removeLockService(accessory);
|
|
@@ -341,11 +339,13 @@ export class Bot extends deviceBase {
|
|
|
341
339
|
accessory.category = 15 /* this.hap.Categories.PROGRAMMABLE_SWITCH */;
|
|
342
340
|
// Initialize StatefulProgrammableSwitch Service
|
|
343
341
|
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
|
|
342
|
+
if (accessory.context.StatefulProgrammableSwitch.Name) {
|
|
343
|
+
accessory.context.StatefulProgrammableSwitch.Name = this.validateAndCleanString(accessory.context.StatefulProgrammableSwitch.Name, 'StatefulProgrammableSwitch Name', accessory.context.StatefulProgrammableSwitch.Name);
|
|
344
|
+
}
|
|
344
345
|
this.StatefulProgrammableSwitch = {
|
|
345
346
|
Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
|
|
346
347
|
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
347
348
|
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
348
|
-
On: accessory.context.On ?? false,
|
|
349
349
|
};
|
|
350
350
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
|
|
351
351
|
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
@@ -353,9 +353,6 @@ export class Bot extends deviceBase {
|
|
|
353
353
|
this.StatefulProgrammableSwitch.Service
|
|
354
354
|
.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
|
|
355
355
|
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
356
|
-
.onGet(() => {
|
|
357
|
-
return this.StatefulProgrammableSwitch.On;
|
|
358
|
-
})
|
|
359
356
|
.onSet(this.OnSet.bind(this));
|
|
360
357
|
// Remove other services
|
|
361
358
|
this.removeFanService(accessory);
|
|
@@ -368,15 +365,17 @@ export class Bot extends deviceBase {
|
|
|
368
365
|
this.removeGarageDoorService(accessory);
|
|
369
366
|
this.removeWindowCoveringService(accessory);
|
|
370
367
|
}
|
|
371
|
-
else {
|
|
368
|
+
else if (this.botDeviceType === 'outlet') {
|
|
372
369
|
// Set category
|
|
373
370
|
accessory.category = 7 /* this.hap.Categories.OUTLET */;
|
|
374
371
|
// Initialize Switch property
|
|
375
372
|
accessory.context.Outlet = accessory.context.Outlet ?? {};
|
|
373
|
+
if (accessory.context.Outlet.Name) {
|
|
374
|
+
accessory.context.Outlet.Name = this.validateAndCleanString(accessory.context.Outlet.Name, 'Outlet Name', accessory.context.Outlet.Name);
|
|
375
|
+
}
|
|
376
376
|
this.Outlet = {
|
|
377
377
|
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
378
378
|
Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet),
|
|
379
|
-
On: accessory.context.On ?? false,
|
|
380
379
|
};
|
|
381
380
|
accessory.context.Outlet = this.Outlet;
|
|
382
381
|
this.debugLog('Displaying as Outlet');
|
|
@@ -384,9 +383,6 @@ export class Bot extends deviceBase {
|
|
|
384
383
|
this.Outlet.Service
|
|
385
384
|
.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
|
|
386
385
|
.getCharacteristic(this.hap.Characteristic.On)
|
|
387
|
-
.onGet(() => {
|
|
388
|
-
return this.Outlet.On;
|
|
389
|
-
})
|
|
390
386
|
.onSet(this.OnSet.bind(this));
|
|
391
387
|
// Remove other services
|
|
392
388
|
this.removeFanService(accessory);
|
|
@@ -399,6 +395,9 @@ export class Bot extends deviceBase {
|
|
|
399
395
|
this.removeWindowCoveringService(accessory);
|
|
400
396
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
401
397
|
}
|
|
398
|
+
else {
|
|
399
|
+
this.errorLog('Device Type not set');
|
|
400
|
+
}
|
|
402
401
|
// Retrieve initial values and updateHomekit
|
|
403
402
|
this.debugLog('Retrieve initial values and update Homekit');
|
|
404
403
|
this.refreshStatus();
|
|
@@ -445,19 +444,10 @@ export class Bot extends deviceBase {
|
|
|
445
444
|
await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}),`
|
|
446
445
|
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
447
446
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
this.setOn(Boolean(this.serviceData.state));
|
|
453
|
-
}
|
|
454
|
-
this.debugLog(`Switch Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
this.setOn(false);
|
|
458
|
-
this.accessory.context.On = await this.getOn();
|
|
459
|
-
this.debugLog(`Press Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
460
|
-
}
|
|
447
|
+
this.On = this.serviceData.mode ? this.serviceData.state : false;
|
|
448
|
+
const mode = this.serviceData.mode ? 'Switch' : 'Press';
|
|
449
|
+
await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`);
|
|
450
|
+
this.accessory.context.On = this.On;
|
|
461
451
|
// BatteryLevel
|
|
462
452
|
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
463
453
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
@@ -474,17 +464,8 @@ export class Bot extends deviceBase {
|
|
|
474
464
|
await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}),`
|
|
475
465
|
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
476
466
|
// On
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
this.accessory.context.On = await this.getOn();
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
this.setOn(this.deviceStatus.power === 'on' ? true : false);
|
|
483
|
-
this.accessory.context.On = await this.getOn();
|
|
484
|
-
if (this.getOn() === undefined) {
|
|
485
|
-
this.setOn(false);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
467
|
+
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on' ? true : false;
|
|
468
|
+
this.accessory.context.On = this.On;
|
|
488
469
|
await this.debugLog(`On: ${this.accessory.context.On}`);
|
|
489
470
|
// Battery Level
|
|
490
471
|
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
@@ -510,13 +491,11 @@ export class Bot extends deviceBase {
|
|
|
510
491
|
}
|
|
511
492
|
async parseStatusWebhook() {
|
|
512
493
|
await this.debugLog('parseStatusWebhook');
|
|
513
|
-
const getOn = await this.getOn();
|
|
514
494
|
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery},`
|
|
515
|
-
+ ` ${this.webhookContext.deviceMode}), current:(${
|
|
495
|
+
+ ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
516
496
|
// On
|
|
517
|
-
|
|
518
|
-
await this.
|
|
519
|
-
await this.debugLog(`On: ${setOn}`);
|
|
497
|
+
this.On = this.webhookContext.power === 'on' ? true : false;
|
|
498
|
+
await this.debugLog(`On: ${this.On}`);
|
|
520
499
|
// BatteryLevel
|
|
521
500
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
522
501
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
@@ -535,7 +514,7 @@ export class Bot extends deviceBase {
|
|
|
535
514
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
536
515
|
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
537
516
|
}
|
|
538
|
-
else if (this.BLE) {
|
|
517
|
+
else if (this.BLE || this.config.options?.BLE) {
|
|
539
518
|
await this.BLERefreshStatus();
|
|
540
519
|
}
|
|
541
520
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
@@ -548,26 +527,45 @@ export class Bot extends deviceBase {
|
|
|
548
527
|
}
|
|
549
528
|
async BLERefreshStatus() {
|
|
550
529
|
await this.debugLog('BLERefreshStatus');
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
560
|
-
// Update HomeKit
|
|
561
|
-
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
562
|
-
this.serviceData = serviceData;
|
|
530
|
+
if (this.config.options?.BLE) {
|
|
531
|
+
await this.debugLog('is listening to Platform BLE.');
|
|
532
|
+
this.device.bleMac = this.device.deviceId.match(/.{1,2}/g).join(':').toLowerCase();
|
|
533
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
534
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
535
|
+
try {
|
|
536
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
537
|
+
this.serviceData = context;
|
|
563
538
|
await this.BLEparseStatus();
|
|
564
539
|
await this.updateHomeKitCharacteristics();
|
|
565
540
|
}
|
|
566
|
-
|
|
567
|
-
await this.errorLog(`failed to
|
|
568
|
-
await this.BLERefreshConnection(switchbot);
|
|
541
|
+
catch (e) {
|
|
542
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
569
543
|
}
|
|
570
|
-
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
await this.debugLog('is using Device BLE Scanning.');
|
|
548
|
+
const switchbot = await this.switchbotBLE();
|
|
549
|
+
if (switchbot === undefined) {
|
|
550
|
+
await this.BLERefreshConnection(switchbot);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
// Start to monitor advertisement packets
|
|
554
|
+
(async () => {
|
|
555
|
+
// Start to monitor advertisement packets
|
|
556
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
557
|
+
// Update HomeKit
|
|
558
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
559
|
+
this.serviceData = serviceData;
|
|
560
|
+
await this.BLEparseStatus();
|
|
561
|
+
await this.updateHomeKitCharacteristics();
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
565
|
+
await this.BLERefreshConnection(switchbot);
|
|
566
|
+
}
|
|
567
|
+
})();
|
|
568
|
+
}
|
|
571
569
|
}
|
|
572
570
|
}
|
|
573
571
|
async openAPIRefreshStatus() {
|
|
@@ -643,31 +641,26 @@ export class Bot extends deviceBase {
|
|
|
643
641
|
}
|
|
644
642
|
async BLEpushChanges() {
|
|
645
643
|
await this.debugLog('BLEpushChanges');
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
644
|
+
if (this.On !== this.accessory.context.On || this.allowPush) {
|
|
645
|
+
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
649
646
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
650
647
|
await this.convertBLEAddress();
|
|
651
648
|
//if (switchbot !== false) {
|
|
649
|
+
await this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
652
650
|
if (this.botMode === 'press') {
|
|
653
|
-
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
654
651
|
switchbot
|
|
655
652
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
656
653
|
.then(async (device_list) => {
|
|
657
|
-
this.infoLog(`On: ${On}`);
|
|
654
|
+
await this.infoLog(`On: ${this.On}`);
|
|
658
655
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
659
656
|
})
|
|
660
657
|
.then(async () => {
|
|
661
|
-
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
658
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
662
659
|
await this.updateHomeKitCharacteristics();
|
|
663
|
-
setTimeout(() => {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
669
|
-
}
|
|
670
|
-
this.debugLog(`On: ${On}, Switch Timeout`);
|
|
660
|
+
setTimeout(async () => {
|
|
661
|
+
this.On = false;
|
|
662
|
+
await this.updateHomeKitCharacteristics();
|
|
663
|
+
this.debugLog(`On: ${this.On}, Switch Timeout`);
|
|
671
664
|
}, 500);
|
|
672
665
|
})
|
|
673
666
|
.catch(async (e) => {
|
|
@@ -677,15 +670,14 @@ export class Bot extends deviceBase {
|
|
|
677
670
|
});
|
|
678
671
|
}
|
|
679
672
|
else if (this.botMode === 'switch') {
|
|
680
|
-
this.debugLog(`Press Mode: ${this.botMode}`);
|
|
681
673
|
switchbot
|
|
682
674
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
683
675
|
.then(async (device_list) => {
|
|
684
|
-
this.infoLog(`On: ${On}`);
|
|
676
|
+
this.infoLog(`On: ${this.On}`);
|
|
685
677
|
return await this.retryBLE({
|
|
686
678
|
max: await this.maxRetryBLE(),
|
|
687
679
|
fn: async () => {
|
|
688
|
-
if (On) {
|
|
680
|
+
if (this.On) {
|
|
689
681
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
690
682
|
}
|
|
691
683
|
else {
|
|
@@ -695,7 +687,7 @@ export class Bot extends deviceBase {
|
|
|
695
687
|
});
|
|
696
688
|
})
|
|
697
689
|
.then(async () => {
|
|
698
|
-
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
690
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
699
691
|
await this.updateHomeKitCharacteristics();
|
|
700
692
|
})
|
|
701
693
|
.catch(async (e) => {
|
|
@@ -709,32 +701,24 @@ export class Bot extends deviceBase {
|
|
|
709
701
|
}
|
|
710
702
|
}
|
|
711
703
|
else {
|
|
712
|
-
await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
704
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
713
705
|
}
|
|
714
706
|
}
|
|
715
707
|
async openAPIpushChanges() {
|
|
716
708
|
await this.debugLog('openAPIpushChanges');
|
|
717
|
-
let On = await this.getOn();
|
|
718
709
|
if (this.multiPressCount > 0) {
|
|
719
710
|
await this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
720
|
-
On = true;
|
|
721
711
|
}
|
|
722
|
-
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
712
|
+
if (this.On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
723
713
|
let command = '';
|
|
724
|
-
if (this.botMode === 'switch'
|
|
725
|
-
command = 'turnOn';
|
|
726
|
-
|
|
727
|
-
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
728
|
-
}
|
|
729
|
-
else if (this.botMode === 'switch' && !On) {
|
|
730
|
-
command = 'turnOff';
|
|
731
|
-
On = false;
|
|
732
|
-
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
714
|
+
if (this.botMode === 'switch') {
|
|
715
|
+
command = this.On ? 'turnOn' : 'turnOff';
|
|
716
|
+
await this.debugLog(`Switch Mode, Command: ${command}`);
|
|
733
717
|
}
|
|
734
718
|
else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
735
719
|
command = 'press';
|
|
736
720
|
await this.debugLog('Press Mode');
|
|
737
|
-
On = false;
|
|
721
|
+
this.On = false;
|
|
738
722
|
}
|
|
739
723
|
else {
|
|
740
724
|
throw new Error('Device Parameters not set for this Bot.');
|
|
@@ -761,7 +745,7 @@ export class Bot extends deviceBase {
|
|
|
761
745
|
this.multiPressCount--;
|
|
762
746
|
if (this.multiPressCount > 0) {
|
|
763
747
|
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
764
|
-
On = true;
|
|
748
|
+
this.On = true;
|
|
765
749
|
await this.openAPIpushChanges();
|
|
766
750
|
}
|
|
767
751
|
}
|
|
@@ -772,127 +756,69 @@ export class Bot extends deviceBase {
|
|
|
772
756
|
}
|
|
773
757
|
}
|
|
774
758
|
else {
|
|
775
|
-
await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
759
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
776
760
|
}
|
|
777
761
|
}
|
|
778
762
|
/**
|
|
779
763
|
* Handle requests to set the "On" characteristic
|
|
780
764
|
*/
|
|
781
765
|
async OnSet(value) {
|
|
782
|
-
if (this.botDeviceType === '
|
|
766
|
+
if (this.botDeviceType === 'switch') {
|
|
767
|
+
if (this.Switch) {
|
|
768
|
+
await this.debugLog(`Set On: ${value}`);
|
|
769
|
+
this.On = value === false ? false : true;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
else if (this.botDeviceType === 'garagedoor') {
|
|
783
773
|
if (this.GarageDoor) {
|
|
784
774
|
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
785
|
-
this.
|
|
786
|
-
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
787
|
-
await this.setOn(false);
|
|
788
|
-
this.GarageDoor.On = false;
|
|
789
|
-
}
|
|
790
|
-
else {
|
|
791
|
-
await this.setOn(true);
|
|
792
|
-
this.GarageDoor.On = true;
|
|
793
|
-
}
|
|
775
|
+
this.On = value === this.hap.Characteristic.TargetDoorState.CLOSED ? false : true;
|
|
794
776
|
}
|
|
795
777
|
}
|
|
796
778
|
else if (this.botDeviceType === 'door') {
|
|
797
779
|
if (this.Door) {
|
|
798
780
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
799
|
-
|
|
800
|
-
await this.setOn(false);
|
|
801
|
-
this.Door.On = false;
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
await this.setOn(true);
|
|
805
|
-
this.Door.On = true;
|
|
806
|
-
}
|
|
781
|
+
this.On = value === 0 ? false : true;
|
|
807
782
|
}
|
|
808
783
|
}
|
|
809
784
|
else if (this.botDeviceType === 'window') {
|
|
810
785
|
if (this.Window) {
|
|
811
786
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
812
|
-
|
|
813
|
-
await this.setOn(false);
|
|
814
|
-
this.Window.On = false;
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
await this.setOn(true);
|
|
818
|
-
this.Window.On = true;
|
|
819
|
-
}
|
|
787
|
+
this.On = value === 0 ? false : true;
|
|
820
788
|
}
|
|
821
789
|
}
|
|
822
790
|
else if (this.botDeviceType === 'windowcovering') {
|
|
823
791
|
if (this.WindowCovering) {
|
|
824
792
|
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
825
|
-
|
|
826
|
-
await this.setOn(false);
|
|
827
|
-
this.WindowCovering.On = false;
|
|
828
|
-
}
|
|
829
|
-
else {
|
|
830
|
-
await this.setOn(true);
|
|
831
|
-
this.WindowCovering.On = true;
|
|
832
|
-
}
|
|
793
|
+
this.On = value === 0 ? false : true;
|
|
833
794
|
}
|
|
834
795
|
}
|
|
835
796
|
else if (this.botDeviceType === 'lock') {
|
|
836
797
|
if (this.LockMechanism) {
|
|
837
798
|
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
838
|
-
|
|
839
|
-
await this.setOn(false);
|
|
840
|
-
this.LockMechanism.On = false;
|
|
841
|
-
}
|
|
842
|
-
else {
|
|
843
|
-
await this.setOn(true);
|
|
844
|
-
this.LockMechanism.On = true;
|
|
845
|
-
}
|
|
799
|
+
this.On = value === this.hap.Characteristic.LockTargetState.SECURED ? false : true;
|
|
846
800
|
}
|
|
847
801
|
}
|
|
848
802
|
else if (this.botDeviceType === 'faucet') {
|
|
849
803
|
if (this.Faucet) {
|
|
850
804
|
await this.debugLog(`Set Active: ${value}`);
|
|
851
|
-
|
|
852
|
-
await this.setOn(false);
|
|
853
|
-
this.Faucet.On = false;
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
await this.setOn(true);
|
|
857
|
-
this.Faucet.On = true;
|
|
858
|
-
}
|
|
805
|
+
this.On = value === this.hap.Characteristic.Active.INACTIVE ? false : true;
|
|
859
806
|
}
|
|
860
807
|
}
|
|
861
808
|
else if (this.botDeviceType === 'stateful') {
|
|
862
809
|
if (this.StatefulProgrammableSwitch) {
|
|
863
810
|
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
864
|
-
|
|
865
|
-
await this.setOn(false);
|
|
866
|
-
this.StatefulProgrammableSwitch.On = false;
|
|
867
|
-
}
|
|
868
|
-
else {
|
|
869
|
-
await this.setOn(true);
|
|
870
|
-
this.StatefulProgrammableSwitch.On = true;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
else if (this.botDeviceType === 'switch') {
|
|
875
|
-
if (this.Switch) {
|
|
876
|
-
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
877
|
-
if (value === 0) {
|
|
878
|
-
await this.setOn(false);
|
|
879
|
-
this.Switch.On = false;
|
|
880
|
-
}
|
|
881
|
-
else {
|
|
882
|
-
await this.setOn(true);
|
|
883
|
-
this.Switch.On = true;
|
|
884
|
-
}
|
|
811
|
+
this.On = value === 0 ? false : true;
|
|
885
812
|
}
|
|
886
813
|
}
|
|
887
814
|
else {
|
|
888
815
|
if (this.Outlet) {
|
|
889
816
|
await this.debugLog(`Set On: ${value}`);
|
|
890
|
-
|
|
891
|
-
this.Outlet.On = value;
|
|
817
|
+
this.On = value === false ? false : true;
|
|
892
818
|
}
|
|
893
819
|
}
|
|
894
820
|
if (this.device.bot?.mode === 'multipress') {
|
|
895
|
-
if (
|
|
821
|
+
if (this.On === true) {
|
|
896
822
|
this.multiPressCount++;
|
|
897
823
|
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
898
824
|
}
|
|
@@ -903,199 +829,192 @@ export class Bot extends deviceBase {
|
|
|
903
829
|
* Updates the status for each of the HomeKit Characteristics
|
|
904
830
|
*/
|
|
905
831
|
async updateHomeKitCharacteristics() {
|
|
832
|
+
await this.debugLog('updateHomeKitCharacteristics');
|
|
833
|
+
// BatteryLevel
|
|
834
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
835
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
839
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
840
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
841
|
+
}
|
|
842
|
+
// StatusLowBattery
|
|
843
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
844
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
848
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
849
|
+
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
850
|
+
}
|
|
906
851
|
// State
|
|
907
|
-
if (this.botDeviceType === '
|
|
908
|
-
if (this.
|
|
909
|
-
await this.debugLog(`On: ${this.
|
|
852
|
+
if (this.botDeviceType === 'switch' && this.Switch) {
|
|
853
|
+
if (this.On === undefined) {
|
|
854
|
+
await this.debugLog(`On: ${this.On}`);
|
|
910
855
|
}
|
|
911
856
|
else {
|
|
912
|
-
|
|
857
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
858
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
else if (this.botDeviceType === 'garagedoor' && this.GarageDoor) {
|
|
862
|
+
if (this.On === undefined) {
|
|
863
|
+
await this.debugLog(`On: ${this.On}`);
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
if (this.On) {
|
|
913
867
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
914
868
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
915
|
-
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.
|
|
869
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`);
|
|
916
870
|
}
|
|
917
871
|
else {
|
|
918
872
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
919
873
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
920
|
-
await this.debugLog(`updateCharacteristicc TargetDoorState:
|
|
874
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`);
|
|
921
875
|
}
|
|
922
876
|
}
|
|
923
|
-
await this.
|
|
924
|
-
await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
|
|
877
|
+
await this.debugLog(`Garage Door On: ${this.On}`);
|
|
925
878
|
}
|
|
926
|
-
else if (this.botDeviceType === 'door') {
|
|
927
|
-
if (this.
|
|
928
|
-
await this.debugLog(`On: ${this.
|
|
879
|
+
else if (this.botDeviceType === 'door' && this.Door) {
|
|
880
|
+
if (this.On === undefined) {
|
|
881
|
+
await this.debugLog(`On: ${this.On}`);
|
|
929
882
|
}
|
|
930
883
|
else {
|
|
931
|
-
if (this.
|
|
884
|
+
if (this.On) {
|
|
932
885
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
933
886
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
934
887
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
935
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
888
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
936
889
|
}
|
|
937
890
|
else {
|
|
938
891
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
939
892
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
940
893
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
941
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
894
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
942
895
|
}
|
|
943
896
|
}
|
|
944
|
-
await this.
|
|
945
|
-
await this.debugLog(`Door On: ${this.Door?.On}`);
|
|
897
|
+
await this.debugLog(`Door On: ${this.On}`);
|
|
946
898
|
}
|
|
947
|
-
else if (this.botDeviceType === 'window') {
|
|
948
|
-
if (this.
|
|
949
|
-
await this.debugLog(`On: ${this.
|
|
899
|
+
else if (this.botDeviceType === 'window' && this.Window) {
|
|
900
|
+
if (this.On === undefined) {
|
|
901
|
+
await this.debugLog(`On: ${this.On}`);
|
|
950
902
|
}
|
|
951
903
|
else {
|
|
952
|
-
if (this.
|
|
904
|
+
if (this.On) {
|
|
953
905
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
954
906
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
955
907
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
956
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
908
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
957
909
|
}
|
|
958
910
|
else {
|
|
959
911
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
960
912
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
961
913
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
962
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
914
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
963
915
|
}
|
|
964
916
|
}
|
|
965
|
-
await this.
|
|
966
|
-
await this.debugLog(`Window On: ${this.Window?.On}`);
|
|
917
|
+
await this.debugLog(`Window On: ${this.On}`);
|
|
967
918
|
}
|
|
968
|
-
else if (this.botDeviceType === 'windowcovering') {
|
|
969
|
-
if (this.
|
|
970
|
-
await this.debugLog(`On: ${this.
|
|
919
|
+
else if (this.botDeviceType === 'windowcovering' && this.WindowCovering) {
|
|
920
|
+
if (this.On === undefined) {
|
|
921
|
+
await this.debugLog(`On: ${this.On}`);
|
|
971
922
|
}
|
|
972
923
|
else {
|
|
973
|
-
if (this.
|
|
924
|
+
if (this.On) {
|
|
974
925
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
975
926
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
976
927
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
977
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.
|
|
928
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
|
|
978
929
|
}
|
|
979
930
|
else {
|
|
980
931
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
981
932
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
982
933
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
983
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.
|
|
934
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
|
|
984
935
|
}
|
|
985
936
|
}
|
|
986
|
-
await this.
|
|
987
|
-
await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
|
|
937
|
+
await this.debugLog(`Window Covering On: ${this.On}`);
|
|
988
938
|
}
|
|
989
|
-
else if (this.botDeviceType === 'lock') {
|
|
990
|
-
if (this.
|
|
991
|
-
await this.debugLog(`On: ${this.
|
|
939
|
+
else if (this.botDeviceType === 'lock' && this.LockMechanism) {
|
|
940
|
+
if (this.On === undefined) {
|
|
941
|
+
await this.debugLog(`On: ${this.On}`);
|
|
992
942
|
}
|
|
993
943
|
else {
|
|
994
|
-
if (this.
|
|
944
|
+
if (this.On) {
|
|
995
945
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
996
946
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
997
|
-
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.
|
|
947
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
|
|
998
948
|
}
|
|
999
949
|
else {
|
|
1000
950
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
1001
951
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
1002
|
-
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.
|
|
952
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
|
|
1003
953
|
}
|
|
1004
954
|
}
|
|
1005
|
-
await this.
|
|
1006
|
-
await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
|
|
955
|
+
await this.debugLog(`Lock On: ${this.On}`);
|
|
1007
956
|
}
|
|
1008
|
-
else if (this.botDeviceType === 'faucet') {
|
|
1009
|
-
if (this.
|
|
1010
|
-
await this.debugLog(`On: ${this.
|
|
957
|
+
else if (this.botDeviceType === 'faucet' && this.Faucet) {
|
|
958
|
+
if (this.On === undefined) {
|
|
959
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1011
960
|
}
|
|
1012
961
|
else {
|
|
1013
|
-
if (this.
|
|
962
|
+
if (this.On) {
|
|
1014
963
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
1015
|
-
await this.debugLog(`updateCharacteristic Active: ${this.
|
|
964
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1016
965
|
}
|
|
1017
966
|
else {
|
|
1018
967
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1019
|
-
await this.debugLog(`updateCharacteristic Active: ${this.
|
|
968
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1020
969
|
}
|
|
1021
970
|
}
|
|
1022
|
-
await this.
|
|
1023
|
-
await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
|
|
971
|
+
await this.debugLog(`Faucet On: ${this.On}`);
|
|
1024
972
|
}
|
|
1025
|
-
else if (this.botDeviceType === 'fan') {
|
|
1026
|
-
if (this.
|
|
1027
|
-
await this.debugLog(`On: ${this.
|
|
973
|
+
else if (this.botDeviceType === 'fan' && this.Fan) {
|
|
974
|
+
if (this.On === undefined) {
|
|
975
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1028
976
|
}
|
|
1029
977
|
else {
|
|
1030
|
-
if (this.
|
|
1031
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.
|
|
1032
|
-
await this.debugLog(`updateCharacteristic
|
|
978
|
+
if (this.On) {
|
|
979
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
980
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1033
981
|
}
|
|
1034
982
|
else {
|
|
1035
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.
|
|
1036
|
-
await this.debugLog(`updateCharacteristic
|
|
983
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
984
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`);
|
|
1037
985
|
}
|
|
1038
986
|
}
|
|
1039
|
-
await this.
|
|
1040
|
-
await this.debugLog(`Fan On: ${this.Fan?.On}`);
|
|
987
|
+
await this.debugLog(`Fan On: ${this.On}`);
|
|
1041
988
|
}
|
|
1042
|
-
else if (this.botDeviceType === 'stateful') {
|
|
1043
|
-
if (this.
|
|
1044
|
-
await this.debugLog(`On: ${this.
|
|
989
|
+
else if (this.botDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
|
|
990
|
+
if (this.On === undefined) {
|
|
991
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1045
992
|
}
|
|
1046
993
|
else {
|
|
1047
|
-
if (this.
|
|
994
|
+
if (this.On) {
|
|
1048
995
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1049
996
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1050
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.
|
|
997
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
1051
998
|
}
|
|
1052
999
|
else {
|
|
1053
1000
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1054
1001
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1055
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.
|
|
1002
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
1056
1003
|
}
|
|
1057
1004
|
}
|
|
1058
|
-
await this.
|
|
1059
|
-
await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1005
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`);
|
|
1060
1006
|
}
|
|
1061
|
-
else if (this.botDeviceType === '
|
|
1062
|
-
if (this.
|
|
1063
|
-
await this.debugLog(`On: ${this.
|
|
1007
|
+
else if (this.botDeviceType === 'outlet' && this.Outlet) {
|
|
1008
|
+
if (this.On === undefined) {
|
|
1009
|
+
await this.debugLog(`On: ${this.On}`);
|
|
1064
1010
|
}
|
|
1065
1011
|
else {
|
|
1066
|
-
this.
|
|
1067
|
-
await this.debugLog(`updateCharacteristic On: ${this.
|
|
1068
|
-
}
|
|
1069
|
-
await this.setOn(Boolean(this.Switch?.On));
|
|
1070
|
-
}
|
|
1071
|
-
else {
|
|
1072
|
-
if (this.Outlet?.On === undefined) {
|
|
1073
|
-
await this.debugLog(`On: ${this.Outlet?.On}`);
|
|
1012
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
1013
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`);
|
|
1074
1014
|
}
|
|
1075
|
-
else {
|
|
1076
|
-
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
|
|
1077
|
-
await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
|
|
1078
|
-
}
|
|
1079
|
-
await this.setOn(Boolean(this.Outlet?.On));
|
|
1080
|
-
}
|
|
1081
|
-
this.accessory.context.On = await this.getOn();
|
|
1082
|
-
// BatteryLevel
|
|
1083
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
1084
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1085
1015
|
}
|
|
1086
1016
|
else {
|
|
1087
|
-
this.
|
|
1088
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1089
|
-
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1090
|
-
}
|
|
1091
|
-
// StatusLowBattery
|
|
1092
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
1093
|
-
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1094
|
-
}
|
|
1095
|
-
else {
|
|
1096
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1097
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1098
|
-
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1017
|
+
await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`);
|
|
1099
1018
|
}
|
|
1100
1019
|
}
|
|
1101
1020
|
async removeOutletService(accessory) {
|
|
@@ -1104,7 +1023,6 @@ export class Bot extends deviceBase {
|
|
|
1104
1023
|
this.Outlet = {
|
|
1105
1024
|
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
1106
1025
|
Service: accessory.getService(this.hap.Service.Outlet),
|
|
1107
|
-
On: accessory.context.On ?? false,
|
|
1108
1026
|
};
|
|
1109
1027
|
accessory.context.Outlet = this.Outlet;
|
|
1110
1028
|
await this.warnLog('Removing any leftover Outlet Service');
|
|
@@ -1116,7 +1034,6 @@ export class Bot extends deviceBase {
|
|
|
1116
1034
|
this.GarageDoor = {
|
|
1117
1035
|
Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
|
|
1118
1036
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener),
|
|
1119
|
-
On: accessory.context.On ?? false,
|
|
1120
1037
|
};
|
|
1121
1038
|
accessory.context.GarageDoor = this.GarageDoor;
|
|
1122
1039
|
await this.warnLog('Removing any leftover Garage Door Service');
|
|
@@ -1128,7 +1045,6 @@ export class Bot extends deviceBase {
|
|
|
1128
1045
|
this.Door = {
|
|
1129
1046
|
Name: accessory.context.Door.Name ?? accessory.displayName,
|
|
1130
1047
|
Service: accessory.getService(this.hap.Service.Door),
|
|
1131
|
-
On: accessory.context.On ?? false,
|
|
1132
1048
|
};
|
|
1133
1049
|
accessory.context.Door = this.Door;
|
|
1134
1050
|
await this.warnLog('Removing any leftover Door Service');
|
|
@@ -1140,7 +1056,6 @@ export class Bot extends deviceBase {
|
|
|
1140
1056
|
this.LockMechanism = {
|
|
1141
1057
|
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
1142
1058
|
Service: accessory.getService(this.hap.Service.LockMechanism),
|
|
1143
|
-
On: accessory.context.On ?? false,
|
|
1144
1059
|
};
|
|
1145
1060
|
accessory.context.LockMechanism = this.LockMechanism;
|
|
1146
1061
|
this.warnLog('Removing any leftover Lock Service');
|
|
@@ -1152,7 +1067,6 @@ export class Bot extends deviceBase {
|
|
|
1152
1067
|
this.Faucet = {
|
|
1153
1068
|
Name: accessory.context.Faucet.Name ?? accessory.displayName,
|
|
1154
1069
|
Service: accessory.getService(this.hap.Service.Valve),
|
|
1155
|
-
On: accessory.context.On ?? false,
|
|
1156
1070
|
};
|
|
1157
1071
|
accessory.context.Faucet = this.Faucet;
|
|
1158
1072
|
await this.warnLog('Removing any leftover Faucet Service');
|
|
@@ -1164,7 +1078,6 @@ export class Bot extends deviceBase {
|
|
|
1164
1078
|
this.Fan = {
|
|
1165
1079
|
Name: accessory.context.Fan.Name ?? accessory.displayName,
|
|
1166
1080
|
Service: accessory.getService(this.hap.Service.Fan),
|
|
1167
|
-
On: accessory.context.On ?? false,
|
|
1168
1081
|
};
|
|
1169
1082
|
accessory.context.Fan = this.Fan;
|
|
1170
1083
|
this.warnLog('Removing any leftover Fan Service');
|
|
@@ -1176,7 +1089,6 @@ export class Bot extends deviceBase {
|
|
|
1176
1089
|
this.Window = {
|
|
1177
1090
|
Name: accessory.context.Window.Name ?? accessory.displayName,
|
|
1178
1091
|
Service: accessory.getService(this.hap.Service.Window),
|
|
1179
|
-
On: accessory.context.On ?? false,
|
|
1180
1092
|
};
|
|
1181
1093
|
accessory.context.Window = this.Window;
|
|
1182
1094
|
await this.warnLog('Removing any leftover Window Service');
|
|
@@ -1188,7 +1100,6 @@ export class Bot extends deviceBase {
|
|
|
1188
1100
|
this.WindowCovering = {
|
|
1189
1101
|
Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
|
|
1190
1102
|
Service: accessory.getService(this.hap.Service.WindowCovering),
|
|
1191
|
-
On: accessory.context.On ?? false,
|
|
1192
1103
|
};
|
|
1193
1104
|
accessory.context.WindowCovering = this.WindowCovering;
|
|
1194
1105
|
await this.warnLog('Removing any leftover Window Covering Service');
|
|
@@ -1200,7 +1111,6 @@ export class Bot extends deviceBase {
|
|
|
1200
1111
|
this.StatefulProgrammableSwitch = {
|
|
1201
1112
|
Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
|
|
1202
1113
|
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch),
|
|
1203
|
-
On: accessory.context.On ?? false,
|
|
1204
1114
|
};
|
|
1205
1115
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
|
|
1206
1116
|
await this.warnLog('Removing any leftover Stateful Programmable Switch Service');
|
|
@@ -1212,98 +1122,11 @@ export class Bot extends deviceBase {
|
|
|
1212
1122
|
this.Switch = {
|
|
1213
1123
|
Name: accessory.context.Switch.Name ?? accessory.displayName,
|
|
1214
1124
|
Service: accessory.getService(this.hap.Service.Switch),
|
|
1215
|
-
On: accessory.context.On ?? false,
|
|
1216
1125
|
};
|
|
1217
1126
|
accessory.context.Switch = this.Switch;
|
|
1218
1127
|
await this.warnLog('Removing any leftover Switch Service');
|
|
1219
1128
|
accessory.removeService(this.Switch.Service);
|
|
1220
1129
|
}
|
|
1221
|
-
async getOn() {
|
|
1222
|
-
let On;
|
|
1223
|
-
if (this.botDeviceType === 'garagedoor') {
|
|
1224
|
-
On = this.GarageDoor?.On ? true : false;
|
|
1225
|
-
}
|
|
1226
|
-
else if (this.botDeviceType === 'door') {
|
|
1227
|
-
On = this.Door?.On ? true : false;
|
|
1228
|
-
}
|
|
1229
|
-
else if (this.botDeviceType === 'window') {
|
|
1230
|
-
On = this.Window?.On ? true : false;
|
|
1231
|
-
}
|
|
1232
|
-
else if (this.botDeviceType === 'windowcovering') {
|
|
1233
|
-
On = this.WindowCovering?.On ? true : false;
|
|
1234
|
-
}
|
|
1235
|
-
else if (this.botDeviceType === 'lock') {
|
|
1236
|
-
On = this.LockMechanism?.On ? true : false;
|
|
1237
|
-
}
|
|
1238
|
-
else if (this.botDeviceType === 'faucet') {
|
|
1239
|
-
On = this.Faucet?.On ? true : false;
|
|
1240
|
-
}
|
|
1241
|
-
else if (this.botDeviceType === 'fan') {
|
|
1242
|
-
On = this.Fan?.On ? true : false;
|
|
1243
|
-
}
|
|
1244
|
-
else if (this.botDeviceType === 'stateful') {
|
|
1245
|
-
On = this.StatefulProgrammableSwitch?.On ? true : false;
|
|
1246
|
-
}
|
|
1247
|
-
else if (this.botDeviceType === 'switch') {
|
|
1248
|
-
On = this.Switch?.On ? true : false;
|
|
1249
|
-
}
|
|
1250
|
-
else {
|
|
1251
|
-
On = this.Outlet?.On ? true : false;
|
|
1252
|
-
}
|
|
1253
|
-
return On;
|
|
1254
|
-
}
|
|
1255
|
-
async setOn(On) {
|
|
1256
|
-
if (this.botDeviceType === 'garagedoor') {
|
|
1257
|
-
if (this.GarageDoor) {
|
|
1258
|
-
this.GarageDoor.On = On;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
else if (this.botDeviceType === 'door') {
|
|
1262
|
-
if (this.Door) {
|
|
1263
|
-
this.Door.On = On;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
else if (this.botDeviceType === 'window') {
|
|
1267
|
-
if (this.Window) {
|
|
1268
|
-
this.Window.On = On;
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
else if (this.botDeviceType === 'windowcovering') {
|
|
1272
|
-
if (this.WindowCovering) {
|
|
1273
|
-
this.WindowCovering.On = On;
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
else if (this.botDeviceType === 'lock') {
|
|
1277
|
-
if (this.LockMechanism) {
|
|
1278
|
-
this.LockMechanism.On = On;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
else if (this.botDeviceType === 'faucet') {
|
|
1282
|
-
if (this.Faucet) {
|
|
1283
|
-
this.Faucet.On = On;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
else if (this.botDeviceType === 'fan') {
|
|
1287
|
-
if (this.Fan) {
|
|
1288
|
-
this.Fan.On = On;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
else if (this.botDeviceType === 'stateful') {
|
|
1292
|
-
if (this.StatefulProgrammableSwitch) {
|
|
1293
|
-
this.StatefulProgrammableSwitch.On = On;
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
else if (this.botDeviceType === 'switch') {
|
|
1297
|
-
if (this.Switch) {
|
|
1298
|
-
this.Switch.On = On;
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
else {
|
|
1302
|
-
if (this.Outlet) {
|
|
1303
|
-
this.Outlet.On = On;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
1130
|
async getBotConfigSettings(device) {
|
|
1308
1131
|
//Bot Device Type
|
|
1309
1132
|
this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
|
|
@@ -1422,6 +1245,8 @@ export class Bot extends deviceBase {
|
|
|
1422
1245
|
}
|
|
1423
1246
|
}
|
|
1424
1247
|
async apiError(e) {
|
|
1248
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1249
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1425
1250
|
if (this.botDeviceType === 'garagedoor') {
|
|
1426
1251
|
if (this.GarageDoor) {
|
|
1427
1252
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
@@ -1482,8 +1307,6 @@ export class Bot extends deviceBase {
|
|
|
1482
1307
|
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
1483
1308
|
}
|
|
1484
1309
|
}
|
|
1485
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1486
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1487
1310
|
}
|
|
1488
1311
|
}
|
|
1489
1312
|
//# sourceMappingURL=bot.js.map
|