@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.0

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.
Files changed (195) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +14 -0
  3. package/assets/security-privacy-bluetooth.png +0 -0
  4. package/config.schema.json +76 -1
  5. package/dist/device/blindtilt.d.ts +18 -8
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +108 -70
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +9 -9
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +133 -160
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +13 -13
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +38 -73
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +12 -12
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +41 -79
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +5 -5
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +20 -42
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +15 -5
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +127 -81
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/device.d.ts +18 -18
  30. package/dist/device/device.d.ts.map +1 -1
  31. package/dist/device/device.js +33 -36
  32. package/dist/device/device.js.map +1 -1
  33. package/dist/device/fan.d.ts +8 -8
  34. package/dist/device/fan.d.ts.map +1 -1
  35. package/dist/device/fan.js +43 -75
  36. package/dist/device/fan.js.map +1 -1
  37. package/dist/device/hub.d.ts +5 -5
  38. package/dist/device/hub.d.ts.map +1 -1
  39. package/dist/device/hub.js +18 -39
  40. package/dist/device/hub.js.map +1 -1
  41. package/dist/device/humidifier.d.ts +5 -5
  42. package/dist/device/humidifier.d.ts.map +1 -1
  43. package/dist/device/humidifier.js +38 -78
  44. package/dist/device/humidifier.js.map +1 -1
  45. package/dist/device/iosensor.d.ts +5 -5
  46. package/dist/device/iosensor.d.ts.map +1 -1
  47. package/dist/device/iosensor.js +21 -40
  48. package/dist/device/iosensor.js.map +1 -1
  49. package/dist/device/lightstrip.d.ts +6 -6
  50. package/dist/device/lightstrip.d.ts.map +1 -1
  51. package/dist/device/lightstrip.js +34 -73
  52. package/dist/device/lightstrip.js.map +1 -1
  53. package/dist/device/lock.d.ts +9 -9
  54. package/dist/device/lock.d.ts.map +1 -1
  55. package/dist/device/lock.js +37 -52
  56. package/dist/device/lock.js.map +1 -1
  57. package/dist/device/meter.d.ts +5 -5
  58. package/dist/device/meter.d.ts.map +1 -1
  59. package/dist/device/meter.js +21 -39
  60. package/dist/device/meter.js.map +1 -1
  61. package/dist/device/meterplus.d.ts +5 -5
  62. package/dist/device/meterplus.d.ts.map +1 -1
  63. package/dist/device/meterplus.js +21 -38
  64. package/dist/device/meterplus.js.map +1 -1
  65. package/dist/device/motion.d.ts +5 -5
  66. package/dist/device/motion.d.ts.map +1 -1
  67. package/dist/device/motion.js +14 -32
  68. package/dist/device/motion.js.map +1 -1
  69. package/dist/device/plug.d.ts +12 -12
  70. package/dist/device/plug.d.ts.map +1 -1
  71. package/dist/device/plug.js +16 -25
  72. package/dist/device/plug.js.map +1 -1
  73. package/dist/device/robotvacuumcleaner.d.ts +11 -11
  74. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  75. package/dist/device/robotvacuumcleaner.js +42 -56
  76. package/dist/device/robotvacuumcleaner.js.map +1 -1
  77. package/dist/device/waterdetector.d.ts +5 -5
  78. package/dist/device/waterdetector.d.ts.map +1 -1
  79. package/dist/device/waterdetector.js +47 -44
  80. package/dist/device/waterdetector.js.map +1 -1
  81. package/dist/homebridge-ui/server.js +2 -2
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +0 -4
  85. package/dist/index.js.map +1 -1
  86. package/dist/irdevice/airconditioner.d.ts +8 -8
  87. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  88. package/dist/irdevice/airconditioner.js +61 -105
  89. package/dist/irdevice/airconditioner.js.map +1 -1
  90. package/dist/irdevice/airpurifier.d.ts +10 -10
  91. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  92. package/dist/irdevice/airpurifier.js +22 -42
  93. package/dist/irdevice/airpurifier.js.map +1 -1
  94. package/dist/irdevice/camera.d.ts +9 -9
  95. package/dist/irdevice/camera.d.ts.map +1 -1
  96. package/dist/irdevice/camera.js +15 -25
  97. package/dist/irdevice/camera.js.map +1 -1
  98. package/dist/irdevice/fan.d.ts +8 -8
  99. package/dist/irdevice/fan.d.ts.map +1 -1
  100. package/dist/irdevice/fan.js +21 -40
  101. package/dist/irdevice/fan.js.map +1 -1
  102. package/dist/irdevice/irdevice.d.ts +11 -11
  103. package/dist/irdevice/irdevice.d.ts.map +1 -1
  104. package/dist/irdevice/irdevice.js +14 -22
  105. package/dist/irdevice/irdevice.js.map +1 -1
  106. package/dist/irdevice/light.d.ts +9 -9
  107. package/dist/irdevice/light.d.ts.map +1 -1
  108. package/dist/irdevice/light.js +24 -47
  109. package/dist/irdevice/light.js.map +1 -1
  110. package/dist/irdevice/other.d.ts +9 -9
  111. package/dist/irdevice/other.d.ts.map +1 -1
  112. package/dist/irdevice/other.js +40 -83
  113. package/dist/irdevice/other.js.map +1 -1
  114. package/dist/irdevice/tv.d.ts +9 -9
  115. package/dist/irdevice/tv.d.ts.map +1 -1
  116. package/dist/irdevice/tv.js +29 -54
  117. package/dist/irdevice/tv.js.map +1 -1
  118. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  119. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  120. package/dist/irdevice/vacuumcleaner.js +11 -21
  121. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  122. package/dist/irdevice/waterheater.d.ts +5 -5
  123. package/dist/irdevice/waterheater.d.ts.map +1 -1
  124. package/dist/irdevice/waterheater.js +11 -22
  125. package/dist/irdevice/waterheater.js.map +1 -1
  126. package/dist/platform.d.ts +20 -19
  127. package/dist/platform.d.ts.map +1 -1
  128. package/dist/platform.js +466 -710
  129. package/dist/platform.js.map +1 -1
  130. package/dist/settings.d.ts +5 -2
  131. package/dist/settings.d.ts.map +1 -1
  132. package/dist/settings.js.map +1 -1
  133. package/dist/types/bledevicestatus.d.ts +9 -9
  134. package/dist/types/bledevicestatus.d.ts.map +1 -1
  135. package/dist/types/devicelist.d.ts +6 -6
  136. package/dist/types/devicelist.d.ts.map +1 -1
  137. package/dist/types/deviceresponse.d.ts +4 -4
  138. package/dist/types/deviceresponse.d.ts.map +1 -1
  139. package/dist/types/devicestatus.d.ts +2 -2
  140. package/dist/types/devicestatus.d.ts.map +1 -1
  141. package/dist/types/devicewebhookstatus.d.ts +5 -5
  142. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  143. package/dist/types/irdevicelist.d.ts +4 -4
  144. package/dist/types/irdevicelist.d.ts.map +1 -1
  145. package/dist/types/pushbody.d.ts +2 -2
  146. package/dist/types/pushbody.d.ts.map +1 -1
  147. package/dist/utils.d.ts +4 -4
  148. package/dist/utils.d.ts.map +1 -1
  149. package/dist/utils.js +9 -13
  150. package/dist/utils.js.map +1 -1
  151. package/eslint.config.js +48 -93
  152. package/package.json +61 -54
  153. package/src/device/blindtilt.ts +509 -460
  154. package/src/device/bot.ts +696 -718
  155. package/src/device/ceilinglight.ts +331 -364
  156. package/src/device/colorbulb.ts +412 -448
  157. package/src/device/contact.ts +200 -221
  158. package/src/device/curtain.ts +506 -444
  159. package/src/device/device.ts +206 -208
  160. package/src/device/fan.ts +307 -340
  161. package/src/device/hub.ts +184 -209
  162. package/src/device/humidifier.ts +297 -342
  163. package/src/device/iosensor.ts +182 -204
  164. package/src/device/lightstrip.ts +362 -399
  165. package/src/device/lock.ts +262 -276
  166. package/src/device/meter.ts +183 -205
  167. package/src/device/meterplus.ts +183 -204
  168. package/src/device/motion.ts +169 -185
  169. package/src/device/plug.ts +174 -177
  170. package/src/device/robotvacuumcleaner.ts +256 -269
  171. package/src/device/waterdetector.ts +185 -185
  172. package/src/homebridge-ui/server.ts +16 -15
  173. package/src/index.ts +5 -6
  174. package/src/irdevice/airconditioner.ts +277 -326
  175. package/src/irdevice/airpurifier.ts +124 -143
  176. package/src/irdevice/camera.ts +58 -64
  177. package/src/irdevice/fan.ts +106 -123
  178. package/src/irdevice/irdevice.ts +116 -119
  179. package/src/irdevice/light.ts +119 -143
  180. package/src/irdevice/other.ts +417 -461
  181. package/src/irdevice/tv.ts +155 -177
  182. package/src/irdevice/vacuumcleaner.ts +54 -60
  183. package/src/irdevice/waterheater.ts +56 -63
  184. package/src/platform.ts +1462 -1678
  185. package/src/settings.ts +173 -170
  186. package/src/types/bledevicestatus.ts +252 -256
  187. package/src/types/devicelist.ts +79 -79
  188. package/src/types/deviceresponse.ts +12 -13
  189. package/src/types/devicestatus.ts +124 -124
  190. package/src/types/devicewebhookstatus.ts +126 -131
  191. package/src/types/irdevicelist.ts +10 -10
  192. package/src/types/pushbody.ts +5 -5
  193. package/src/utils.ts +64 -65
  194. package/tsconfig.json +10 -9
  195. package/.github/npm-version-script.cjs +0 -81
