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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +14 -0
  3. package/assets/security-privacy-bluetooth.png +0 -0
  4. package/config.schema.json +78 -3
  5. package/dist/device/blindtilt.d.ts +18 -8
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +108 -70
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +9 -9
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +143 -170
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +13 -13
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +38 -73
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +12 -12
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +41 -79
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +5 -5
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +20 -42
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +15 -5
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +127 -81
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/device.d.ts +18 -18
  30. package/dist/device/device.d.ts.map +1 -1
  31. package/dist/device/device.js +33 -36
  32. package/dist/device/device.js.map +1 -1
  33. package/dist/device/fan.d.ts +8 -8
  34. package/dist/device/fan.d.ts.map +1 -1
  35. package/dist/device/fan.js +43 -75
  36. package/dist/device/fan.js.map +1 -1
  37. package/dist/device/hub.d.ts +5 -5
  38. package/dist/device/hub.d.ts.map +1 -1
  39. package/dist/device/hub.js +18 -39
  40. package/dist/device/hub.js.map +1 -1
  41. package/dist/device/humidifier.d.ts +5 -5
  42. package/dist/device/humidifier.d.ts.map +1 -1
  43. package/dist/device/humidifier.js +38 -78
  44. package/dist/device/humidifier.js.map +1 -1
  45. package/dist/device/iosensor.d.ts +5 -5
  46. package/dist/device/iosensor.d.ts.map +1 -1
  47. package/dist/device/iosensor.js +21 -40
  48. package/dist/device/iosensor.js.map +1 -1
  49. package/dist/device/lightstrip.d.ts +6 -6
  50. package/dist/device/lightstrip.d.ts.map +1 -1
  51. package/dist/device/lightstrip.js +34 -73
  52. package/dist/device/lightstrip.js.map +1 -1
  53. package/dist/device/lock.d.ts +9 -9
  54. package/dist/device/lock.d.ts.map +1 -1
  55. package/dist/device/lock.js +37 -52
  56. package/dist/device/lock.js.map +1 -1
  57. package/dist/device/meter.d.ts +5 -5
  58. package/dist/device/meter.d.ts.map +1 -1
  59. package/dist/device/meter.js +21 -39
  60. package/dist/device/meter.js.map +1 -1
  61. package/dist/device/meterplus.d.ts +5 -5
  62. package/dist/device/meterplus.d.ts.map +1 -1
  63. package/dist/device/meterplus.js +21 -38
  64. package/dist/device/meterplus.js.map +1 -1
  65. package/dist/device/motion.d.ts +5 -5
  66. package/dist/device/motion.d.ts.map +1 -1
  67. package/dist/device/motion.js +14 -32
  68. package/dist/device/motion.js.map +1 -1
  69. package/dist/device/plug.d.ts +12 -12
  70. package/dist/device/plug.d.ts.map +1 -1
  71. package/dist/device/plug.js +16 -25
  72. package/dist/device/plug.js.map +1 -1
  73. package/dist/device/robotvacuumcleaner.d.ts +11 -11
  74. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  75. package/dist/device/robotvacuumcleaner.js +42 -56
  76. package/dist/device/robotvacuumcleaner.js.map +1 -1
  77. package/dist/device/waterdetector.d.ts +5 -5
  78. package/dist/device/waterdetector.d.ts.map +1 -1
  79. package/dist/device/waterdetector.js +47 -44
  80. package/dist/device/waterdetector.js.map +1 -1
  81. package/dist/homebridge-ui/server.js +2 -2
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +0 -4
  85. package/dist/index.js.map +1 -1
  86. package/dist/irdevice/airconditioner.d.ts +8 -8
  87. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  88. package/dist/irdevice/airconditioner.js +61 -105
  89. package/dist/irdevice/airconditioner.js.map +1 -1
  90. package/dist/irdevice/airpurifier.d.ts +10 -10
  91. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  92. package/dist/irdevice/airpurifier.js +22 -42
  93. package/dist/irdevice/airpurifier.js.map +1 -1
  94. package/dist/irdevice/camera.d.ts +9 -9
  95. package/dist/irdevice/camera.d.ts.map +1 -1
  96. package/dist/irdevice/camera.js +15 -25
  97. package/dist/irdevice/camera.js.map +1 -1
  98. package/dist/irdevice/fan.d.ts +8 -8
  99. package/dist/irdevice/fan.d.ts.map +1 -1
  100. package/dist/irdevice/fan.js +21 -40
  101. package/dist/irdevice/fan.js.map +1 -1
  102. package/dist/irdevice/irdevice.d.ts +11 -11
  103. package/dist/irdevice/irdevice.d.ts.map +1 -1
  104. package/dist/irdevice/irdevice.js +14 -22
  105. package/dist/irdevice/irdevice.js.map +1 -1
  106. package/dist/irdevice/light.d.ts +9 -9
  107. package/dist/irdevice/light.d.ts.map +1 -1
  108. package/dist/irdevice/light.js +24 -47
  109. package/dist/irdevice/light.js.map +1 -1
  110. package/dist/irdevice/other.d.ts +9 -9
  111. package/dist/irdevice/other.d.ts.map +1 -1
  112. package/dist/irdevice/other.js +40 -83
  113. package/dist/irdevice/other.js.map +1 -1
  114. package/dist/irdevice/tv.d.ts +9 -9
  115. package/dist/irdevice/tv.d.ts.map +1 -1
  116. package/dist/irdevice/tv.js +29 -54
  117. package/dist/irdevice/tv.js.map +1 -1
  118. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  119. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  120. package/dist/irdevice/vacuumcleaner.js +11 -21
  121. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  122. package/dist/irdevice/waterheater.d.ts +5 -5
  123. package/dist/irdevice/waterheater.d.ts.map +1 -1
  124. package/dist/irdevice/waterheater.js +11 -22
  125. package/dist/irdevice/waterheater.js.map +1 -1
  126. package/dist/platform.d.ts +24 -23
  127. package/dist/platform.d.ts.map +1 -1
  128. package/dist/platform.js +471 -715
  129. package/dist/platform.js.map +1 -1
  130. package/dist/settings.d.ts +6 -3
  131. package/dist/settings.d.ts.map +1 -1
  132. package/dist/settings.js.map +1 -1
  133. package/dist/types/bledevicestatus.d.ts +9 -9
  134. package/dist/types/bledevicestatus.d.ts.map +1 -1
  135. package/dist/types/devicelist.d.ts +6 -6
  136. package/dist/types/devicelist.d.ts.map +1 -1
  137. package/dist/types/deviceresponse.d.ts +4 -4
  138. package/dist/types/deviceresponse.d.ts.map +1 -1
  139. package/dist/types/devicestatus.d.ts +2 -2
  140. package/dist/types/devicestatus.d.ts.map +1 -1
  141. package/dist/types/devicewebhookstatus.d.ts +5 -5
  142. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  143. package/dist/types/irdevicelist.d.ts +4 -4
  144. package/dist/types/irdevicelist.d.ts.map +1 -1
  145. package/dist/types/pushbody.d.ts +2 -2
  146. package/dist/types/pushbody.d.ts.map +1 -1
  147. package/dist/utils.d.ts +4 -4
  148. package/dist/utils.d.ts.map +1 -1
  149. package/dist/utils.js +9 -13
  150. package/dist/utils.js.map +1 -1
  151. package/eslint.config.js +48 -93
  152. package/package.json +62 -55
  153. package/src/device/blindtilt.ts +509 -460
  154. package/src/device/bot.ts +696 -718
  155. package/src/device/ceilinglight.ts +331 -364
  156. package/src/device/colorbulb.ts +412 -448
  157. package/src/device/contact.ts +200 -221
  158. package/src/device/curtain.ts +506 -444
  159. package/src/device/device.ts +206 -208
  160. package/src/device/fan.ts +307 -340
  161. package/src/device/hub.ts +184 -209
  162. package/src/device/humidifier.ts +297 -342
  163. package/src/device/iosensor.ts +182 -204
  164. package/src/device/lightstrip.ts +362 -399
  165. package/src/device/lock.ts +262 -276
  166. package/src/device/meter.ts +183 -205
  167. package/src/device/meterplus.ts +183 -204
  168. package/src/device/motion.ts +169 -185
  169. package/src/device/plug.ts +174 -177
  170. package/src/device/robotvacuumcleaner.ts +256 -269
  171. package/src/device/waterdetector.ts +185 -185
  172. package/src/homebridge-ui/server.ts +16 -15
  173. package/src/index.ts +5 -6
  174. package/src/irdevice/airconditioner.ts +277 -326
  175. package/src/irdevice/airpurifier.ts +124 -143
  176. package/src/irdevice/camera.ts +58 -64
  177. package/src/irdevice/fan.ts +106 -123
  178. package/src/irdevice/irdevice.ts +116 -119
  179. package/src/irdevice/light.ts +119 -143
  180. package/src/irdevice/other.ts +417 -461
  181. package/src/irdevice/tv.ts +155 -177
  182. package/src/irdevice/vacuumcleaner.ts +54 -60
  183. package/src/irdevice/waterheater.ts +56 -63
  184. package/src/platform.ts +1467 -1683
  185. package/src/settings.ts +173 -170
  186. package/src/types/bledevicestatus.ts +252 -256
  187. package/src/types/devicelist.ts +79 -79
  188. package/src/types/deviceresponse.ts +12 -13
  189. package/src/types/devicestatus.ts +124 -124
  190. package/src/types/devicewebhookstatus.ts +126 -131
  191. package/src/types/irdevicelist.ts +10 -10
  192. package/src/types/pushbody.ts +5 -5
  193. package/src/utils.ts +64 -65
  194. package/tsconfig.json +10 -9
  195. package/.github/npm-version-script.cjs +0 -81
