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

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