@@ -2,90 +2,103 @@
2
2
  *
3
3
  * blindtilt.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { deviceBase } from './device.js';
6
- import { BlindTiltMappingMode } from '../utils.js';
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 { blindTiltServiceData } from '../types/bledevicestatus.js'
10
+ import type { device } from '../types/devicelist.js'
11
+ import type { blindTiltStatus } from '../types/devicestatus.js'
12
+ import type { blindTiltWebhookContext } from '../types/devicewebhookstatus.js'
13
+
7
14
  /*
8
15
  * For Testing Locally:
9
16
  * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
10
17
  */
11
- import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
12
- import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
13
-
14
- import type { devicesConfig } from '../settings.js';
15
- import type { device } from '../types/devicelist.js';
16
- import type { SwitchBotPlatform } from '../platform.js';
17
- import type { blindTiltServiceData } from '../types/bledevicestatus.js';
18
- import type { blindTiltStatus } from '../types/devicestatus.js';
19
- import type { blindTiltWebhookContext } from '../types/devicewebhookstatus.js';
20
- import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
18
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
19
+ import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
21
20
 
21
+ import { BlindTiltMappingMode } from '../utils.js'
22
+ import { deviceBase } from './device.js'
22
23
 
23
24
  export class BlindTilt extends deviceBase {
24
25
  // Services
25
26
  private WindowCovering: {
26
- Name: CharacteristicValue;
27
- Service: Service;
28
- PositionState: CharacteristicValue;
29
- TargetPosition: CharacteristicValue;
30
- CurrentPosition: CharacteristicValue;
31
- TargetHorizontalTiltAngle: CharacteristicValue;
32
- CurrentHorizontalTiltAngle: CharacteristicValue;
33
- };
27
+ Name: CharacteristicValue
28
+ Service: Service
29
+ PositionState: CharacteristicValue
30
+ TargetPosition: CharacteristicValue
31
+ CurrentPosition: CharacteristicValue
32
+ TargetHorizontalTiltAngle: CharacteristicValue
33
+ CurrentHorizontalTiltAngle: CharacteristicValue
34
+ }
34
35
 
35
36
  private Battery: {
36
- Name: CharacteristicValue;
37
- Service: Service;
38
- BatteryLevel: CharacteristicValue;
39
- StatusLowBattery: CharacteristicValue;
40
- ChargingState?: CharacteristicValue;
41
- };
37
+ Name: CharacteristicValue
38
+ Service: Service
39
+ BatteryLevel: CharacteristicValue
40
+ StatusLowBattery: CharacteristicValue
41
+ ChargingState?: CharacteristicValue
42
+ }
42
43
 
43
44
  private LightSensor?: {
44
- Name: CharacteristicValue;
45
- Service: Service;
46
- CurrentAmbientLightLevel?: CharacteristicValue;
47
- };
45
+ Name: CharacteristicValue
46
+ Service: Service
47
+ CurrentAmbientLightLevel?: CharacteristicValue
48
+ }
49
+
50
+ private OpenModeSwitch?: {
51
+ Name: CharacteristicValue
52
+ Service: Service
53
+ On: CharacteristicValue
54
+ }
55
+
56
+ private CloseModeSwitch?: {
57
+ Name: CharacteristicValue
58
+ Service: Service
59
+ On: CharacteristicValue
60
+ }
48
61
 
49
62
  // OpenAPI
50
- deviceStatus!: blindTiltStatus;
51
- mappingMode: BlindTiltMappingMode = BlindTiltMappingMode.OnlyUp;
63
+ deviceStatus!: blindTiltStatus
64
+ mappingMode: BlindTiltMappingMode = BlindTiltMappingMode.OnlyUp
52
65
 
53
- //Webhook
54
- webhookContext!: blindTiltWebhookContext;
66
+ // Webhook
67
+ webhookContext!: blindTiltWebhookContext
55
68
 
56
69
  // BLE
57
- serviceData!: blindTiltServiceData;
70
+ serviceData!: blindTiltServiceData
58
71
 
59
72
  // Target
60
- setNewTarget!: boolean;
61
- setNewTargetTimer!: NodeJS.Timeout;
73
+ setNewTarget!: boolean
74
+ setNewTargetTimer!: NodeJS.Timeout
62
75
 
63
76
  // Updates
64
- blindTiltMoving: boolean;
65
- blindTiltUpdateInProgress: boolean;
66
- doBlindTiltUpdate: Subject<void>;
77
+ blindTiltMoving: boolean
78
+ blindTiltUpdateInProgress: boolean
79
+ doBlindTiltUpdate: Subject<void>
67
80
 
68
81
  constructor(
69
82
  readonly platform: SwitchBotPlatform,
70
83
  accessory: PlatformAccessory,
71
84
  device: device & devicesConfig,
72
85
  ) {
73
- super(platform, accessory, device);
86
+ super(platform, accessory, device)
74
87
  // Set category
75
- accessory.category = this.hap.Categories.WINDOW_COVERING;
88
+ accessory.category = this.hap.Categories.WINDOW_COVERING
76
89
 
77
90
  // default placeholders
78
- this.mappingMode = (device.blindTilt?.mode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp;
79
- this.debugLog(`Mapping mode: ${this.mappingMode}`);
91
+ this.mappingMode = (device.blindTilt?.mode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp
92
+ this.debugLog(`Mapping mode: ${this.mappingMode}`)
80
93
 
81
94
  // this is subject we use to track when we need to POST changes to the SwitchBot API
82
- this.doBlindTiltUpdate = new Subject();
83
- this.blindTiltMoving = false;
84
- this.blindTiltUpdateInProgress = false;
85
- this.setNewTarget = false;
95
+ this.doBlindTiltUpdate = new Subject()
96
+ this.blindTiltMoving = false
97
+ this.blindTiltUpdateInProgress = false
98
+ this.setNewTarget = false
86
99
 
87
100
  // Initialize WindowCovering Service
88
- accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
101
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
89
102
  this.WindowCovering = {
90
103
  Name: accessory.displayName,
91
104
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
@@ -94,310 +107,336 @@ export class BlindTilt extends deviceBase {
94
107
  CurrentPosition: accessory.context.CurrentPosition ?? 100,
95
108
  TargetHorizontalTiltAngle: accessory.context.TargetHorizontalTiltAngle ?? 90,
96
109
  CurrentHorizontalTiltAngle: accessory.context.CurrentHorizontalTiltAngle ?? 90,
97
- };
98
- accessory.context.WindowCovering = this.WindowCovering as object;
110
+ }
111
+ accessory.context.WindowCovering = this.WindowCovering as object
99
112
 
100
113
  // Initialize WindowCovering Characteristics
101
- this.WindowCovering.Service
102
- .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
103
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
104
- .setProps({
105
- minStep: device.blindTilt?.set_minStep ?? 1,
106
- minValue: 0,
107
- maxValue: 100,
108
- validValueRanges: [0, 100],
109
- })
110
- .onGet(() => {
111
- return this.WindowCovering.TargetPosition;
112
- })
113
- .onSet(this.TargetPositionSet.bind(this));
114
+ this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
115
+ minStep: device.blindTilt?.set_minStep ?? 1,
116
+ minValue: 0,
117
+ maxValue: 100,
118
+ validValueRanges: [0, 100],
119
+ }).onGet(() => {
120
+ return this.WindowCovering.TargetPosition
121
+ }).onSet(this.TargetPositionSet.bind(this))
114
122
 
115
123
  // Initialize WindowCovering CurrentPosition Characteristic
116
- this.WindowCovering.Service
117
- .getCharacteristic(this.hap.Characteristic.CurrentPosition)
118
- .setProps({
119
- minStep: device.blindTilt?.set_minStep ?? 1,
120
- minValue: 0,
121
- maxValue: 100,
122
- validValueRanges: [0, 100],
123
- }).onGet(() => {
124
- return this.WindowCovering.CurrentPosition ?? 0;
125
- });
124
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.CurrentPosition).setProps({
125
+ minStep: device.blindTilt?.set_minStep ?? 1,
126
+ minValue: 0,
127
+ maxValue: 100,
128
+ validValueRanges: [0, 100],
129
+ }).onGet(() => {
130
+ return this.WindowCovering.CurrentPosition ?? 0
131
+ })
126
132
 