@@ -2,12 +2,13 @@
2
2
  *
3
3
  * light.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { irdeviceBase } from './irdevice.js';
5
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
6
 
7
- import type { SwitchBotPlatform } from '../platform.js';
8
- import type { irDevicesConfig } from '../settings.js';
9
- import type { irdevice } from '../types/irdevicelist.js';
10
- import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
7
+ import type { SwitchBotPlatform } from '../platform.js'
8
+ import type { irDevicesConfig } from '../settings.js'
9
+ import type { irdevice } from '../types/irdevicelist.js'
10
+
11
+ import { irdeviceBase } from './irdevice.js'
11
12
 
12
13
  /**
13
14
  * Platform Accessory
@@ -17,127 +18,108 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
17
18
  export class Light extends irdeviceBase {
18
19
  // Services
19
20
  private LightBulb?: {
20
- Name: CharacteristicValue;
21
- Service: Service;
22
- On: CharacteristicValue;
23
- };
21
+ Name: CharacteristicValue
22
+ Service: Service
23
+ On: CharacteristicValue
24
+ }
24
25
 
25
26
  private ProgrammableSwitchOn?: {
26
- Name: CharacteristicValue;
27
- Service: Service;
28
- ProgrammableSwitchEvent: CharacteristicValue;
29
- ProgrammableSwitchOutputState: CharacteristicValue;
30
- };
27
+ Name: CharacteristicValue
28
+ Service: Service
29
+ ProgrammableSwitchEvent: CharacteristicValue
30
+ ProgrammableSwitchOutputState: CharacteristicValue
31
+ }
31
32
 
32
33
  private ProgrammableSwitchOff?: {
33
- Name: CharacteristicValue;
34
- Service: Service;
35
- ProgrammableSwitchEvent: CharacteristicValue;
36
- ProgrammableSwitchOutputState: CharacteristicValue;
37
- };
34
+ Name: CharacteristicValue
35
+ Service: Service
36
+ ProgrammableSwitchEvent: CharacteristicValue
37
+ ProgrammableSwitchOutputState: CharacteristicValue
38
+ }
38
39
 
39
40
  constructor(
40
41
  readonly platform: SwitchBotPlatform,
41
42
  accessory: PlatformAccessory,
42
43
  device: irdevice & irDevicesConfig,
43
44
  ) {
44
- super(platform, accessory, device);
45
+ super(platform, accessory, device)
45
46
  // Set category
46
- accessory.category = this.hap.Categories.LIGHTBULB;
47
+ accessory.category = this.hap.Categories.LIGHTBULB
47
48
 
48
49
  if (!device.irlight?.stateless) {
49
50
  // Initialize LightBulb Service
50
- accessory.context.LightBulb = accessory.context.LightBulb ?? {};
51
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {}
51
52
  this.LightBulb = {
52
53
  Name: accessory.displayName,
53
54
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
54
55
  On: accessory.context.On || false,
55
- };
56
- accessory.context.LightBulb = this.LightBulb as object;
56
+ }
57
+ accessory.context.LightBulb = this.LightBulb as object
57
58
 
58
- this.LightBulb.Service
59
- .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
60
- .getCharacteristic(this.hap.Characteristic.On)
61
- .onGet(() => {
62
- return this.LightBulb!.On;
63
- })
64
- .onSet(this.OnSet.bind(this));
59
+ this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
60
+ return this.LightBulb!.On
61
+ }).onSet(this.OnSet.bind(this))
65
62
  } else {
66
63
  // Initialize ProgrammableSwitchOn Service
67
- accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
64
+ accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {}
68
65
  this.ProgrammableSwitchOn = {
69
66
  Name: `${accessory.displayName} On`,
70
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
71
- ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
67
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
72
68
  ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
73
69
  ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
74
- };
75
- accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object;
70
+ }
71
+ accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object
76
72
 
77
73
  // Initialize ProgrammableSwitchOn Characteristics
78
- this.ProgrammableSwitchOn?.Service
79
- .setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name)
80
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
81
- validValueRanges: [0, 0],
82
- minValue: 0,
83
- maxValue: 0,
84
- validValues: [0],
85
- })
86
- .onGet(() => {
87
- return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent;
88
- });
89
-
90
- this.ProgrammableSwitchOn?.Service
91
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
92
- .onGet(() => {
93
- return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState;
94
- })
95
- .onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
74
+ this.ProgrammableSwitchOn?.Service.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
75
+ validValueRanges: [0, 0],
76
+ minValue: 0,
77
+ maxValue: 0,
78
+ validValues: [0],
79
+ }).onGet(() => {
80
+ return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent
81
+ })
82
+
83
+ this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onGet(() => {
84
+ return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState
85
+ }).onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this))
96
86
 
97
87
  // Initialize ProgrammableSwitchOff Service
98
- accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
88
+ accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {}
99
89
  this.ProgrammableSwitchOff = {
100
90
  Name: `${accessory.displayName} Off`,
101
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
102
- ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
91
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
103
92
  ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
104
93
  ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
105
- };
106
- accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object;
94
+ }
95
+ accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object
107
96
 
108
97
  // Initialize ProgrammableSwitchOff Characteristics
109
- this.ProgrammableSwitchOff?.Service
110
- .setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name)
111
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
112
- validValueRanges: [0, 0],
113
- minValue: 0,
114
- maxValue: 0,
115
- validValues: [0],
116
- })
117
- .onGet(() => {
118
- return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent;
119
- });
120
-
121
- this.ProgrammableSwitchOff?.Service
122
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
123
- .onGet(() => {
124
- return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState;
125
- })
126
- .onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
98
+ this.ProgrammableSwitchOff?.Service.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
99
+ validValueRanges: [0, 0],
100
+ minValue: 0,
101
+ maxValue: 0,
102
+ validValues: [0],
103
+ }).onGet(() => {
104
+ return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent
105
+ })
106
+
107
+ this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onGet(() => {
108
+ return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState
109
+ }).onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this))
127
110
  }
128
-
129
111
  }
130
112
 
131
113
  async OnSet(value: CharacteristicValue): Promise<void> {
132
- await this.debugLog(`On: ${value}`);
114
+ await this.debugLog(`On: ${value}`)
133
115
 
134
- this.LightBulb!.On = value;
116
+ this.LightBulb!.On = value
135
117
  if (this.LightBulb?.On) {
136
- const On = true;
137
- await this.pushLightOnChanges(On);
118
+ const On = true
119
+ await this.pushLightOnChanges(On)
138
120
  } else {
139
- const On = false;
140
- await this.pushLightOffChanges(On);
121
+ const On = false
122
+ await this.pushLightOffChanges(On)
141
123
  }
142
124
  /**
143
125
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -146,12 +128,12 @@ export class Light extends irdeviceBase {
146
128
  }
147
129
 
148
130
  async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
149
- await this.debugLog(`On: ${value}`);
131
+ await this.debugLog(`On: ${value}`)
150
132
 
151
- this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value;
133
+ this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value
152
134
  if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
153
- const On = true;
154
- await this.pushLightOnChanges(On);
135
+ const On = true
136
+ await this.pushLightOnChanges(On)
155
137
  }
156
138
  /**
157
139
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -160,12 +142,12 @@ export class Light extends irdeviceBase {
160
142
  }
161
143
 
162
144
  async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
163
- await this.debugLog(`On: ${value}`);
145
+ await this.debugLog(`On: ${value}`)
164
146
 
165
- this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value;
147
+ this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value
166
148
  if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
167
- const On = false;
168
- await this.pushLightOffChanges(On);
149
+ const On = false
150
+ await this.pushLightOffChanges(On)
169
151
  }
170
152
  /**
171
153
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -173,100 +155,94 @@ export class Light extends irdeviceBase {
173
155
  */
