@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-beta.21

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 (199) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +14 -0
  3. package/assets/security-privacy-bluetooth.png +0 -0
  4. package/config.schema.json +74 -2
  5. package/dist/device/blindtilt.d.ts +21 -9
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +167 -96
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot-old.d.ts +132 -0
  10. package/dist/device/bot-old.d.ts.map +1 -0
  11. package/dist/device/bot-old.js +1482 -0
  12. package/dist/device/bot-old.js.map +1 -0
  13. package/dist/device/bot.d.ts +10 -9
  14. package/dist/device/bot.d.ts.map +1 -1
  15. package/dist/device/bot.js +186 -187
  16. package/dist/device/bot.js.map +1 -1
  17. package/dist/device/ceilinglight.d.ts +14 -13
  18. package/dist/device/ceilinglight.d.ts.map +1 -1
  19. package/dist/device/ceilinglight.js +87 -97
  20. package/dist/device/ceilinglight.js.map +1 -1
  21. package/dist/device/colorbulb.d.ts +13 -12
  22. package/dist/device/colorbulb.d.ts.map +1 -1
  23. package/dist/device/colorbulb.js +92 -105
  24. package/dist/device/colorbulb.js.map +1 -1
  25. package/dist/device/contact.d.ts +6 -5
  26. package/dist/device/contact.d.ts.map +1 -1
  27. package/dist/device/contact.js +71 -68
  28. package/dist/device/contact.js.map +1 -1
  29. package/dist/device/curtain.d.ts +17 -5
  30. package/dist/device/curtain.d.ts.map +1 -1
  31. package/dist/device/curtain.js +184 -118
  32. package/dist/device/curtain.js.map +1 -1
  33. package/dist/device/device.d.ts +18 -18
  34. package/dist/device/device.d.ts.map +1 -1
  35. package/dist/device/device.js +33 -36
  36. package/dist/device/device.js.map +1 -1
  37. package/dist/device/fan.d.ts +9 -8
  38. package/dist/device/fan.d.ts.map +1 -1
  39. package/dist/device/fan.js +94 -101
  40. package/dist/device/fan.js.map +1 -1
  41. package/dist/device/hub.d.ts +6 -5
  42. package/dist/device/hub.d.ts.map +1 -1
  43. package/dist/device/hub.js +69 -65
  44. package/dist/device/hub.js.map +1 -1
  45. package/dist/device/humidifier.d.ts +6 -5
  46. package/dist/device/humidifier.d.ts.map +1 -1
  47. package/dist/device/humidifier.js +89 -104
  48. package/dist/device/humidifier.js.map +1 -1
  49. package/dist/device/iosensor.d.ts +6 -5
  50. package/dist/device/iosensor.d.ts.map +1 -1
  51. package/dist/device/iosensor.js +72 -66
  52. package/dist/device/iosensor.js.map +1 -1
  53. package/dist/device/lightstrip.d.ts +7 -6
  54. package/dist/device/lightstrip.d.ts.map +1 -1
  55. package/dist/device/lightstrip.js +85 -99
  56. package/dist/device/lightstrip.js.map +1 -1
  57. package/dist/device/lock.d.ts +10 -9
  58. package/dist/device/lock.d.ts.map +1 -1
  59. package/dist/device/lock.js +89 -79
  60. package/dist/device/lock.js.map +1 -1
  61. package/dist/device/meter.d.ts +6 -5
  62. package/dist/device/meter.d.ts.map +1 -1
  63. package/dist/device/meter.js +72 -65
  64. package/dist/device/meter.js.map +1 -1
  65. package/dist/device/meterplus.d.ts +6 -5
  66. package/dist/device/meterplus.d.ts.map +1 -1
  67. package/dist/device/meterplus.js +72 -64
  68. package/dist/device/meterplus.js.map +1 -1
  69. package/dist/device/motion.d.ts +6 -5
  70. package/dist/device/motion.d.ts.map +1 -1
  71. package/dist/device/motion.js +65 -58
  72. package/dist/device/motion.js.map +1 -1
  73. package/dist/device/plug.d.ts +13 -12
  74. package/dist/device/plug.d.ts.map +1 -1
  75. package/dist/device/plug.js +68 -52
  76. package/dist/device/plug.js.map +1 -1
  77. package/dist/device/robotvacuumcleaner.d.ts +12 -11
  78. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  79. package/dist/device/robotvacuumcleaner.js +93 -82
  80. package/dist/device/robotvacuumcleaner.js.map +1 -1
  81. package/dist/device/waterdetector.d.ts +6 -5
  82. package/dist/device/waterdetector.d.ts.map +1 -1
  83. package/dist/device/waterdetector.js +73 -63
  84. package/dist/device/waterdetector.js.map +1 -1
  85. package/dist/homebridge-ui/server.js +2 -2
  86. package/dist/homebridge-ui/server.js.map +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +0 -4
  89. package/dist/index.js.map +1 -1
  90. package/dist/irdevice/airconditioner.d.ts +8 -8
  91. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  92. package/dist/irdevice/airconditioner.js +61 -105
  93. package/dist/irdevice/airconditioner.js.map +1 -1
  94. package/dist/irdevice/airpurifier.d.ts +10 -10
  95. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  96. package/dist/irdevice/airpurifier.js +22 -42
  97. package/dist/irdevice/airpurifier.js.map +1 -1
  98. package/dist/irdevice/camera.d.ts +9 -9
  99. package/dist/irdevice/camera.d.ts.map +1 -1
  100. package/dist/irdevice/camera.js +15 -25
  101. package/dist/irdevice/camera.js.map +1 -1
  102. package/dist/irdevice/fan.d.ts +8 -8
  103. package/dist/irdevice/fan.d.ts.map +1 -1
  104. package/dist/irdevice/fan.js +21 -40
  105. package/dist/irdevice/fan.js.map +1 -1
  106. package/dist/irdevice/irdevice.d.ts +11 -11
  107. package/dist/irdevice/irdevice.d.ts.map +1 -1
  108. package/dist/irdevice/irdevice.js +14 -22
  109. package/dist/irdevice/irdevice.js.map +1 -1
  110. package/dist/irdevice/light.d.ts +9 -9
  111. package/dist/irdevice/light.d.ts.map +1 -1
  112. package/dist/irdevice/light.js +24 -47
  113. package/dist/irdevice/light.js.map +1 -1
  114. package/dist/irdevice/other.d.ts +9 -9
  115. package/dist/irdevice/other.d.ts.map +1 -1
  116. package/dist/irdevice/other.js +40 -83
  117. package/dist/irdevice/other.js.map +1 -1
  118. package/dist/irdevice/tv.d.ts +9 -9
  119. package/dist/irdevice/tv.d.ts.map +1 -1
  120. package/dist/irdevice/tv.js +29 -54
  121. package/dist/irdevice/tv.js.map +1 -1
  122. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  123. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  124. package/dist/irdevice/vacuumcleaner.js +11 -21
  125. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  126. package/dist/irdevice/waterheater.d.ts +5 -5
  127. package/dist/irdevice/waterheater.d.ts.map +1 -1
  128. package/dist/irdevice/waterheater.js +11 -22
  129. package/dist/irdevice/waterheater.js.map +1 -1
  130. package/dist/platform.d.ts +24 -23
  131. package/dist/platform.d.ts.map +1 -1
  132. package/dist/platform.js +509 -723
  133. package/dist/platform.js.map +1 -1
  134. package/dist/settings.d.ts +5 -2
  135. package/dist/settings.d.ts.map +1 -1
  136. package/dist/settings.js.map +1 -1
  137. package/dist/types/bledevicestatus.d.ts +9 -9
  138. package/dist/types/bledevicestatus.d.ts.map +1 -1
  139. package/dist/types/devicelist.d.ts +6 -6
  140. package/dist/types/devicelist.d.ts.map +1 -1
  141. package/dist/types/deviceresponse.d.ts +4 -4
  142. package/dist/types/deviceresponse.d.ts.map +1 -1
  143. package/dist/types/devicestatus.d.ts +2 -2
  144. package/dist/types/devicestatus.d.ts.map +1 -1
  145. package/dist/types/devicewebhookstatus.d.ts +5 -5
  146. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  147. package/dist/types/irdevicelist.d.ts +4 -4
  148. package/dist/types/irdevicelist.d.ts.map +1 -1
  149. package/dist/types/pushbody.d.ts +2 -2
  150. package/dist/types/pushbody.d.ts.map +1 -1
  151. package/dist/utils.d.ts +4 -4
  152. package/dist/utils.d.ts.map +1 -1
  153. package/dist/utils.js +9 -13
  154. package/dist/utils.js.map +1 -1
  155. package/eslint.config.js +48 -93
  156. package/package.json +64 -57
  157. package/src/device/blindtilt.ts +537 -456
  158. package/src/device/bot-old.ts +1540 -0
  159. package/src/device/bot.ts +732 -725
  160. package/src/device/ceilinglight.ts +359 -368
  161. package/src/device/colorbulb.ts +441 -453
  162. package/src/device/contact.ts +229 -226
  163. package/src/device/curtain.ts +526 -444
  164. package/src/device/device.ts +206 -208
  165. package/src/device/fan.ts +336 -345
  166. package/src/device/hub.ts +213 -214
  167. package/src/device/humidifier.ts +326 -347
  168. package/src/device/iosensor.ts +211 -209
  169. package/src/device/lightstrip.ts +391 -404
  170. package/src/device/lock.ts +292 -282
  171. package/src/device/meter.ts +212 -210
  172. package/src/device/meterplus.ts +212 -209
  173. package/src/device/motion.ts +198 -190
  174. package/src/device/plug.ts +203 -182
  175. package/src/device/robotvacuumcleaner.ts +280 -269
  176. package/src/device/waterdetector.ts +198 -189
  177. package/src/homebridge-ui/server.ts +16 -15
  178. package/src/index.ts +5 -6
  179. package/src/irdevice/airconditioner.ts +277 -326
  180. package/src/irdevice/airpurifier.ts +124 -143
  181. package/src/irdevice/camera.ts +58 -64
  182. package/src/irdevice/fan.ts +106 -123
  183. package/src/irdevice/irdevice.ts +116 -119
  184. package/src/irdevice/light.ts +119 -143
  185. package/src/irdevice/other.ts +417 -461
  186. package/src/irdevice/tv.ts +155 -177
  187. package/src/irdevice/vacuumcleaner.ts +54 -60
  188. package/src/irdevice/waterheater.ts +56 -63
  189. package/src/platform.ts +1491 -1681
  190. package/src/settings.ts +172 -169
  191. package/src/types/bledevicestatus.ts +252 -256
  192. package/src/types/devicelist.ts +79 -79
  193. package/src/types/deviceresponse.ts +12 -13
  194. package/src/types/devicestatus.ts +124 -124
  195. package/src/types/devicewebhookstatus.ts +126 -131
  196. package/src/types/irdevicelist.ts +10 -10
  197. package/src/types/pushbody.ts +5 -5
  198. package/src/utils.ts +64 -65
  199. package/tsconfig.json +10 -9