127
133
  // Initialize WindowCovering TargetHorizontalTiltAngle Characteristic
128
- this.WindowCovering.Service
129
- .getCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle)
130
- .setProps({
131
- minStep: 180,
132
- minValue: -90,
133
- maxValue: 90,
134
- validValues: [-90, 90],
135
- })
136
- .onGet(() => {
137
- return this.WindowCovering.TargetHorizontalTiltAngle;
138
- })
139
- .onSet(this.TargetHorizontalTiltAngleSet.bind(this));
134
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle).setProps({
135
+ minStep: 180,
136
+ minValue: -90,
137
+ maxValue: 90,
138
+ validValues: [-90, 90],
139
+ }).onGet(() => {
140
+ return this.WindowCovering.TargetHorizontalTiltAngle
141
+ }).onSet(this.TargetHorizontalTiltAngleSet.bind(this))
140
142
 
141
143
  // Initialize WindowCovering CurrentHorizontalTiltAngle Characteristic
142
- this.WindowCovering.Service
143
- .getCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle)
144
- .setProps({
145
- minStep: 180,
146
- minValue: -90,
147
- maxValue: 90,
148
- validValues: [-90, 90],
149
- }).onGet(() => {
150
- return this.WindowCovering.CurrentHorizontalTiltAngle ?? 0;
151
- });
144
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle).setProps({
145
+ minStep: 180,
146
+ minValue: -90,
147
+ maxValue: 90,
148
+ validValues: [-90, 90],
149
+ }).onGet(() => {
150
+ return this.WindowCovering.CurrentHorizontalTiltAngle ?? 0
151
+ })
152
152
 
153
153
  // Initialize Battery Service
154
- accessory.context.Battery = accessory.context.Battery ?? {};
154
+ accessory.context.Battery = accessory.context.Battery ?? {}
155
155
  this.Battery = {
156
156
  Name: `${accessory.displayName} Battery`,
157
157
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
158
158
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
159
159
  StatusLowBattery: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
160
160
  ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
161
- };
162
- accessory.context.Battery = this.Battery as object;
161
+ }
162
+ accessory.context.Battery = this.Battery as object
163
163
 
164
164
  // Initialize Battery Name Characteristic
165
- this.Battery.Service
166
- .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
167
- .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
165
+ this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
168
166
 
169
167
  // Initialize LightSensor Service
170
168
  if (device.blindTilt?.hide_lightsensor) {
171
169
  if (this.LightSensor?.Service) {
172
- this.debugLog('Removing Light Sensor Service');
173
- this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor) as Service;
174
- accessory.removeService(this.LightSensor.Service);
175
- accessory.context.LightSensor = {};
170
+ this.debugLog('Removing Light Sensor Service')
171
+ this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor) as Service
172
+ accessory.removeService(this.LightSensor.Service)
173
+ accessory.context.LightSensor = {}
176
174
  } else {
177
- this.debugLog('Light Sensor Service is already removed');
175
+ this.debugLog('Light Sensor Service is already removed')
178
176
  }
179
177
  } else {
180
- accessory.context.LightSensor = accessory.context.LightSensor ?? {};
178
+ accessory.context.LightSensor = accessory.context.LightSensor ?? {}
181
179
  this.LightSensor = {
182
180
  Name: `${accessory.displayName} Light Sensor`,
183
181
  Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor) as Service,
184
182
  CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
185
- };
186
- accessory.context.LightSensor = this.LightSensor as object;
183
+ }
184
+ accessory.context.LightSensor = this.LightSensor as object
187
185
 
188
186
  // Initialize LightSensor Characteristics
189
- this.LightSensor.Service
190
- .setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name)
191
- .setCharacteristic(this.hap.Characteristic.StatusActive, true)
192
- .getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
193
- .onGet(() => {
194
- return this.LightSensor?.CurrentAmbientLightLevel ?? 0.0001;
195
- });
187
+ this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true).getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel).onGet(() => {
188
+ return this.LightSensor?.CurrentAmbientLightLevel ?? 0.0001
189
+ })
190
+ }
191
+
192
+ // Initialize Open Mode Switch Service
193
+ if (!device.blindTilt?.silentModeSwitch) {
194
+ if (this.OpenModeSwitch?.Service) {
195
+ this.debugLog('Removing Open Mode Switch Service')
196
+ this.OpenModeSwitch.Service = this.accessory.getService(this.hap.Service.Switch) as Service
197
+ accessory.removeService(this.OpenModeSwitch.Service)
198
+ accessory.context.OpenModeSwitch = {}
199
+ }
200
+ } else {
201
+ accessory.context.OpenModeSwitch = accessory.context.OpenModeSwitch ?? {}
202
+ this.OpenModeSwitch = {
203
+ Name: `${accessory.displayName} Silent Open Mode`,
204
+ Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
205
+ On: accessory.context.OpenModeSwitch.On ?? false,
206
+ }
207
+ accessory.context.OpenModeSwitch = this.OpenModeSwitch as object
208
+
209
+ // Initialize Open Mode Switch Service
210
+ this.OpenModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.OpenModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
211
+ return this.OpenModeSwitch?.On ?? false
212
+ })
213
+
214
+ this.OpenModeSwitch.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OpenModeSwitchSet.bind(this))
215
+ }
216
+
217
+ // Initialize Close Mode Switch Service
218
+ if (!device.blindTilt?.silentModeSwitch) {
219
+ if (this.CloseModeSwitch?.Service) {
220
+ this.debugLog('Removing Close Mode Switch Service')
221
+ this.CloseModeSwitch.Service = this.accessory.getService(this.hap.Service.Switch) as Service
222
+ accessory.removeService(this.CloseModeSwitch.Service)
223
+ accessory.context.CloseModeSwitch = {}
224
+ }
225
+ } else {
226
+ accessory.context.CloseModeSwitch = accessory.context.CloseModeSwitch ?? {}
227
+ this.CloseModeSwitch = {
228
+ Name: `${accessory.displayName} Silent Close Mode`,
229
+ Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
230
+ On: accessory.context.CloseModeSwitch.On ?? false,
231
+ }
232
+ accessory.context.CloseModeSwitch = this.CloseModeSwitch as object
233
+
234
+ // Initialize Close Mode Switch Service
235
+ this.CloseModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.CloseModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
236
+ return this.CloseModeSwitch?.On ?? false
237
+ })
238
+
239
+ this.CloseModeSwitch.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.CloseModeSwitchSet.bind(this))
196
240
  }
197
241
 
198
242
  // Retrieve initial values and updateHomekit
199
243
  try {
200
- this.debugLog('Retrieve initial values and update Homekit');
201
- this.refreshStatus();
244
+ this.debugLog('Retrieve initial values and update Homekit')
245
+ this.refreshStatus()
202
246
  } catch (e: any) {
203
- this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
247
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
204
248
  }
205
249
 