174
156
  }
175
157
 
176
-
177
-
178
158
  /**
179
159
  * Pushes the requested changes to the SwitchBot API
180
- * deviceType commandType Command command parameter Description
181
- * Light - "command" "turnOff" "default" = set to OFF state
182
- * Light - "command" "turnOn" "default" = set to ON state
183
- * Light - "command" "volumeAdd" "default" = volume up
184
- * Light - "command" "volumeSub" "default" = volume down
185
- * Light - "command" "channelAdd" "default" = next channel
186
- * Light - "command" "channelSub" "default" = previous channel
160
+ * deviceType commandType Command command parameter Description
161
+ * Light - "command" "turnOff" "default" = set to OFF state
162
+ * Light - "command" "turnOn" "default" = set to ON state
163
+ * Light - "command" "volumeAdd" "default" = volume up
164
+ * Light - "command" "volumeSub" "default" = volume down
165
+ * Light - "command" "channelAdd" "default" = next channel
166
+ * Light - "command" "channelSub" "default" = previous channel
187
167
  */
188
168
  async pushLightOnChanges(On: boolean): Promise<void> {
189
- await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
169
+ await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`)
190
170
  if (On === true && this.disablePushOn === false) {
191
- const commandType: string = await this.commandType();
192
- const command: string = await this.commandOn();
171
+ const commandType: string = await this.commandType()
172
+ const command: string = await this.commandOn()
193
173
  const bodyChange = JSON.stringify({
194
- command: command,
174
+ command,
195
175
  parameter: 'default',
196
- commandType: commandType,
197
- });
198
- await this.pushChanges(bodyChange, On);
176
+ commandType,
177
+ })
178
+ await this.pushChanges(bodyChange, On)
199
179
  }
200
180
  }
201
181
 
202
182
  async pushLightOffChanges(On: boolean): Promise<void> {
203
- await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
183
+ await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`)
204
184
  if (On === false && this.disablePushOff === false) {
205
- const commandType: string = await this.commandType();
206
- const command: string = await this.commandOff();
185
+ const commandType: string = await this.commandType()
186
+ const command: string = await this.commandOff()
207
187
  const bodyChange = JSON.stringify({
208
- command: command,
188
+ command,
209
189
  parameter: 'default',
210
- commandType: commandType,
211
- });
212
- await this.pushChanges(bodyChange, On);
190
+ commandType,
191
+ })
192
+ await this.pushChanges(bodyChange, On)
213
193
  }