@@ -2,18 +2,24 @@
2
2
  *
3
3
  * lightstrip.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { deviceBase } from './device.js';
6
- import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
7
- import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
8
- import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
9
-
10
- import type { devicesConfig } from '../settings.js';
11
- import type { device } from '../types/devicelist.js';
12
- import type { SwitchBotPlatform } from '../platform.js';
13
- import type { stripLightStatus } from '../types/devicestatus.js';
14
- import type { stripLightServiceData } from '../types/bledevicestatus.js';
15
- import type { stripLightWebhookContext } from '../types/devicewebhookstatus.js';
16
- import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
5
+ import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
6
+
7
+ import type { SwitchBotPlatform } from '../platform.js'
8
+ import type { devicesConfig } from '../settings.js'
9
+ import type { stripLightServiceData } from '../types/bledevicestatus.js'
10
+ import type { device } from '../types/devicelist.js'
11
+ import type { stripLightStatus } from '../types/devicestatus.js'
12
+ import type { stripLightWebhookContext } from '../types/devicewebhookstatus.js'
13
+
14
+ /*
15
+ * For Testing Locally:
16
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
17
+ */
18
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
19
+ import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
20
+
21
+ import { hs2rgb, m2hs, rgb2hs } from '../utils.js'
22
+ import { deviceBase } from './device.js'
17
23
 