206
- //regisiter webhook event handler if enabled
250
+ // regisiter webhook event handler if enabled
207
251
  try {
208
- this.debugLog('Registering Webhook Event Handler');
209
- this.registerWebhook();
252
+ this.debugLog('Registering Webhook Event Handler')
253
+ this.registerWebhook()
210
254
  } catch (e: any) {
211
- this.errorLog(`failed to registerWebhook, Error: ${e}`);
255
+ this.errorLog(`failed to registerWebhook, Error: ${e}`)
212
256
  }
213
257
 
214
- //regisiter platform BLE event handler if enabled
258
+ // regisiter platform BLE event handler if enabled
215
259
  try {
216
- this.debugLog('Registering Platform BLE Event Handler');
217
- this.registerPlatformBLE();
260
+ this.debugLog('Registering Platform BLE Event Handler')
261
+ this.registerPlatformBLE()
218
262
  } catch (e: any) {
219
- this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
263
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
220
264
  }
221
265
 
222
266
  // Start an update interval
223
267
  interval(this.deviceRefreshRate * 1000)
224
268
  .pipe(skipWhile(() => this.blindTiltUpdateInProgress))
225
269
  .subscribe(async () => {
226
- await this.refreshStatus();
227
- });
270
+ await this.refreshStatus()
271
+ })
228
272
 
229
273
  // update slide progress
230
274
  interval(this.deviceUpdateRate * 1000)
231
275
  .pipe(skipWhile(() => !this.blindTiltMoving))
232
276
  .subscribe(async () => {
233
277
  if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
234
- return;
278
+ return
235
279
  }
236
- this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`);
237
- await this.refreshStatus();
238
- });
280
+ this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`)
281
+ await this.refreshStatus()
282
+ })
239
283
 
240
284
  // Watch for BlindTilt change events
241
285
  // We put in a debounce of 100ms so we don't make duplicate calls
242
286
  this.doBlindTiltUpdate
243
287
  .pipe(
244
288
  tap(() => {
245
- this.blindTiltUpdateInProgress = true;
289
+ this.blindTiltUpdateInProgress = true
246
290
  }),
247
291
  debounceTime(this.devicePushRate * 1000),
248
292
  )
249
293
  .subscribe(async () => {
250
294
  try {
251
- await this.pushChanges();
295
+ await this.pushChanges()
252
296
  } catch (e: any) {
253
- await this.apiError(e);
254
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
297
+ await this.apiError(e)
298
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
255
299
  }
256
- this.blindTiltUpdateInProgress = false;
257
- });
300
+ this.blindTiltUpdateInProgress = false
301
+ })
258
302
  }
259
303
 
260
304
  /**
261
305
  * Parse the device status from the SwitchBotBLE API
262
306
  */
263
307
  async BLEparseStatus(): Promise<void> {
264
- await this.debugLog('BLEparseStatus');
265
- await this.debugLog(`(direction, slidePosition, battery, version) = BLE:(${this.serviceData.tilt}, ${this.serviceData.tilt},`
266
- + ` ${this.serviceData.battery}, ${this.accessory.context.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle},`
267
- + ` ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
308
+ await this.debugLog('BLEparseStatus')
309
+ await this.debugLog(`(direction, slidePosition, battery, version) = BLE:(${this.serviceData.tilt}, ${this.serviceData.tilt}, ${this.serviceData.battery}, ${this.accessory.context.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
268
310
 
269
311
  // CurrentPosition
270
- this.WindowCovering.CurrentPosition = 100 - Number(this.serviceData.tilt);
271
- await this.setMinMax();
272
- await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
312
+ this.WindowCovering.CurrentPosition = 100 - Number(this.serviceData.tilt)
313
+ await this.setMinMax()
314
+ await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
273
315
  if (this.setNewTarget) {
274
- await this.infoLog('Checking Status ...');
316
+ await this.infoLog('Checking Status ...')
275
317
  }
276
318
  if (this.setNewTarget && this.serviceData.inMotion) {
277
- this.blindTiltMoving = true;
278
- await this.setMinMax();
319
+ this.blindTiltMoving = true
320
+ await this.setMinMax()
279
321
  if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
280
- await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
281
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
282
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
283
- await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
322
+ await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
323
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
324
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
325
+ await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
284
326
  } else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
285
- await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
286
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
287
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
288
- await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
327
+ await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
328
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
329
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
330
+ await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
289
331
  } else {
290
- await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
291
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
292
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
293
- await this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState);
332
+ await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
333
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
334
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
335
+ await this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState)
294
336
  }
295
337
  } else {
296
- this.blindTiltMoving = false;
297
- await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
298
- this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
299
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
300
- await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
338
+ this.blindTiltMoving = false
339
+ await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
340
+ this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
341
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
342
+ await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
301
343
  }
