@switchbot/homebridge-switchbot 3.7.1-beta.12 → 3.7.1-beta.13
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/blindtilt.d.ts +8 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +34 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +61 -97
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +5 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +36 -71
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +22 -37
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +141 -146
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +54 -47
- package/src/device/blindtilt.ts +419 -456
- package/src/device/bot.ts +656 -693
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +400 -435
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +169 -184
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +280 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1281 -1281
- package/src/settings.ts +170 -170
- package/src/types/bledevicestatus.ts +255 -255
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -127
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
package/src/device/bot.ts
CHANGED
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
*
|
|
3
3
|
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { botServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { botStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { botWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
6
14
|
/*
|
|
7
15
|
* For Testing Locally:
|
|
8
16
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
9
17
|
*/
|
|
10
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
11
|
-
import {
|
|
18
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
12
20
|
|
|
13
|
-
import
|
|
14
|
-
import type { device } from '../types/devicelist.js';
|
|
15
|
-
import type { SwitchBotPlatform } from '../platform.js';
|
|
16
|
-
import type { botServiceData } from '../types/bledevicestatus.js';
|
|
17
|
-
import type { botStatus } from '../types/devicestatus.js';
|
|
18
|
-
import type { botWebhookContext } from '../types/devicewebhookstatus.js';
|
|
19
|
-
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
21
|
+
import { deviceBase } from './device.js'
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Platform Accessory
|
|
@@ -26,444 +28,403 @@ import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge
|
|
|
26
28
|
export class Bot extends deviceBase {
|
|
27
29
|
// Services
|
|
28
30
|
private Battery: {
|
|
29
|
-
Name: CharacteristicValue
|
|
30
|
-
Service: Service
|
|
31
|
-
BatteryLevel: CharacteristicValue
|
|
32
|
-
StatusLowBattery: CharacteristicValue
|
|
33
|
-
}
|
|
31
|
+
Name: CharacteristicValue
|
|
32
|
+
Service: Service
|
|
33
|
+
BatteryLevel: CharacteristicValue
|
|
34
|
+
StatusLowBattery: CharacteristicValue
|
|
35
|
+
}
|
|
34
36
|
|
|
35
37
|
private Switch?: {
|
|
36
|
-
Name: CharacteristicValue
|
|
37
|
-
Service: Service
|
|
38
|
-
}
|
|
38
|
+
Name: CharacteristicValue
|
|
39
|
+
Service: Service
|
|
40
|
+
}
|
|
39
41
|
|
|
40
42
|
private GarageDoor?: {
|
|
41
|
-
Name: CharacteristicValue
|
|
42
|
-
Service: Service
|
|
43
|
-
}
|
|
43
|
+
Name: CharacteristicValue
|
|
44
|
+
Service: Service
|
|
45
|
+
}
|
|
44
46
|
|
|
45
47
|
private Door?: {
|
|
46
|
-
Name: CharacteristicValue
|
|
47
|
-
Service: Service
|
|
48
|
-
}
|
|
48
|
+
Name: CharacteristicValue
|
|
49
|
+
Service: Service
|
|
50
|
+
}
|
|
49
51
|
|
|
50
52
|
private Window?: {
|
|
51
|
-
Name: CharacteristicValue
|
|
52
|
-
Service: Service
|
|
53
|
-
}
|
|
53
|
+
Name: CharacteristicValue
|
|
54
|
+
Service: Service
|
|
55
|
+
}
|
|
54
56
|
|
|
55
57
|
private WindowCovering?: {
|
|
56
|
-
Name: CharacteristicValue
|
|
57
|
-
Service: Service
|
|
58
|
-
}
|
|
58
|
+
Name: CharacteristicValue
|
|
59
|
+
Service: Service
|
|
60
|
+
}
|
|
59
61
|
|
|
60
62
|
private LockMechanism?: {
|
|
61
|
-
Name: CharacteristicValue
|
|
62
|
-
Service: Service
|
|
63
|
-
}
|
|
63
|
+
Name: CharacteristicValue
|
|
64
|
+
Service: Service
|
|
65
|
+
}
|
|
64
66
|
|
|
65
67
|
private Faucet?: {
|
|
66
|
-
Name: CharacteristicValue
|
|
67
|
-
Service: Service
|
|
68
|
-
}
|
|
68
|
+
Name: CharacteristicValue
|
|
69
|
+
Service: Service
|
|
70
|
+
}
|
|
69
71
|
|
|
70
72
|
private Fan?: {
|
|
71
|
-
Name: CharacteristicValue
|
|
72
|
-
Service: Service
|
|
73
|
-
}
|
|
73
|
+
Name: CharacteristicValue
|
|
74
|
+
Service: Service
|
|
75
|
+
}
|
|
74
76
|
|
|
75
77
|
private StatefulProgrammableSwitch?: {
|
|
76
|
-
Name: CharacteristicValue
|
|
77
|
-
Service: Service
|
|
78
|
-
}
|
|
78
|
+
Name: CharacteristicValue
|
|
79
|
+
Service: Service
|
|
80
|
+
}
|
|
79
81
|
|
|
80
82
|
private Outlet?: {
|
|
81
|
-
Name: CharacteristicValue
|
|
82
|
-
Service: Service
|
|
83
|
-
}
|
|
83
|
+
Name: CharacteristicValue
|
|
84
|
+
Service: Service
|
|
85
|
+
}
|
|
84
86
|
|
|
85
|
-
On!: boolean
|
|
87
|
+
On!: boolean
|
|
86
88
|
|
|
87
89
|
// OpenAPI
|
|
88
|
-
deviceStatus!: botStatus
|
|
90
|
+
deviceStatus!: botStatus
|
|
89
91
|
|
|
90
|
-
//Webhook
|
|
91
|
-
webhookContext!: botWebhookContext
|
|
92
|
+
// Webhook
|
|
93
|
+
webhookContext!: botWebhookContext
|
|
92
94
|
|
|
93
95
|
// BLE
|
|
94
|
-
serviceData!: botServiceData
|
|
96
|
+
serviceData!: botServiceData
|
|
95
97
|
|
|
96
98
|
// Config
|
|
97
|
-
botMode!: string
|
|
98
|
-
allowPush?: boolean
|
|
99
|
-
doublePress!: number
|
|
100
|
-
botDeviceType!: string
|
|
101
|
-
pushRatePress!: number
|
|
102
|
-
multiPressCount!: number
|
|
99
|
+
botMode!: string
|
|
100
|
+
allowPush?: boolean
|
|
101
|
+
doublePress!: number
|
|
102
|
+
botDeviceType!: string
|
|
103
|
+
pushRatePress!: number
|
|
104
|
+
multiPressCount!: number
|
|
103
105
|
|
|
104
106
|
// Updates
|
|
105
|
-
botUpdateInProgress!: boolean
|
|
106
|
-
doBotUpdate!: Subject<void
|
|
107
|
+
botUpdateInProgress!: boolean
|
|
108
|
+
doBotUpdate!: Subject<void>
|
|
107
109
|
|
|
108
110
|
constructor(
|
|
109
111
|
readonly platform: SwitchBotPlatform,
|
|
110
112
|
accessory: PlatformAccessory,
|
|
111
113
|
device: device & devicesConfig,
|
|
112
114
|
) {
|
|
113
|
-
super(platform, accessory, device)
|
|
115
|
+
super(platform, accessory, device)
|
|
114
116
|
|
|
115
117
|
// default placeholders
|
|
116
|
-
this.getBotConfigSettings(device)
|
|
118
|
+
this.getBotConfigSettings(device)
|
|
117
119
|
|
|
118
120
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
119
|
-
this.doBotUpdate = new Subject()
|
|
120
|
-
this.botUpdateInProgress = false
|
|
121
|
+
this.doBotUpdate = new Subject()
|
|
122
|
+
this.botUpdateInProgress = false
|
|
121
123
|
|
|
122
124
|
// Initialize Battery property
|
|
123
|
-
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
125
|
+
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
124
126
|
this.Battery = {
|
|
125
127
|
Name: `${accessory.displayName} Battery`,
|
|
126
128
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
127
129
|
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
128
130
|
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
129
|
-
}
|
|
130
|
-
accessory.context.Battery = this.Battery as object
|
|
131
|
+
}
|
|
132
|
+
accessory.context.Battery = this.Battery as object
|
|
131
133
|
// Initialize Battery Characteristics
|
|
132
|
-
this.Battery.Service
|
|
133
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
134
|
-
.setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
135
|
-
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
134
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
136
135
|
|
|
137
136
|
// deviceType
|
|
138
137
|
if (this.botDeviceType === 'switch') {
|
|
139
138
|
// Set category
|
|
140
|
-
accessory.category = this.hap.Categories.SWITCH
|
|
139
|
+
accessory.category = this.hap.Categories.SWITCH
|
|
141
140
|
// Initialize Switch Service
|
|
142
|
-
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
141
|
+
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
143
142
|
this.Switch = {
|
|
144
143
|
Name: accessory.displayName,
|
|
145
144
|
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
146
|
-
}
|
|
147
|
-
accessory.context.Switch = this.Switch as object
|
|
148
|
-
this.debugLog('Displaying as Switch')
|
|
145
|
+
}
|
|
146
|
+
accessory.context.Switch = this.Switch as object
|
|
147
|
+
this.debugLog('Displaying as Switch')
|
|
149
148
|
// Initialize Switch Characteristics
|
|
150
|
-
this.Switch.Service
|
|
151
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
152
|
-
.getCharacteristic(this.hap.Characteristic.On)
|
|
153
|
-
.onSet(this.OnSet.bind(this));
|
|
149
|
+
this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this))
|
|
154
150
|
// Remove other services
|
|
155
|
-
this.removeFanService(accessory)
|
|
156
|
-
this.removeLockService(accessory)
|
|
157
|
-
this.removeDoorService(accessory)
|
|
158
|
-
this.removeFaucetService(accessory)
|
|
159
|
-
this.removeOutletService(accessory)
|
|
160
|
-
this.removeWindowService(accessory)
|
|
161
|
-
this.removeGarageDoorService(accessory)
|
|
162
|
-
this.removeWindowCoveringService(accessory)
|
|
163
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
151
|
+
this.removeFanService(accessory)
|
|
152
|
+
this.removeLockService(accessory)
|
|
153
|
+
this.removeDoorService(accessory)
|
|
154
|
+
this.removeFaucetService(accessory)
|
|
155
|
+
this.removeOutletService(accessory)
|
|
156
|
+
this.removeWindowService(accessory)
|
|
157
|
+
this.removeGarageDoorService(accessory)
|
|
158
|
+
this.removeWindowCoveringService(accessory)
|
|
159
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
164
160
|
} else if (this.botDeviceType === 'garagedoor') {
|
|
165
161
|
// Set category
|
|
166
|
-
accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER
|
|
162
|
+
accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER
|
|
167
163
|
// Initialize GarageDoor Service
|
|
168
|
-
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
|
|
164
|
+
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
|
|
169
165
|
this.GarageDoor = {
|
|
170
166
|
Name: accessory.displayName,
|
|
171
167
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
|
|
172
|
-
}
|
|
173
|
-
accessory.context.GarageDoor = this.GarageDoor as object
|
|
174
|
-
this.debugLog('Displaying as Garage Door Opener')
|
|
168
|
+
}
|
|
169
|
+
accessory.context.GarageDoor = this.GarageDoor as object
|
|
170
|
+
this.debugLog('Displaying as Garage Door Opener')
|
|
175
171
|
// Initialize GarageDoor Characteristics
|
|
176
|
-
this.GarageDoor.Service
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
minValue: 0,
|
|
183
|
-
maxValue: 100,
|
|
184
|
-
minStep: 100,
|
|
185
|
-
})
|
|
186
|
-
.onSet(this.OnSet.bind(this));
|
|
172
|
+
this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name).setCharacteristic(this.hap.Characteristic.ObstructionDetected, false).getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
|
|
173
|
+
validValues: [0, 100],
|
|
174
|
+
minValue: 0,
|
|
175
|
+
maxValue: 100,
|
|
176
|
+
minStep: 100,
|
|
177
|
+
}).onSet(this.OnSet.bind(this))
|
|
187
178
|
// Remove other services
|
|
188
|
-
this.removeFanService(accessory)
|
|
189
|
-
this.removeLockService(accessory)
|
|
190
|
-
this.removeDoorService(accessory)
|
|
191
|
-
this.removeFaucetService(accessory)
|
|
192
|
-
this.removeOutletService(accessory)
|
|
193
|
-
this.removeSwitchService(accessory)
|
|
194
|
-
this.removeWindowService(accessory)
|
|
195
|
-
this.removeWindowCoveringService(accessory)
|
|
196
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
179
|
+
this.removeFanService(accessory)
|
|
180
|
+
this.removeLockService(accessory)
|
|
181
|
+
this.removeDoorService(accessory)
|
|
182
|
+
this.removeFaucetService(accessory)
|
|
183
|
+
this.removeOutletService(accessory)
|
|
184
|
+
this.removeSwitchService(accessory)
|
|
185
|
+
this.removeWindowService(accessory)
|
|
186
|
+
this.removeWindowCoveringService(accessory)
|
|
187
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
197
188
|
} else if (this.botDeviceType === 'door') {
|
|
198
189
|
// Set category
|
|
199
|
-
accessory.category = this.hap.Categories.DOOR
|
|
190
|
+
accessory.category = this.hap.Categories.DOOR
|
|
200
191
|
// Initialize Door Service
|
|
201
|
-
accessory.context.Door = accessory.context.Door ?? {}
|
|
192
|
+
accessory.context.Door = accessory.context.Door ?? {}
|
|
202
193
|
this.Door = {
|
|
203
194
|
Name: accessory.displayName,
|
|
204
195
|
Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
|
|
205
|
-
}
|
|
206
|
-
accessory.context.Door = this.Door as object
|
|
207
|
-
this.debugLog('Displaying as Door')
|
|
196
|
+
}
|
|
197
|
+
accessory.context.Door = this.Door as object
|
|
198
|
+
this.debugLog('Displaying as Door')
|
|
208
199
|
// Initialize Door Characteristics
|
|
209
|
-
this.Door.Service
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
maxValue: 100,
|
|
216
|
-
minStep: 100,
|
|
217
|
-
})
|
|
218
|
-
.onSet(this.OnSet.bind(this));
|
|
200
|
+
this.Door.Service.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
201
|
+
validValues: [0, 100],
|
|
202
|
+
minValue: 0,
|
|
203
|
+
maxValue: 100,
|
|
204
|
+
minStep: 100,
|
|
205
|
+
}).onSet(this.OnSet.bind(this))
|
|
219
206
|
// Remove other services
|
|
220
|
-
this.removeFanService(accessory)
|
|
221
|
-
this.removeLockService(accessory)
|
|
222
|
-
this.removeOutletService(accessory)
|
|
223
|
-
this.removeFaucetService(accessory)
|
|
224
|
-
this.removeSwitchService(accessory)
|
|
225
|
-
this.removeWindowService(accessory)
|
|
226
|
-
this.removeGarageDoorService(accessory)
|
|
227
|
-
this.removeWindowCoveringService(accessory)
|
|
228
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
207
|
+
this.removeFanService(accessory)
|
|
208
|
+
this.removeLockService(accessory)
|
|
209
|
+
this.removeOutletService(accessory)
|
|
210
|
+
this.removeFaucetService(accessory)
|
|
211
|
+
this.removeSwitchService(accessory)
|
|
212
|
+
this.removeWindowService(accessory)
|
|
213
|
+
this.removeGarageDoorService(accessory)
|
|
214
|
+
this.removeWindowCoveringService(accessory)
|
|
215
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
229
216
|
} else if (this.botDeviceType === 'window') {
|
|
230
217
|
// Set category
|
|
231
|
-
accessory.category = this.hap.Categories.WINDOW
|
|
218
|
+
accessory.category = this.hap.Categories.WINDOW
|
|
232
219
|
// Initialize Window Service
|
|
233
|
-
accessory.context.Window = accessory.context.Window ?? {}
|
|
220
|
+
accessory.context.Window = accessory.context.Window ?? {}
|
|
234
221
|
this.Window = {
|
|
235
222
|
Name: accessory.displayName,
|
|
236
223
|
Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
|
|
237
|
-
}
|
|
238
|
-
accessory.context.Window = this.Window as object
|
|
239
|
-
this.debugLog('Displaying as Window')
|
|
224
|
+
}
|
|
225
|
+
accessory.context.Window = this.Window as object
|
|
226
|
+
this.debugLog('Displaying as Window')
|
|
240
227
|
// Initialize Window Characteristics
|
|
241
|
-
this.Window.Service
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
maxValue: 100,
|
|
248
|
-
minStep: 100,
|
|
249
|
-
})
|
|
250
|
-
.onSet(this.OnSet.bind(this));
|
|
228
|
+
this.Window.Service.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
229
|
+
validValues: [0, 100],
|
|
230
|
+
minValue: 0,
|
|
231
|
+
maxValue: 100,
|
|
232
|
+
minStep: 100,
|
|
233
|
+
}).onSet(this.OnSet.bind(this))
|
|
251
234
|
// Remove other services
|
|
252
|
-
this.removeFanService(accessory)
|
|
253
|
-
this.removeLockService(accessory)
|
|
254
|
-
this.removeDoorService(accessory)
|
|
255
|
-
this.removeOutletService(accessory)
|
|
256
|
-
this.removeFaucetService(accessory)
|
|
257
|
-
this.removeSwitchService(accessory)
|
|
258
|
-
this.removeGarageDoorService(accessory)
|
|
259
|
-
this.removeWindowCoveringService(accessory)
|
|
260
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
235
|
+
this.removeFanService(accessory)
|
|
236
|
+
this.removeLockService(accessory)
|
|
237
|
+
this.removeDoorService(accessory)
|
|
238
|
+
this.removeOutletService(accessory)
|
|
239
|
+
this.removeFaucetService(accessory)
|
|
240
|
+
this.removeSwitchService(accessory)
|
|
241
|
+
this.removeGarageDoorService(accessory)
|
|
242
|
+
this.removeWindowCoveringService(accessory)
|
|
243
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
261
244
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
262
245
|
// Set category
|
|
263
|
-
accessory.category = this.hap.Categories.WINDOW_COVERING
|
|
246
|
+
accessory.category = this.hap.Categories.WINDOW_COVERING
|
|
264
247
|
// Initialize WindowCovering Service
|
|
265
|
-
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
248
|
+
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
266
249
|
this.WindowCovering = {
|
|
267
250
|
Name: accessory.displayName,
|
|
268
251
|
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
|
|
269
|
-
}
|
|
270
|
-
accessory.context.WindowCovering = this.WindowCovering as object
|
|
271
|
-
this.debugLog('Displaying as Window Covering')
|
|
252
|
+
}
|
|
253
|
+
accessory.context.WindowCovering = this.WindowCovering as object
|
|
254
|
+
this.debugLog('Displaying as Window Covering')
|
|
272
255
|
// Initialize WindowCovering Characteristics
|
|
273
|
-
this.WindowCovering.Service
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
minValue: 0,
|
|
280
|
-
maxValue: 100,
|
|
281
|
-
minStep: 100,
|
|
282
|
-
})
|
|
283
|
-
.onSet(this.OnSet.bind(this));
|
|
256
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
257
|
+
validValues: [0, 100],
|
|
258
|
+
minValue: 0,
|
|
259
|
+
maxValue: 100,
|
|
260
|
+
minStep: 100,
|
|
261
|
+
}).onSet(this.OnSet.bind(this))
|
|
284
262
|
// Remove other services
|
|
285
|
-
this.removeFanService(accessory)
|
|
286
|
-
this.removeLockService(accessory)
|
|
287
|
-
this.removeDoorService(accessory)
|
|
288
|
-
this.removeOutletService(accessory)
|
|
289
|
-
this.removeFaucetService(accessory)
|
|
290
|
-
this.removeSwitchService(accessory)
|
|
291
|
-
this.removeWindowService(accessory)
|
|
292
|
-
this.removeGarageDoorService(accessory)
|
|
293
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
263
|
+
this.removeFanService(accessory)
|
|
264
|
+
this.removeLockService(accessory)
|
|
265
|
+
this.removeDoorService(accessory)
|
|
266
|
+
this.removeOutletService(accessory)
|
|
267
|
+
this.removeFaucetService(accessory)
|
|
268
|
+
this.removeSwitchService(accessory)
|
|
269
|
+
this.removeWindowService(accessory)
|
|
270
|
+
this.removeGarageDoorService(accessory)
|
|
271
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
294
272
|
} else if (this.botDeviceType === 'lock') {
|
|
295
273
|
// Set category
|
|
296
|
-
accessory.category = this.hap.Categories.DOOR_LOCK
|
|
274
|
+
accessory.category = this.hap.Categories.DOOR_LOCK
|
|
297
275
|
// Initialize Lock Service
|
|
298
|
-
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
|
|
276
|
+
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
|
|
299
277
|
this.LockMechanism = {
|
|
300
278
|
Name: accessory.displayName,
|
|
301
279
|
Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
|
|
302
|
-
}
|
|
303
|
-
accessory.context.LockMechanism = this.LockMechanism as object
|
|
304
|
-
this.debugLog('Displaying as Lock')
|
|
280
|
+
}
|
|
281
|
+
accessory.context.LockMechanism = this.LockMechanism as object
|
|
282
|
+
this.debugLog('Displaying as Lock')
|
|
305
283
|
// Initialize Lock Characteristics
|
|
306
|
-
this.LockMechanism.Service
|
|
307
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
308
|
-
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
309
|
-
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
310
|
-
.onSet(this.OnSet.bind(this));
|
|
284
|
+
this.LockMechanism.Service.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this))
|
|
311
285
|
// Remove other services
|
|
312
|
-
this.removeFanService(accessory)
|
|
313
|
-
this.removeDoorService(accessory)
|
|
314
|
-
this.removeOutletService(accessory)
|
|
315
|
-
this.removeSwitchService(accessory)
|
|
316
|
-
this.removeFaucetService(accessory)
|
|
317
|
-
this.removeWindowService(accessory)
|
|
318
|
-
this.removeGarageDoorService(accessory)
|
|
319
|
-
this.removeWindowCoveringService(accessory)
|
|
320
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
286
|
+
this.removeFanService(accessory)
|
|
287
|
+
this.removeDoorService(accessory)
|
|
288
|
+
this.removeOutletService(accessory)
|
|
289
|
+
this.removeSwitchService(accessory)
|
|
290
|
+
this.removeFaucetService(accessory)
|
|
291
|
+
this.removeWindowService(accessory)
|
|
292
|
+
this.removeGarageDoorService(accessory)
|
|
293
|
+
this.removeWindowCoveringService(accessory)
|
|
294
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
321
295
|
} else if (this.botDeviceType === 'faucet') {
|
|
322
296
|
// Set category
|
|
323
|
-
accessory.category = this.hap.Categories.FAUCET
|
|
297
|
+
accessory.category = this.hap.Categories.FAUCET
|
|
324
298
|
// Initialize Faucet Service
|
|
325
|
-
accessory.context.Faucet = accessory.context.Faucet ?? {}
|
|
299
|
+
accessory.context.Faucet = accessory.context.Faucet ?? {}
|
|
326
300
|
this.Faucet = {
|
|
327
301
|
Name: accessory.displayName,
|
|
328
302
|
Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
|
|
329
|
-
}
|
|
330
|
-
accessory.context.Faucet = this.Faucet as object
|
|
331
|
-
this.debugLog('Displaying as Faucet')
|
|
303
|
+
}
|
|
304
|
+
accessory.context.Faucet = this.Faucet as object
|
|
305
|
+
this.debugLog('Displaying as Faucet')
|
|
332
306
|
// Initialize Faucet Characteristics
|
|
333
|
-
this.Faucet.Service
|
|
334
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
|
|
335
|
-
.getCharacteristic(this.hap.Characteristic.Active)
|
|
336
|
-
.onSet(this.OnSet.bind(this));
|
|
307
|
+
this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this))
|
|
337
308
|
// Remove other services
|
|
338
|
-
this.removeFanService(accessory)
|
|
339
|
-
this.removeLockService(accessory)
|
|
340
|
-
this.removeDoorService(accessory)
|
|
341
|
-
this.removeOutletService(accessory)
|
|
342
|
-
this.removeSwitchService(accessory)
|
|
343
|
-
this.removeWindowService(accessory)
|
|
344
|
-
this.removeGarageDoorService(accessory)
|
|
345
|
-
this.removeWindowCoveringService(accessory)
|
|
346
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
309
|
+
this.removeFanService(accessory)
|
|
310
|
+
this.removeLockService(accessory)
|
|
311
|
+
this.removeDoorService(accessory)
|
|
312
|
+
this.removeOutletService(accessory)
|
|
313
|
+
this.removeSwitchService(accessory)
|
|
314
|
+
this.removeWindowService(accessory)
|
|
315
|
+
this.removeGarageDoorService(accessory)
|
|
316
|
+
this.removeWindowCoveringService(accessory)
|
|
317
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
347
318
|
} else if (this.botDeviceType === 'fan') {
|
|
348
319
|
// Set category
|
|
349
|
-
accessory.category = this.hap.Categories.FAN
|
|
320
|
+
accessory.category = this.hap.Categories.FAN
|
|
350
321
|
// Initialize Fan Service
|
|
351
|
-
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
322
|
+
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
352
323
|
this.Fan = {
|
|
353
324
|
Name: accessory.displayName,
|
|
354
325
|
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
|
|
355
|
-
}
|
|
356
|
-
accessory.context.Fan = this.Fan as object
|
|
357
|
-
this.debugLog('Displaying as Fan')
|
|
326
|
+
}
|
|
327
|
+
accessory.context.Fan = this.Fan as object
|
|
328
|
+
this.debugLog('Displaying as Fan')
|
|
358
329
|
// Initialize Fan Characteristics
|
|
359
|
-
this.Fan.Service
|
|
360
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
361
|
-
.getCharacteristic(this.hap.Characteristic.Active)
|
|
362
|
-
.onSet(this.OnSet.bind(this));
|
|
330
|
+
this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this))
|
|
363
331
|
// Remove other services
|
|
364
|
-
this.removeLockService(accessory)
|
|
365
|
-
this.removeDoorService(accessory)
|
|
366
|
-
this.removeFaucetService(accessory)
|
|
367
|
-
this.removeOutletService(accessory)
|
|
368
|
-
this.removeSwitchService(accessory)
|
|
369
|
-
this.removeWindowService(accessory)
|
|
370
|
-
this.removeGarageDoorService(accessory)
|
|
371
|
-
this.removeWindowCoveringService(accessory)
|
|
372
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
332
|
+
this.removeLockService(accessory)
|
|
333
|
+
this.removeDoorService(accessory)
|
|
334
|
+
this.removeFaucetService(accessory)
|
|
335
|
+
this.removeOutletService(accessory)
|
|
336
|
+
this.removeSwitchService(accessory)
|
|
337
|
+
this.removeWindowService(accessory)
|
|
338
|
+
this.removeGarageDoorService(accessory)
|
|
339
|
+
this.removeWindowCoveringService(accessory)
|
|
340
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
373
341
|
} else if (this.botDeviceType === 'stateful') {
|
|
374
342
|
// Set category
|
|
375
|
-
accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH
|
|
343
|
+
accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH
|
|
376
344
|
// Initialize StatefulProgrammableSwitch Service
|
|
377
|
-
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
|
|
345
|
+
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
|
|
378
346
|
this.StatefulProgrammableSwitch = {
|
|
379
347
|
Name: accessory.displayName,
|
|
380
|
-
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
348
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
349
|
+
}
|
|
350
|
+
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object
|
|
351
|
+
this.debugLog('Displaying as Stateful Programmable Switch')
|
|
385
352
|
// Initialize StatefulProgrammableSwitch Characteristics
|
|
386
|
-
this.StatefulProgrammableSwitch.Service
|
|
387
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
|
|
388
|
-
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
389
|
-
.onSet(this.OnSet.bind(this));
|
|
353
|
+
this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onSet(this.OnSet.bind(this))
|
|
390
354
|
// Remove other services
|
|
391
|
-
this.removeFanService(accessory)
|
|
392
|
-
this.removeLockService(accessory)
|
|
393
|
-
this.removeDoorService(accessory)
|
|
394
|
-
this.removeFaucetService(accessory)
|
|
395
|
-
this.removeOutletService(accessory)
|
|
396
|
-
this.removeSwitchService(accessory)
|
|
397
|
-
this.removeWindowService(accessory)
|
|
398
|
-
this.removeGarageDoorService(accessory)
|
|
399
|
-
this.removeWindowCoveringService(accessory)
|
|
355
|
+
this.removeFanService(accessory)
|
|
356
|
+
this.removeLockService(accessory)
|
|
357
|
+
this.removeDoorService(accessory)
|
|
358
|
+
this.removeFaucetService(accessory)
|
|
359
|
+
this.removeOutletService(accessory)
|
|
360
|
+
this.removeSwitchService(accessory)
|
|
361
|
+
this.removeWindowService(accessory)
|
|
362
|
+
this.removeGarageDoorService(accessory)
|
|
363
|
+
this.removeWindowCoveringService(accessory)
|
|
400
364
|
} else if (this.botDeviceType === 'outlet') {
|
|
401
365
|
// Set category
|
|
402
|
-
accessory.category = this.hap.Categories.OUTLET
|
|
366
|
+
accessory.category = this.hap.Categories.OUTLET
|
|
403
367
|
// Initialize Switch property
|
|
404
|
-
accessory.context.Outlet = accessory.context.Outlet ?? {}
|
|
368
|
+
accessory.context.Outlet = accessory.context.Outlet ?? {}
|
|
405
369
|
this.Outlet = {
|
|
406
370
|
Name: accessory.displayName,
|
|
407
371
|
Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
|
|
408
|
-
}
|
|
409
|
-
accessory.context.Outlet = this.Outlet as object
|
|
410
|
-
this.debugLog('Displaying as Outlet')
|
|
372
|
+
}
|
|
373
|
+
accessory.context.Outlet = this.Outlet as object
|
|
374
|
+
this.debugLog('Displaying as Outlet')
|
|
411
375
|
// Initialize Outlet Characteristics
|
|
412
|
-
this.Outlet.Service
|
|
413
|
-
.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
|
|
414
|
-
.getCharacteristic(this.hap.Characteristic.On)
|
|
415
|
-
.onSet(this.OnSet.bind(this));
|
|
376
|
+
this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this))
|
|
416
377
|
// Remove other services
|
|
417
|
-
this.removeFanService(accessory)
|
|
418
|
-
this.removeLockService(accessory)
|
|
419
|
-
this.removeDoorService(accessory)
|
|
420
|
-
this.removeFaucetService(accessory)
|
|
421
|
-
this.removeSwitchService(accessory)
|
|
422
|
-
this.removeWindowService(accessory)
|
|
423
|
-
this.removeGarageDoorService(accessory)
|
|
424
|
-
this.removeWindowCoveringService(accessory)
|
|
425
|
-
this.removeStatefulProgrammableSwitchService(accessory)
|
|
378
|
+
this.removeFanService(accessory)
|
|
379
|
+
this.removeLockService(accessory)
|
|
380
|
+
this.removeDoorService(accessory)
|
|
381
|
+
this.removeFaucetService(accessory)
|
|
382
|
+
this.removeSwitchService(accessory)
|
|
383
|
+
this.removeWindowService(accessory)
|
|
384
|
+
this.removeGarageDoorService(accessory)
|
|
385
|
+
this.removeWindowCoveringService(accessory)
|
|
386
|
+
this.removeStatefulProgrammableSwitchService(accessory)
|
|
426
387
|
} else {
|
|
427
|
-
this.errorLog('Device Type not set')
|
|
388
|
+
this.errorLog('Device Type not set')
|
|
428
389
|
}
|
|
429
390
|
|
|
430
391
|
// Retrieve initial values and updateHomekit
|
|
431
392
|
try {
|
|
432
|
-
this.debugLog('Retrieve initial values and update Homekit')
|
|
433
|
-
this.refreshStatus()
|
|
393
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
394
|
+
this.refreshStatus()
|
|
434
395
|
} catch (e: any) {
|
|
435
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
396
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
436
397
|
}
|
|
437
398
|
|
|
438
|
-
//regisiter webhook event handler if enabled
|
|
399
|
+
// regisiter webhook event handler if enabled
|
|
439
400
|
try {
|
|
440
|
-
this.debugLog('Registering Webhook Event Handler')
|
|
441
|
-
this.registerWebhook()
|
|
401
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
402
|
+
this.registerWebhook()
|
|
442
403
|
} catch (e: any) {
|
|
443
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
404
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
444
405
|
}
|
|
445
406
|
|
|
446
|
-
//regisiter platform BLE event handler if enabled
|
|
407
|
+
// regisiter platform BLE event handler if enabled
|
|
447
408
|
try {
|
|
448
|
-
this.debugLog('Registering Platform BLE Event Handler')
|
|
449
|
-
this.registerPlatformBLE()
|
|
409
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
410
|
+
this.registerPlatformBLE()
|
|
450
411
|
} catch (e: any) {
|
|
451
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
412
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
452
413
|
}
|
|
453
414
|
|
|
454
415
|
// Start an update interval
|
|
455
416
|
interval(this.deviceRefreshRate * 1000)
|
|
456
417
|
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
457
418
|
.subscribe(async () => {
|
|
458
|
-
await this.refreshStatus()
|
|
459
|
-
})
|
|
419
|
+
await this.refreshStatus()
|
|
420
|
+
})
|
|
460
421
|
|
|
461
422
|
// Watch for Bot change events
|
|
462
423
|
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
463
424
|
this.doBotUpdate
|
|
464
425
|
.pipe(
|
|
465
426
|
tap(() => {
|
|
466
|
-
this.botUpdateInProgress = true
|
|
427
|
+
this.botUpdateInProgress = true
|
|
467
428
|
}),
|
|
468
429
|
debounceTime(this.devicePushRate * 1000),
|
|
469
430
|
)
|
|
@@ -473,103 +434,102 @@ export class Bot extends deviceBase {
|
|
|
473
434
|
interval(this.pushRatePress * 1000)
|
|
474
435
|
.pipe(take(this.doublePress!))
|
|
475
436
|
.subscribe(async () => {
|
|
476
|
-
await this.pushChanges()
|
|
477
|
-
})
|
|
437
|
+
await this.pushChanges()
|
|
438
|
+
})
|
|
478
439
|
} else {
|
|
479
|
-
await this.pushChanges()
|
|
440
|
+
await this.pushChanges()
|
|
480
441
|
}
|
|
481
442
|
} catch (e: any) {
|
|
482
|
-
await this.apiError(e)
|
|
483
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
443
|
+
await this.apiError(e)
|
|
444
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
484
445
|
}
|
|
485
|
-
this.botUpdateInProgress = false
|
|
486
|
-
})
|
|
446
|
+
this.botUpdateInProgress = false
|
|
447
|
+
})
|
|
487
448
|
}
|
|
488
449
|
|
|
489
450
|
/**
|
|
490
451
|
* Parse the device status from the SwitchBotBLE API
|
|
491
452
|
*/
|
|
492
453
|
async BLEparseStatus(): Promise<void> {
|
|
493
|
-
await this.debugLog('BLEparseStatus')
|
|
494
|
-
await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode})
|
|
495
|
-
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
454
|
+
await this.debugLog('BLEparseStatus')
|
|
455
|
+
await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
496
456
|
|
|
497
457
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
498
|
-
this.On = this.serviceData.mode ? this.serviceData.state : false
|
|
499
|
-
const mode = this.serviceData.mode ? 'Switch' : 'Press'
|
|
500
|
-
await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`)
|
|
501
|
-
this.accessory.context.On = this.On
|
|
458
|
+
this.On = this.serviceData.mode ? this.serviceData.state : false
|
|
459
|
+
const mode = this.serviceData.mode ? 'Switch' : 'Press'
|
|
460
|
+
await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`)
|
|
461
|
+
this.accessory.context.On = this.On
|
|
502
462
|
|
|
503
463
|
// BatteryLevel
|
|
504
|
-
this.Battery.BatteryLevel = this.serviceData.battery
|
|
505
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
464
|
+
this.Battery.BatteryLevel = this.serviceData.battery
|
|
465
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
506
466
|
|
|
507
467
|
// StatusLowBattery
|
|
508
468
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
509
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
510
|
-
|
|
469
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
470
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
471
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
511
472
|
}
|
|
512
473
|
|
|
513
|
-
|
|
514
474
|
/**
|
|
515
475
|
* Parse the device status from the SwitchBot OpenAPI
|
|
516
476
|
*/
|
|
517
477
|
async openAPIparseStatus(): Promise<void> {
|
|
518
|
-
await this.debugLog('openAPIparseStatus')
|
|
519
|
-
await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode})
|
|
520
|
-
+ ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
478
|
+
await this.debugLog('openAPIparseStatus')
|
|
479
|
+
await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
521
480
|
|
|
522
481
|
// On
|
|
523
|
-
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on'
|
|
524
|
-
this.accessory.context.On = this.On
|
|
525
|
-
await this.debugLog(`On: ${this.accessory.context.On}`)
|
|
482
|
+
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on'
|
|
483
|
+
this.accessory.context.On = this.On
|
|
484
|
+
await this.debugLog(`On: ${this.accessory.context.On}`)
|
|
526
485
|
|
|
527
486
|
// Battery Level
|
|
528
|
-
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
529
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
487
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
488
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
530
489
|
|
|
531
490
|
// StatusLowBattery
|
|
532
491
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
533
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
534
|
-
|
|
492
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
493
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
494
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
535
495
|
|
|
536
496
|
// Firmware Version
|
|
537
497
|
if (this.deviceStatus.version) {
|
|
538
|
-
const version = this.deviceStatus.version.toString()
|
|
539
|
-
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
540
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
498
|
+
const version = this.deviceStatus.version.toString()
|
|
499
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
500
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
541
501
|
this.accessory
|
|
542
502
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
543
503
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
544
504
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
545
505
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
546
|
-
.updateValue(deviceVersion)
|
|
547
|
-
this.accessory.context.version = deviceVersion
|
|
548
|
-
await this.debugLog(`version: ${this.accessory.context.version}`)
|
|
506
|
+
.updateValue(deviceVersion)
|
|
507
|
+
this.accessory.context.version = deviceVersion
|
|
508
|
+
await this.debugLog(`version: ${this.accessory.context.version}`)
|
|
549
509
|
}
|
|
550
510
|
}
|
|
551
511
|
|
|
552
512
|
async parseStatusWebhook(): Promise<void> {
|
|
553
|
-
await this.debugLog('parseStatusWebhook')
|
|
554
|
-
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}
|
|
555
|
-
+ ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
513
|
+
await this.debugLog('parseStatusWebhook')
|
|
514
|
+
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
556
515
|
|
|
557
516
|
// On
|
|
558
|
-
this.On = this.webhookContext.power === 'on'
|
|
559
|
-
await this.debugLog(`On: ${this.On}`)
|
|
517
|
+
this.On = this.webhookContext.power === 'on'
|
|
518
|
+
await this.debugLog(`On: ${this.On}`)
|
|
560
519
|
|
|
561
520
|
// BatteryLevel
|
|
562
|
-
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
563
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
521
|
+
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
522
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
564
523
|
|
|
565
524
|
// StatusLowBattery
|
|
566
525
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
567
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
568
|
-
|
|
526
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
527
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
528
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
569
529
|
|
|
570
530
|
// Mode
|
|
571
|
-
this.botMode = this.webhookContext.deviceMode
|
|
572
|
-
await this.debugLog(`Mode: ${this.botMode}`)
|
|
531
|
+
this.botMode = this.webhookContext.deviceMode
|
|
532
|
+
await this.debugLog(`Mode: ${this.botMode}`)
|
|
573
533
|
}
|
|
574
534
|
|
|
575
535
|
/**
|
|
@@ -577,237 +537,237 @@ export class Bot extends deviceBase {
|
|
|
577
537
|
*/
|
|
578
538
|
async refreshStatus(): Promise<void> {
|
|
579
539
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
580
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
540
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
581
541
|
} else if (this.BLE) {
|
|
582
|
-
await this.BLERefreshStatus()
|
|
542
|
+
await this.BLERefreshStatus()
|
|
583
543
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
584
|
-
await this.openAPIRefreshStatus()
|
|
544
|
+
await this.openAPIRefreshStatus()
|
|
585
545
|
} else {
|
|
586
|
-
await this.offlineOff()
|
|
587
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
546
|
+
await this.offlineOff()
|
|
547
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
588
548
|
}
|
|
589
549
|
}
|
|
590
550
|
|
|
591
551
|
async BLERefreshStatus(): Promise<void> {
|
|
592
|
-
await this.debugLog('BLERefreshStatus')
|
|
593
|
-
const switchbot = await this.switchbotBLE()
|
|
552
|
+
await this.debugLog('BLERefreshStatus')
|
|
553
|
+
const switchbot = await this.switchbotBLE()
|
|
594
554
|
if (switchbot === undefined) {
|
|
595
|
-
await this.BLERefreshConnection(switchbot)
|
|
555
|
+
await this.BLERefreshConnection(switchbot)
|
|
596
556
|
} else {
|
|
597
557
|
// Start to monitor advertisement packets
|
|
598
558
|
(async () => {
|
|
599
559
|
// Start to monitor advertisement packets
|
|
600
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData
|
|
560
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData
|
|
601
561
|
// Update HomeKit
|
|
602
562
|
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
603
|
-
this.serviceData = serviceData
|
|
604
|
-
await this.BLEparseStatus()
|
|
605
|
-
await this.updateHomeKitCharacteristics()
|
|
563
|
+
this.serviceData = serviceData
|
|
564
|
+
await this.BLEparseStatus()
|
|
565
|
+
await this.updateHomeKitCharacteristics()
|
|
606
566
|
} else {
|
|
607
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
608
|
-
await this.BLERefreshConnection(switchbot)
|
|
567
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
568
|
+
await this.BLERefreshConnection(switchbot)
|
|
609
569
|
}
|
|
610
|
-
})()
|
|
570
|
+
})()
|
|
611
571
|
}
|
|
612
572
|
}
|
|
613
573
|
|
|
614
574
|
async registerPlatformBLE(): Promise<void> {
|
|
615
|
-
await this.debugLog('registerPlatformBLE')
|
|
575
|
+
await this.debugLog('registerPlatformBLE')
|
|
616
576
|
if (this.config.options?.BLE) {
|
|
617
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
618
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
619
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
577
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
578
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
579
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
620
580
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
|
|
621
581
|
try {
|
|
622
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
623
|
-
this.serviceData = context
|
|
624
|
-
await this.BLEparseStatus()
|
|
625
|
-
await this.updateHomeKitCharacteristics()
|
|
582
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
583
|
+
this.serviceData = context
|
|
584
|
+
await this.BLEparseStatus()
|
|
585
|
+
await this.updateHomeKitCharacteristics()
|
|
626
586
|
} catch (e: any) {
|
|
627
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
587
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
628
588
|
}
|
|
629
|
-
}
|
|
589
|
+
}
|
|
630
590
|
} else {
|
|
631
|
-
await this.debugLog('is not listening to Platform BLE')
|
|
591
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
632
592
|
}
|
|
633
593
|
}
|
|
634
594
|
|
|
635
595
|
async openAPIRefreshStatus(): Promise<void> {
|
|
636
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
596
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
637
597
|
try {
|
|
638
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
639
|
-
const deviceStatus: any = await body.json()
|
|
640
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
598
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
599
|
+
const deviceStatus: any = await body.json()
|
|
600
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
641
601
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
642
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
643
|
-
this.deviceStatus = deviceStatus.body
|
|
644
|
-
await this.openAPIparseStatus()
|
|
645
|
-
await this.updateHomeKitCharacteristics()
|
|
602
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
603
|
+
this.deviceStatus = deviceStatus.body
|
|
604
|
+
await this.openAPIparseStatus()
|
|
605
|
+
await this.updateHomeKitCharacteristics()
|
|
646
606
|
} else {
|
|
647
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
648
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
607
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
608
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
649
609
|
}
|
|
650
610
|
} catch (e: any) {
|
|
651
|
-
await this.apiError(e)
|
|
652
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
611
|
+
await this.apiError(e)
|
|
612
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
653
613
|
}
|
|
654
614
|
}
|
|
655
615
|
|
|
656
616
|
async registerWebhook() {
|
|
657
617
|
if (this.device.webhook) {
|
|
658
|
-
await this.debugLog('is listening webhook.')
|
|
618
|
+
await this.debugLog('is listening webhook.')
|
|
659
619
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: botWebhookContext) => {
|
|
660
620
|
try {
|
|
661
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
662
|
-
this.webhookContext = context
|
|
663
|
-
await this.parseStatusWebhook()
|
|
664
|
-
await this.updateHomeKitCharacteristics()
|
|
621
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
622
|
+
this.webhookContext = context
|
|
623
|
+
await this.parseStatusWebhook()
|
|
624
|
+
await this.updateHomeKitCharacteristics()
|
|
665
625
|
} catch (e: any) {
|
|
666
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
626
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
667
627
|
}
|
|
668
|
-
}
|
|
628
|
+
}
|
|
669
629
|
} else {
|
|
670
|
-
await this.debugLog('is not listening webhook.')
|
|
630
|
+
await this.debugLog('is not listening webhook.')
|
|
671
631
|
}
|
|
672
632
|
}
|
|
673
633
|
|
|
674
634
|
/**
|
|
675
635
|
* Pushes the requested changes to the SwitchBot API
|
|
676
|
-
* deviceType
|
|
677
|
-
* Bot
|
|
678
|
-
* Bot
|
|
679
|
-
* Bot
|
|
636
|
+
* deviceType commandType Command command parameter Description
|
|
637
|
+
* Bot "command" "turnOff" "default" = set to OFF state
|
|
638
|
+
* Bot "command" "turnOn" "default" = set to ON state
|
|
639
|
+
* Bot "command" "press" "default" = trigger press
|
|
680
640
|
*/
|
|
681
641
|
async pushChanges(): Promise<void> {
|
|
682
642
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
683
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
643
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
684
644
|
} else if (this.BLE) {
|
|
685
|
-
await this.BLEpushChanges()
|
|
645
|
+
await this.BLEpushChanges()
|
|
686
646
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
687
|
-
await this.openAPIpushChanges()
|
|
647
|
+
await this.openAPIpushChanges()
|
|
688
648
|
} else {
|
|
689
|
-
await this.offlineOff()
|
|
690
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
649
|
+
await this.offlineOff()
|
|
650
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
691
651
|
}
|
|
692
652
|
// Refresh the status from the API
|
|
693
653
|
interval(15000)
|
|
694
654
|
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
695
655
|
.pipe(take(1))
|
|
696
656
|
.subscribe(async () => {
|
|
697
|
-
await this.refreshStatus()
|
|
698
|
-
})
|
|
657
|
+
await this.refreshStatus()
|
|
658
|
+
})
|
|
699
659
|
}
|
|
700
660
|
|
|
701
661
|
async BLEpushChanges(): Promise<void> {
|
|
702
|
-
await this.debugLog('BLEpushChanges')
|
|
662
|
+
await this.debugLog('BLEpushChanges')
|
|
703
663
|
if (this.On !== this.accessory.context.On || this.allowPush) {
|
|
704
|
-
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
705
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
706
|
-
await this.convertBLEAddress()
|
|
707
|
-
//if (switchbot !== false) {
|
|
708
|
-
await this.debugLog(`Bot Mode: ${this.botMode}`)
|
|
664
|
+
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
665
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
666
|
+
await this.convertBLEAddress()
|
|
667
|
+
// if (switchbot !== false) {
|
|
668
|
+
await this.debugLog(`Bot Mode: ${this.botMode}`)
|
|
709
669
|
if (this.botMode === 'press') {
|
|
710
670
|
switchbot
|
|
711
671
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
712
672
|
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
|
|
713
|
-
await this.infoLog(`On: ${this.On}`)
|
|
714
|
-
return await device_list[0].press({ id: this.device.bleMac })
|
|
673
|
+
await this.infoLog(`On: ${this.On}`)
|
|
674
|
+
return await device_list[0].press({ id: this.device.bleMac })
|
|
715
675
|
})
|
|
716
676
|
.then(async () => {
|
|
717
|
-
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
718
|
-
await this.updateHomeKitCharacteristics()
|
|
677
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
678
|
+
await this.updateHomeKitCharacteristics()
|
|
719
679
|
setTimeout(async () => {
|
|
720
|
-
this.On = false
|
|
721
|
-
await this.updateHomeKitCharacteristics()
|
|
722
|
-
this.debugLog(`On: ${this.On}, Switch Timeout`)
|
|
723
|
-
}, 500)
|
|
680
|
+
this.On = false
|
|
681
|
+
await this.updateHomeKitCharacteristics()
|
|
682
|
+
this.debugLog(`On: ${this.On}, Switch Timeout`)
|
|
683
|
+
}, 500)
|
|
724
684
|
})
|
|
725
685
|
.catch(async (e: any) => {
|
|
726
|
-
await this.apiError(e)
|
|
727
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
728
|
-
await this.BLEPushConnection()
|
|
729
|
-
})
|
|
686
|
+
await this.apiError(e)
|
|
687
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
688
|
+
await this.BLEPushConnection()
|
|
689
|
+
})
|
|
730
690
|
} else if (this.botMode === 'switch') {
|
|
731
691
|
switchbot
|
|
732
692
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
733
693
|
.then(async (device_list: any) => {
|
|
734
|
-
this.infoLog(`On: ${this.On}`)
|
|
694
|
+
this.infoLog(`On: ${this.On}`)
|
|
735
695
|
return await this.retryBLE({
|
|
736
696
|
max: await this.maxRetryBLE(),
|
|
737
697
|
fn: async () => {
|
|
738
698
|
if (this.On) {
|
|
739
|
-
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
699
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
740
700
|
} else {
|
|
741
|
-
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
701
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
742
702
|
}
|
|
743
703
|
},
|
|
744
|
-
})
|
|
704
|
+
})
|
|
745
705
|
})
|
|
746
706
|
.then(async () => {
|
|
747
|
-
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
748
|
-
await this.updateHomeKitCharacteristics()
|
|
707
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
708
|
+
await this.updateHomeKitCharacteristics()
|
|
749
709
|
})
|
|
750
710
|
.catch(async (e: any) => {
|
|
751
|
-
await this.apiError(e)
|
|
752
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
753
|
-
await this.BLEPushConnection()
|
|
754
|
-
})
|
|
711
|
+
await this.apiError(e)
|
|
712
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
713
|
+
await this.BLEPushConnection()
|
|
714
|
+
})
|
|
755
715
|
} else {
|
|
756
|
-
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
|
|
716
|
+
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
|
|
757
717
|
}
|
|
758
718
|
} else {
|
|
759
|
-
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
719
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
760
720
|
}
|
|
761
721
|
}
|
|
762
722
|
|
|
763
723
|
async openAPIpushChanges(): Promise<void> {
|
|
764
|
-
await this.debugLog('openAPIpushChanges')
|
|
724
|
+
await this.debugLog('openAPIpushChanges')
|
|
765
725
|
if (this.multiPressCount > 0) {
|
|
766
|
-
await this.debugLog(`${this.multiPressCount} request(s) queued.`)
|
|
726
|
+
await this.debugLog(`${this.multiPressCount} request(s) queued.`)
|
|
767
727
|
}
|
|
768
728
|
if (this.On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
769
|
-
let command = ''
|
|
729
|
+
let command = ''
|
|
770
730
|
if (this.botMode === 'switch') {
|
|
771
|
-
command = this.On ? 'turnOn' : 'turnOff'
|
|
772
|
-
await this.debugLog(`Switch Mode, Command: ${command}`)
|
|
731
|
+
command = this.On ? 'turnOn' : 'turnOff'
|
|
732
|
+
await this.debugLog(`Switch Mode, Command: ${command}`)
|
|
773
733
|
} else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
774
|
-
command = 'press'
|
|
775
|
-
await this.debugLog('Press Mode')
|
|
776
|
-
this.On = false
|
|
734
|
+
command = 'press'
|
|
735
|
+
await this.debugLog('Press Mode')
|
|
736
|
+
this.On = false
|
|
777
737
|
} else {
|
|
778
|
-
throw new Error('Device Parameters not set for this Bot.')
|
|
738
|
+
throw new Error('Device Parameters not set for this Bot.')
|
|
779
739
|
}
|
|
780
740
|
const bodyChange = JSON.stringify({
|
|
781
741
|
command: `${command}`,
|
|
782
742
|
parameter: 'default',
|
|
783
743
|
commandType: 'command',
|
|
784
|
-
})
|
|
785
|
-
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
744
|
+
})
|
|
745
|
+
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
786
746
|
try {
|
|
787
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
788
|
-
const deviceStatus: any = await body.json()
|
|
789
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
747
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
748
|
+
const deviceStatus: any = await body.json()
|
|
749
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
790
750
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
791
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
792
|
-
await this.updateHomeKitCharacteristics()
|
|
751
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
752
|
+
await this.updateHomeKitCharacteristics()
|
|
793
753
|
} else {
|
|
794
|
-
await this.statusCode(statusCode)
|
|
795
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
754
|
+
await this.statusCode(statusCode)
|
|
755
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
796
756
|
}
|
|
797
757
|
if (this.device.bot?.mode === 'multipress') {
|
|
798
|
-
this.multiPressCount
|
|
758
|
+
this.multiPressCount--
|
|
799
759
|
if (this.multiPressCount > 0) {
|
|
800
|
-
await this.debugLog(`multiPressCount: ${this.multiPressCount}`)
|
|
801
|
-
this.On = true
|
|
802
|
-
await this.openAPIpushChanges()
|
|
760
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`)
|
|
761
|
+
this.On = true
|
|
762
|
+
await this.openAPIpushChanges()
|
|
803
763
|
}
|
|
804
764
|
}
|
|
805
765
|
} catch (e: any) {
|
|
806
|
-
await this.apiError(e)
|
|
807
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
766
|
+
await this.apiError(e)
|
|
767
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
808
768
|
}
|
|
809
769
|
} else {
|
|
810
|
-
await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
770
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
811
771
|
}
|
|
812
772
|
}
|
|
813
773
|
|
|
@@ -816,399 +776,403 @@ export class Bot extends deviceBase {
|
|
|
816
776
|
*/
|
|
817
777
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
818
778
|
if (this.botDeviceType === 'garagedoor') {
|
|
819
|
-
this.debugLog(`Set TargetDoorState: ${value}`)
|
|
779
|
+
this.debugLog(`Set TargetDoorState: ${value}`)
|
|
820
780
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
821
|
-
this.On = false
|
|
781
|
+
this.On = false
|
|
822
782
|
} else {
|
|
823
|
-
this.On = true
|
|
783
|
+
this.On = true
|
|
824
784
|
}
|
|
825
785
|
} else if (
|
|
826
|
-
this.botDeviceType === 'door'
|
|
827
|
-
this.botDeviceType === 'window'
|
|
828
|
-
this.botDeviceType === 'windowcovering'
|
|
786
|
+
this.botDeviceType === 'door'
|
|
787
|
+
|| this.botDeviceType === 'window'
|
|
788
|
+
|| this.botDeviceType === 'windowcovering'
|
|
829
789
|
) {
|
|
830
|
-
this.debugLog(`Set TargetPosition: ${value}`)
|
|
790
|
+
this.debugLog(`Set TargetPosition: ${value}`)
|
|
831
791
|
if (value === 0) {
|
|
832
|
-
this.On = false
|
|
792
|
+
this.On = false
|
|
833
793
|
} else {
|
|
834
|
-
this.On = true
|
|
794
|
+
this.On = true
|
|
835
795
|
}
|
|
836
796
|
} else if (this.botDeviceType === 'lock') {
|
|
837
|
-
this.debugLog(`Set LockTargetState: ${value}`)
|
|
797
|
+
this.debugLog(`Set LockTargetState: ${value}`)
|
|
838
798
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
839
|
-
this.On = false
|
|
799
|
+
this.On = false
|
|
840
800
|
} else {
|
|
841
|
-
this.On = true
|
|
801
|
+
this.On = true
|
|
842
802
|
}
|
|
843
803
|
} else if (this.botDeviceType === 'faucet') {
|
|
844
|
-
this.debugLog(`Set Active: ${value}`)
|
|
804
|
+
this.debugLog(`Set Active: ${value}`)
|
|
845
805
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
846
|
-
this.On = false
|
|
806
|
+
this.On = false
|
|
847
807
|
} else {
|
|
848
|
-
this.On = true
|
|
808
|
+
this.On = true
|
|
849
809
|
}
|
|
850
810
|
} else if (this.botDeviceType === 'stateful') {
|
|
851
|
-
this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`)
|
|
811
|
+
this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`)
|
|
852
812
|
if (value === 0) {
|
|
853
|
-
this.On = false
|
|
813
|
+
this.On = false
|
|
854
814
|
} else {
|
|
855
|
-
this.On = true
|
|
815
|
+
this.On = true
|
|
856
816
|
}
|
|
857
817
|
} else {
|
|
858
|
-
this.debugLog(`Set On: ${value}`)
|
|
818
|
+
this.debugLog(`Set On: ${value}`)
|
|
859
819
|
if (this.device.bot?.mode === 'multipress') {
|
|
860
820
|
if (value === true) {
|
|
861
|
-
this.multiPressCount
|
|
862
|
-
this.debugLog(`set to Multi-Press. Multi-Press count: ${this.multiPressCount}`)
|
|
821
|
+
this.multiPressCount++
|
|
822
|
+
this.debugLog(`set to Multi-Press. Multi-Press count: ${this.multiPressCount}`)
|
|
863
823
|
}
|
|
864
824
|
}
|
|
865
|
-
this.On = value as boolean
|
|
825
|
+
this.On = value as boolean
|
|
866
826
|
}
|
|
867
|
-
this.doBotUpdate.next()
|
|
827
|
+
this.doBotUpdate.next()
|
|
868
828
|
}
|
|
869
829
|
|
|
870
830
|
/**
|
|
871
831
|
* Updates the status for each of the HomeKit Characteristics
|
|
872
832
|
*/
|
|
873
833
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
874
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
834
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
875
835
|
// BatteryLevel
|
|
876
836
|
if (this.Battery.BatteryLevel === undefined) {
|
|
877
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
837
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
878
838
|
} else {
|
|
879
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel
|
|
880
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel)
|
|
881
|
-
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
839
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel
|
|
840
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel)
|
|
841
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
882
842
|
}
|
|
883
843
|
// StatusLowBattery
|
|
884
844
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
885
|
-
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
845
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
886
846
|
} else {
|
|
887
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery
|
|
888
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
889
|
-
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
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}`)
|
|
890
850
|
}
|
|
891
851
|
// State
|
|
892
852
|
if (this.botDeviceType === 'switch' && this.Switch) {
|
|
893
853
|
if (this.On === undefined) {
|
|
894
|
-
await this.debugLog(`On: ${this.On}`)
|
|
854
|
+
await this.debugLog(`On: ${this.On}`)
|
|
895
855
|
} else {
|
|
896
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
|
|
897
|
-
await this.debugLog(`updateCharacteristic On: ${this.On}`)
|
|
856
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
|
|
857
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`)
|
|
898
858
|
}
|
|
899
859
|
} else if (this.botDeviceType === 'garagedoor' && this.GarageDoor) {
|
|
900
860
|
if (this.On === undefined) {
|
|
901
|
-
await this.debugLog(`On: ${this.On}`)
|
|
861
|
+
await this.debugLog(`On: ${this.On}`)
|
|
902
862
|
} else {
|
|
903
863
|
if (this.On) {
|
|
904
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN)
|
|
905
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN)
|
|
906
|
-
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`)
|
|
864
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN)
|
|
865
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN)
|
|
866
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`)
|
|
907
867
|
} else {
|
|
908
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
|
|
909
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
|
|
910
|
-
await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`)
|
|
868
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
|
|
869
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
|
|
870
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`)
|
|
911
871
|
}
|
|
912
872
|
}
|
|
913
|
-
await this.debugLog(`Garage Door On: ${this.On}`)
|
|
873
|
+
await this.debugLog(`Garage Door On: ${this.On}`)
|
|
914
874
|
} else if (this.botDeviceType === 'door' && this.Door) {
|
|
915
875
|
if (this.On === undefined) {
|
|
916
|
-
await this.debugLog(`On: ${this.On}`)
|
|
876
|
+
await this.debugLog(`On: ${this.On}`)
|
|
917
877
|
} else {
|
|
918
878
|
if (this.On) {
|
|
919
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
920
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
921
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
922
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
879
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
880
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
881
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
882
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
923
883
|
} else {
|
|
924
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
925
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
926
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
927
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
884
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
885
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
886
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
887
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
928
888
|
}
|
|
929
889
|
}
|
|
930
|
-
await this.debugLog(`Door On: ${this.On}`)
|
|
890
|
+
await this.debugLog(`Door On: ${this.On}`)
|
|
931
891
|
} else if (this.botDeviceType === 'window' && this.Window) {
|
|
932
892
|
if (this.On === undefined) {
|
|
933
|
-
await this.debugLog(`On: ${this.On}`)
|
|
893
|
+
await this.debugLog(`On: ${this.On}`)
|
|
934
894
|
} else {
|
|
935
895
|
if (this.On) {
|
|
936
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
937
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
938
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
939
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
896
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
897
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
898
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
899
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
940
900
|
} else {
|
|
941
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
942
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
943
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
944
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
901
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
902
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
903
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
904
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
945
905
|
}
|
|
946
906
|
}
|
|
947
|
-
await this.debugLog(`Window On: ${this.On}`)
|
|
907
|
+
await this.debugLog(`Window On: ${this.On}`)
|
|
948
908
|
} else if (this.botDeviceType === 'windowcovering' && this.WindowCovering) {
|
|
949
909
|
if (this.On === undefined) {
|
|
950
|
-
await this.debugLog(`On: ${this.On}`)
|
|
910
|
+
await this.debugLog(`On: ${this.On}`)
|
|
951
911
|
} else {
|
|
952
912
|
if (this.On) {
|
|
953
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
954
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
955
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
956
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
913
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
914
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
915
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
916
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
|
|
957
917
|
} else {
|
|
958
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
959
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
960
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
961
|
-
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
918
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
919
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
920
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
921
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
|
|
962
922
|
}
|
|
963
923
|
}
|
|
964
|
-
await this.debugLog(`Window Covering On: ${this.On}`)
|
|
924
|
+
await this.debugLog(`Window Covering On: ${this.On}`)
|
|
965
925
|
} else if (this.botDeviceType === 'lock' && this.LockMechanism) {
|
|
966
926
|
if (this.On === undefined) {
|
|
967
|
-
await this.debugLog(`On: ${this.On}`)
|
|
927
|
+
await this.debugLog(`On: ${this.On}`)
|
|
968
928
|
} else {
|
|
969
929
|
if (this.On) {
|
|
970
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
971
|
-
|
|
972
|
-
this.
|
|
973
|
-
this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
974
|
-
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
|
|
930
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED)
|
|
931
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED)
|
|
932
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`)
|
|
975
933
|
} else {
|
|
976
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
977
|
-
|
|
978
|
-
this.
|
|
979
|
-
this.hap.Characteristic.LockCurrentState.SECURED);
|
|
980
|
-
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
|
|
934
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED)
|
|
935
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED)
|
|
936
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`)
|
|
981
937
|
}
|
|
982
938
|
}
|
|
983
|
-
await this.debugLog(`Lock On: ${this.On}`)
|
|
939
|
+
await this.debugLog(`Lock On: ${this.On}`)
|
|
984
940
|
} else if (this.botDeviceType === 'faucet' && this.Faucet) {
|
|
985
941
|
if (this.On === undefined) {
|
|
986
|
-
await this.debugLog(`On: ${this.On}`)
|
|
942
|
+
await this.debugLog(`On: ${this.On}`)
|
|
987
943
|
} else {
|
|
988
944
|
if (this.On) {
|
|
989
|
-
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
|
|
990
|
-
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
945
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
|
|
946
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
991
947
|
} else {
|
|
992
|
-
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
993
|
-
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
948
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
949
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
994
950
|
}
|
|
995
951
|
}
|
|
996
|
-
await this.debugLog(`Faucet On: ${this.On}`)
|
|
952
|
+
await this.debugLog(`Faucet On: ${this.On}`)
|
|
997
953
|
} else if (this.botDeviceType === 'fan' && this.Fan) {
|
|
998
954
|
if (this.On === undefined) {
|
|
999
|
-
await this.debugLog(`On: ${this.On}`)
|
|
955
|
+
await this.debugLog(`On: ${this.On}`)
|
|
1000
956
|
} else {
|
|
1001
957
|
if (this.On) {
|
|
1002
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
|
|
1003
|
-
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
958
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
|
|
959
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
1004
960
|
} else {
|
|
1005
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
1006
|
-
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
961
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
962
|
+
await this.debugLog(`updateCharacteristic Active: ${this.On}`)
|
|
1007
963
|
}
|
|
1008
964
|
}
|
|
1009
|
-
await this.debugLog(`Fan On: ${this.On}`)
|
|
965
|
+
await this.debugLog(`Fan On: ${this.On}`)
|
|
1010
966
|
} else if (this.botDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
|
|
1011
967
|
if (this.On === undefined) {
|
|
1012
|
-
await this.debugLog(`On: ${this.On}`)
|
|
968
|
+
await this.debugLog(`On: ${this.On}`)
|
|
1013
969
|
} else {
|
|
1014
970
|
if (this.On) {
|
|
1015
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1016
|
-
|
|
1017
|
-
this.
|
|
1018
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
971
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
|
|
972
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1)
|
|
973
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`)
|
|
1019
974
|
} else {
|
|
1020
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1021
|
-
|
|
1022
|
-
this.
|
|
1023
|
-
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
|
|
975
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
|
|
976
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0)
|
|
977
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`)
|
|
1024
978
|
}
|
|
1025
979
|
}
|
|
1026
|
-
await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`)
|
|
980
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`)
|
|
1027
981
|
} else if (this.botDeviceType === 'outlet' && this.Outlet) {
|
|
1028
982
|
if (this.On === undefined) {
|
|
1029
|
-
await this.debugLog(`On: ${this.On}`)
|
|
983
|
+
await this.debugLog(`On: ${this.On}`)
|
|
1030
984
|
} else {
|
|
1031
|
-
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
|
|
1032
|
-
await this.debugLog(`updateCharacteristic On: ${this.On}`)
|
|
985
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
|
|
986
|
+
await this.debugLog(`updateCharacteristic On: ${this.On}`)
|
|
1033
987
|
}
|
|
1034
988
|
} else {
|
|
1035
|
-
await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`)
|
|
989
|
+
await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`)
|
|
1036
990
|
}
|
|
1037
991
|
}
|
|
1038
992
|
|
|
1039
993
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
1040
994
|
// If outletService still present, then remove first
|
|
1041
|
-
accessory.context.Outlet = accessory.context.Outlet ?? {}
|
|
995
|
+
accessory.context.Outlet = accessory.context.Outlet ?? {}
|
|
1042
996
|
this.Outlet = {
|
|
1043
997
|
Name: accessory.context.Outlet.Name ?? accessory.displayName,
|
|
1044
998
|
Service: accessory.getService(this.hap.Service.Outlet) as Service,
|
|
1045
|
-
}
|
|
1046
|
-
accessory.context.Outlet = this.Outlet as object
|
|
1047
|
-
await this.debugWarnLog('Removing any leftover Outlet Service')
|
|
1048
|
-
accessory.removeService(this.Outlet.Service)
|
|
999
|
+
}
|
|
1000
|
+
accessory.context.Outlet = this.Outlet as object
|
|
1001
|
+
await this.debugWarnLog('Removing any leftover Outlet Service')
|
|
1002
|
+
accessory.removeService(this.Outlet.Service)
|
|
1049
1003
|
}
|
|
1050
1004
|
|
|
1051
1005
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1052
1006
|
// If garageDoorService still present, then remove first
|
|
1053
|
-
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
|
|
1007
|
+
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
|
|
1054
1008
|
this.GarageDoor = {
|
|
1055
1009
|
Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
|
|
1056
1010
|
Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
|
|
1057
|
-
}
|
|
1058
|
-
accessory.context.GarageDoor = this.GarageDoor as object
|
|
1059
|
-
await this.debugWarnLog('Removing any leftover Garage Door Service')
|
|
1060
|
-
accessory.removeService(this.GarageDoor.Service)
|
|
1011
|
+
}
|
|
1012
|
+
accessory.context.GarageDoor = this.GarageDoor as object
|
|
1013
|
+
await this.debugWarnLog('Removing any leftover Garage Door Service')
|
|
1014
|
+
accessory.removeService(this.GarageDoor.Service)
|
|
1061
1015
|
}
|
|
1062
1016
|
|
|
1063
1017
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1064
1018
|
// If doorService still present, then remove first
|
|
1065
|
-
accessory.context.Door = accessory.context.Door ?? {}
|
|
1019
|
+
accessory.context.Door = accessory.context.Door ?? {}
|
|
1066
1020
|
this.Door = {
|
|
1067
1021
|
Name: accessory.context.Door.Name ?? accessory.displayName,
|
|
1068
1022
|
Service: accessory.getService(this.hap.Service.Door) as Service,
|
|
1069
|
-
}
|
|
1070
|
-
accessory.context.Door = this.Door as object
|
|
1071
|
-
await this.debugWarnLog('Removing any leftover Door Service')
|
|
1072
|
-
accessory.removeService(this.Door.Service)
|
|
1023
|
+
}
|
|
1024
|
+
accessory.context.Door = this.Door as object
|
|
1025
|
+
await this.debugWarnLog('Removing any leftover Door Service')
|
|
1026
|
+
accessory.removeService(this.Door.Service)
|
|
1073
1027
|
}
|
|
1074
1028
|
|
|
1075
1029
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
1076
1030
|
// If lockService still present, then remove first
|
|
1077
|
-
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
|
|
1031
|
+
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
|
|
1078
1032
|
this.LockMechanism = {
|
|
1079
1033
|
Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
|
|
1080
1034
|
Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
|
|
1081
|
-
}
|
|
1082
|
-
accessory.context.LockMechanism = this.LockMechanism as object
|
|
1083
|
-
await this.debugWarnLog('Removing any leftover Lock Service')
|
|
1084
|
-
accessory.removeService(this.LockMechanism.Service)
|
|
1035
|
+
}
|
|
1036
|
+
accessory.context.LockMechanism = this.LockMechanism as object
|
|
1037
|
+
await this.debugWarnLog('Removing any leftover Lock Service')
|
|
1038
|
+
accessory.removeService(this.LockMechanism.Service)
|
|
1085
1039
|
}
|
|
1086
1040
|
|
|
1087
1041
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
1088
1042
|
// If faucetService still present, then remove first
|
|
1089
|
-
accessory.context.Faucet = accessory.context.Faucet ?? {}
|
|
1043
|
+
accessory.context.Faucet = accessory.context.Faucet ?? {}
|
|
1090
1044
|
this.Faucet = {
|
|
1091
1045
|
Name: accessory.context.Faucet.Name ?? accessory.displayName,
|
|
1092
1046
|
Service: accessory.getService(this.hap.Service.Valve) as Service,
|
|
1093
|
-
}
|
|
1094
|
-
accessory.context.Faucet = this.Faucet as object
|
|
1095
|
-
await this.debugWarnLog('Removing any leftover Faucet Service')
|
|
1096
|
-
accessory.removeService(this.Faucet.Service)
|
|
1047
|
+
}
|
|
1048
|
+
accessory.context.Faucet = this.Faucet as object
|
|
1049
|
+
await this.debugWarnLog('Removing any leftover Faucet Service')
|
|
1050
|
+
accessory.removeService(this.Faucet.Service)
|
|
1097
1051
|
}
|
|
1098
1052
|
|
|
1099
1053
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
1100
1054
|
// If fanService still present, then remove first
|
|
1101
|
-
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
1055
|
+
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
1102
1056
|
this.Fan = {
|
|
1103
1057
|
Name: accessory.context.Fan.Name ?? accessory.displayName,
|
|
1104
1058
|
Service: accessory.getService(this.hap.Service.Fan) as Service,
|
|
1105
|
-
}
|
|
1106
|
-
accessory.context.Fan = this.Fan as object
|
|
1107
|
-
await this.debugWarnLog('Removing any leftover Fan Service')
|
|
1108
|
-
accessory.removeService(this.Fan.Service)
|
|
1059
|
+
}
|
|
1060
|
+
accessory.context.Fan = this.Fan as object
|
|
1061
|
+
await this.debugWarnLog('Removing any leftover Fan Service')
|
|
1062
|
+
accessory.removeService(this.Fan.Service)
|
|
1109
1063
|
}
|
|
1110
1064
|
|
|
1111
1065
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
1112
1066
|
// If windowService still present, then remove first
|
|
1113
|
-
accessory.context.Window = accessory.context.Window ?? {}
|
|
1067
|
+
accessory.context.Window = accessory.context.Window ?? {}
|
|
1114
1068
|
this.Window = {
|
|
1115
1069
|
Name: accessory.context.Window.Name ?? accessory.displayName,
|
|
1116
1070
|
Service: accessory.getService(this.hap.Service.Window) as Service,
|
|
1117
|
-
}
|
|
1118
|
-
accessory.context.Window = this.Window as object
|
|
1119
|
-
await this.debugWarnLog('Removing any leftover Window Service')
|
|
1120
|
-
accessory.removeService(this.Window.Service)
|
|
1071
|
+
}
|
|
1072
|
+
accessory.context.Window = this.Window as object
|
|
1073
|
+
await this.debugWarnLog('Removing any leftover Window Service')
|
|
1074
|
+
accessory.removeService(this.Window.Service)
|
|
1121
1075
|
}
|
|
1122
1076
|
|
|
1123
1077
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
1124
1078
|
// If windowCoveringService still present, then remove first
|
|
1125
|
-
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
1079
|
+
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
1126
1080
|
this.WindowCovering = {
|
|
1127
1081
|
Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
|
|
1128
1082
|
Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
|
|
1129
|
-
}
|
|
1130
|
-
accessory.context.WindowCovering = this.WindowCovering as object
|
|
1131
|
-
await this.debugWarnLog('Removing any leftover Window Covering Service')
|
|
1132
|
-
accessory.removeService(this.WindowCovering.Service)
|
|
1083
|
+
}
|
|
1084
|
+
accessory.context.WindowCovering = this.WindowCovering as object
|
|
1085
|
+
await this.debugWarnLog('Removing any leftover Window Covering Service')
|
|
1086
|
+
accessory.removeService(this.WindowCovering.Service)
|
|
1133
1087
|
}
|
|
1134
1088
|
|
|
1135
1089
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1136
1090
|
// If statefulProgrammableSwitchService still present, then remove first
|
|
1137
|
-
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
|
|
1091
|
+
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
|
|
1138
1092
|
this.StatefulProgrammableSwitch = {
|
|
1139
1093
|
Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
|
|
1140
1094
|
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
1141
|
-
}
|
|
1142
|
-
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object
|
|
1143
|
-
await this.debugWarnLog('Removing any leftover Stateful Programmable Switch Service')
|
|
1144
|
-
accessory.removeService(this.StatefulProgrammableSwitch.Service)
|
|
1095
|
+
}
|
|
1096
|
+
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object
|
|
1097
|
+
await this.debugWarnLog('Removing any leftover Stateful Programmable Switch Service')
|
|
1098
|
+
accessory.removeService(this.StatefulProgrammableSwitch.Service)
|
|
1145
1099
|
}
|
|
1146
1100
|
|
|
1147
1101
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1148
1102
|
// If switchService still present, then remove first
|
|
1149
|
-
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
1103
|
+
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
1150
1104
|
this.Switch = {
|
|
1151
1105
|
Name: accessory.context.Switch.Name ?? accessory.displayName,
|
|
1152
1106
|
Service: accessory.getService(this.hap.Service.Switch) as Service,
|
|
1153
|
-
}
|
|
1154
|
-
accessory.context.Switch = this.Switch as object
|
|
1155
|
-
await this.debugWarnLog('Removing any leftover Switch Service')
|
|
1156
|
-
accessory.removeService(this.Switch.Service)
|
|
1107
|
+
}
|
|
1108
|
+
accessory.context.Switch = this.Switch as object
|
|
1109
|
+
await this.debugWarnLog('Removing any leftover Switch Service')
|
|
1110
|
+
accessory.removeService(this.Switch.Service)
|
|
1157
1111
|
}
|
|
1158
1112
|
|
|
1159
1113
|
async getBotConfigSettings(device: device & devicesConfig) {
|
|
1160
|
-
//Bot Device Type
|
|
1161
|
-
this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1114
|
+
// Bot Device Type
|
|
1115
|
+
this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType
|
|
1116
|
+
? this.accessory.context.botDeviceType
|
|
1117
|
+
: device.bot?.deviceType ?? 'outlet'
|
|
1118
|
+
const botDeviceType = this.accessory.context.botDeviceType
|
|
1119
|
+
? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
|
|
1120
|
+
: device.bot?.deviceType
|
|
1121
|
+
? `Using Device Type: ${this.botDeviceType}`
|
|
1122
|
+
: `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`
|
|
1123
|
+
await this.debugWarnLog(botDeviceType)
|
|
1124
|
+
this.accessory.context.botDeviceType = this.botDeviceType
|
|
1168
1125
|
// Bot Mode
|
|
1169
|
-
this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch'
|
|
1170
|
-
const botMode = this.accessory.context.botMode
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1126
|
+
this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch'
|
|
1127
|
+
const botMode = this.accessory.context.botMode
|
|
1128
|
+
? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
|
|
1129
|
+
: device.bot?.mode ? `Using Bot Mode: ${this.botMode}` : `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`
|
|
1130
|
+
await this.debugWarnLog(botMode)
|
|
1131
|
+
this.accessory.context.botMode = this.botMode
|
|
1174
1132
|
// Bot Double Press
|
|
1175
|
-
this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1
|
|
1176
|
-
const doublePress = this.accessory.context.doublePress
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1133
|
+
this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1
|
|
1134
|
+
const doublePress = this.accessory.context.doublePress
|
|
1135
|
+
? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
|
|
1136
|
+
: device.bot?.doublePress
|
|
1137
|
+
? `Using Double Press: ${this.doublePress}`
|
|
1138
|
+
: `No Double Press Set, Using default Double Press: ${this.doublePress}`
|
|
1139
|
+
await this.debugWarnLog(doublePress)
|
|
1140
|
+
this.accessory.context.doublePress = this.doublePress
|
|
1181
1141
|
// Bot Press PushRate
|
|
1182
|
-
this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15
|
|
1183
|
-
const pushRatePress = this.accessory.context.pushRatePress
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1142
|
+
this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15
|
|
1143
|
+
const pushRatePress = this.accessory.context.pushRatePress
|
|
1144
|
+
? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
|
|
1145
|
+
: device.bot?.pushRatePress
|
|
1146
|
+
? `Using Bot Push Rate Press: ${this.pushRatePress}`
|
|
1147
|
+
: `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`
|
|
1148
|
+
await this.debugWarnLog(pushRatePress)
|
|
1149
|
+
this.accessory.context.pushRatePress = this.pushRatePress
|
|
1188
1150
|
// Bot Allow Push
|
|
1189
|
-
this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false
|
|
1190
|
-
const allowPush = this.accessory.context.allowPush
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1151
|
+
this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false
|
|
1152
|
+
const allowPush = this.accessory.context.allowPush
|
|
1153
|
+
? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
|
|
1154
|
+
: device.bot?.allowPush
|
|
1155
|
+
? `Using Allow Push: ${this.allowPush}`
|
|
1156
|
+
: `No Allow Push Set, Using default Allow Push: ${this.allowPush}`
|
|
1157
|
+
await this.debugWarnLog(allowPush)
|
|
1158
|
+
this.accessory.context.allowPush = this.allowPush
|
|
1195
1159
|
// Bot Multi Press Count
|
|
1196
|
-
this.multiPressCount = 0
|
|
1197
|
-
await this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`)
|
|
1160
|
+
this.multiPressCount = 0
|
|
1161
|
+
await this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`)
|
|
1198
1162
|
}
|
|
1199
1163
|
|
|
1200
1164
|
async BLEPushConnection() {
|
|
1201
1165
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1202
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
1203
|
-
await this.openAPIpushChanges()
|
|
1166
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
1167
|
+
await this.openAPIpushChanges()
|
|
1204
1168
|
}
|
|
1205
1169
|
}
|
|
1206
1170
|
|
|
1207
1171
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
1208
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
1172
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
1209
1173
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1210
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
1211
|
-
await this.openAPIRefreshStatus()
|
|
1174
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
1175
|
+
await this.openAPIRefreshStatus()
|
|
1212
1176
|
}
|
|
1213
1177
|
}
|
|
1214
1178
|
|
|
@@ -1216,111 +1180,110 @@ export class Bot extends deviceBase {
|
|
|
1216
1180
|
if (this.device.offline) {
|
|
1217
1181
|
if (this.botDeviceType === 'garagedoor') {
|
|
1218
1182
|
if (this.GarageDoor) {
|
|
1219
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
|
|
1220
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
|
|
1221
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
1183
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
|
|
1184
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
|
|
1185
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
1222
1186
|
}
|
|
1223
1187
|
} else if (this.botDeviceType === 'door') {
|
|
1224
1188
|
if (this.Door) {
|
|
1225
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1226
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1227
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1189
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1190
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1191
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1228
1192
|
}
|
|
1229
1193
|
} else if (this.botDeviceType === 'window') {
|
|
1230
1194
|
if (this.Window) {
|
|
1231
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1232
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1233
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1195
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1196
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1197
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1234
1198
|
}
|
|
1235
1199
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
1236
1200
|
if (this.WindowCovering) {
|
|
1237
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1238
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1239
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1201
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
|
|
1202
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
|
|
1203
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
1240
1204
|
}
|
|
1241
1205
|
} else if (this.botDeviceType === 'lock') {
|
|
1242
1206
|
if (this.LockMechanism) {
|
|
1243
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED)
|
|
1244
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED)
|
|
1207
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED)
|
|
1208
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED)
|
|
1245
1209
|
}
|
|
1246
1210
|
} else if (this.botDeviceType === 'faucet') {
|
|
1247
1211
|
if (this.Faucet) {
|
|
1248
|
-
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
1212
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
1249
1213
|
}
|
|
1250
1214
|
} else if (this.botDeviceType === 'fan') {
|
|
1251
1215
|
if (this.Fan) {
|
|
1252
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1216
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1253
1217
|
}
|
|
1254
1218
|
} else if (this.botDeviceType === 'stateful') {
|
|
1255
1219
|
if (this.StatefulProgrammableSwitch) {
|
|
1256
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1257
|
-
|
|
1258
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1220
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
|
|
1221
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0)
|
|
1259
1222
|
}
|
|
1260
1223
|
} else if (this.botDeviceType === 'switch') {
|
|
1261
1224
|
if (this.Switch) {
|
|
1262
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1225
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1263
1226
|
}
|
|
1264
1227
|
} else {
|
|
1265
1228
|
if (this.Outlet) {
|
|
1266
|
-
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1229
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
1267
1230
|
}
|
|
1268
1231
|
}
|
|
1269
1232
|
}
|
|
1270
1233
|
}
|
|
1271
1234
|
|
|
1272
1235
|
async apiError(e: any): Promise<void> {
|
|
1273
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
1274
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
1236
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
1237
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
1275
1238
|
if (this.botDeviceType === 'garagedoor') {
|
|
1276
1239
|
if (this.GarageDoor) {
|
|
1277
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e)
|
|
1278
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e)
|
|
1279
|
-
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e)
|
|
1240
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e)
|
|
1241
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e)
|
|
1242
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e)
|
|
1280
1243
|
}
|
|
1281
1244
|
} else if (this.botDeviceType === 'door') {
|
|
1282
1245
|
if (this.Door) {
|
|
1283
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1284
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1285
|
-
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1246
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1247
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1248
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1286
1249
|
}
|
|
1287
1250
|
} else if (this.botDeviceType === 'window') {
|
|
1288
1251
|
if (this.Window) {
|
|
1289
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1290
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1291
|
-
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1252
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1253
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1254
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1292
1255
|
}
|
|
1293
1256
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
1294
1257
|
if (this.WindowCovering) {
|
|
1295
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1296
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1297
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1258
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
1259
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
1260
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
1298
1261
|
}
|
|
1299
1262
|
} else if (this.botDeviceType === 'lock') {
|
|
1300
1263
|
if (this.LockMechanism) {
|
|
1301
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e)
|
|
1302
|
-
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e)
|
|
1264
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e)
|
|
1265
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e)
|
|
1303
1266
|
}
|
|
1304
1267
|
} else if (this.botDeviceType === 'faucet') {
|
|
1305
1268
|
if (this.Faucet) {
|
|
1306
|
-
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
1269
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
1307
1270
|
}
|
|
1308
1271
|
} else if (this.botDeviceType === 'fan') {
|
|
1309
1272
|
if (this.Fan) {
|
|
1310
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1273
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1311
1274
|
}
|
|
1312
1275
|
} else if (this.botDeviceType === 'stateful') {
|
|
1313
1276
|
if (this.StatefulProgrammableSwitch) {
|
|
1314
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
1315
|
-
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
1277
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
1278
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
1316
1279
|
}
|
|
1317
1280
|
} else if (this.botDeviceType === 'switch') {
|
|
1318
1281
|
if (this.Switch) {
|
|
1319
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1282
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1320
1283
|
}
|
|
1321
1284
|
} else {
|
|
1322
1285
|
if (this.Outlet) {
|
|
1323
|
-
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1286
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
1324
1287
|
}
|
|
1325
1288
|
}
|
|
1326
1289
|
}
|