18
24
  /**
19
25
  * Platform Accessory
@@ -23,51 +29,51 @@ import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstru
23
29
  export class StripLight extends deviceBase {
24
30
  // Services
25
31
  private LightBulb: {
26
- Name: CharacteristicValue;
27
- Service: Service;
28
- On: CharacteristicValue;
29
- Hue: CharacteristicValue;
30
- Saturation: CharacteristicValue;
31
- Brightness: CharacteristicValue;
32
- ColorTemperature?: CharacteristicValue;
33
- };
32
+ Name: CharacteristicValue
33
+ Service: Service
34
+ On: CharacteristicValue
35
+ Hue: CharacteristicValue
36
+ Saturation: CharacteristicValue
37
+ Brightness: CharacteristicValue
38
+ ColorTemperature?: CharacteristicValue
39
+ }
34
40
 
35
41
  // OpenAPI
36
- deviceStatus!: stripLightStatus;
42
+ deviceStatus!: stripLightStatus
37
43
 
38
- //Webhook
39
- webhookContext!: stripLightWebhookContext;
44
+ // Webhook
45
+ webhookContext!: stripLightWebhookContext
40
46
 
41
47
  // BLE
42
- serviceData!: stripLightServiceData;
48
+ serviceData!: stripLightServiceData
43
49
 
44
50
  // Adaptive Lighting
45
- adaptiveLighting!: boolean;
46
- adaptiveLightingShift!: number;
47
- AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
51
+ adaptiveLighting!: boolean
52
+ adaptiveLightingShift!: number
53
+ AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>
48
54
 
49
55
  // Updates
50
- stripLightUpdateInProgress!: boolean;
51
- doStripLightUpdate!: Subject<void>;
56
+ stripLightUpdateInProgress!: boolean
57
+ doStripLightUpdate!: Subject<void>
52
58
 
53
59
  constructor(
54
60
  readonly platform: SwitchBotPlatform,
55
61
  accessory: PlatformAccessory,
56
62
  device: device & devicesConfig,
57
63
  ) {
58
- super(platform, accessory, device);
64
+ super(platform, accessory, device)
59
65
  // Set category
60
- accessory.category = this.hap.Categories.LIGHTBULB;
66
+ accessory.category = this.hap.Categories.LIGHTBULB
61
67
 
62
68
  // Adaptive Lighting
63
- this.getAdaptiveLightingSettings(accessory, device);
69
+ this.getAdaptiveLightingSettings(accessory, device)
64
70
 
65
71
  // this is subject we use to track when we need to POST changes to the SwitchBot API
66
- this.doStripLightUpdate = new Subject();
67
- this.stripLightUpdateInProgress = false;
72
+ this.doStripLightUpdate = new Subject()
73
+ this.stripLightUpdateInProgress = false
68
74
 
69
75
  // Initialize the LightBulb Service
70
- accessory.context.LightBulb = accessory.context.LightBulb ?? {};
76
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {}
71
77
  this.LightBulb = {
72
78
  Name: accessory.displayName,
73
79
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
@@ -76,226 +82,216 @@ export class StripLight extends deviceBase {
76
82
  Saturation: accessory.context.Saturation ?? 0,
77
83
  Brightness: accessory.context.Brightness ?? 0,
78
84
  ColorTemperature: accessory.context.ColorTemperature ?? 140,
79
- };
80
- accessory.context.LightBulb = this.LightBulb as object;
85
+ }
86
+ accessory.context.LightBulb = this.LightBulb as object
81
87
 
82
88
  if (this.adaptiveLighting && this.adaptiveLightingShift === -1 && this.LightBulb) {
83
- accessory.removeService(this.LightBulb.Service);
84
- this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
85
- accessory.context.adaptiveLighting = false;
86
- this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
89
+ accessory.removeService(this.LightBulb.Service)
90
+ this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb)
91
+ accessory.context.adaptiveLighting = false
92
+ this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
87
93
  } else if (this.adaptiveLighting && this.adaptiveLightingShift >= 0 && this.LightBulb) {
88
94
  this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
89
95
  controllerMode: this.hap.AdaptiveLightingControllerMode.AUTOMATIC,
90
96
  customTemperatureAdjustment: this.adaptiveLightingShift,
91
- });
92
- accessory.configureController(this.AdaptiveLightingController);
93
- accessory.context.adaptiveLighting = true;
97
+ })
98
+ accessory.configureController(this.AdaptiveLightingController)
99
+ accessory.context.adaptiveLighting = true
94
100
  this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}, adaptiveLightingShift: ${this.adaptiveLightingShift}`,
95
- );
101
+ )
96
102
  } else {
97
- accessory.context.adaptiveLighting = false;
98
- this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`);
103
+ accessory.context.adaptiveLighting = false
104
+ this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`)
99
105
  }
100
106
 
101
107
  // Initialize LightBulb Characteristics
102
- this.LightBulb.Service
103
- .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
104
- .getCharacteristic(this.hap.Characteristic.On)
105
- .onGet(() => {
106
- return this.LightBulb.On;
107
- })
108
- .onSet(this.OnSet.bind(this));
108
+ this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
109
+ return this.LightBulb.On
110
+ }).onSet(this.OnSet.bind(this))
109
111
 
110
112
  // Initialize LightBulb Brightness Characteristic
111
- this.LightBulb.Service
112
- .getCharacteristic(this.hap.Characteristic.Brightness)
113
- .setProps({
114
- minStep: device.striplight?.set_minStep ?? 1,
115
- minValue: 0,
116
- maxValue: 100,
117
- validValueRanges: [0, 100],
118
- })
119
- .onGet(() => {
120
- return this.LightBulb.Brightness;
121
- })
122
- .onSet(this.BrightnessSet.bind(this));
113
+ this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Brightness).setProps({
114
+ minStep: device.striplight?.set_minStep ?? 1,
115
+ minValue: 0,
116
+ maxValue: 100,
117
+ validValueRanges: [0, 100],
118
+ }).onGet(() => {
119
+ return this.LightBulb.Brightness
120
+ }).onSet(this.BrightnessSet.bind(this))
123
121
 
124
122
  // Initialize LightBulb ColorTemperature Characteristic
125
- this.LightBulb.Service
126
- .getCharacteristic(this.hap.Characteristic.ColorTemperature)
127
- .setProps({
128
- minValue: 140,
129
- maxValue: 500,
130
- validValueRanges: [140, 500],
131
- })
132
- .onGet(() => {
133
- return this.LightBulb.ColorTemperature!;
134
- })
135
- .onSet(this.ColorTemperatureSet.bind(this));
123
+ this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.ColorTemperature).setProps({
124
+ minValue: 140,
125
+ maxValue: 500,
126
+ validValueRanges: [140, 500],
127
+ }).onGet(() => {
128
+ return this.LightBulb.ColorTemperature!
129
+ }).onSet(this.ColorTemperatureSet.bind(this))
136
130
 
137
131
  // Initialize LightBulb Hue Characteristic
138
- this.LightBulb.Service
139
- .getCharacteristic(this.hap.Characteristic.Hue)
140
- .setProps({
141
- minValue: 0,
142
- maxValue: 360,
143
- validValueRanges: [0, 360],
144
- })
145
- .onGet(() => {
146
- return this.LightBulb.Hue;
147
- })
148
- .onSet(this.HueSet.bind(this));
132
+ this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Hue).setProps({
133
+ minValue: 0,
134
+ maxValue: 360,
135
+ validValueRanges: [0, 360],
136
+ }).onGet(() => {
137
+ return this.LightBulb.Hue
138
+ }).onSet(this.HueSet.bind(this))
149
139
 
150
140
  // Initialize LightBulb Saturation Characteristic
151
- this.LightBulb.Service
152
- .getCharacteristic(this.hap.Characteristic.Saturation)
153
- .setProps({
154
- minValue: 0,
155
- maxValue: 100,
156
- validValueRanges: [0, 100],
157
- })
158
- .onGet(() => {
159
- return this.LightBulb.Saturation;
160
- })
161
- .onSet(this.SaturationSet.bind(this));
141
+ this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Saturation).setProps({
142
+ minValue: 0,
143
+ maxValue: 100,
144
+ validValueRanges: [0, 100],
145
+ }).onGet(() => {
146
+ return this.LightBulb.Saturation
147
+ }).onSet(this.SaturationSet.bind(this))
162
148
 
163
149
  // Retrieve initial values and updateHomekit
164
- this.debugLog('Retrieve initial values and update Homekit');
165
- this.refreshStatus();
150
+ try {
151
+ this.debugLog('Retrieve initial values and update Homekit')
152
+ this.refreshStatus()
153
+ } catch (e: any) {
154
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
155
+ }
156
+
157
+ // regisiter webhook event handler if enabled
158
+ try {
159
+ this.debugLog('Registering Webhook Event Handler')
160
+ this.registerWebhook()
161
+ } catch (e: any) {
162
+ this.errorLog(`failed to registerWebhook, Error: ${e}`)
163
+ }
166
164
 
167
- //regisiter webhook event handler
168
- this.debugLog('Registering Webhook Event Handler');
169
- this.registerWebhook();
165
+ // regisiter platform BLE event handler if enabled
166
+ try {
167
+ this.debugLog('Registering Platform BLE Event Handler')
168
+ this.registerPlatformBLE()
169
+ } catch (e: any) {
170
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
171
+ }
170
172
 
171
173
  // Start an update interval
172
174
  interval(this.deviceRefreshRate * 1000)
173
175
  .pipe(skipWhile(() => this.stripLightUpdateInProgress))
174
176
  .subscribe(async () => {
175
- await this.refreshStatus();
176
- });
177
+ await this.refreshStatus()
178
+ })
177
179
 
178
180
  // Watch for Bulb change events
179
181
  // We put in a debounce of 1000ms so we don't make duplicate calls
180
182
  this.doStripLightUpdate
181
183
  .pipe(
182
184
  tap(() => {
183
- this.stripLightUpdateInProgress = true;
185
+ this.stripLightUpdateInProgress = true
184
186
  }),
185
187
  debounceTime(this.devicePushRate * 1000),
186
188
  )
187
189
  .subscribe(async () => {
188
190
  try {
189
- await this.pushChanges();
191
+ await this.pushChanges()
190
192
  } catch (e: any) {
191
- await this.apiError(e);
192
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
193
+ await this.apiError(e)
194
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
193
195
  }
194
- this.stripLightUpdateInProgress = false;
195
- });
196
+ this.stripLightUpdateInProgress = false
197
+ })
196
198
  }
197
199
 
198
200
  async BLEparseStatus(): Promise<void> {
199
- await this.debugLog('BLEparseStatus');
200
- await this.debugLog(`(power, brightness, color) = BLE:(${this.serviceData.power}, ${this.serviceData.brightness},`
201
- + ` ${this.serviceData.red}:${this.serviceData.green}:${this.serviceData.blue}), current:(${this.LightBulb.On},`
202
- + ` ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
201
+ await this.debugLog('BLEparseStatus')
202
+ await this.debugLog(`(power, brightness, color) = BLE:(${this.serviceData.power}, ${this.serviceData.brightness}, ${this.serviceData.red}:${this.serviceData.green}:${this.serviceData.blue}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`)
203
203
 
204
204
  // On
205
- this.LightBulb.On = this.serviceData.power;
206
- await this.debugLog(`On: ${this.LightBulb.On}`);
205
+ this.LightBulb.On = this.serviceData.power
206
+ await this.debugLog(`On: ${this.LightBulb.On}`)
207
207
 
208
208
  // Brightness
209
- this.LightBulb.Brightness = this.serviceData.brightness;
210
- await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
209
+ this.LightBulb.Brightness = this.serviceData.brightness
210
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
211
211
 
212
212
  // Color, Hue & Brightness
213
- await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`);
214
- const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue);
215
- await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`);
213
+ await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`)
214
+ const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue)
215
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`)
216
216
 
217
217
  // Hue
218
- this.LightBulb.Hue = hue;
219
- this.debugLog(`Hue: ${this.LightBulb.Hue}`);
218
+ this.LightBulb.Hue = hue
219
+ this.debugLog(`Hue: ${this.LightBulb.Hue}`)
220
220
 
221
221
  // Saturation
222
- this.LightBulb.Saturation = saturation;
223
- this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
222
+ this.LightBulb.Saturation = saturation
223
+ this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
224
224
  }
225
225
 
226
226
  async openAPIparseStatus(): Promise<void> {
227
- await this.debugLog('openAPIparseStatus');
228
- await this.debugLog(`(power, brightness, color) = API:(${this.deviceStatus.power}, ${this.deviceStatus.brightness},`
229
- + ` ${this.deviceStatus.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
230
- + ` ${this.LightBulb.Saturation})`);
227
+ await this.debugLog('openAPIparseStatus')
228
+ await this.debugLog(`(power, brightness, color) = API:(${this.deviceStatus.power}, ${this.deviceStatus.brightness}, ${this.deviceStatus.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`)
231
229
 
232
230
  // On
233
- this.LightBulb.On = this.deviceStatus.power === 'on' ? true : false;
234
- await this.debugLog(`On: ${this.LightBulb.On}`);
231
+ this.LightBulb.On = this.deviceStatus.power === 'on'
232
+ await this.debugLog(`On: ${this.LightBulb.On}`)
235
233
 
236
234
  // Brightness
237
- this.LightBulb.Brightness = this.deviceStatus.brightness;
238
- await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
235
+ this.LightBulb.Brightness = this.deviceStatus.brightness
236
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
239
237
 
240
238
  // Color, Hue & Brightness
241
- await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`);
242
- const [red, green, blue] = this.deviceStatus.color.split(':');
243
- await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
244
- const [hue, saturation] = rgb2hs(red, green, blue);
245
- await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
239
+ await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`)
240
+ const [red, green, blue] = this.deviceStatus.color.split(':')
241
+ await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
242
+ const [hue, saturation] = rgb2hs(red, green, blue)
243
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
246
244
 
247
245
  // Hue
248
- this.LightBulb.Hue = hue;
249
- await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
246
+ this.LightBulb.Hue = hue
247
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
250
248
 
251
249
  // Saturation
252
- this.LightBulb.Saturation = saturation;
253
- await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
250
+ this.LightBulb.Saturation = saturation
251
+ await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
254
252
 
255
253
  // Firmware Version
256
254
  if (this.deviceStatus.version) {
257
- const version = this.deviceStatus.version.toString();
258
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
259
- const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
255
+ const version = this.deviceStatus.version.toString()
256
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
257
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
260
258
  this.accessory
261
259
  .getService(this.hap.Service.AccessoryInformation)!
262
260
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
263
261
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
264
262
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
265
- .updateValue(deviceVersion);
266
- this.accessory.context.version = deviceVersion;
267
- await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
263
+ .updateValue(deviceVersion)
264
+ this.accessory.context.version = deviceVersion
265
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
268
266
  }
269
267
  }
270
268
 
271
269
  async parseStatusWebhook(): Promise<void> {
272
- await this.debugLog('parseStatusWebhook');
273
- await this.debugLog(`(powerState, brightness, color) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness},`
274
- + ` ${this.webhookContext.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
275
- + ` ${this.LightBulb.Saturation})`);
270
+ await this.debugLog('parseStatusWebhook')
271
+ await this.debugLog(`(powerState, brightness, color) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`)
276
272
 
277
273
  // On
278
- this.LightBulb.On = this.webhookContext.powerState === 'ON' ? true : false;
279
- await this.debugLog(`On: ${this.LightBulb.On}`);
274
+ this.LightBulb.On = this.webhookContext.powerState === 'ON'
275
+ await this.debugLog(`On: ${this.LightBulb.On}`)
280
276
 
281
277
  // Brightness
282
- this.LightBulb.Brightness = this.webhookContext.brightness;
283
- await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
278
+ this.LightBulb.Brightness = this.webhookContext.brightness
279
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
284
280
 
285
281
  // Color, Hue & Brightness
286
- await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`);
287
- const [red, green, blue] = this.webhookContext.color.split(':');
288
- await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
289
- const [hue, saturation] = rgb2hs(red, green, blue);
290
- await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
282
+ await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`)
283
+ const [red, green, blue] = this.webhookContext.color.split(':')
284
+ await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
285
+ const [hue, saturation] = rgb2hs(red, green, blue)
286
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
291
287
 
292
288
  // Hue
293
- this.LightBulb.Hue = hue;
294
- await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
289
+ this.LightBulb.Hue = hue
290
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
295
291
 
296
292
  // Saturation
297
- this.LightBulb.Saturation = saturation;
298
- await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
293
+ this.LightBulb.Saturation = saturation
294
+ await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
299
295
  }
300
296
 
301
297
  /**
@@ -303,99 +299,103 @@ export class StripLight extends deviceBase {
303
299
  */
