@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/curtain.ts
CHANGED
|
@@ -2,84 +2,86 @@
|
|
|
2
2
|
*
|
|
3
3
|
* curtain.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { CharacteristicChange, CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { curtain3ServiceData, curtainServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { curtainStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { curtain3WebhookContext, curtainWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
14
|
+
import { hostname } from 'node:os'
|
|
15
|
+
|
|
7
16
|
/*
|
|
8
17
|
* For Testing Locally:
|
|
9
18
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
19
|
*/
|
|
11
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
12
|
-
|
|
13
|
-
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
20
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
21
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
14
22
|
|
|
15
|
-
import
|
|
16
|
-
import type { device } from '../types/devicelist.js';
|
|
17
|
-
import type { SwitchBotPlatform } from '../platform.js';
|
|
18
|
-
import type { curtainStatus } from '../types/devicestatus.js';
|
|
19
|
-
import type { curtainServiceData, curtain3ServiceData } from '../types/bledevicestatus.js';
|
|
20
|
-
import type { curtain3WebhookContext, curtainWebhookContext } from '../types/devicewebhookstatus.js';
|
|
21
|
-
import type { Service, PlatformAccessory, CharacteristicValue, CharacteristicChange } from 'homebridge';
|
|
23
|
+
import { deviceBase } from './device.js'
|
|
22
24
|
|
|
23
25
|
export class Curtain extends deviceBase {
|
|
24
26
|
// Services
|
|
25
27
|
private WindowCovering: {
|
|
26
|
-
Name: CharacteristicValue
|
|
27
|
-
Service: Service
|
|
28
|
-
PositionState: CharacteristicValue
|
|
29
|
-
TargetPosition: CharacteristicValue
|
|
30
|
-
CurrentPosition: CharacteristicValue
|
|
31
|
-
HoldPosition: CharacteristicValue
|
|
32
|
-
}
|
|
28
|
+
Name: CharacteristicValue
|
|
29
|
+
Service: Service
|
|
30
|
+
PositionState: CharacteristicValue
|
|
31
|
+
TargetPosition: CharacteristicValue
|
|
32
|
+
CurrentPosition: CharacteristicValue
|
|
33
|
+
HoldPosition: CharacteristicValue
|
|
34
|
+
}
|
|
33
35
|
|
|
34
36
|
private Battery: {
|
|
35
|
-
Name: CharacteristicValue
|
|
36
|
-
Service: Service
|
|
37
|
-
BatteryLevel: CharacteristicValue
|
|
38
|
-
StatusLowBattery: CharacteristicValue
|
|
39
|
-
ChargingState: CharacteristicValue
|
|
40
|
-
}
|
|
37
|
+
Name: CharacteristicValue
|
|
38
|
+
Service: Service
|
|
39
|
+
BatteryLevel: CharacteristicValue
|
|
40
|
+
StatusLowBattery: CharacteristicValue
|
|
41
|
+
ChargingState: CharacteristicValue
|
|
42
|
+
}
|
|
41
43
|
|
|
42
44
|
private LightSensor?: {
|
|
43
|
-
Name: CharacteristicValue
|
|
44
|
-
Service: Service
|
|
45
|
-
CurrentAmbientLightLevel?: CharacteristicValue
|
|
46
|
-
}
|
|
45
|
+
Name: CharacteristicValue
|
|
46
|
+
Service: Service
|
|
47
|
+
CurrentAmbientLightLevel?: CharacteristicValue
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
// OpenAPI
|
|
49
|
-
deviceStatus!: curtainStatus
|
|
51
|
+
deviceStatus!: curtainStatus
|
|
50
52
|
|
|
51
|
-
//Webhook
|
|
52
|
-
webhookContext!: curtainWebhookContext | curtain3WebhookContext
|
|
53
|
+
// Webhook
|
|
54
|
+
webhookContext!: curtainWebhookContext | curtain3WebhookContext
|
|
53
55
|
|
|
54
56
|
// BLE
|
|
55
|
-
serviceData!: curtainServiceData | curtain3ServiceData
|
|
57
|
+
serviceData!: curtainServiceData | curtain3ServiceData
|
|
56
58
|
|
|
57
59
|
// Target
|
|
58
|
-
setNewTarget!: boolean
|
|
59
|
-
setNewTargetTimer!: NodeJS.Timeout
|
|
60
|
+
setNewTarget!: boolean
|
|
61
|
+
setNewTargetTimer!: NodeJS.Timeout
|
|
60
62
|
|
|
61
63
|
// Updates
|
|
62
|
-
curtainMoving!: boolean
|
|
63
|
-
curtainUpdateInProgress!: boolean
|
|
64
|
-
doCurtainUpdate!: Subject<void
|
|
64
|
+
curtainMoving!: boolean
|
|
65
|
+
curtainUpdateInProgress!: boolean
|
|
66
|
+
doCurtainUpdate!: Subject<void>
|
|
65
67
|
|
|
66
68
|
constructor(
|
|
67
69
|
readonly platform: SwitchBotPlatform,
|
|
68
70
|
accessory: PlatformAccessory,
|
|
69
71
|
device: device & devicesConfig,
|
|
70
72
|
) {
|
|
71
|
-
super(platform, accessory, device)
|
|
73
|
+
super(platform, accessory, device)
|
|
72
74
|
// Set category
|
|
73
|
-
accessory.category = this.hap.Categories.WINDOW_COVERING
|
|
75
|
+
accessory.category = this.hap.Categories.WINDOW_COVERING
|
|
74
76
|
|
|
75
77
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
76
|
-
this.doCurtainUpdate = new Subject()
|
|
77
|
-
this.curtainMoving = false
|
|
78
|
-
this.curtainUpdateInProgress = false
|
|
79
|
-
this.setNewTarget = false
|
|
78
|
+
this.doCurtainUpdate = new Subject()
|
|
79
|
+
this.curtainMoving = false
|
|
80
|
+
this.curtainUpdateInProgress = false
|
|
81
|
+
this.setNewTarget = false
|
|
80
82
|
|
|
81
83
|
// Initialize WindowCovering Service
|
|
82
|
-
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
84
|
+
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
|
|
83
85
|
this.WindowCovering = {
|
|
84
86
|
Name: accessory.displayName,
|
|
85
87
|
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
|
|
@@ -87,186 +89,161 @@ export class Curtain extends deviceBase {
|
|
|
87
89
|
TargetPosition: accessory.context.TargetPosition ?? 100,
|
|
88
90
|
CurrentPosition: accessory.context.CurrentPosition ?? 100,
|
|
89
91
|
HoldPosition: accessory.context.HoldPosition ?? false,
|
|
90
|
-
}
|
|
91
|
-
accessory.context.WindowCovering = this.WindowCovering as object
|
|
92
|
+
}
|
|
93
|
+
accessory.context.WindowCovering = this.WindowCovering as object
|
|
92
94
|
|
|
93
95
|
// Initialize WindowCovering Service
|
|
94
|
-
this.WindowCovering.Service.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.getCharacteristic(this.hap.Characteristic.PositionState)
|
|
98
|
-
.onGet(() => {
|
|
99
|
-
return this.WindowCovering.PositionState;
|
|
100
|
-
});
|
|
96
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).setCharacteristic(this.hap.Characteristic.ObstructionDetected, false).getCharacteristic(this.hap.Characteristic.PositionState).onGet(() => {
|
|
97
|
+
return this.WindowCovering.PositionState
|
|
98
|
+
})
|
|
101
99
|
|
|
102
100
|
// Initialize WindowCovering CurrentPosition
|
|
103
|
-
this.WindowCovering.Service
|
|
104
|
-
.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.onGet(() => {
|
|
112
|
-
return this.WindowCovering.CurrentPosition;
|
|
113
|
-
});
|
|
101
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.CurrentPosition).setProps({
|
|
102
|
+
minStep: device.curtain?.set_minStep ?? 1,
|
|
103
|
+
minValue: 0,
|
|
104
|
+
maxValue: 100,
|
|
105
|
+
validValueRanges: [0, 100],
|
|
106
|
+
}).onGet(() => {
|
|
107
|
+
return this.WindowCovering.CurrentPosition
|
|
108
|
+
})
|
|
114
109
|
|
|
115
110
|
// Initialize WindowCovering TargetPosition
|
|
116
|
-
this.WindowCovering.Service
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.onGet(() => {
|
|
125
|
-
return this.WindowCovering.TargetPosition;
|
|
126
|
-
})
|
|
127
|
-
.onSet(this.TargetPositionSet.bind(this));
|
|
111
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
112
|
+
minStep: device.curtain?.set_minStep ?? 1,
|
|
113
|
+
minValue: 0,
|
|
114
|
+
maxValue: 100,
|
|
115
|
+
validValueRanges: [0, 100],
|
|
116
|
+
}).onGet(() => {
|
|
117
|
+
return this.WindowCovering.TargetPosition
|
|
118
|
+
}).onSet(this.TargetPositionSet.bind(this))
|
|
128
119
|
|
|
129
120
|
// Initialize WindowCovering TargetPosition
|
|
130
|
-
this.WindowCovering.Service
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return this.WindowCovering.HoldPosition;
|
|
134
|
-
})
|
|
135
|
-
.onSet(this.HoldPositionSet.bind(this));
|
|
121
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.HoldPosition).onGet(() => {
|
|
122
|
+
return this.WindowCovering.HoldPosition
|
|
123
|
+
}).onSet(this.HoldPositionSet.bind(this))
|
|
136
124
|
|
|
137
125
|
// Initialize Battery Service
|
|
138
|
-
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
126
|
+
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
139
127
|
this.Battery = {
|
|
140
128
|
Name: `${accessory.displayName} Battery`,
|
|
141
129
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
142
130
|
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
143
131
|
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
144
132
|
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
|
|
145
|
-
}
|
|
146
|
-
accessory.context.Battery = this.Battery as object
|
|
133
|
+
}
|
|
134
|
+
accessory.context.Battery = this.Battery as object
|
|
147
135
|
|
|
148
136
|
// Initialize Battery Service
|
|
149
|
-
this.Battery.Service
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
.
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
this.Battery.Service
|
|
163
|
-
.getCharacteristic(this.hap.Characteristic.ChargingState)
|
|
164
|
-
.onGet(() => {
|
|
165
|
-
return this.Battery.ChargingState;
|
|
166
|
-
});
|
|
137
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).getCharacteristic(this.hap.Characteristic.BatteryLevel).onGet(() => {
|
|
138
|
+
return this.Battery.BatteryLevel
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
this.Battery.Service.getCharacteristic(this.hap.Characteristic.StatusLowBattery).onGet(() => {
|
|
142
|
+
return this.Battery.StatusLowBattery
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
this.Battery.Service.getCharacteristic(this.hap.Characteristic.ChargingState).onGet(() => {
|
|
146
|
+
return this.Battery.ChargingState
|
|
147
|
+
})
|
|
167
148
|
|
|
168
149
|
// Initialize LightSensor Service
|
|
169
150
|
if (device.curtain?.hide_lightsensor) {
|
|
170
151
|
if (this.LightSensor?.Service) {
|
|
171
|
-
this.debugLog('Removing Light Sensor Service')
|
|
172
|
-
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
|
|
173
|
-
accessory.removeService(this.LightSensor.Service)
|
|
174
|
-
accessory.context.LightSensor = {}
|
|
152
|
+
this.debugLog('Removing Light Sensor Service')
|
|
153
|
+
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
|
|
154
|
+
accessory.removeService(this.LightSensor.Service)
|
|
155
|
+
accessory.context.LightSensor = {}
|
|
175
156
|
}
|
|
176
157
|
} else {
|
|
177
|
-
accessory.context.LightSensor = accessory.context.LightSensor ?? {}
|
|
158
|
+
accessory.context.LightSensor = accessory.context.LightSensor ?? {}
|
|
178
159
|
this.LightSensor = {
|
|
179
160
|
Name: `${accessory.displayName} Light Sensor`,
|
|
180
161
|
Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor) as Service,
|
|
181
162
|
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
|
|
182
|
-
}
|
|
183
|
-
accessory.context.LightSensor = this.LightSensor as object
|
|
163
|
+
}
|
|
164
|
+
accessory.context.LightSensor = this.LightSensor as object
|
|
184
165
|
|
|
185
166
|
// Initialize LightSensor Characteristic
|
|
186
|
-
this.LightSensor.Service
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
.getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
|
|
190
|
-
.onGet(() => {
|
|
191
|
-
return this.LightSensor!.CurrentAmbientLightLevel!;
|
|
192
|
-
});
|
|
167
|
+
this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true).getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel).onGet(() => {
|
|
168
|
+
return this.LightSensor!.CurrentAmbientLightLevel!
|
|
169
|
+
})
|
|
193
170
|
}
|
|
194
171
|
|
|
195
172
|
// Retrieve initial values and updateHomekit
|
|
196
173
|
try {
|
|
197
|
-
this.debugLog('Retrieve initial values and update Homekit')
|
|
198
|
-
this.refreshStatus()
|
|
174
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
175
|
+
this.refreshStatus()
|
|
199
176
|
} catch (e: any) {
|
|
200
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
177
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
201
178
|
}
|
|
202
179
|
|
|
203
|
-
//regisiter webhook event handler if enabled
|
|
180
|
+
// regisiter webhook event handler if enabled
|
|
204
181
|
try {
|
|
205
|
-
this.debugLog('Registering Webhook Event Handler')
|
|
206
|
-
this.registerWebhook()
|
|
182
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
183
|
+
this.registerWebhook()
|
|
207
184
|
} catch (e: any) {
|
|
208
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
185
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
209
186
|
}
|
|
210
187
|
|
|
211
|
-
//regisiter platform BLE event handler if enabled
|
|
188
|
+
// regisiter platform BLE event handler if enabled
|
|
212
189
|
try {
|
|
213
|
-
this.debugLog('Registering Platform BLE Event Handler')
|
|
214
|
-
this.registerPlatformBLE()
|
|
190
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
191
|
+
this.registerPlatformBLE()
|
|
215
192
|
} catch (e: any) {
|
|
216
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
193
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
217
194
|
}
|
|
218
195
|
|
|
219
196
|
// History
|
|
220
|
-
this.history()
|
|
197
|
+
this.history()
|
|
221
198
|
|
|
222
199
|
// Start an update interval
|
|
223
200
|
interval(this.deviceRefreshRate * 1000)
|
|
224
201
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
225
202
|
.subscribe(async () => {
|
|
226
|
-
await this.refreshStatus()
|
|
227
|
-
})
|
|
203
|
+
await this.refreshStatus()
|
|
204
|
+
})
|
|
228
205
|
|
|
229
206
|
// update slide progress
|
|
230
207
|
interval(this.deviceUpdateRate * 1000)
|
|
231
208
|
.pipe(skipWhile(() => !this.curtainMoving))
|
|
232
209
|
.subscribe(async () => {
|
|
233
210
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
234
|
-
return
|
|
211
|
+
return
|
|
235
212
|
}
|
|
236
|
-
await this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`)
|
|
237
|
-
await this.refreshStatus()
|
|
238
|
-
})
|
|
213
|
+
await this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`)
|
|
214
|
+
await this.refreshStatus()
|
|
215
|
+
})
|
|
239
216
|
|
|
240
217
|
// Watch for Curtain change events
|
|
241
218
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
242
219
|
this.doCurtainUpdate
|
|
243
220
|
.pipe(
|
|
244
221
|
tap(() => {
|
|
245
|
-
this.curtainUpdateInProgress = true
|
|
222
|
+
this.curtainUpdateInProgress = true
|
|
246
223
|
}),
|
|
247
224
|
debounceTime(this.devicePushRate * 1000),
|
|
248
225
|
)
|
|
249
226
|
.subscribe(async () => {
|
|
250
227
|
try {
|
|
251
|
-
await this.pushChanges()
|
|
228
|
+
await this.pushChanges()
|
|
252
229
|
} catch (e: any) {
|
|
253
|
-
await this.apiError(e)
|
|
254
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
230
|
+
await this.apiError(e)
|
|
231
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
255
232
|
}
|
|
256
|
-
this.curtainUpdateInProgress = false
|
|
257
|
-
})
|
|
233
|
+
this.curtainUpdateInProgress = false
|
|
234
|
+
})
|
|
258
235
|
|
|
259
236
|
// Setup EVE history features
|
|
260
|
-
this.setupHistoryService()
|
|
237
|
+
this.setupHistoryService()
|
|
261
238
|
}
|
|
262
239
|
|
|
263
240
|
async history() {
|
|
264
241
|
if (this.device.history === true) {
|
|
265
242
|
// initialize when this accessory is newly created.
|
|
266
|
-
this.accessory.context.lastActivation = this.accessory.context.lastActivation ?? 0
|
|
243
|
+
this.accessory.context.lastActivation = this.accessory.context.lastActivation ?? 0
|
|
267
244
|
} else {
|
|
268
245
|
// removes cached values if history is turned off
|
|
269
|
-
delete this.accessory.context.lastActivation
|
|
246
|
+
delete this.accessory.context.lastActivation
|
|
270
247
|
}
|
|
271
248
|
}
|
|
272
249
|
|
|
@@ -275,173 +252,172 @@ export class Curtain extends deviceBase {
|
|
|
275
252
|
*/
|
|
276
253
|
async setupHistoryService(): Promise<void> {
|
|
277
254
|
if (this.device.history !== true) {
|
|
278
|
-
return
|
|
255
|
+
return
|
|
279
256
|
}
|
|
280
257
|
|
|
281
258
|
const mac = this.device
|
|
282
259
|
.deviceId!.match(/.{1,2}/g)!
|
|
283
260
|
.join(':')
|
|
284
|
-
.toLowerCase()
|
|
261
|
+
.toLowerCase()
|
|
285
262
|
this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
|
|
286
263
|
log: this.platform.log,
|
|
287
264
|
storage: 'fs',
|
|
288
265
|
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
289
|
-
})
|
|
290
|
-
const motion: Service
|
|
291
|
-
this.accessory.getService(this.hap.Service.MotionSensor)
|
|
292
|
-
this.accessory.addService(this.hap.Service.MotionSensor, 'Motion')
|
|
293
|
-
motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation)
|
|
266
|
+
})
|
|
267
|
+
const motion: Service
|
|
268
|
+
= this.accessory.getService(this.hap.Service.MotionSensor)
|
|
269
|
+
|| this.accessory.addService(this.hap.Service.MotionSensor, 'Motion')
|
|
270
|
+
motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation)
|
|
294
271
|
motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
|
|
295
272
|
const lastActivation = this.accessory.context.lastActivation
|
|
296
273
|
? Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime())
|
|
297
|
-
: 0
|
|
298
|
-
return lastActivation
|
|
299
|
-
})
|
|
300
|
-
await this.setMinMax()
|
|
274
|
+
: 0
|
|
275
|
+
return lastActivation
|
|
276
|
+
})
|
|
277
|
+
await this.setMinMax()
|
|
301
278
|
motion.getCharacteristic(this.hap.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
|
|
302
279
|
if (event.newValue !== event.oldValue) {
|
|
303
|
-
const sensor = this.accessory.getService(this.hap.Service.MotionSensor)
|
|
280
|
+
const sensor = this.accessory.getService(this.hap.Service.MotionSensor)
|
|
304
281
|
const entry = {
|
|
305
282
|
time: Math.round(new Date().valueOf() / 1000),
|
|
306
283
|
motion: event.newValue,
|
|
307
|
-
}
|
|
308
|
-
this.accessory.context.lastActivation = entry.time
|
|
284
|
+
}
|
|
285
|
+
this.accessory.context.lastActivation = entry.time
|
|
309
286
|
sensor?.updateCharacteristic(
|
|
310
287
|
this.platform.eve.Characteristics.LastActivation,
|
|
311
|
-
Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime())
|
|
312
|
-
|
|
288
|
+
Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime()),
|
|
289
|
+
)
|
|
290
|
+
this.historyService.addEntry(entry)
|
|
313
291
|
}
|
|
314
|
-
})
|
|
315
|
-
this.updateHistory()
|
|
292
|
+
})
|
|
293
|
+
this.updateHistory()
|
|
316
294
|
}
|
|
317
295
|
|
|
318
296
|
async updateHistory(): Promise<void> {
|
|
319
|
-
const motion = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
|
|
297
|
+
const motion = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
|
|
320
298
|
this.historyService.addEntry({
|
|
321
299
|
time: Math.round(new Date().valueOf() / 1000),
|
|
322
|
-
motion
|
|
323
|
-
})
|
|
300
|
+
motion,
|
|
301
|
+
})
|
|
324
302
|
setTimeout(async () => {
|
|
325
|
-
await this.updateHistory()
|
|
326
|
-
}, 10 * 60 * 1000)
|
|
303
|
+
await this.updateHistory()
|
|
304
|
+
}, 10 * 60 * 1000)
|
|
327
305
|
}
|
|
328
306
|
|
|
329
307
|
async BLEparseStatus(): Promise<void> {
|
|
330
|
-
await this.debugLog('BLEparseStatus')
|
|
331
|
-
await this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery})
|
|
332
|
-
+ ` current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
|
|
308
|
+
await this.debugLog('BLEparseStatus')
|
|
309
|
+
await this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
333
310
|
// CurrentPosition
|
|
334
|
-
this.WindowCovering.CurrentPosition = 100 -this.serviceData.position
|
|
335
|
-
await this.getCurrentPostion()
|
|
311
|
+
this.WindowCovering.CurrentPosition = 100 - this.serviceData.position
|
|
312
|
+
await this.getCurrentPostion()
|
|
336
313
|
// CurrentAmbientLightLevel
|
|
337
314
|
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
338
|
-
const set_minLux = this.device.curtain?.set_minLux ?? 1
|
|
339
|
-
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001
|
|
340
|
-
const lightLevel = this.serviceData.lightLevel
|
|
341
|
-
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
342
|
-
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}
|
|
343
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
315
|
+
const set_minLux = this.device.curtain?.set_minLux ?? 1
|
|
316
|
+
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001
|
|
317
|
+
const lightLevel = this.serviceData.lightLevel
|
|
318
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
319
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
344
320
|
}
|
|
345
321
|
// BatteryLevel
|
|
346
|
-
this.Battery.BatteryLevel = this.serviceData.battery
|
|
347
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
322
|
+
this.Battery.BatteryLevel = this.serviceData.battery
|
|
323
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
348
324
|
// StatusLowBattery
|
|
349
325
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
350
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
351
|
-
|
|
326
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
327
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
328
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
352
329
|
}
|
|
353
330
|
|
|
354
331
|
async openAPIparseStatus(): Promise<void> {
|
|
355
|
-
await this.debugLog('openAPIparseStatus')
|
|
356
|
-
await this.debugLog(`(slidePosition, battery) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery})
|
|
357
|
-
+ ` current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
|
|
332
|
+
await this.debugLog('openAPIparseStatus')
|
|
333
|
+
await this.debugLog(`(slidePosition, battery) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
358
334
|
// CurrentPosition
|
|
359
|
-
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition
|
|
360
|
-
await this.setMinMax()
|
|
361
|
-
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
335
|
+
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition
|
|
336
|
+
await this.setMinMax()
|
|
337
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
362
338
|
if (this.setNewTarget) {
|
|
363
|
-
await this.infoLog('Checking Status ...')
|
|
339
|
+
await this.infoLog('Checking Status ...')
|
|
364
340
|
}
|
|
365
341
|
if (this.setNewTarget && this.deviceStatus.moving) {
|
|
366
|
-
this.curtainMoving = true
|
|
367
|
-
await this.setMinMax()
|
|
342
|
+
this.curtainMoving = true
|
|
343
|
+
await this.setMinMax()
|
|
368
344
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
369
|
-
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
370
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
371
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
372
|
-
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
345
|
+
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
346
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
347
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
348
|
+
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
373
349
|
} else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
374
|
-
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
375
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
376
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
377
|
-
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
350
|
+
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
351
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
352
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
353
|
+
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
378
354
|
} else {
|
|
379
|
-
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
380
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
381
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
382
|
-
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
355
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
356
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
357
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
358
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
383
359
|
}
|
|
384
360
|
} else {
|
|
385
|
-
this.curtainMoving = false
|
|
386
|
-
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
387
|
-
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
388
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
389
|
-
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
361
|
+
this.curtainMoving = false
|
|
362
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
363
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
364
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
365
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
390
366
|
}
|
|
391
|
-
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
392
|
-
+ ` PositionState: ${this.WindowCovering.PositionState},`);
|
|
367
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`)
|
|
393
368
|
|
|
394
369
|
// Brightness
|
|
395
370
|
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
396
|
-
const set_minLux = this.device.curtain?.set_minLux ?? 1
|
|
397
|
-
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001
|
|
398
|
-
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
399
|
-
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
400
|
-
await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
371
|
+
const set_minLux = this.device.curtain?.set_minLux ?? 1
|
|
372
|
+
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001
|
|
373
|
+
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
374
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
375
|
+
await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
401
376
|
}
|
|
402
377
|
|
|
403
378
|
// BatteryLevel
|
|
404
|
-
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
405
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
379
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
380
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
406
381
|
|
|
407
382
|
// StatusLowBattery
|
|
408
383
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
409
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
410
|
-
|
|
384
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
385
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
386
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
411
387
|
|
|
412
388
|
// Firmware Version
|
|
413
389
|
if (this.deviceStatus.version) {
|
|
414
|
-
const version = this.deviceStatus.version.toString()
|
|
415
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
416
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
390
|
+
const version = this.deviceStatus.version.toString()
|
|
391
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
392
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
417
393
|
this.accessory
|
|
418
394
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
419
395
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
420
396
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
421
397
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
422
|
-
.updateValue(deviceVersion)
|
|
423
|
-
this.accessory.context.version = deviceVersion
|
|
424
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
398
|
+
.updateValue(deviceVersion)
|
|
399
|
+
this.accessory.context.version = deviceVersion
|
|
400
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
425
401
|
}
|
|
426
402
|
}
|
|
427
403
|
|
|
428
404
|
async parseStatusWebhook(): Promise<void> {
|
|
429
|
-
await this.debugLog('parseStatusWebhook')
|
|
430
|
-
await this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery})
|
|
431
|
-
+ ` current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
|
|
405
|
+
await this.debugLog('parseStatusWebhook')
|
|
406
|
+
await this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
432
407
|
|
|
433
408
|
// CurrentPosition
|
|
434
|
-
this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition
|
|
435
|
-
await this.getCurrentPostion()
|
|
409
|
+
this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition
|
|
410
|
+
await this.getCurrentPostion()
|
|
436
411
|
|
|
437
412
|
// BatteryLevel
|
|
438
|
-
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
439
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
413
|
+
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
414
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
440
415
|
|
|
441
416
|
// StatusLowBattery
|
|
442
417
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
443
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
444
|
-
|
|
418
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
419
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
420
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
445
421
|
}
|
|
446
422
|
|
|
447
423
|
/**
|
|
@@ -449,98 +425,98 @@ export class Curtain extends deviceBase {
|
|
|
449
425
|
*/
|
|
450
426
|
async refreshStatus(): Promise<void> {
|
|
451
427
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
452
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
428
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
453
429
|
} else if (this.BLE) {
|
|
454
|
-
await this.BLERefreshStatus()
|
|
430
|
+
await this.BLERefreshStatus()
|
|
455
431
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
456
|
-
await this.openAPIRefreshStatus()
|
|
432
|
+
await this.openAPIRefreshStatus()
|
|
457
433
|
} else {
|
|
458
|
-
await this.offlineOff()
|
|
459
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
434
|
+
await this.offlineOff()
|
|
435
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
460
436
|
}
|
|
461
437
|
}
|
|
462
438
|
|
|
463
439
|
async BLERefreshStatus(): Promise<void> {
|
|
464
|
-
await this.debugLog('BLERefreshStatus')
|
|
465
|
-
const switchbot = await this.switchbotBLE()
|
|
440
|
+
await this.debugLog('BLERefreshStatus')
|
|
441
|
+
const switchbot = await this.switchbotBLE()
|
|
466
442
|
if (switchbot === undefined) {
|
|
467
|
-
await this.BLERefreshConnection(switchbot)
|
|
443
|
+
await this.BLERefreshConnection(switchbot)
|
|
468
444
|
} else {
|
|
469
445
|
// Start to monitor advertisement packets
|
|
470
446
|
(async () => {
|
|
471
447
|
// Start to monitor advertisement packets
|
|
472
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData
|
|
448
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData
|
|
473
449
|
// Update HomeKit
|
|
474
450
|
if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
|
|
475
451
|
&& (serviceData.modelName === SwitchBotBLEModelName.Curtain || SwitchBotBLEModelName.Curtain3)) {
|
|
476
|
-
this.serviceData = serviceData
|
|
477
|
-
await this.BLEparseStatus()
|
|
478
|
-
await this.updateHomeKitCharacteristics()
|
|
452
|
+
this.serviceData = serviceData
|
|
453
|
+
await this.BLEparseStatus()
|
|
454
|
+
await this.updateHomeKitCharacteristics()
|
|
479
455
|
} else {
|
|
480
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
481
|
-
await this.BLERefreshConnection(switchbot)
|
|
456
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
457
|
+
await this.BLERefreshConnection(switchbot)
|
|
482
458
|
}
|
|
483
|
-
})()
|
|
459
|
+
})()
|
|
484
460
|
}
|
|
485
461
|
}
|
|
486
462
|
|
|
487
463
|
async openAPIRefreshStatus(): Promise<void> {
|
|
488
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
464
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
489
465
|
try {
|
|
490
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
491
|
-
const deviceStatus: any = await body.json()
|
|
492
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
466
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
467
|
+
const deviceStatus: any = await body.json()
|
|
468
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
493
469
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
494
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
495
|
-
this.deviceStatus = deviceStatus.body
|
|
496
|
-
await this.openAPIparseStatus()
|
|
497
|
-
await this.updateHomeKitCharacteristics()
|
|
470
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
471
|
+
this.deviceStatus = deviceStatus.body
|
|
472
|
+
await this.openAPIparseStatus()
|
|
473
|
+
await this.updateHomeKitCharacteristics()
|
|
498
474
|
} else {
|
|
499
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
500
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
475
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
476
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
501
477
|
}
|
|
502
478
|
} catch (e: any) {
|
|
503
|
-
await this.apiError(e)
|
|
504
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
479
|
+
await this.apiError(e)
|
|
480
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
505
481
|
}
|
|
506
482
|
}
|
|
507
483
|
|
|
508
484
|
async registerWebhook() {
|
|
509
485
|
if (this.device.webhook) {
|
|
510
|
-
await this.debugLog('is listening webhook.')
|
|
486
|
+
await this.debugLog('is listening webhook.')
|
|
511
487
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: curtainWebhookContext | curtain3WebhookContext) => {
|
|
512
488
|
try {
|
|
513
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
514
|
-
this.webhookContext = context
|
|
515
|
-
await this.parseStatusWebhook()
|
|
516
|
-
await this.updateHomeKitCharacteristics()
|
|
489
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
490
|
+
this.webhookContext = context
|
|
491
|
+
await this.parseStatusWebhook()
|
|
492
|
+
await this.updateHomeKitCharacteristics()
|
|
517
493
|
} catch (e: any) {
|
|
518
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
494
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
519
495
|
}
|
|
520
|
-
}
|
|
496
|
+
}
|
|
521
497
|
} else {
|
|
522
|
-
await this.debugLog('is not listening webhook.')
|
|
498
|
+
await this.debugLog('is not listening webhook.')
|
|
523
499
|
}
|
|
524
500
|
}
|
|
525
501
|
|
|
526
502
|
async registerPlatformBLE(): Promise<void> {
|
|
527
|
-
await this.debugLog('registerPlatformBLE')
|
|
503
|
+
await this.debugLog('registerPlatformBLE')
|
|
528
504
|
if (this.config.options?.BLE) {
|
|
529
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
530
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
531
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
505
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
506
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
507
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
532
508
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
|
|
533
509
|
try {
|
|
534
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
535
|
-
this.serviceData = context
|
|
536
|
-
await this.BLEparseStatus()
|
|
537
|
-
await this.updateHomeKitCharacteristics()
|
|
510
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
511
|
+
this.serviceData = context
|
|
512
|
+
await this.BLEparseStatus()
|
|
513
|
+
await this.updateHomeKitCharacteristics()
|
|
538
514
|
} catch (e: any) {
|
|
539
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
515
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
540
516
|
}
|
|
541
|
-
}
|
|
517
|
+
}
|
|
542
518
|
} else {
|
|
543
|
-
await this.debugLog('is not listening to Platform BLE')
|
|
519
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
544
520
|
}
|
|
545
521
|
}
|
|
546
522
|
|
|
@@ -549,32 +525,32 @@ export class Curtain extends deviceBase {
|
|
|
549
525
|
*/
|
|
550
526
|
async pushChanges(): Promise<void> {
|
|
551
527
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
552
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
528
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
553
529
|
} else if (this.BLE) {
|
|
554
|
-
await this.BLEpushChanges()
|
|
530
|
+
await this.BLEpushChanges()
|
|
555
531
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
556
|
-
await this.openAPIpushChanges()
|
|
532
|
+
await this.openAPIpushChanges()
|
|
557
533
|
} else {
|
|
558
|
-
await this.offlineOff()
|
|
559
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
534
|
+
await this.offlineOff()
|
|
535
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
560
536
|
}
|
|
561
537
|
// Refresh the status from the API
|
|
562
538
|
interval(15000)
|
|
563
539
|
.pipe(skipWhile(() => this.curtainUpdateInProgress))
|
|
564
540
|
.pipe(take(1))
|
|
565
541
|
.subscribe(async () => {
|
|
566
|
-
await this.refreshStatus()
|
|
567
|
-
})
|
|
542
|
+
await this.refreshStatus()
|
|
543
|
+
})
|
|
568
544
|
}
|
|
569
545
|
|
|
570
546
|
async BLEpushChanges(): Promise<void> {
|
|
571
|
-
await this.debugLog('BLEpushChanges')
|
|
547
|
+
await this.debugLog('BLEpushChanges')
|
|
572
548
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
573
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
574
|
-
await this.convertBLEAddress()
|
|
575
|
-
const { setPositionMode, Mode }: { setPositionMode: number
|
|
576
|
-
const adjustedMode = setPositionMode === 1 ? 0x01 :
|
|
577
|
-
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
549
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
550
|
+
await this.convertBLEAddress()
|
|
551
|
+
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
552
|
+
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF
|
|
553
|
+
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
578
554
|
if (switchbot !== false) {
|
|
579
555
|
switchbot
|
|
580
556
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
@@ -582,70 +558,68 @@ export class Curtain extends deviceBase {
|
|
|
582
558
|
return await this.retryBLE({
|
|
583
559
|
max: await this.maxRetryBLE(),
|
|
584
560
|
fn: async () => {
|
|
585
|
-
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), adjustedMode)
|
|
561
|
+
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), adjustedMode)
|
|
586
562
|
},
|
|
587
|
-
})
|
|
563
|
+
})
|
|
588
564
|
})
|
|
589
565
|
.then(async () => {
|
|
590
|
-
await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
|
|
591
|
-
await this.updateHomeKitCharacteristics()
|
|
566
|
+
await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
|
|
567
|
+
await this.updateHomeKitCharacteristics()
|
|
592
568
|
})
|
|
593
569
|
.catch(async (e: any) => {
|
|
594
|
-
await this.apiError(e)
|
|
595
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
596
|
-
await this.BLEPushConnection()
|
|
597
|
-
})
|
|
570
|
+
await this.apiError(e)
|
|
571
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
572
|
+
await this.BLEPushConnection()
|
|
573
|
+
})
|
|
598
574
|
} else {
|
|
599
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
600
|
-
await this.BLEPushConnection()
|
|
575
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
576
|
+
await this.BLEPushConnection()
|
|
601
577
|
}
|
|
602
578
|
} else {
|
|
603
|
-
await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}
|
|
604
|
-
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
579
|
+
await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
605
580
|
}
|
|
606
581
|
}
|
|
607
582
|
|
|
608
583
|
async openAPIpushChanges(): Promise<void> {
|
|
609
|
-
await this.debugLog('openAPIpushChanges')
|
|
584
|
+
await this.debugLog('openAPIpushChanges')
|
|
610
585
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition || this.device.disableCaching) {
|
|
611
|
-
await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`)
|
|
612
|
-
const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition)
|
|
613
|
-
const { setPositionMode, Mode }: { setPositionMode: number
|
|
614
|
-
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
615
|
-
const adjustedMode = setPositionMode || 'ff'
|
|
616
|
-
let bodyChange: string
|
|
586
|
+
await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`)
|
|
587
|
+
const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition)
|
|
588
|
+
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
589
|
+
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
590
|
+
const adjustedMode = setPositionMode || 'ff'
|
|
591
|
+
let bodyChange: string
|
|
617
592
|
if (this.WindowCovering.HoldPosition) {
|
|
618
593
|
bodyChange = JSON.stringify({
|
|
619
594
|
command: 'pause',
|
|
620
595
|
parameter: 'default',
|
|
621
596
|
commandType: 'command',
|
|
622
|
-
})
|
|
597
|
+
})
|
|
623
598
|
} else {
|
|
624
599
|
bodyChange = JSON.stringify({
|
|
625
600
|
command: 'setPosition',
|
|
626
601
|
parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
627
602
|
commandType: 'command',
|
|
628
|
-
})
|
|
603
|
+
})
|
|
629
604
|
}
|
|
630
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
605
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
631
606
|
try {
|
|
632
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
633
|
-
const deviceStatus: any = await body.json()
|
|
634
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
607
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
608
|
+
const deviceStatus: any = await body.json()
|
|
609
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
635
610
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
636
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
637
|
-
await this.updateHomeKitCharacteristics()
|
|
611
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
612
|
+
await this.updateHomeKitCharacteristics()
|
|
638
613
|
} else {
|
|
639
|
-
await this.statusCode(statusCode)
|
|
640
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
614
|
+
await this.statusCode(statusCode)
|
|
615
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
641
616
|
}
|
|
642
617
|
} catch (e: any) {
|
|
643
|
-
await this.apiError(e)
|
|
644
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
618
|
+
await this.apiError(e)
|
|
619
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
645
620
|
}
|
|
646
621
|
} else {
|
|
647
|
-
await this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}
|
|
648
|
-
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
622
|
+
await this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`)
|
|
649
623
|
}
|
|
650
624
|
}
|
|
651
625
|
|
|
@@ -654,208 +628,199 @@ export class Curtain extends deviceBase {
|
|
|
654
628
|
*/
|
|
655
629
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
656
630
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
657
|
-
await this.infoLog(`Set TargetPosition: ${value}`)
|
|
631
|
+
await this.infoLog(`Set TargetPosition: ${value}`)
|
|
658
632
|
} else {
|
|
659
|
-
await this.debugLog(`No Changes, TargetPosition: ${value}`)
|
|
633
|
+
await this.debugLog(`No Changes, TargetPosition: ${value}`)
|
|
660
634
|
}
|
|
661
635
|
|
|
662
636
|
// Set HoldPosition to false when TargetPosition is changed
|
|
663
|
-
this.WindowCovering.HoldPosition = false
|
|
664
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition)
|
|
637
|
+
this.WindowCovering.HoldPosition = false
|
|
638
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition)
|
|
665
639
|
|
|
666
|
-
this.WindowCovering.TargetPosition = value
|
|
667
|
-
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition)
|
|
668
|
-
await this.mqtt('HoldPosition', this.WindowCovering.HoldPosition)
|
|
669
|
-
await this.startUpdatingCurtainIfNeeded()
|
|
640
|
+
this.WindowCovering.TargetPosition = value
|
|
641
|
+
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition)
|
|
642
|
+
await this.mqtt('HoldPosition', this.WindowCovering.HoldPosition)
|
|
643
|
+
await this.startUpdatingCurtainIfNeeded()
|
|
670
644
|
}
|
|
671
645
|
|
|
672
646
|
async startUpdatingCurtainIfNeeded() {
|
|
673
|
-
await this.setMinMax()
|
|
647
|
+
await this.setMinMax()
|
|
674
648
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
675
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
676
|
-
this.setNewTarget = true
|
|
677
|
-
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
649
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
650
|
+
this.setNewTarget = true
|
|
651
|
+
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
678
652
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
679
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
680
|
-
this.setNewTarget = true
|
|
681
|
-
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
653
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
654
|
+
this.setNewTarget = true
|
|
655
|
+
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
682
656
|
} else {
|
|
683
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
684
|
-
this.setNewTarget = false
|
|
685
|
-
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
657
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
658
|
+
this.setNewTarget = false
|
|
659
|
+
await this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
686
660
|
}
|
|
687
|
-
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
|
|
688
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
661
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
|
|
662
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
689
663
|
|
|
690
664
|
/**
|
|
691
665
|
* If Curtain movement time is short, the moving flag from backend is always false.
|
|
692
666
|
* The minimum time depends on the network control latency.
|
|
693
667
|
*/
|
|
694
|
-
clearTimeout(this.setNewTargetTimer)
|
|
695
|
-
await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
|
|
668
|
+
clearTimeout(this.setNewTargetTimer)
|
|
669
|
+
await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
|
|
696
670
|
if (this.setNewTarget) {
|
|
697
671
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
698
|
-
await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
|
|
699
|
-
this.setNewTarget = false
|
|
700
|
-
}, this.deviceUpdateRate * 1000)
|
|
672
|
+
await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
|
|
673
|
+
this.setNewTarget = false
|
|
674
|
+
}, this.deviceUpdateRate * 1000)
|
|
701
675
|
}
|
|
702
|
-
this.doCurtainUpdate.next()
|
|
676
|
+
this.doCurtainUpdate.next()
|
|
703
677
|
}
|
|
704
678
|
|
|
705
679
|
/**
|
|
706
680
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
707
681
|
*/
|
|
708
682
|
async HoldPositionSet(value: CharacteristicValue): Promise<void> {
|
|
709
|
-
this.debugLog(`HoldPosition: ${value}`)
|
|
710
|
-
this.WindowCovering.HoldPosition = value
|
|
711
|
-
this.doCurtainUpdate.next()
|
|
683
|
+
this.debugLog(`HoldPosition: ${value}`)
|
|
684
|
+
this.WindowCovering.HoldPosition = value
|
|
685
|
+
this.doCurtainUpdate.next()
|
|
712
686
|
}
|
|
713
687
|
|
|
714
688
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
715
|
-
await this.setMinMax()
|
|
689
|
+
await this.setMinMax()
|
|
716
690
|
// CurrentPosition
|
|
717
|
-
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition,
|
|
718
|
-
this.WindowCovering.CurrentPosition, 'CurrentPosition');
|
|
691
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition, this.WindowCovering.CurrentPosition, 'CurrentPosition')
|
|
719
692
|
// PositionState
|
|
720
|
-
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState,
|
|
721
|
-
this.WindowCovering.PositionState, 'PositionState');
|
|
693
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState, this.WindowCovering.PositionState, 'PositionState')
|
|
722
694
|
// TargetPosition
|
|
723
|
-
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition,
|
|
724
|
-
this.WindowCovering.TargetPosition, 'TargetPosition');
|
|
695
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition, this.WindowCovering.TargetPosition, 'TargetPosition')
|
|
725
696
|
// HoldPosition
|
|
726
|
-
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.HoldPosition,
|
|
727
|
-
this.WindowCovering.HoldPosition, 'HoldPosition');
|
|
697
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition, 'HoldPosition')
|
|
728
698
|
// CurrentAmbientLightLevel
|
|
729
699
|
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
730
|
-
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel }
|
|
731
|
-
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
732
|
-
this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
|
|
700
|
+
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel }
|
|
701
|
+
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history)
|
|
733
702
|
}
|
|
734
703
|
// BatteryLevel
|
|
735
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
736
|
-
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
704
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel')
|
|
737
705
|
// StatusLowBattery
|
|
738
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
739
|
-
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
706
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery')
|
|
740
707
|
// ChargingState
|
|
741
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
742
|
-
this.Battery.ChargingState, 'ChargingState');
|
|
708
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState')
|
|
743
709
|
}
|
|
744
710
|
|
|
745
711
|
async BLEPushConnection() {
|
|
746
712
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
747
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
748
|
-
await this.openAPIpushChanges()
|
|
713
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
714
|
+
await this.openAPIpushChanges()
|
|
749
715
|
}
|
|
750
716
|
}
|
|
751
717
|
|
|
752
718
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
753
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
719
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
754
720
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
755
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
756
|
-
await this.openAPIRefreshStatus()
|
|
721
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
722
|
+
await this.openAPIRefreshStatus()
|
|
757
723
|
}
|
|
758
724
|
}
|
|
759
725
|
|
|
760
726
|
async setPerformance() {
|
|
761
|
-
let setPositionMode: number
|
|
762
|
-
let Mode: string
|
|
727
|
+
let setPositionMode: number
|
|
728
|
+
let Mode: string
|
|
763
729
|
if (Number(this.WindowCovering.TargetPosition) > 50) {
|
|
764
730
|
if (this.device.curtain?.setOpenMode === '1') {
|
|
765
|
-
setPositionMode = 1
|
|
766
|
-
Mode = 'Silent Mode'
|
|
731
|
+
setPositionMode = 1
|
|
732
|
+
Mode = 'Silent Mode'
|
|
767
733
|
} else if (this.device.curtain?.setOpenMode === '0') {
|
|
768
|
-
setPositionMode = 0
|
|
769
|
-
Mode = 'Performance Mode'
|
|
734
|
+
setPositionMode = 0
|
|
735
|
+
Mode = 'Performance Mode'
|
|
770
736
|
} else {
|
|
771
|
-
setPositionMode = 0
|
|
772
|
-
Mode = 'Default Mode'
|
|
737
|
+
setPositionMode = 0
|
|
738
|
+
Mode = 'Default Mode'
|
|
773
739
|
}
|
|
774
740
|
} else {
|
|
775
741
|
if (this.device.curtain?.setCloseMode === '1') {
|
|
776
|
-
setPositionMode = 1
|
|
777
|
-
Mode = 'Silent Mode'
|
|
742
|
+
setPositionMode = 1
|
|
743
|
+
Mode = 'Silent Mode'
|
|
778
744
|
} else if (this.device.curtain?.setOpenMode === '0') {
|
|
779
|
-
setPositionMode = 0
|
|
780
|
-
Mode = 'Performance Mode'
|
|
745
|
+
setPositionMode = 0
|
|
746
|
+
Mode = 'Performance Mode'
|
|
781
747
|
} else {
|
|
782
|
-
setPositionMode = 0
|
|
783
|
-
Mode = 'Default Mode'
|
|
748
|
+
setPositionMode = 0
|
|
749
|
+
Mode = 'Default Mode'
|
|
784
750
|
}
|
|
785
751
|
}
|
|
786
|
-
return { setPositionMode, Mode }
|
|
752
|
+
return { setPositionMode, Mode }
|
|
787
753
|
}
|
|
788
754
|
|
|
789
755
|
async getCurrentPostion() {
|
|
790
|
-
await this.setMinMax()
|
|
791
|
-
await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
|
|
756
|
+
await this.setMinMax()
|
|
757
|
+
await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
|
|
792
758
|
if (this.setNewTarget) {
|
|
793
|
-
this.curtainMoving = true
|
|
794
|
-
this.infoLog('Checking Status ...')
|
|
795
|
-
await this.setMinMax()
|
|
759
|
+
this.curtainMoving = true
|
|
760
|
+
this.infoLog('Checking Status ...')
|
|
761
|
+
await this.setMinMax()
|
|
796
762
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
797
|
-
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
798
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
799
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
800
|
-
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
763
|
+
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
764
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
765
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
766
|
+
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
801
767
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
802
|
-
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
803
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
804
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
805
|
-
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
768
|
+
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
769
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
770
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
771
|
+
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
806
772
|
} else {
|
|
807
|
-
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
808
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
809
|
-
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
810
|
-
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
773
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
774
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
775
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
776
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
811
777
|
}
|
|
812
778
|
} else {
|
|
813
|
-
this.curtainMoving = false
|
|
814
|
-
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
815
|
-
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
816
|
-
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
817
|
-
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
818
|
-
}
|
|
819
|
-
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
|
|
820
|
-
+ ` PositionState: ${this.WindowCovering.PositionState},`);
|
|
779
|
+
this.curtainMoving = false
|
|
780
|
+
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
781
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
782
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
783
|
+
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
784
|
+
}
|
|
785
|
+
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`)
|
|
821
786
|
}
|
|
822
787
|
|
|
823
788
|
async setMinMax(): Promise<void> {
|
|
824
789
|
if (this.device.curtain?.set_min) {
|
|
825
790
|
if (Number(this.WindowCovering.CurrentPosition) <= this.device.curtain?.set_min) {
|
|
826
|
-
this.WindowCovering.CurrentPosition = 0
|
|
791
|
+
this.WindowCovering.CurrentPosition = 0
|
|
827
792
|
}
|
|
828
793
|
}
|
|
829
794
|
if (this.device.curtain?.set_max) {
|
|
830
795
|
if (Number(this.WindowCovering.CurrentPosition) >= this.device.curtain?.set_max) {
|
|
831
|
-
this.WindowCovering.CurrentPosition = 100
|
|
796
|
+
this.WindowCovering.CurrentPosition = 100
|
|
832
797
|
}
|
|
833
798
|
}
|
|
834
799
|
if (this.device.history) {
|
|
835
|
-
const motion = this.accessory.getService(this.hap.Service.MotionSensor)
|
|
836
|
-
const state = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
|
|
837
|
-
motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state)
|
|
800
|
+
const motion = this.accessory.getService(this.hap.Service.MotionSensor)
|
|
801
|
+
const state = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
|
|
802
|
+
motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state)
|
|
838
803
|
}
|
|
839
804
|
}
|
|
840
805
|
|
|
841
806
|
async offlineOff(): Promise<void> {
|
|
842
807
|
if (this.device.offline) {
|
|
843
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
844
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
845
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
808
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
|
|
809
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
|
|
810
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
846
811
|
}
|
|
847
812
|
}
|
|
848
813
|
|
|
849
814
|
async apiError(e: any): Promise<void> {
|
|
850
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
851
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
852
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
853
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
854
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
855
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e)
|
|
815
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
|
|
816
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
|
|
817
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
|
|
818
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
819
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
820
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e)
|
|
856
821
|
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
857
|
-
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
858
|
-
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
|
|
822
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
823
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
|
|
859
824
|
}
|
|
860
825
|
}
|
|
861
826
|
}
|