214
194
  }
215
195
 
216
196
  async pushChanges(bodyChange: any, On: boolean): Promise<void> {
217
- this.debugLog('pushChanges');
197
+ this.debugLog('pushChanges')
218
198
  if (this.device.connectionType === 'OpenAPI') {
219
- this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
199
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
220
200
  try {
221
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
222
- const deviceStatus: any = await body.json();
223
- await this.pushStatusCodes(statusCode, deviceStatus);
201
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
202
+ const deviceStatus: any = await body.json()
203
+ await this.pushStatusCodes(statusCode, deviceStatus)
224
204
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
225
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
226
- this.accessory.context.On = On;
227
- await this.updateHomeKitCharacteristics();
205
+ await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
206
+ this.accessory.context.On = On
207
+ await this.updateHomeKitCharacteristics()
228
208
  } else {
229
- await this.statusCode(statusCode);
230
- await this.statusCode(deviceStatus.statusCode);
209
+ await this.statusCode(statusCode)
210
+ await this.statusCode(deviceStatus.statusCode)
231
211
  }
232
212
  } catch (e: any) {
233
- await this.apiError(e);
234
- await this.pushChangeError(e);
213
+ await this.apiError(e)
214
+ await this.pushChangeError(e)
235
215
  }
236
216
  } else {
237
- this.warnLog('Connection Type: '
238
- + `${this.device.connectionType}, commands will not be sent to OpenAPI`);
217
+ this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
239
218
  }