304
300
  async refreshStatus(): Promise<void> {
305
301
  if (!this.device.enableCloudService && this.OpenAPI) {
306
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
307
- } else if (this.BLE || this.config.options?.BLE) {
308
- await this.BLERefreshStatus();
302
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
303
+ } else if (this.BLE) {
304
+ await this.BLERefreshStatus()
309
305
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
310
- await this.openAPIRefreshStatus();
306
+ await this.openAPIRefreshStatus()
311
307
  } else {
312
- await this.offlineOff();
313
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
308
+ await this.offlineOff()
309
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
314
310
  }
315
311
  }
316
312
 
317
313
  async BLERefreshStatus(): Promise<void> {
318
- await this.debugLog('BLERefreshStatus');
314
+ await this.debugLog('BLERefreshStatus')
315
+ const switchbot = await this.switchbotBLE()
316
+ if (switchbot === undefined) {
317
+ await this.BLERefreshConnection(switchbot)
318
+ } else {
319
+ // Start to monitor advertisement packets
320
+ (async () => {
321
+ // Start to monitor advertisement packets
322
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData
323
+ // Update HomeKit
324
+ if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
325
+ this.serviceData = serviceData
326
+ await this.BLEparseStatus()
327
+ await this.updateHomeKitCharacteristics()
328
+ } else {
329
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
330
+ await this.BLERefreshConnection(switchbot)
331
+ }
332
+ })()
333
+ }
334
+ }
335
+
336
+ async registerPlatformBLE(): Promise<void> {
337
+ await this.debugLog('registerPlatformBLE')
319
338
  if (this.config.options?.BLE) {
320
- await this.debugLog('is listening to Platform BLE.');
321
- this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
322
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
339
+ await this.debugLog('is listening to Platform BLE.')
340
+ this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
341
+ await this.debugLog(`bleMac: ${this.device.bleMac}`)
323
342
  this.platform.bleEventHandler[this.device.bleMac] = async (context: stripLightServiceData) => {
324
343
  try {
325
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
326
- this.serviceData = context;
327
- await this.BLEparseStatus();
328
- await this.updateHomeKitCharacteristics();
344
+ await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
345
+ this.serviceData = context
346
+ await this.BLEparseStatus()
347
+ await this.updateHomeKitCharacteristics()
329
348
  } catch (e: any) {
330
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
349
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
331
350
  }
332
- };
333
- } else {
334
- await this.debugLog('is using Device BLE Scanning.');
335
- const switchbot = await this.switchbotBLE();
336
- if (switchbot === undefined) {
337
- await this.BLERefreshConnection(switchbot);
338
- } else {
339
- // Start to monitor advertisement packets
340
- (async () => {
341
- // Start to monitor advertisement packets
342
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
343
- // Update HomeKit
344
- if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
345
- this.serviceData = serviceData;
346
- await this.BLEparseStatus();
347
- await this.updateHomeKitCharacteristics();
348
- } else {
349
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
350
- await this.BLERefreshConnection(switchbot);
351
- }
352
- })();
353
351
  }
352
+ } else {
353
+ await this.debugLog('is not listening to Platform BLE')
354
354
  }