302
- await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
303
- + ` PositionState: ${this.WindowCovering.PositionState}`);
344
+ await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`)
304
345
 
305
346
  // CurrentAmbientLightLevel
306
347
  if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
307
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
308
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
309
- const spaceBetweenLevels = 9;
348
+ const set_minLux = this.device.blindTilt?.set_minLux ?? 1
349
+ const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
350
+ const spaceBetweenLevels = 9
310
351
 
311
-
312
- await this.getLightLevel(this.serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
313
- await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
352
+ await this.getLightLevel(this.serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels)
353
+ await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
314
354
  }
315
355
 
316
356
  // BatteryLevel
317
- this.Battery.BatteryLevel = this.serviceData.battery;
318
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
357
+ this.Battery.BatteryLevel = this.serviceData.battery
358
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
319
359
 
320
360
  // StatusLowBattery
321
361
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
322
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
323
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
362
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
363
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
364
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
324
365
  };
325
366
 
326
367
  /**
327
368
  * Parse the device status from the SwitchBot OpenAPI
328
369
  */
329
370
  async openAPIparseStatus(): Promise<void> {
330
- await this.debugLog('openAPIparseStatus');
331
- await this.debugLog(`(direction, slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.direction}, ${this.deviceStatus.slidePosition},`
332
- + ` ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle},`
333
- + ` ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
371
+ await this.debugLog('openAPIparseStatus')
372
+ await this.debugLog(`(direction, slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.direction}, ${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
334
373
 
335
374
  // CurrentPosition
336
- await this.getCurrentPosttionDirection(this.deviceStatus.direction, this.deviceStatus.slidePosition);
375
+ await this.getCurrentPosttionDirection(this.deviceStatus.direction, this.deviceStatus.slidePosition)
337
376
 
338
377
  if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
339
- const set_minLux = this.device.blindTilt?.set_minLux ?? 1;
340
- const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001;
341
- const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux;
342
- this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
343
- await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
378
+ const set_minLux = this.device.blindTilt?.set_minLux ?? 1
379
+ const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
380
+ const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
381
+ this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
382
+ await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
344
383
  }
345
384
 
346
385
  // BatteryLevel
347
- this.Battery.BatteryLevel = this.deviceStatus.battery;
348
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
386
+ this.Battery.BatteryLevel = this.deviceStatus.battery
387
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
349
388
 
350
389
  // StatusLowBattery
351
390
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
352
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
353
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
391
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
392
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
393
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
354
394
 
355
395
  // Firmware Version
356
- const version = this.deviceStatus.version.toString();
357
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
358
- let deviceVersion: string;
396
+ const version = this.deviceStatus.version.toString()
397
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
398
+ let deviceVersion: string
359
399
  if (version?.includes('.') === false) {
360
- const replace = version?.replace(/^V|-.*$/g, '');
361
- const match = replace?.match(/.{1,1}/g);
362
- const blindTiltVersion = match?.join('.') ?? '0.0.0';
363
- deviceVersion = blindTiltVersion;
400
+ const replace = version?.replace(/^V|-.*$/g, '')
401
+ const match = replace?.match(/./g)
402
+ const blindTiltVersion = match?.join('.') ?? '0.0.0'
403
+ deviceVersion = blindTiltVersion
364
404
  } else {
365
- deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
405
+ deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
366
406
  }
367
407
  this.accessory
368
408
  .getService(this.hap.Service.AccessoryInformation)!
369
409
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
370
410
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
371
411
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
372
- .updateValue(deviceVersion);
373
- this.accessory.context.version = deviceVersion;
374
- await this.debugLog(`version: ${this.accessory.context.version}`);
412
+ .updateValue(deviceVersion)
413
+ this.accessory.context.version = deviceVersion
414
+ await this.debugLog(`version: ${this.accessory.context.version}`)
375
415
  }
376
416
 
377
417
  async parseStatusWebhook(): Promise<void> {
378
- await this.debugLog('parseStatusWebhook');
379
- await this.debugLog(`(slidePosition, battery, version) = Webhook:(${this.webhookContext.direction}, ${this.webhookContext.slidePosition},`
380
- + ` ${this.webhookContext.battery}, ${this.webhookContext.version}, current:(${this.WindowCovering.CurrentHorizontalTiltAngle},`
381
- + ` ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
418
+ await this.debugLog('parseStatusWebhook')
419
+ await this.debugLog(`(slidePosition, battery, version) = Webhook:(${this.webhookContext.direction}, ${this.webhookContext.slidePosition}, ${this.webhookContext.battery}, ${this.webhookContext.version}, current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
382
420
  // CurrentPosition and CurrentHorizontalTiltAngle
383
- await this.getCurrentPosttionDirection(this.webhookContext.direction, this.webhookContext.slidePosition);
421
+ await this.getCurrentPosttionDirection(this.webhookContext.direction, this.webhookContext.slidePosition)
384
422
  // BatteryLevel
385
- this.Battery.BatteryLevel = this.webhookContext.battery;
386
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
423
+ this.Battery.BatteryLevel = this.webhookContext.battery
424
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
387
425
  // StatusLowBattery
388
426
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
389
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
390
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
427
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
428
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
429
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
391
430
  // Firmware Version
392
- const deviceVersion = this.webhookContext.version.replace(/^V|-.*$/g, '') ?? '0.0.0';
431
+ const deviceVersion = this.webhookContext.version.replace(/^V|-.*$/g, '') ?? '0.0.0'
393
432
  this.accessory
394
433
  .getService(this.hap.Service.AccessoryInformation)!
395
434
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
396
435
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
397
436
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
398
- .updateValue(deviceVersion);
399
- this.accessory.context.version = deviceVersion;
400
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
437
+ .updateValue(deviceVersion)
438
+ this.accessory.context.version = deviceVersion
439
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
401
440
  }
402
441
 
403
442
  /**
@@ -405,128 +444,128 @@ export class BlindTilt extends deviceBase {
405
444
  */
406
445
  async refreshStatus(): Promise<void> {
407
446
  if (!this.device.enableCloudService && this.OpenAPI) {
408
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
447
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
409
448
  } else if (this.BLE) {
410
- await this.BLERefreshStatus();
449
+ await this.BLERefreshStatus()
411
450
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
412
- await this.openAPIRefreshStatus();
451
+ await this.openAPIRefreshStatus()
413
452
  } else {
414
- await this.offlineOff();
415
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
453
+ await this.offlineOff()
454
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
416
455
  }
417
456
  }
418
457
 
419
458
  async BLERefreshStatus(): Promise<void> {
420
- await this.debugLog('BLERefreshStatus');
421
- const switchbot = await this.switchbotBLE();
459
+ await this.debugLog('BLERefreshStatus')
460
+ const switchbot = await this.switchbotBLE()
422
461
  if (switchbot === undefined) {
423
- await this.BLERefreshConnection(switchbot);
462
+ await this.BLERefreshConnection(switchbot)
424
463
  } else {
425
464
  // Start to monitor advertisement packets
426
465
  (async () => {
427
466
  // Start to monitor advertisement packets
428
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as blindTiltServiceData;
467
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as blindTiltServiceData
429
468
  // Update HomeKit
430
469
  if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
431
- this.serviceData = serviceData;
432
- await this.BLEparseStatus();
433
- await this.updateHomeKitCharacteristics();
470
+ this.serviceData = serviceData
471
+ await this.BLEparseStatus()
472
+ await this.updateHomeKitCharacteristics()
434
473
  } else {
435
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
436
- await this.BLERefreshConnection(switchbot);
474
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
475
+ await this.BLERefreshConnection(switchbot)
437
476
  }
438
- })();
477
+ })()
439
478
  }
440
479
  }
441
480
 
442
481
  async registerPlatformBLE(): Promise<void> {
443
- await this.debugLog('registerPlatformBLE');
482
+ await this.debugLog('registerPlatformBLE')
444
483
  if (this.config.options?.BLE) {
445
- await this.debugLog('is listening to Platform BLE.');
446
- this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
447
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
484
+ await this.debugLog('is listening to Platform BLE.')
485
+ this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
486
+ await this.debugLog(`bleMac: ${this.device.bleMac}`)
448
487
  this.platform.bleEventHandler[this.device.bleMac] = async (context: blindTiltServiceData) => {
449
488
  try {
450
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
451
- this.serviceData = context;
452
- await this.BLEparseStatus();
453
- await this.updateHomeKitCharacteristics();
489
+ await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
490
+ this.serviceData = context
491
+ await this.BLEparseStatus()
492
+ await this.updateHomeKitCharacteristics()
454
493
  } catch (e: any) {
455
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
494
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
456
495
  }
457
- };
496
+ }
458
497
  } else {
459
- await this.debugLog('is not listening to Platform BLE');
498
+ await this.debugLog('is not listening to Platform BLE')
460
499
  }
461
500
  }
462
501
 
463
502
  async openAPIRefreshStatus(): Promise<void> {
464
- await this.debugLog('openAPIRefreshStatus');
503
+ await this.debugLog('openAPIRefreshStatus')
465
504
  try {
466
- const { body, statusCode } = await this.deviceRefreshStatus();
467
- const deviceStatus: any = await body.json();
468
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
505
+ const { body, statusCode } = await this.deviceRefreshStatus()
506
+ const deviceStatus: any = await body.json()
507
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
469
508
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
470
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
471
- this.deviceStatus = deviceStatus.body;
472
- await this.openAPIparseStatus();
473
- await this.updateHomeKitCharacteristics();
509
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
510
+ this.deviceStatus = deviceStatus.body
511
+ await this.openAPIparseStatus()
512
+ await this.updateHomeKitCharacteristics()
474
513
  } else {
475
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
476
- await this.debugWarnLog(statusCode, deviceStatus);
514
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
515
+ await this.debugWarnLog(statusCode, deviceStatus)
477
516
  }
478
517
  } catch (e: any) {
479
- await this.apiError(e);
480
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
518
+ await this.apiError(e)
519
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
481
520
  }
482
521
  }
483
522
 
484
523
  async registerWebhook(): Promise<void> {
485
524
  if (this.device.webhook) {
486
- await this.debugLog('is listening webhook.');
525
+ await this.debugLog('is listening webhook.')
487
526
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: blindTiltWebhookContext) => {
488
527
  try {
489
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
490
- this.webhookContext = context;
491
- await this.parseStatusWebhook();
492
- await this.updateHomeKitCharacteristics();
528
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
529
+ this.webhookContext = context
530
+ await this.parseStatusWebhook()
531
+ await this.updateHomeKitCharacteristics()
493
532
  } catch (e: any) {
494
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
533
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
495
534
  }
496
- };
535
+ }
497
536
  } else {
498
- await this.debugLog('is not listening webhook.');
537
+ await this.debugLog('is not listening webhook.')
499
538
  }
500
539
  }
501
540
 
502
541
  async pushChanges(): Promise<void> {
503
542
  if (!this.device.enableCloudService && this.OpenAPI) {
504
- await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
543
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
505
544
  } else if (this.BLE) {
506
- await this.BLEpushChanges();
545
+ await this.BLEpushChanges()
507
546
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
508
- await this.openAPIpushChanges();
547
+ await this.openAPIpushChanges()
509
548
  } else {
510
- await this.offlineOff();
511
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
549
+ await this.offlineOff()
550
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
512
551
  }
513
552
  // Refresh the status from the API
514
553
  interval(15000)
515
554
  .pipe(skipWhile(() => this.blindTiltUpdateInProgress))
516
555
  .pipe(take(1))
517
556
  .subscribe(async () => {
518
- await this.refreshStatus();
519
- });
557
+ await this.refreshStatus()
558
+ })
520
559
  }
521
560
 
522
561
  async BLEpushChanges(): Promise<void> {
523
- await this.debugLog('BLEpushChanges');
562
+ await this.debugLog('BLEpushChanges')
524
563
  if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
525
- await this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`);
526
- const switchbot = await this.platform.connectBLE(this.accessory, this.device);
527
- await this.convertBLEAddress();
528
- const { setPositionMode, Mode }: { setPositionMode: number; Mode: string; } = await this.setPerformance();
529
- await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
564
+ await this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`)
565
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device)
566
+ await this.convertBLEAddress()
567
+ const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
568
+ await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
530
569
  if (switchbot !== false) {
531
570
  switchbot
532
571
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
@@ -534,82 +573,78 @@ export class BlindTilt extends deviceBase {
534
573
  return await this.retryBLE({
535
574
  max: await this.maxRetryBLE(),
536
575
  fn: async () => {
537
- return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode);
576
+ return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode)
538
577
  },
539
- });
578
+ })
540
579
  })
541
580
  .then(async () => {
542
- await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
543
- await this.updateHomeKitCharacteristics();
581
+ await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
582
+ await this.updateHomeKitCharacteristics()
544
583
  })
545
584
  .catch(async (e: any) => {
546
- await this.apiError(e);
547
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
548
- await this.BLEPushConnection();
549
- });
585
+ await this.apiError(e)
586
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
587
+ await this.BLEPushConnection()
588
+ })
550
589
  } else {
551
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
552
- await this.BLEPushConnection();
590
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
591
+ await this.BLEPushConnection()
553
592
  }
554
593
  } else {
555
- await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition},`
556
- + ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
594
+ await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
557
595
  }
558
596
  }
559
597
 
560
598
  async openAPIpushChanges(): Promise<void> {
561
- await this.debugLog('openAPIpushChanges');
562
- const hasDifferentAndRelevantHorizontalTiltAngle =
563
- this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
564
- && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle;
599
+ await this.debugLog('openAPIpushChanges')
600
+ const hasDifferentAndRelevantHorizontalTiltAngle
601
+ = this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
602
+ && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle
565
603
  if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition
566
604
  || hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
567
- const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition),
568
- Number(this.WindowCovering.TargetHorizontalTiltAngle));
569
- const { Mode, setPositionMode }: { setPositionMode: number; Mode: string; } = await this.setPerformance();
570
- await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`);
571
- await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
572
- let bodyChange: string;
605
+ const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition), Number(this.WindowCovering.TargetHorizontalTiltAngle))
606
+ const { Mode, setPositionMode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
607
+ await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`)
608
+ await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
609
+ let bodyChange: string
573
610
  if (position === 100) {
574
611
  bodyChange = JSON.stringify({
575
612
  command: 'fullyOpen',
576
613
  parameter: 'default',
577
614
  commandType: 'command',
578
- });
615
+ })
579
616
  } else if (position === 0) {
580
617
  bodyChange = JSON.stringify({
581
618
  command: direction === 'up' ? 'closeUp' : 'closeDown',
582
619
  parameter: 'default',
583
620
  commandType: 'command',
584
- });
621
+ })
585
622
  } else {
586
623
  bodyChange = JSON.stringify({
587
624
  command: 'setPosition',
588
625
  parameter: `${direction};${position}`,
589
626
  commandType: 'command',
590
- });
627
+ })
591
628
  }