240
219
  }
241
220
 
242
221
  async updateHomeKitCharacteristics(): Promise<void> {
243
- await this.debugLog('updateHomeKitCharacteristics');
222
+ await this.debugLog('updateHomeKitCharacteristics')
244
223
  if (!this.device.irlight?.stateless && this.LightBulb?.Service) {
245
224
  // On
246
- await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
247
- this.LightBulb.On, 'On');
225
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
248
226
  } else {
249
227
  if (this.ProgrammableSwitchOn?.Service) {
250
- // On Stateful Programmable Switch
251
- await this.updateCharacteristic(this.ProgrammableSwitchOn.Service, this.hap.Characteristic.ProgrammableSwitchOutputState,
252
- this.ProgrammableSwitchOn.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState');
228
+ // On Stateful Programmable Switch
229
+ await this.updateCharacteristic(this.ProgrammableSwitchOn.Service, this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOn.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState')
253
230
  }
254
231
  if (this.ProgrammableSwitchOff?.Service) {
255
- // Off Stateful Programmable Switch
256
- await this.updateCharacteristic(this.ProgrammableSwitchOff.Service, this.hap.Characteristic.ProgrammableSwitchOutputState,
257
- this.ProgrammableSwitchOff.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState');
232
+ // Off Stateful Programmable Switch
233
+ await this.updateCharacteristic(this.ProgrammableSwitchOff.Service, this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOff.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState')
258
234
  }
259
235
  }
260
236
  }
261
237
 
262
238
  async apiError(e: any): Promise<void> {
263
239
  if (!this.device.irlight?.stateless) {
264
- this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e);
240
+ this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e)
265
241
  } else {
266
- this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
267
- this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
268
- this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
269
- this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
242
+ this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
243
+ this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
244
+ this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
245
+ this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
270
246
  }
271
247
  }
272
248
  }