355
355
  }
356
356
 
357
357
  async openAPIRefreshStatus(): Promise<void> {
358
- await this.debugLog('openAPIRefreshStatus');
358
+ await this.debugLog('openAPIRefreshStatus')
359
359
  try {
360
- const { body, statusCode } = await this.deviceRefreshStatus();
361
- const deviceStatus: any = await body.json();
362
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
360
+ const { body, statusCode } = await this.deviceRefreshStatus()
361
+ const deviceStatus: any = await body.json()
362
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
363
363
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
364
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
365
- this.deviceStatus = deviceStatus.body;
366
- await this.openAPIparseStatus();
367
- await this.updateHomeKitCharacteristics();
364
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
365
+ this.deviceStatus = deviceStatus.body
366
+ await this.openAPIparseStatus()
367
+ await this.updateHomeKitCharacteristics()
368
368
  } else {
369
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
370
- await this.debugWarnLog(statusCode, deviceStatus);
369
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
370
+ await this.debugWarnLog(statusCode, deviceStatus)
371
371
  }
372
372
  } catch (e: any) {
373
- await this.apiError(e);
374
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
373
+ await this.apiError(e)
374
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
375
375
  }
376
376
  }
377
377
 
378
378
  async registerWebhook() {
379
379
  if (this.device.webhook) {
380
- await this.debugLog('is listening webhook.');
380
+ await this.debugLog('is listening webhook.')
381
381
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: stripLightWebhookContext) => {
382
382
  try {
383
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
384
- this.webhookContext = context;
385
- await this.parseStatusWebhook();
386
- await this.updateHomeKitCharacteristics();
383
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
384
+ this.webhookContext = context
385
+ await this.parseStatusWebhook()
386
+ await this.updateHomeKitCharacteristics()
387
387
  } catch (e: any) {
388
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
388
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
389
389
  }
390
- };
390
+ }
391
391
  } else {
392
- await this.debugLog('is not listening webhook.');
392
+ await this.debugLog('is not listening webhook.')
393
393
  }