592
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
629
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
593
630
  try {
594
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
595
- const deviceStatus: any = await body.json();
596
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
631
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
632
+ const deviceStatus: any = await body.json()
633
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
597
634
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
598
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
599
- await this.updateHomeKitCharacteristics();
635
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
636
+ await this.updateHomeKitCharacteristics()
600
637
  } else {
601
- await this.statusCode(statusCode);
602
- await this.statusCode(deviceStatus.statusCode);
638
+ await this.statusCode(statusCode)
639
+ await this.statusCode(deviceStatus.statusCode)
603
640
  }
604
641
  } catch (e: any) {
605
- await this.apiError(e);
606
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
642
+ await this.apiError(e)
643
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
607
644
  }
608
645
  } else {
609
- await this.debugLog(`No changes (openAPIpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition},`
610
- + ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
611
- await this.debugLog(`No changes (openAPIpushChanges), TargetHorizontalTiltAngle: ${this.WindowCovering.TargetHorizontalTiltAngle},`
612
- + ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
646
+ await this.debugLog(`No changes (openAPIpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
647
+ await this.debugLog(`No changes (openAPIpushChanges), TargetHorizontalTiltAngle: ${this.WindowCovering.TargetHorizontalTiltAngle}, CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`)
613
648
  }
614
649
  }
615
650
 
@@ -618,15 +653,15 @@ export class BlindTilt extends deviceBase {
618
653
  */
619
654
  async TargetHorizontalTiltAngleSet(value: CharacteristicValue): Promise<void> {
620
655
  if (this.WindowCovering.TargetHorizontalTiltAngle !== this.accessory.context.TargetHorizontalTiltAngle) {
621
- await this.debugLog(`Set TargetHorizontalTiltAngle: ${value}`);
656
+ await this.debugLog(`Set TargetHorizontalTiltAngle: ${value}`)
622
657
  } else {
623
- await this.debugLog(`No changes, TargetHorizontalTiltAngle: ${value}`);
658
+ await this.debugLog(`No changes, TargetHorizontalTiltAngle: ${value}`)
624
659
  }
625
660
 
626
- //value = value < 0 ? -90 : 90;
627
- this.WindowCovering.TargetHorizontalTiltAngle = value;
628
- await this.mqtt('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle);
629
- await this.startUpdatingBlindTiltIfNeeded();
661
+ // value = value < 0 ? -90 : 90;
662
+ this.WindowCovering.TargetHorizontalTiltAngle = value
663
+ await this.mqtt('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle)
664
+ await this.startUpdatingBlindTiltIfNeeded()
630
665
  }
631
666
 
632
667
  /**
@@ -634,172 +669,188 @@ export class BlindTilt extends deviceBase {
634
669
  */
635
670
  async TargetPositionSet(value: CharacteristicValue): Promise<void> {
636
671
  if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
637
- await this.debugLog(`Set TargetPosition: ${value}`);
672
+ await this.debugLog(`Set TargetPosition: ${value}`)
638
673
  } else {
639
- await this.debugLog(`No changes, TargetPosition: ${value}`);
674
+ await this.debugLog(`No changes, TargetPosition: ${value}`)
640
675
  }
641
676
 
642
- this.WindowCovering.TargetPosition = value;
643
- await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
644
- await this.startUpdatingBlindTiltIfNeeded();
677
+ this.WindowCovering.TargetPosition = value
678
+ await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition)
679
+ await this.startUpdatingBlindTiltIfNeeded()
645
680
  }
646
681
 
647
682
  async startUpdatingBlindTiltIfNeeded(): Promise<void> {
648
- await this.setMinMax();
649
- await this.debugLog('setMinMax');
683
+ await this.setMinMax()
684
+ await this.debugLog('setMinMax')
650
685
  if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
651
686
  || this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
652
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
653
- this.setNewTarget = true;
654
- await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
687
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
688
+ this.setNewTarget = true
689
+ await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
655
690
  } else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
656
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
657
- this.setNewTarget = true;
658
- await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
691
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
692
+ this.setNewTarget = true
693
+ await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
659
694
  } else {
660
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
661
- this.setNewTarget = false;
662
- await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
695
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
696
+ this.setNewTarget = false
697
+ await this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
663
698
  }
664
- this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
665
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
699
+ this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
700
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
666
701
 
667
702
  /**
668
703
  * If Blind Tilt movement time is short, the moving flag from backend is always false.
669
704
  * The minimum time depends on the network control latency.
670
705
  */
671
- clearTimeout(this.setNewTargetTimer);
672
- await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
706
+ clearTimeout(this.setNewTargetTimer)
707
+ await this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
673
708
  if (this.setNewTarget) {
674
709
  this.setNewTargetTimer = setTimeout(async () => {
675
- await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
676
- this.setNewTarget = false;
677
- }, this.deviceUpdateRate * 1000);
710
+ await this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
711
+ this.setNewTarget = false
712
+ }, this.deviceUpdateRate * 1000)
713
+ }
714
+ this.doBlindTiltUpdate.next()
715
+ }
716
+
717
+ /**
718
+ * Handle requests to set the value of the "Target Position" characteristic
719
+ */
720
+ async OpenModeSwitchSet(value: CharacteristicValue): Promise<void> {
721
+ if (this.OpenModeSwitch && this.device.blindTilt?.silentModeSwitch) {
722
+ this.debugLog(`Silent Open Mode: ${value}`)
723
+ this.OpenModeSwitch.On = value
724
+ this.accessory.context.OpenModeSwitch.On = value
725
+ this.doBlindTiltUpdate.next()
726
+ }
727
+ }
728
+
729
+ /**
730
+ * Handle requests to set the value of the "Target Position" characteristic
731
+ */
732
+ async CloseModeSwitchSet(value: CharacteristicValue): Promise<void> {
733
+ if (this.CloseModeSwitch && this.device.blindTilt?.silentModeSwitch) {
734
+ this.debugLog(`Silent Close Mode: ${value}`)
735
+ this.CloseModeSwitch.On = value
736
+ this.accessory.context.CloseModeSwitch.On = value
737
+ this.doBlindTiltUpdate.next()
678
738
  }
679
- this.doBlindTiltUpdate.next();
680
739
  }
681
740
 
682
741
  async updateHomeKitCharacteristics(): Promise<void> {
683
- await this.setMinMax();
742
+ await this.setMinMax()
684
743
  // CurrentHorizontalTiltAngle
685
744
  if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
686
- await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentHorizontalTiltAngle,
687
- this.WindowCovering.CurrentHorizontalTiltAngle, 'CurrentHorizontalTiltAngle');
745
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentHorizontalTiltAngle, this.WindowCovering.CurrentHorizontalTiltAngle, 'CurrentHorizontalTiltAngle')
688
746
  }
689
747
  // CurrentPosition
690
- await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition,
691
- this.WindowCovering.CurrentPosition, 'CurrentPosition');
748
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition, this.WindowCovering.CurrentPosition, 'CurrentPosition')
692
749
  // PositionState
693
- await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState,
694
- this.WindowCovering.PositionState, 'PositionState');
750
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState, this.WindowCovering.PositionState, 'PositionState')
695
751
  // TargetPosition
696
- await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition,
697
- this.WindowCovering.TargetPosition, 'TargetPosition');
752
+ await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition, this.WindowCovering.TargetPosition, 'TargetPosition')
698
753
  // CurrentAmbientLightLevel
699
754
  if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
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,
702
- this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
755
+ const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel }
756
+ await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history)
703
757
  }
704
758
  // BatteryLevel
705
- await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
706
- this.Battery.BatteryLevel, 'BatteryLevel');
759
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel')
707
760
  // StatusLowBattery
708
- await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
709
- this.Battery.StatusLowBattery, 'StatusLowBattery');
761
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery')
710
762
  // ChargingState
711
- await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
712
- this.Battery.ChargingState, 'ChargingState');
763
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState')
713
764
  }
714
765
 
715
766
  async BLEPushConnection() {
716
767
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
717
- await this.warnLog('Using OpenAPI Connection to Push Changes');
718
- await this.openAPIpushChanges();
768
+ await this.warnLog('Using OpenAPI Connection to Push Changes')
769
+ await this.openAPIpushChanges()
719
770
  }
720
771
  }
721
772
 
722
773
  async BLERefreshConnection(switchbot: any): Promise<void> {
723
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
774
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
724
775
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
725
- await this.warnLog('Using OpenAPI Connection to Refresh Status');
726
- await this.openAPIRefreshStatus();
776
+ await this.warnLog('Using OpenAPI Connection to Refresh Status')
777
+ await this.openAPIRefreshStatus()
727
778
  }
728
779
  }
729
780
 
730
781
  async setPerformance() {
731
- let setPositionMode: number;
732
- let Mode: string;
782
+ let setPositionMode: number
783
+ let Mode: string
733
784
  if (Number(this.WindowCovering.TargetPosition) > 50) {
734
- if (this.device.blindTilt?.setOpenMode === '1') {
735
- setPositionMode = 1;
736
- Mode = 'Silent Mode';
737
- } else if (this.device.blindTilt?.setOpenMode === '0') {
738
- setPositionMode = 0;
739
- Mode = 'Performance Mode';
785
+ if (this.device.blindTilt?.setOpenMode === '1' || this.OpenModeSwitch?.On) {
786
+ setPositionMode = 1
787
+ Mode = 'Silent Mode'
788
+ } else if (this.device.blindTilt?.setOpenMode === '0' || !this.OpenModeSwitch?.On) {
789
+ setPositionMode = 0
790
+ Mode = 'Performance Mode'
740
791
  } else {
741
- setPositionMode = 0;
742
- Mode = 'Default Mode';
792
+ setPositionMode = 0
793
+ Mode = 'Default Mode'
743
794
  }
744
795
  } else {
745
- if (this.device.blindTilt?.setCloseMode === '1') {
746
- setPositionMode = 1;
747
- Mode = 'Silent Mode';
748
- } else if (this.device.blindTilt?.setOpenMode === '0') {
749
- setPositionMode = 0;
750
- Mode = 'Performance Mode';
796
+ if (this.device.blindTilt?.setCloseMode === '1' || this.CloseModeSwitch?.On) {
797
+ setPositionMode = 1
798
+ Mode = 'Silent Mode'
799
+ } else if (this.device.blindTilt?.setOpenMode === '0' || !this.CloseModeSwitch?.On) {
800
+ setPositionMode = 0
801
+ Mode = 'Performance Mode'
751
802
  } else {
752
- setPositionMode = 0;
753
- Mode = 'Default Mode';
803
+ setPositionMode = 0
804
+ Mode = 'Default Mode'
754
805
  }
755
806
  }
756
- return { setPositionMode, Mode };
807
+ return { setPositionMode, Mode }
757
808
  }
758
809
 
759
810
  async setMinMax(): Promise<void> {
760
811
  if (this.device.blindTilt?.set_min) {
761
812
  if (Number(this.WindowCovering.CurrentPosition) <= this.device.blindTilt?.set_min) {
762
- this.WindowCovering.CurrentPosition = 0;
813
+ this.WindowCovering.CurrentPosition = 0
763
814
  }
764
815
  }
765
816
  if (this.device.blindTilt?.set_max) {
766
817
  if (Number(this.WindowCovering.CurrentPosition) >= this.device.blindTilt?.set_max) {
767
- this.WindowCovering.CurrentPosition = 100;
818
+ this.WindowCovering.CurrentPosition = 100
768
819
  }
769
820
  }
770
821
  if (this.device.history) {
771
- const motion = this.accessory.getService(this.hap.Service.MotionSensor);
772
- const state = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0;
773
- motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state);
822
+ const motion = this.accessory.getService(this.hap.Service.MotionSensor)
823
+ const state = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
824
+ motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state)
774
825
  }
775
826
 
776
827
  if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
777
- this.WindowCovering.CurrentHorizontalTiltAngle = Number(this.WindowCovering.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
828
+ this.WindowCovering.CurrentHorizontalTiltAngle = Number(this.WindowCovering.CurrentHorizontalTiltAngle) < 0 ? -90 : 90
778
829
  }
779
830
  }
780
831
 
781
832
  async offlineOff(): Promise<void> {
782
833
  if (this.device.offline) {
783
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
784
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
785
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
786
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, 90);
787
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, 90);
834
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
835
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
836
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
837
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, 90)
838
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, 90)
788
839
  }
789
840
  }
790
841
 
791
842
  async apiError(e: any): Promise<void> {
792
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
793
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
794
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
795
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, e);
796
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, e);
797
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
798
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
799
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e);
843
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
844
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
845
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
846
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, e)
847
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, e)
848
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
849
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
850
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e)
800
851
  if (!this.device.blindTilt?.hide_lightsensor && this.LightSensor?.Service) {
801
- this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
802
- this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
852
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
853
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
803
854
  }
804
855
  }
805
856
 
@@ -807,60 +858,58 @@ export class BlindTilt extends deviceBase {
807
858
  direction: blindTiltStatus['direction'] | blindTiltWebhookContext['direction'],
808
859
  slidePosition: blindTiltStatus['slidePosition'] | blindTiltWebhookContext['slidePosition'],
809
860
  ) {
810
- const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(slidePosition),
811
- String(direction));
812
- await this.debugLog(`Slide Position: ${slidePosition}`);
813
- await this.debugLog(`Homekit Position: ${homekitPosition}`);
861
+ const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(slidePosition), String(direction))
862
+ await this.debugLog(`Slide Position: ${slidePosition}`)
863
+ await this.debugLog(`Homekit Position: ${homekitPosition}`)
814
864
 
815
- this.WindowCovering.CurrentPosition = homekitPosition;
816
- await this.setMinMax();
817
- await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
865
+ this.WindowCovering.CurrentPosition = homekitPosition
866
+ await this.setMinMax()
867
+ await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
818
868
 
819
869
  if (homekitTiltAngle) {
820
- this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle!;
821
- await this.debugLog(`CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
870
+ this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle!
871
+ await this.debugLog(`CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`)
822
872
  }
823
873
 
824
874
  if (this.setNewTarget) {
825
- this.blindTiltMoving = true;
826
- await this.infoLog('Checking Status ...');
827
- await this.setMinMax();
875
+ this.blindTiltMoving = true
876
+ await this.infoLog('Checking Status ...')
877
+ await this.setMinMax()
828
878
  if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
829
879
  || (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
830
- await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
831
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
832
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
833
- await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
880
+ await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
881
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
882
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
883
+ await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
834
884
  } else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
835
- await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
836
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
837
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
838
- await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
885
+ await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
886
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
887
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
888
+ await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
839
889
  } else {
840
- await this.debugLog(`Standby because reached position, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
841
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
842
- this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
843
- await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
890
+ await this.debugLog(`Standby because reached position, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
891
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
892
+ this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
893
+ await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
844
894
  }
845
895
  } else {
846
- this.blindTiltMoving = false;
847
- await this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
848
- this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
896
+ this.blindTiltMoving = false
897
+ await this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
898
+ this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
849
899
  if (homekitTiltAngle) {
850
- this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
900
+ this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle
851
901
  }
852
- this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
853
- await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
902
+ this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
903
+ await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
854
904
  }
855
- await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition},`
856
- + ` PositionState: ${this.WindowCovering.PositionState}`);
905
+ await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`)
857
906
  }
