@switchbot/homebridge-switchbot 3.5.0-beta.56 → 3.5.0-beta.58

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 (164) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/dist/device/blindtilt.d.ts +4 -4
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +2 -2
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +3 -3
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +1 -1
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +3 -3
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +2 -2
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +3 -3
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +1 -1
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +4 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +8 -2
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +3 -3
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +1 -1
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +4 -4
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +4 -0
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +3 -3
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +1 -1
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +4 -4
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +1 -5
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +3 -3
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +1 -1
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +3 -3
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +1 -5
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +4 -4
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +2 -2
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +3 -3
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +1 -1
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +3 -3
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +1 -5
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +3 -3
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +1 -5
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +3 -3
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +27 -12
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +3 -3
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +1 -1
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +4 -4
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +3 -3
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +3 -3
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +1 -1
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/homebridge-ui/public/index.html +20 -14
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +1 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/irdevice/airconditioner.d.ts +3 -3
  84. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  85. package/dist/irdevice/airconditioner.js +9 -9
  86. package/dist/irdevice/airconditioner.js.map +1 -1
  87. package/dist/irdevice/airpurifier.d.ts +3 -3
  88. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  89. package/dist/irdevice/airpurifier.js +1 -1
  90. package/dist/irdevice/airpurifier.js.map +1 -1
  91. package/dist/irdevice/camera.d.ts +3 -3
  92. package/dist/irdevice/camera.d.ts.map +1 -1
  93. package/dist/irdevice/camera.js +2 -2
  94. package/dist/irdevice/camera.js.map +1 -1
  95. package/dist/irdevice/fan.d.ts +6 -6
  96. package/dist/irdevice/fan.d.ts.map +1 -1
  97. package/dist/irdevice/fan.js +37 -29
  98. package/dist/irdevice/fan.js.map +1 -1
  99. package/dist/irdevice/irdevice.d.ts +3 -3
  100. package/dist/irdevice/irdevice.d.ts.map +1 -1
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -14
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +67 -88
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +3 -3
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +1 -1
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +3 -3
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +3 -3
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +3 -3
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +2 -2
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +3 -3
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +2 -2
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +7 -7
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +20 -23
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +24 -10
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js +16 -0
  129. package/dist/settings.js.map +1 -1
  130. package/eslint.config.js +89 -78
  131. package/package.json +3 -3
  132. package/src/device/blindtilt.ts +9 -7
  133. package/src/device/bot.ts +17 -15
  134. package/src/device/ceilinglight.ts +7 -5
  135. package/src/device/colorbulb.ts +6 -4
  136. package/src/device/contact.ts +22 -13
  137. package/src/device/curtain.ts +10 -8
  138. package/src/device/device.ts +5 -4
  139. package/src/device/fan.ts +7 -5
  140. package/src/device/hub.ts +10 -7
  141. package/src/device/humidifier.ts +9 -7
  142. package/src/device/iosensor.ts +11 -8
  143. package/src/device/lightstrip.ts +7 -5
  144. package/src/device/lock.ts +9 -7
  145. package/src/device/meter.ts +10 -7
  146. package/src/device/meterplus.ts +10 -7
  147. package/src/device/motion.ts +36 -16
  148. package/src/device/plug.ts +6 -4
  149. package/src/device/robotvacuumcleaner.ts +9 -7
  150. package/src/device/waterdetector.ts +7 -5
  151. package/src/homebridge-ui/public/index.html +20 -14
  152. package/src/index.ts +3 -2
  153. package/src/irdevice/airconditioner.ts +15 -13
  154. package/src/irdevice/airpurifier.ts +7 -5
  155. package/src/irdevice/camera.ts +7 -5
  156. package/src/irdevice/fan.ts +43 -30
  157. package/src/irdevice/irdevice.ts +4 -5
  158. package/src/irdevice/light.ts +83 -103
  159. package/src/irdevice/other.ts +15 -13
  160. package/src/irdevice/tv.ts +9 -7
  161. package/src/irdevice/vacuumcleaner.ts +7 -5
  162. package/src/irdevice/waterheater.ts +7 -5
  163. package/src/platform.ts +59 -66
  164. package/src/settings.ts +73 -58