394
394
  }
395
395
 
396
396
  /**
397
397
  * Pushes the requested changes to the SwitchBot API
398
- * deviceType commandType Command command parameter Description
398
+ * deviceType commandType Command command parameter Description
399
399
  * Strip Light - "command" "turnOn" "default" = set to ON state |
400
400
  * Strip Light - "command" "turnOff" "default" = set to OFF state |
401
401
  * Strip Light - "command" "toggle" "default" = toggle state |
@@ -405,250 +405,242 @@ export class StripLight extends deviceBase {
405
405
  */
406
406
  async pushChanges(): Promise<void> {
407
407
  if (!this.device.enableCloudService && this.OpenAPI) {
408
- this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
408
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
409
409
  } else if (this.BLE) {
410
- await this.BLEpushChanges();
410
+ await this.BLEpushChanges()
411
411
  if (this.LightBulb.On) {
412
412
  // Push Brightness Update
413
- await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
414
- await this.BLEpushBrightnessChanges();
413
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
414
+ await this.BLEpushBrightnessChanges()
415
415
  // Push Hue & Saturation Update
416
- await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
417
- await this.BLEpushRGBChanges();
416
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
417
+ await this.BLEpushRGBChanges()
418
418
  // Set ColorTemperature
419
419
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
420
- const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
421
- this.accessory.context.kelvin = kelvin;
420
+ const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
421
+ this.accessory.context.kelvin = kelvin
422
422
  } else {
423
- await this.debugLog(`No pushColorTemperatureChanges, ColorTemperature: ${this.LightBulb.ColorTemperature},`
424
- + ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
423
+ await this.debugLog(`No pushColorTemperatureChanges, ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
425
424
  }
426
425
  } else {
427
- await this.debugLog('BLE (Brightness), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
426
+ await this.debugLog('BLE (Brightness), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
428
427
  }
429
428
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
430
- await this.openAPIpushChanges();
429
+ await this.openAPIpushChanges()
431
430
  if (this.LightBulb.On) {
432
431
  // Push Brightness Update
433
- await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
434
- await this.pushBrightnessChanges();
432
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
433
+ await this.pushBrightnessChanges()
435
434
  // Push Hue & Saturation Update
436
- await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
437
- await this.pushHueSaturationChanges();
435
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
436
+ await this.pushHueSaturationChanges()
438
437
  } else {
439
- await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
438
+ await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
440
439
  }
441
440
  } else {
442
- await this.offlineOff();
443
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
441
+ await this.offlineOff()
442
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
444
443
  }
445
444
  // Refresh the status from the API
446
445
  interval(15000)
447
446
  .pipe(skipWhile(() => this.stripLightUpdateInProgress))
448
447
  .pipe(take(1))
449
448
  .subscribe(async () => {
450
- await this.refreshStatus();
451
- });
449
+ await this.refreshStatus()
450
+ })
452
451
  }
453
452
 
454
453
  async BLEpushChanges(): Promise<void> {
455
- await this.debugLog('BLEpushChanges');
454
+ await this.debugLog('BLEpushChanges')
456
455
  if (this.LightBulb.On !== this.accessory.context.On) {
457
- await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
458
- const switchbot = await this.platform.connectBLE(this.accessory, this.device);
459
- await this.convertBLEAddress();
456
+ await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
457
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device)
458
+ await this.convertBLEAddress()
460
459
  if (switchbot !== false) {
461
460
  switchbot
462
461
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
463
462
  .then(async (device_list: any) => {
464
- await this.infoLog(`On: ${this.LightBulb.On}`);
463
+ await this.infoLog(`On: ${this.LightBulb.On}`)
465
464
  return await this.retryBLE({
466
465
  max: await this.maxRetryBLE(),
467
466
  fn: async () => {
468
467
  if (this.LightBulb.On) {
469
- return await device_list[0].turnOn({ id: this.device.bleMac });
468
+ return await device_list[0].turnOn({ id: this.device.bleMac })
470
469
  } else {
471
- return await device_list[0].turnOff({ id: this.device.bleMac });
470
+ return await device_list[0].turnOff({ id: this.device.bleMac })
472
471
  }
473
472
  },
474
- });
473
+ })
475
474
  })
476
475
  .then(async () => {
477
- await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
478
- await this.updateHomeKitCharacteristics();
476
+ await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
477
+ await this.updateHomeKitCharacteristics()
479
478
  })
480
479
  .catch(async (e: any) => {
481
- await this.apiError(e);
482
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
483
- await this.BLEPushConnection();
484
- });
480
+ await this.apiError(e)
481
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
482
+ await this.BLEPushConnection()
483
+ })
485
484
  } else {
486
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
487
- await this.BLEPushConnection();
485
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
486
+ await this.BLEPushConnection()
488
487
  }
489
488
  } else {
490
- await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
489
+ await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
491
490
  }
492
491
  }
493
492
 
494
493
  async BLEpushBrightnessChanges(): Promise<void> {
495
- await this.debugLog('BLEpushBrightnessChanges');
494
+ await this.debugLog('BLEpushBrightnessChanges')
496
495
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
497
- const switchbot = await this.platform.connectBLE(this.accessory, this.device);
498
- await this.convertBLEAddress();
496
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device)
497
+ await this.convertBLEAddress()
499
498
  if (switchbot !== false) {
500
499
  switchbot
501
500
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
502
501
  .then(async (device_list: any) => {
503
- await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`);
504
- return await device_list[0].setBrightness(this.LightBulb.Brightness);
502
+ await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
503
+ return await device_list[0].setBrightness(this.LightBulb.Brightness)
505
504
  })
506
505
  .then(async () => {
507
- await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`);
508
- await this.updateHomeKitCharacteristics();
506
+ await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
507
+ await this.updateHomeKitCharacteristics()
509
508
  })
510
509
  .catch(async (e: any) => {
511
- await this.apiError(e);
512
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
513
- await this.BLEPushConnection();
514
- });
510
+ await this.apiError(e)
511
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
512
+ await this.BLEPushConnection()
513
+ })
515
514
  } else {
516
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
517
- await this.BLEPushConnection();
515
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
516
+ await this.BLEPushConnection()
518
517
  }
519
518
  } else {
520
- await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
521
- + ` BrightnessCached: ${this.accessory.context.Brightness}`);
519
+ await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
522
520
  }
523
521
  }
524
522
 
525
523
  async BLEpushRGBChanges(): Promise<void> {
526
- await this.debugLog('BLEpushRGBChanges');
524
+ await this.debugLog('BLEpushRGBChanges')
527
525
  if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
528
- await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
529
- const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
530
- await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
531
- const switchbot = await this.platform.connectBLE(this.accessory, this.device);
532
- await this.convertBLEAddress();
526
+ await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
527
+ const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
528
+ await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
529
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device)
530
+ await this.convertBLEAddress()
533
531
  if (switchbot !== false) {
534
532
  switchbot
535
533
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
536
534
  .then(async (device_list: any) => {
537
- await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
538
- return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
535
+ await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
536
+ return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
539
537
  })
540
538
  .then(async () => {
541
- await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`);
542
- await this.updateHomeKitCharacteristics();
539
+ await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
540
+ await this.updateHomeKitCharacteristics()
543
541
  })
544
542
  .catch(async (e: any) => {
545
- await this.apiError(e);
546
- await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection,`
547
- + ` Error Message: ${JSON.stringify(e.message)}`);
548
- await this.BLEPushConnection();
549
- });
543
+ await this.apiError(e)
544
+ await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
545
+ await this.BLEPushConnection()
546
+ })
550
547
  } else {
551
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
552
- await this.BLEPushConnection();
548
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
549
+ await this.BLEPushConnection()
553
550
  }
554
551
  } else {
555
- await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
556
- + ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
552
+ await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
557
553
  }
558
554
  }
559
555
 
560
556
  async openAPIpushChanges() {
561
- await this.debugLog('openAPIpushChanges');
557
+ await this.debugLog('openAPIpushChanges')
562
558
  if (this.LightBulb.On !== this.accessory.context.On) {
563
- const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
559
+ const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
564
560
  const bodyChange = JSON.stringify({
565
561
  command: `${command}`,
566
562
  parameter: 'default',
567
563
  commandType: 'command',
568
- });
569
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
564
+ })
565
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
570
566
  try {
571
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
572
- const deviceStatus: any = await body.json();
573
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
567
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
568
+ const deviceStatus: any = await body.json()
569
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
574
570
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
575
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
576
- await this.updateHomeKitCharacteristics();
571
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
572
+ await this.updateHomeKitCharacteristics()
577
573
  } else {
578
- await this.statusCode(statusCode);
579
- await this.statusCode(deviceStatus.statusCode);
574
+ await this.statusCode(statusCode)
575
+ await this.statusCode(deviceStatus.statusCode)
580
576
  }
581
577
  } catch (e: any) {
582
- await this.apiError(e);
583
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
578
+ await this.apiError(e)
579
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
584
580
  }
585
581
  } else {
586
- await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
582
+ await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
587
583
  }
588
584
  }
589
585
 
590
586
  async pushHueSaturationChanges(): Promise<void> {
591
- await this.debugLog('pushHueSaturationChanges');
587
+ await this.debugLog('pushHueSaturationChanges')
592
588
  if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
593
- await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
594
- const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
595
- await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
589
+ await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
590
+ const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
591
+ await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
596
592
  const bodyChange = JSON.stringify({
597
593
  command: 'setColor',
598
594
  parameter: `${red}:${green}:${blue}`,
599
595
  commandType: 'command',
600
- });
601
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
596
+ })
597
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
602
598
  try {
603
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
604
- const deviceStatus: any = await body.json();
605
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
599
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
600
+ const deviceStatus: any = await body.json()
601
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
606
602
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
607
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
608
- await this.updateHomeKitCharacteristics();
603
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
604
+ await this.updateHomeKitCharacteristics()
609
605
  } else {
610
- await this.statusCode(statusCode);
611
- await this.statusCode(deviceStatus.statusCode);
606
+ await this.statusCode(statusCode)
607
+ await this.statusCode(deviceStatus.statusCode)
612
608
  }
613
609
  } catch (e: any) {
614
- await this.apiError(e);
615
- await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
616
- + ` Error Message: ${JSON.stringify(e.message)}`);
610
+ await this.apiError(e)
611
+ await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
617
612
  }
618
613
  } else {
619
- await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
620
- + ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
614
+ await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
621
615
  }
622
616
  }
623
617
 
624
618
  async pushBrightnessChanges(): Promise<void> {
625
- await this.debugLog('pushBrightnessChanges');
619
+ await this.debugLog('pushBrightnessChanges')
626
620
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
627
621
  const bodyChange = JSON.stringify({
628
622
  command: 'setBrightness',
629
623
  parameter: `${this.LightBulb.Brightness}`,
630
624
  commandType: 'command',
631
- });
632
- await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
625
+ })
626
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
633
627
  try {
634
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
635
- const deviceStatus: any = await body.json();
636
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
628
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
629
+ const deviceStatus: any = await body.json()
630
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
637
631
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
638
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
639
- await this.updateHomeKitCharacteristics();
632
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
633
+ await this.updateHomeKitCharacteristics()
640
634
  } else {
641
- await this.statusCode(statusCode);
642
- await this.statusCode(deviceStatus.statusCode);
635
+ await this.statusCode(statusCode)
636
+ await this.statusCode(deviceStatus.statusCode)
643
637
  }
644
638
  } catch (e: any) {
645
- await this.apiError(e);
646
- await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
647
- + ` Error Message: ${JSON.stringify(e.message)}`);
639
+ await this.apiError(e)
640
+ await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
648
641
  }
649
642
  } else {
650
- await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
651
- + ` BrightnessCached: ${this.accessory.context.Brightness}`);
643
+ await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
652
644
  }
653
645
  }
654
646
 
@@ -657,13 +649,13 @@ export class StripLight extends deviceBase {
657
649
  */
658
650
  async OnSet(value: CharacteristicValue): Promise<void> {
659
651
  if (this.LightBulb.On !== this.accessory.context.On) {
660
- await this.infoLog(`Set On: ${value}`);
652
+ await this.infoLog(`Set On: ${value}`)
661
653
  } else {
662
- await this.debugLog(`No Changes, On: ${value}`);
654
+ await this.debugLog(`No Changes, On: ${value}`)
663
655
  }
664
656
 
665
- this.LightBulb.On = value;
666
- this.doStripLightUpdate.next();
657
+ this.LightBulb.On = value
658
+ this.doStripLightUpdate.next()
667
659
  }
668
660
 
669
661
  /**
@@ -671,17 +663,17 @@ export class StripLight extends deviceBase {
671
663
  */
672
664
  async BrightnessSet(value: CharacteristicValue): Promise<void> {
673
665
  if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
674
- await this.infoLog(`Set Brightness: ${value}`);
666
+ await this.infoLog(`Set Brightness: ${value}`)
675
667
  } else {
676
668
  if (this.LightBulb.On) {
677
- this.debugLog(`No Changes, Brightness: ${value}`);
669
+ this.debugLog(`No Changes, Brightness: ${value}`)
678
670
  } else {
679
- this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
671
+ this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`)
680
672
  }
681
673
  }
