@switchbot/homebridge-switchbot 3.5.0-beta.57 → 3.5.0-beta.59

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 +5 -5
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +103 -69
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +4 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +201 -154
  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 +41 -36
  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 +36 -37
  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 +76 -55
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +4 -4
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +99 -55
  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 +11 -9
  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 +54 -24
  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 +40 -57
  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 +39 -39
  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 +41 -50
  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 +36 -33
  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 +68 -59
  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 +42 -51
  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 +42 -51
  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 +52 -40
  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 +13 -13
  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 +81 -98
  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 +39 -31
  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 +120 -87
  133. package/src/device/bot.ts +238 -175
  134. package/src/device/ceilinglight.ts +49 -46
  135. package/src/device/colorbulb.ts +40 -43
  136. package/src/device/contact.ts +91 -65
  137. package/src/device/curtain.ts +113 -66
  138. package/src/device/device.ts +12 -13
  139. package/src/device/fan.ts +66 -29
  140. package/src/device/hub.ts +53 -60
  141. package/src/device/humidifier.ts +54 -56
  142. package/src/device/iosensor.ts +57 -56
  143. package/src/device/lightstrip.ts +43 -39
  144. package/src/device/lock.ts +79 -68
  145. package/src/device/meter.ts +54 -54
  146. package/src/device/meterplus.ts +54 -54
  147. package/src/device/motion.ts +62 -46
  148. package/src/device/plug.ts +19 -18
  149. package/src/device/robotvacuumcleaner.ts +89 -104
  150. package/src/device/waterdetector.ts +46 -34
  151. package/src/homebridge-ui/public/index.html +20 -14
  152. package/src/index.ts +3 -2
  153. package/src/irdevice/airconditioner.ts +13 -11
  154. package/src/irdevice/airpurifier.ts +5 -3
  155. package/src/irdevice/camera.ts +6 -4
  156. package/src/irdevice/fan.ts +42 -29
  157. package/src/irdevice/irdevice.ts +4 -5
  158. package/src/irdevice/light.ts +83 -103
  159. package/src/irdevice/other.ts +5 -3
  160. package/src/irdevice/tv.ts +7 -5
  161. package/src/irdevice/vacuumcleaner.ts +6 -4
  162. package/src/irdevice/waterheater.ts +6 -4
  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) as Service,
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
@@ -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
@@ -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
@@ -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
@@ -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
  }