@@ -3,10 +3,12 @@
3
3
  * light.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
6
7
  import { irdeviceBase } from './irdevice.js';
7
- import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
12
 
11
13
  /**
12
14
  * Platform Accessory
@@ -15,20 +17,22 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
15
17
  */
16
18
  export class Light extends irdeviceBase {
17
19
  // Services
18
- private LightBulb!: {
20
+ private LightBulb?: {
19
21
  Service: Service;
20
22
  On: CharacteristicValue;
21
23
  };
22
24
 
23
- ProgrammableSwitchServiceOn?: Service;
24
- ProgrammableSwitchServiceOff?: Service;
25
+ private ProgrammableSwitchOn?: {
26
+ Service: Service;
27
+ ProgrammableSwitchEvent: CharacteristicValue;
28
+ ProgrammableSwitchOutputState: CharacteristicValue;
29
+ };
25
30
 
26
- // Characteristic Values
27
- On!: CharacteristicValue;
28
- ProgrammableSwitchEventOn?: CharacteristicValue;
29
- ProgrammableSwitchOutputStateOn?: CharacteristicValue;
30
- ProgrammableSwitchEventOff?: CharacteristicValue;
31
- ProgrammableSwitchOutputStateOff?: CharacteristicValue;
31
+ private ProgrammableSwitchOff?: {
32
+ Service: Service;
33
+ ProgrammableSwitchEvent: CharacteristicValue;
34
+ ProgrammableSwitchOutputState: CharacteristicValue;
35
+ };
32
36
 
33
37
  constructor(
34
38
  readonly platform: SwitchBotPlatform,
@@ -40,7 +44,7 @@ export class Light extends irdeviceBase {
40
44
  if (!device.irlight?.stateless) {
41
45
  // Initialize LightBulb property
42
46
  this.LightBulb = {
43
- Service: accessory.getService(this.hap.Service.Lightbulb)!,
47
+ Service: accessory.getService(this.hap.Service.Lightbulb)! as Service,
44
48
  On: accessory.context.On || false,
45
49
  };
46
50
  // get the Light service if it exists, otherwise create a new Light service
@@ -57,47 +61,47 @@ export class Light extends irdeviceBase {
57
61
  } else {
58
62
 
59
63
  // create a new Stateful Programmable Switch On service
60
- const ProgrammableSwitchServiceOn = `${accessory.displayName} ${device.remoteType} On`;
61
- (this.ProgrammableSwitchServiceOn = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
62
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOn;
64
+ const ProgrammableSwitchOn = `${accessory.displayName} ${device.remoteType} On`;
65
+ (this.ProgrammableSwitchOn!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
66
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOn;
63
67
 
64
68
 
65
- this.ProgrammableSwitchServiceOn.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
69
+ this.ProgrammableSwitchOn?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
66
70
 
67
- this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
71
+ this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
68
72
  validValueRanges: [0, 0],
69
73
  minValue: 0,
70
74
  maxValue: 0,
71
75
  validValues: [0],
72
76
  })
73
77
  .onGet(() => {
74
- return this.ProgrammableSwitchEventOn!;
78
+ return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent;
75
79
  });
76
80
 
77
- this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
81
+ this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
78
82
  .onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
79
83
 
80
84
 
81
85
 
82
86
  // create a new Stateful Programmable Switch Off service
83
- const ProgrammableSwitchServiceOff = `${accessory.displayName} ${device.remoteType} Off`;
84
- (this.ProgrammableSwitchServiceOff = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
85
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOff;
87
+ const ProgrammableSwitchOff = `${accessory.displayName} ${device.remoteType} Off`;
88
+ (this.ProgrammableSwitchOff!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
89
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOff;
86
90
 
87
91
 
88
- this.ProgrammableSwitchServiceOff.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
92
+ this.ProgrammableSwitchOff?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
89
93
 
90
- this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
94
+ this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
91
95
  validValueRanges: [0, 0],
92
96
  minValue: 0,
93
97
  maxValue: 0,
94
98
  validValues: [0],
95
99
  })
96
100
  .onGet(() => {
97
- return this.ProgrammableSwitchEventOff!;
101
+ return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent;
98
102
  });
99
103
 
100
- this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
104
+ this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
101
105
  .onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
102
106
  }
103
107
 
@@ -106,11 +110,13 @@ export class Light extends irdeviceBase {
106
110
  async OnSet(value: CharacteristicValue): Promise<void> {
107
111
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
108
112
 
109
- this.On = value;
110
- if (this.On) {
111
- await this.pushLightOnChanges();
113
+ this.LightBulb!.On = value;
114
+ if (this.LightBulb?.On) {
115
+ const On = true;
116
+ await this.pushLightOnChanges(On);
112
117
  } else {
113
- await this.pushLightOffChanges();
118
+ const On = false;
119
+ await this.pushLightOffChanges(On);
114
120
  }
115
121
  /**
116
122
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -121,10 +127,10 @@ export class Light extends irdeviceBase {
121
127
  async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
122
128
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
123
129
 
124
- this.ProgrammableSwitchOutputStateOn = value;
125
- if (this.ProgrammableSwitchOutputStateOn === 1) {
126
- this.On = true;
127
- await this.pushLightOnChanges();
130
+ this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value;
131
+ if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
132
+ const On = true;
133
+ await this.pushLightOnChanges(On);
128
134
  }
129
135
  /**
130
136
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -135,10 +141,10 @@ export class Light extends irdeviceBase {
135
141
  async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
136
142
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
137
143
 
138
- this.ProgrammableSwitchOutputStateOff = value;
139
- if (this.ProgrammableSwitchOutputStateOff === 1) {
140
- this.On = false;
141
- await this.pushLightOffChanges();
144
+ this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value;
145
+ if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
146
+ const On = false;
147
+ await this.pushLightOffChanges(On);
142
148
  }
143
149
  /**
144
150
  * pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
@@ -158,11 +164,9 @@ export class Light extends irdeviceBase {
158
164
  * Light - "command" "channelAdd" "default" = next channel
159
165
  * Light - "command" "channelSub" "default" = previous channel
160
166
  */
161
- async pushLightOnChanges(): Promise<void> {
162
- this.debugLog(
163
- `${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${this.On},` + ` disablePushOn: ${this.disablePushOn}`,
164
- );
165
- if (this.On && !this.disablePushOn) {
167
+ async pushLightOnChanges(On: boolean): Promise<void> {
168
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`);
169
+ if (On === true && this.disablePushOn === false) {
166
170
  const commandType: string = await this.commandType();
167
171
  const command: string = await this.commandOn();
168
172
  const bodyChange = JSON.stringify({
@@ -170,15 +174,13 @@ export class Light extends irdeviceBase {
170
174
  parameter: 'default',
171
175
  commandType: commandType,
172
176
  });
173
- await this.pushChanges(bodyChange);
177
+ await this.pushChanges(bodyChange, On);
174
178
  }
175
179
  }
176
180
 
177
- async pushLightOffChanges(): Promise<void> {
178
- this.debugLog(
179
- `${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${this.On},` + ` disablePushOff: ${this.disablePushOff}`,
180
- );
181
- if (!this.On && !this.disablePushOff) {
181
+ async pushLightOffChanges(On: boolean): Promise<void> {
182
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`);
183
+ if (On === false && this.disablePushOff === false) {
182
184
  const commandType: string = await this.commandType();
183
185
  const command: string = await this.commandOff();
184
186
  const bodyChange = JSON.stringify({
@@ -186,29 +188,11 @@ export class Light extends irdeviceBase {
186
188
  parameter: 'default',
187
189
  commandType: commandType,
188
190
  });
189
- await this.pushChanges(bodyChange);
191
+ await this.pushChanges(bodyChange, On);
190
192
  }
191
193
  }
192
194
 
193
- /*async pushLightBrightnessUpChanges(): Promise<void> {
194
- const bodyChange = JSON.stringify({
195
- command: 'brightnessUp',
196
- parameter: 'default',
197
- commandType: 'command',
198
- });
199
- await this.pushChanges(bodyChange);
200
- }
201
-
202
- async pushLightBrightnessDownChanges(): Promise<void> {
203
- const bodyChange = JSON.stringify({
204
- command: 'brightnessDown',
205
- parameter: 'default',
206
- commandType: 'command',
207
- });
208
- await this.pushChanges(bodyChange);
209
- }*/
210
-
211
- async pushChanges(bodyChange: any): Promise<void> {
195
+ async pushChanges(bodyChange: any, On: boolean): Promise<void> {
212
196
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
213
197
  if (this.device.connectionType === 'OpenAPI') {
214
198
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
@@ -227,7 +211,7 @@ export class Light extends irdeviceBase {
227
211
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
228
212
  this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
229
213
  + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
230
- this.accessory.context.On = this.On;
214
+ this.accessory.context.On = On;
231
215
  this.updateHomeKitCharacteristics();
232
216
  } else {
233
217
  this.statusCode(statusCode);
@@ -235,63 +219,59 @@ export class Light extends irdeviceBase {
235
219
  }
236
220
  } catch (e: any) {
237
221
  this.apiError(e);
238
- this.errorLog(
239
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
240
- ` Connection, Error Message: ${JSON.stringify(e.message)}`,
241
- );
222
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
223
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
242
224
  }
243
225
  } else {
244
- this.warnLog(
245
- `${this.device.remoteType}: ${this.accessory.displayName}` +
246
- ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
247
- );
226
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Connection Type: `
227
+ + `${this.device.connectionType}, commands will not be sent to OpenAPI`);
248
228
  }
249
229
  }
250
230
 
251
231
  async updateHomeKitCharacteristics(): Promise<void> {
252
- if (this.device.irlight?.stateless) {
232
+ if (!this.device.irlight?.stateless) {
253
233
  // On
254
- if (this.On === undefined) {
255
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
234
+ if (this.LightBulb?.On === undefined) {
235
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LightBulb?.On}`);
256
236
  } else {
257
- this.accessory.context.On = this.On;
258
- this.LightBulb.Service?.updateCharacteristic(this.hap.Characteristic.On, this.On);
259
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
237
+ this.accessory.context.On = this.LightBulb.On;
238
+ this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
239
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
260
240
  }
261
241
  } else {
262
242
  // On Stateful Programmable Switch
263
- if (this.ProgrammableSwitchOutputStateOn === undefined) {
243
+ if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === undefined) {
264
244
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
265
- + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
245
+ + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState}`);
266
246
  } else {
267
- this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOutputStateOn;
268
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
269
- this.ProgrammableSwitchOutputStateOn);
247
+ this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOn.ProgrammableSwitchOutputState;
248
+ this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
249
+ this.ProgrammableSwitchOn.ProgrammableSwitchOutputState);
270
250
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
271
- + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
251
+ + ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOn.ProgrammableSwitchOutputState}`);
272
252
  }
273
253
  // Off Stateful Programmable Switch
274
- if (this.ProgrammableSwitchOutputStateOff === undefined) {
254
+ if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === undefined) {
275
255
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
276
- + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
256
+ + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
277
257
  } else {
278
- this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOutputStateOff;
279
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
280
- this.ProgrammableSwitchOutputStateOff);
258
+ this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOff.ProgrammableSwitchOutputState;
259
+ this.ProgrammableSwitchOff.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
260
+ this.ProgrammableSwitchOff.ProgrammableSwitchOutputState);
281
261
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
282
- + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
262
+ + ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState}`);
283
263
  }
284
264
  }
285
265
  }
286
266
 
287
267
  async apiError(e: any): Promise<void> {
288
- if (this.device.irlight?.stateless) {
289
- this.LightBulb.Service?.updateCharacteristic(this.hap.Characteristic.On, e);
268
+ if (!this.device.irlight?.stateless) {
269
+ this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e);
290
270
  } else {
291
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
292
- this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
293
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
294
- this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
271
+ this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
272
+ this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
273
+ this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
274
+ this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
295
275
  }
296
276
  }
297
277
  }
@@ -3,10 +3,12 @@
3
3
  * other.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
6
7
  import { irdeviceBase } from './irdevice.js';
7
- import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
12
 
11
13
  /**
12
14
  * Platform Accessory
@@ -82,7 +84,7 @@ export class Others extends irdeviceBase {
82
84
  if (this.otherDeviceType === 'switch') {
83
85
  // Initialize Switch property
84
86
  this.Switch = {
85
- Service: accessory.getService(this.hap.Service.Switch)!,
87
+ Service: accessory.getService(this.hap.Service.Switch) as Service,
86
88
  On: accessory.context.On || false,
87
89
  };
88
90
  this.removeFanService(accessory);
@@ -106,7 +108,7 @@ export class Others extends irdeviceBase {
106
108
  } else if (this.otherDeviceType === 'garagedoor') {
107
109
  // Initialize Garage Door property
108
110
  this.GarageDoor = {
109
- Service: accessory.getService(this.hap.Service.GarageDoorOpener)!,
111
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
110
112
  On: accessory.context.On || false,
111
113
  };
112
114
  this.removeFanService(accessory);
@@ -131,7 +133,7 @@ export class Others extends irdeviceBase {
131
133
  } else if (this.otherDeviceType === 'door') {
132
134
  // Initialize Door property
133
135
  this.Door = {
134
- Service: accessory.getService(this.hap.Service.Door)!,
136
+ Service: accessory.getService(this.hap.Service.Door) as Service,
135
137
  On: accessory.context.On || false,
136
138
  };
137
139
  this.removeFanService(accessory);
@@ -164,7 +166,7 @@ export class Others extends irdeviceBase {
164
166
  } else if (this.otherDeviceType === 'window') {
165
167
  // Initialize Window property
166
168
  this.Window = {
167
- Service: accessory.getService(this.hap.Service.Window)!,
169
+ Service: accessory.getService(this.hap.Service.Window) as Service,
168
170
  On: accessory.context.On || false,
169
171
  };
170
172
  this.removeFanService(accessory);
@@ -197,7 +199,7 @@ export class Others extends irdeviceBase {
197
199
  } else if (this.otherDeviceType === 'windowcovering') {
198
200
  // Initialize WindowCovering property
199
201
  this.WindowCovering = {
200
- Service: accessory.getService(this.hap.Service.WindowCovering)!,
202
+ Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
201
203
  On: accessory.context.On || false,
202
204
  };
203
205
  this.removeFanService(accessory);
@@ -230,7 +232,7 @@ export class Others extends irdeviceBase {
230
232
  } else if (this.otherDeviceType === 'lock') {
231
233
  // Initialize Lock property
232
234
  this.Lock = {
233
- Service: accessory.getService(this.hap.Service.LockMechanism)!,
235
+ Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
234
236
  On: accessory.context.On || false,
235
237
  };
236
238
  this.removeFanService(accessory);
@@ -254,7 +256,7 @@ export class Others extends irdeviceBase {
254
256
  } else if (this.otherDeviceType === 'faucet') {
255
257
  // Initialize Faucet property
256
258
  this.Faucet = {
257
- Service: accessory.getService(this.hap.Service.Faucet)!,
259
+ Service: accessory.getService(this.hap.Service.Faucet) as Service,
258
260
  On: accessory.context.On || false,
259
261
  };
260
262
  this.removeFanService(accessory);
@@ -278,7 +280,7 @@ export class Others extends irdeviceBase {
278
280
  } else if (this.otherDeviceType === 'fan') {
279
281
  // Initialize Fan property
280
282
  this.Fan = {
281
- Service: accessory.getService(this.hap.Service.Fanv2)!,
283
+ Service: accessory.getService(this.hap.Service.Fanv2) as Service,
282
284
  On: accessory.context.On || false,
283
285
  };
284
286
  this.removeLockService(accessory);
@@ -302,7 +304,7 @@ export class Others extends irdeviceBase {
302
304
  } else if (this.otherDeviceType === 'stateful') {
303
305
  // Initialize StatefulProgrammableSwitch property
304
306
  this.StatefulProgrammableSwitch = {
305
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)!,
307
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
306
308
  On: accessory.context.On || false,
307
309
  };
308
310
  this.removeFanService(accessory);
@@ -328,7 +330,7 @@ export class Others extends irdeviceBase {
328
330
  } else {
329
331
  // Initialize Outlet property
330
332
  this.Outlet = {
331
- Service: accessory.getService(this.hap.Service.Outlet)!,
333
+ Service: accessory.getService(this.hap.Service.Outlet) as Service,
332
334
  On: accessory.context.On || false,
333
335
  };
334
336
  this.removeFanService(accessory);
@@ -3,10 +3,12 @@
3
3
  * tv.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
6
7
  import { irdeviceBase } from './irdevice.js';
7
- import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
12
 
11
13
  /**
12
14
  * Platform Accessory
@@ -41,7 +43,7 @@ export class TV extends irdeviceBase {
41
43
 
42
44
  // Initialize Television property
43
45
  this.Television = {
44
- Service: accessory.getService(this.hap.Service.Television)!,
46
+ Service: accessory.getService(this.hap.Service.Television) as Service,
45
47
  Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
46
48
  ActiveIdentifier: accessory.context.ActiveIdentifier || 1,
47
49
  SleepDiscoveryMode: accessory.context.SleepDiscoveryMode || this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
@@ -50,7 +52,7 @@ export class TV extends irdeviceBase {
50
52
 
51
53
  // Initialize TelevisionSpeaker property
52
54
  this.TelevisionSpeaker = {
53
- Service: accessory.getService(this.hap.Service.TelevisionSpeaker)!,
55
+ Service: accessory.getService(this.hap.Service.TelevisionSpeaker) as Service,
54
56
  Active: accessory.context.Active || false,
55
57
  VolumeControlType: accessory.context.VolumeControlType || this.hap.Characteristic.VolumeControlType.ABSOLUTE,
56
58
  VolumeSelector: accessory.context.VolumeSelector || this.hap.Characteristic.VolumeSelector.INCREMENT,
@@ -418,7 +420,7 @@ export class TV extends irdeviceBase {
418
420
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Television.Active}`);
419
421
  } else {
420
422
  this.accessory.context.Active = this.Television.Active;
421
- this.Television.Service?.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
423
+ this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
422
424
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Television.Active}`);
423
425
  }
424
426
  // ActiveIdentifier
@@ -426,7 +428,7 @@ export class TV extends irdeviceBase {
426
428
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
427
429
  } else {
428
430
  this.accessory.context.ActiveIdentifier = this.Television.ActiveIdentifier;
429
- this.Television.Service?.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
431
+ this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
430
432
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
431
433
  + ` ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
432
434
  }
@@ -3,10 +3,12 @@
3
3
  * vacuumcleaner.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
6
7
  import { irdeviceBase } from './irdevice.js';
7
- import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
12
 
11
13
  /**
12
14
  * Platform Accessory
@@ -29,7 +31,7 @@ export class VacuumCleaner extends irdeviceBase {
29
31
 
30
32
  // Initialize Switch property
31
33
  this.Switch = {
32
- Service: accessory.getService(this.hap.Service.Switch)!,
34
+ Service: accessory.getService(this.hap.Service.Switch) as Service,
33
35
  On: accessory.context.On || false,
34
36
  };
35
37
 
@@ -133,7 +135,7 @@ export class VacuumCleaner extends irdeviceBase {
133
135
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
134
136
  } else {
135
137
  this.accessory.context.On = this.Switch.On;
136
- this.Switch.Service?.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
138
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
137
139
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
138
140
  }
139
141
  }
@@ -3,10 +3,12 @@
3
3
  * waterheater.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { request } from 'undici';
6
+ import { Devices } from '../settings.js';
6
7
  import { irdeviceBase } from './irdevice.js';
7
- import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
12
 
11
13
  /**
12
14
  * Platform Accessory
@@ -29,7 +31,7 @@ export class WaterHeater extends irdeviceBase {
29
31
 
30
32
  // Initialize Valve property
31
33
  this.Valve = {
32
- Service: accessory.getService(this.hap.Service.Valve)!,
34
+ Service: accessory.getService(this.hap.Service.Valve) as Service,
33
35
  Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
34
36
  };
35
37
 
@@ -138,7 +140,7 @@ export class WaterHeater extends irdeviceBase {
138
140
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Valve.Active}`);
139
141
  } else {
140
142
  this.accessory.context.Active = this.Valve.Active;
141
- this.Valve.Service?.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
143
+ this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
142
144
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Valve.Active}`);
143
145
  }
144
146
  }