682
674
 
683
- this.LightBulb.Brightness = value;
684
- this.doStripLightUpdate.next();
675
+ this.LightBulb.Brightness = value
676
+ this.doStripLightUpdate.next()
685
677
  }
686
678
 
687
679
  /**
@@ -689,33 +681,33 @@ export class StripLight extends deviceBase {
689
681
  */
690
682
  async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
691
683
  if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
692
- this.infoLog(`Set ColorTemperature: ${value}`);
684
+ this.infoLog(`Set ColorTemperature: ${value}`)
693
685
  } else {
694
686
  if (this.LightBulb.On) {
695
- this.debugLog(`No Changes, ColorTemperature: ${value}`);
687
+ this.debugLog(`No Changes, ColorTemperature: ${value}`)
696
688
  } else {
697
- this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
689
+ this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`)
698
690
  }
699
691
  }
700
692
 
701
- const minKelvin = 2000;
702
- const maxKelvin = 9000;
693
+ const minKelvin = 2000
694
+ const maxKelvin = 9000
703
695
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
704
- const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
696
+ const kelvin = Math.round(1000000 / Number(value) / 100) * 100
705
697
  // Check and increase/decrease kelvin to range of device
706
- const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin);
698
+ const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin)
707
699
 
708
700
  if (!this.accessory.context.On || this.accessory.context.maxKelvin === k) {
709
- return;
701
+ return
710
702
  }
711
703
 
712
704
  // Updating the hue/sat to the corresponding values mimics native adaptive lighting
713
- const hs = m2hs(value);
714
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
715
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
705
+ const hs = m2hs(value)
706
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0])
707
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1])
716
708
 
717
- this.LightBulb.ColorTemperature = value;
718
- this.doStripLightUpdate.next();
709
+ this.LightBulb.ColorTemperature = value
710
+ this.doStripLightUpdate.next()
719
711
  }
720
712
 
721
713
  /**
@@ -723,19 +715,19 @@ export class StripLight extends deviceBase {
723
715
  */
724
716
  async HueSet(value: CharacteristicValue): Promise<void> {
725
717
  if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
726
- this.infoLog(`Set Hue: ${value}`);
718
+ this.infoLog(`Set Hue: ${value}`)
727
719
  } else {
728
720
  if (this.LightBulb.On) {
729
- this.debugLog(`No Changes, Hue: ${value}`);
721
+ this.debugLog(`No Changes, Hue: ${value}`)
730
722
  } else {
731
- this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
723
+ this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`)
732
724
  }
