@switchbot/homebridge-switchbot 3.7.1-beta.11 → 3.7.1-beta.13

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