858
907
 
859
908
  /**
860
909
  * Maps device values to homekit values
861
910
  *
862
911
  * @param devicePosition the position as reported by the devide
863
- * @param direction the direction as reported by the device
912
+ * @param deviceDirection the direction as reported by the device
864
913
  * @returns [homekit position, homekit tiltAngle]
865
914
  */
866
915
  mapDeviceValuesToHomekitValues(devicePosition: number, deviceDirection: string): [CharacteristicValue, CharacteristicValue?] {
@@ -870,44 +919,44 @@ export class BlindTilt extends deviceBase {
870
919
 
871
920
  // homekit position 0 => closed
872
921
  // homekit position 100 => open
873
- const direction = deviceDirection === 'up' ? 'up' : 'down';
874
- this.debugLog(`Mapping device values to homekit values, devicePostion: ${devicePosition}, deviceDirection: ${direction}`);
922
+ const direction = deviceDirection === 'up' ? 'up' : 'down'
923
+ this.debugLog(`Mapping device values to homekit values, devicePostion: ${devicePosition}, deviceDirection: ${direction}`)
875
924
  switch (this.mappingMode) {
876
925
  case BlindTiltMappingMode.OnlyUp:
877
926
  // we only close upwards, so we see anything that is tilted downwards(<50) as open
878
927
  if (devicePosition < 50) {
879
- return [100, undefined]; // fully open in homekit
928
+ return [100, undefined] // fully open in homekit
880
929
  } else {
881
930
  // we range from 50->100, with 100 being closed, so map to homekit by scaling to 0..100 and then reversing
882
- return [100 - (devicePosition - 50) * 2, undefined];
931
+ return [100 - (devicePosition - 50) * 2, undefined]
883
932
  }
884
933
 
885
934
  case BlindTiltMappingMode.OnlyDown:
886
935
  // we only close downwards, so we see anything that is tilted upwards(>50) as upwards
887
936
  if (devicePosition > 50) {
888
- return [100, undefined]; // fully open in homekit
937
+ return [100, undefined] // fully open in homekit
889
938
  } else {
890
939
  // we range from 0..50 so scale to homekit and then reverse
891
- return [devicePosition * 2, undefined];
940
+ return [devicePosition * 2, undefined]
892
941
  }
893
942
 
894
943
  case BlindTiltMappingMode.DownAndUp:
895
944
  // we close both ways with closed downwards being 0 in homekit and closed upwards in homekit being 100. Open is 50 in homekit
896
- return [devicePosition, undefined];
945
+ return [devicePosition, undefined]
897
946
 
898
947
  case BlindTiltMappingMode.UpAndDown:
899
948
  // we close both ways with closed downwards being 1000 in homekit and closed upwards in homekit being 0. Open is 50 in homekit.,
900
949
  // so we reverse the value
901
- return [100 - devicePosition, undefined];
950
+ return [100 - devicePosition, undefined]
902
951
 
903
952
  case BlindTiltMappingMode.UseTiltForDirection:
904
953
  // we use tilt for direction, so being closed downwards is 0 in homekit with -90 tilt, while being closed upwards is 0 with 90 tilt.
905
954
  if (devicePosition <= 50) {
906
955
  // downwards tilted, so we range from 0..50, with 0 being closed and 50 being open, so scale.
907
- return [devicePosition * 2, -90];
956
+ return [devicePosition * 2, -90]
908
957
  } else {
909
958
  // upwards tilted, so we range from 50..100, with 50 being open and 100 being closed, so scale and rever
910
- return [100 - (devicePosition - 50) * 2, 90];
959
+ return [100 - (devicePosition - 50) * 2, 90]
911
960
  }
912
961
  }
913
962
  }
@@ -916,7 +965,7 @@ export class BlindTilt extends deviceBase {
916
965
  * Maps homekit values to device values
917
966
  *
918
967
  * @param homekitPosition the position as reported by homekit
919
- * @param homekitTiltAngle? the tilt angle as reported by homekit
968
+ * @param homekitTiltAngle the tilt angle as reported by homekit
920
969
  * @returns [device position, device direction]
921
970
  */
922
971
  mapHomekitValuesToDeviceValues(homekitPosition: number, homekitTiltAngle: number): [string, number] {
@@ -931,10 +980,10 @@ export class BlindTilt extends deviceBase {
931
980
  switch (this.mappingMode) {
932
981
  case BlindTiltMappingMode.OnlyUp:
933
982
  // invert
934
- return ['up', homekitPosition];
983
+ return ['up', homekitPosition]
935
984
  case BlindTiltMappingMode.OnlyDown:
936
985
  // invert
937
- return ['down', homekitPosition];
986
+ return ['down', homekitPosition]
938
987
 
939
988
  case BlindTiltMappingMode.DownAndUp:
940
989
  // homekit 0 = downwards closed,
@@ -942,10 +991,10 @@ export class BlindTilt extends deviceBase {
942
991
  // homekit 100 = upwards closed
943
992
  if (homekitPosition <= 50) {
944
993
  // homekit 0..50 -> device 100..0 so scale and invert
945
- return ['down', 100 - homekitPosition * 2];
994
+ return ['down', 100 - homekitPosition * 2]
946
995
  } else {
947
996
  // homekit 50..100 -> device 0..100, so rebase, scale and invert
948
- return ['up', (homekitPosition - 50) * 2];
997
+ return ['up', (homekitPosition - 50) * 2]
949
998
  }
950
999
 
951
1000
  case BlindTiltMappingMode.UpAndDown:
@@ -954,10 +1003,10 @@ export class BlindTilt extends deviceBase {
954
1003
  // homekit 100 = upwards closed
955
1004
  if (homekitPosition <= 50) {
956
1005
  // homekit 0..50 -> device 0..100 so scale and invert
957
- return ['up', homekitPosition * 2];
1006
+ return ['up', homekitPosition * 2]
958
1007
  } else {
959
1008
  // homekit 50..100 -> device 100...0 so scale
960
- return ['down', 100 - homekitPosition * 2];
1009
+ return ['down', 100 - homekitPosition * 2]
961
1010
  }
962
1011
 
963
1012
  case BlindTiltMappingMode.UseTiltForDirection:
@@ -968,11 +1017,11 @@ export class BlindTilt extends deviceBase {
968
1017
  if (homekitTiltAngle! <= 0) {
969
1018
  // downwards
970
1019
  // homekit 0..100 -> device 0..100, so invert
971
- return ['down', homekitPosition];
1020
+ return ['down', homekitPosition]
972
1021
  } else {
973
1022
  // upwards
974
1023
  // homekit 0..100 -> device 0..100, so invert
975
- return ['up', homekitPosition];
1024
+ return ['up', homekitPosition]
976
1025
  }
977
1026
  }
978
1027
  }