733
725
  }
734
726
 
735
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
727
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
736
728
 
737
- this.LightBulb.Hue = value;
738
- this.doStripLightUpdate.next();
729
+ this.LightBulb.Hue = value
730
+ this.doStripLightUpdate.next()
739
731
  }
740
732
 
741
733
  /**
@@ -743,79 +735,74 @@ export class StripLight extends deviceBase {
743
735
  */
744
736
  async SaturationSet(value: CharacteristicValue): Promise<void> {
745
737
  if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
746
- this.infoLog(`Set Saturation: ${value}`);
738
+ this.infoLog(`Set Saturation: ${value}`)
747
739
  } else {
748
740
  if (this.LightBulb.On) {
749
- this.debugLog(`No Changes, Saturation: ${value}`);
741
+ this.debugLog(`No Changes, Saturation: ${value}`)
750
742
  } else {
751
- this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
743
+ this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`)
752
744
  }
753
745
  }
754
746
 
755
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
747
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
756
748
 
757
- this.LightBulb.Saturation = value;
758
- this.doStripLightUpdate.next();
749
+ this.LightBulb.Saturation = value
750
+ this.doStripLightUpdate.next()
759
751
  }
760
752
 
761
753
  async updateHomeKitCharacteristics(): Promise<void> {
762
754
  // On
763
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
764
- this.LightBulb.On, 'On');
755
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
765
756
  // Brightness
766
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
767
- this.LightBulb.Brightness, 'Brightness');
757
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness')
768
758
  // ColorTemperature
769
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
770
- this.LightBulb.ColorTemperature, 'ColorTemperature');
759
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature, 'ColorTemperature')
771
760
  // Hue
772
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
773
- this.LightBulb.Hue, 'Hue');
761
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue, this.LightBulb.Hue, 'Hue')
774
762
  // Saturation
775
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
776
- this.LightBulb.Saturation, 'Saturation');
763
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation, this.LightBulb.Saturation, 'Saturation')
777
764
  }
778
765
 
779
766
  async getAdaptiveLightingSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
780
767
  // Adaptive Lighting
781
- this.adaptiveLighting = accessory.context.adaptiveLighting ?? true;
782
- await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
768
+ this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
769
+ await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
783
770
  // Adaptive Lighting Shift
784
771
  if (device.striplight?.adaptiveLightingShift) {
785
- this.adaptiveLightingShift = device.striplight.adaptiveLightingShift;
786
- this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
772
+ this.adaptiveLightingShift = device.striplight.adaptiveLightingShift
773
+ this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
787
774
  } else {
788
- this.adaptiveLightingShift = 0;
789
- this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
775
+ this.adaptiveLightingShift = 0
776
+ this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
790
777
  }
791
778
  }
792
779
 
793
780
  async BLEPushConnection() {
794
781
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
795
- await this.warnLog('Using OpenAPI Connection to Push Changes');
796
- await this.openAPIpushChanges();
782
+ await this.warnLog('Using OpenAPI Connection to Push Changes')
783
+ await this.openAPIpushChanges()
797
784
  }
798
785
  }
799
786
 
800
787
  async BLERefreshConnection(switchbot: any): Promise<void> {
801
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
788
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
802
789
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
803
- await this.warnLog('Using OpenAPI Connection to Refresh Status');
804
- await this.openAPIRefreshStatus();
790
+ await this.warnLog('Using OpenAPI Connection to Refresh Status')
791
+ await this.openAPIRefreshStatus()
805
792
  }
806
793
  }
807
794
 
808
795
  async offlineOff(): Promise<void> {
809
796
  if (this.device.offline) {
810
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
797
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
811
798
  }
812
799
  }
813
800
 
814
801
  async apiError(e: any): Promise<void> {
815
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
816
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
817
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
818
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e);
819
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e);
802
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
803
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e)
804
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e)
805
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e)
806
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e)
820
807
  }
821
808
  }