@switchbot/homebridge-switchbot 3.5.0-beta.62 → 3.5.0-beta.64

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 (113) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +9 -6
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +33 -22
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts.map +1 -1
  8. package/dist/device/ceilinglight.js +4 -3
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.js +3 -2
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -10
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +11 -8
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/device.js +11 -10
  19. package/dist/device/device.js.map +1 -1
  20. package/dist/device/fan.d.ts.map +1 -1
  21. package/dist/device/fan.js +7 -5
  22. package/dist/device/fan.js.map +1 -1
  23. package/dist/device/hub.d.ts.map +1 -1
  24. package/dist/device/hub.js +9 -6
  25. package/dist/device/hub.js.map +1 -1
  26. package/dist/device/humidifier.d.ts.map +1 -1
  27. package/dist/device/humidifier.js +6 -4
  28. package/dist/device/humidifier.js.map +1 -1
  29. package/dist/device/iosensor.d.ts.map +1 -1
  30. package/dist/device/iosensor.js +10 -6
  31. package/dist/device/iosensor.js.map +1 -1
  32. package/dist/device/lightstrip.d.ts.map +1 -1
  33. package/dist/device/lightstrip.js +3 -2
  34. package/dist/device/lightstrip.js.map +1 -1
  35. package/dist/device/lock.d.ts.map +1 -1
  36. package/dist/device/lock.js +12 -8
  37. package/dist/device/lock.js.map +1 -1
  38. package/dist/device/meter.d.ts.map +1 -1
  39. package/dist/device/meter.js +8 -5
  40. package/dist/device/meter.js.map +1 -1
  41. package/dist/device/meterplus.d.ts.map +1 -1
  42. package/dist/device/meterplus.js +9 -6
  43. package/dist/device/meterplus.js.map +1 -1
  44. package/dist/device/motion.d.ts.map +1 -1
  45. package/dist/device/motion.js +10 -6
  46. package/dist/device/motion.js.map +1 -1
  47. package/dist/device/plug.d.ts.map +1 -1
  48. package/dist/device/plug.js +3 -2
  49. package/dist/device/plug.js.map +1 -1
  50. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  51. package/dist/device/robotvacuumcleaner.js +6 -4
  52. package/dist/device/robotvacuumcleaner.js.map +1 -1
  53. package/dist/device/waterdetector.d.ts.map +1 -1
  54. package/dist/device/waterdetector.js +6 -4
  55. package/dist/device/waterdetector.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts +1 -1
  57. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  58. package/dist/irdevice/airconditioner.js +65 -83
  59. package/dist/irdevice/airconditioner.js.map +1 -1
  60. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  61. package/dist/irdevice/airpurifier.js +37 -19
  62. package/dist/irdevice/airpurifier.js.map +1 -1
  63. package/dist/irdevice/camera.d.ts.map +1 -1
  64. package/dist/irdevice/camera.js +13 -11
  65. package/dist/irdevice/camera.js.map +1 -1
  66. package/dist/irdevice/fan.d.ts.map +1 -1
  67. package/dist/irdevice/fan.js +25 -15
  68. package/dist/irdevice/fan.js.map +1 -1
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +50 -24
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +1 -1
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +180 -138
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts.map +1 -1
  77. package/dist/irdevice/tv.js +50 -59
  78. package/dist/irdevice/tv.js.map +1 -1
  79. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.js +13 -10
  81. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  82. package/dist/irdevice/waterheater.d.ts.map +1 -1
  83. package/dist/irdevice/waterheater.js +14 -13
  84. package/dist/irdevice/waterheater.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/blindtilt.ts +9 -6
  87. package/src/device/bot.ts +33 -22
  88. package/src/device/ceilinglight.ts +4 -3
  89. package/src/device/colorbulb.ts +3 -3
  90. package/src/device/contact.ts +14 -10
  91. package/src/device/curtain.ts +11 -8
  92. package/src/device/device.ts +11 -11
  93. package/src/device/fan.ts +7 -5
  94. package/src/device/hub.ts +9 -6
  95. package/src/device/humidifier.ts +6 -4
  96. package/src/device/iosensor.ts +10 -6
  97. package/src/device/lightstrip.ts +3 -2
  98. package/src/device/lock.ts +12 -8
  99. package/src/device/meter.ts +8 -5
  100. package/src/device/meterplus.ts +9 -6
  101. package/src/device/motion.ts +10 -6
  102. package/src/device/plug.ts +3 -2
  103. package/src/device/robotvacuumcleaner.ts +6 -4
  104. package/src/device/waterdetector.ts +6 -4
  105. package/src/irdevice/airconditioner.ts +73 -86
  106. package/src/irdevice/airpurifier.ts +43 -23
  107. package/src/irdevice/camera.ts +14 -13
  108. package/src/irdevice/fan.ts +26 -18
  109. package/src/irdevice/light.ts +65 -45
  110. package/src/irdevice/other.ts +210 -154
  111. package/src/irdevice/tv.ts +57 -70
  112. package/src/irdevice/vacuumcleaner.ts +14 -12
  113. package/src/irdevice/waterheater.ts +15 -16
@@ -18,51 +18,61 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class Others extends irdeviceBase {
19
19
  // Services
20
20
  private Switch?: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  On: CharacteristicValue;
23
24
  };
24
25
 
25
26
  private GarageDoor?: {
27
+ Name: CharacteristicValue;
26
28
  Service: Service;
27
29
  On: CharacteristicValue;
28
30
  };
29
31
 
30
32
  private Door?: {
33
+ Name: CharacteristicValue;
31
34
  Service: Service;
32
35
  On: CharacteristicValue;
33
36
  };
34
37
 
35
38
  private Window?: {
39
+ Name: CharacteristicValue;
36
40
  Service: Service;
37
41
  On: CharacteristicValue;
38
42
  };
39
43
 
40
44
  private WindowCovering?: {
45
+ Name: CharacteristicValue;
41
46
  Service: Service;
42
47
  On: CharacteristicValue;
43
48
  };
44
49
 
45
- private Lock?: {
50
+ private LockMechanism?: {
51
+ Name: CharacteristicValue;
46
52
  Service: Service;
47
53
  On: CharacteristicValue;
48
54
  };
49
55
 
50
56
  private Faucet?: {
57
+ Name: CharacteristicValue;
51
58
  Service: Service;
52
59
  On: CharacteristicValue;
53
60
  };
54
61
 
55
62
  private Fan?: {
63
+ Name: CharacteristicValue;
56
64
  Service: Service;
57
65
  On: CharacteristicValue;
58
66
  };
59
67
 
60
68
  private StatefulProgrammableSwitch?: {
69
+ Name: CharacteristicValue;
61
70
  Service: Service;
62
71
  On: CharacteristicValue;
63
72
  };
64
73
 
65
74
  private Outlet?: {
75
+ Name: CharacteristicValue;
66
76
  Service: Service;
67
77
  On: CharacteristicValue;
68
78
  };
@@ -82,11 +92,25 @@ export class Others extends irdeviceBase {
82
92
 
83
93
  // deviceType
84
94
  if (this.otherDeviceType === 'switch') {
85
- // Initialize Switch property
95
+ // Initialize Switch Service
96
+ accessory.context.Switch = accessory.context.Switch ?? {};
86
97
  this.Switch = {
87
- Service: accessory.getService(this.hap.Service.Switch) as Service,
88
- On: accessory.context.On || false,
98
+ Name: accessory.context.Switch.Name ?? `${accessory.displayName} Switch`,
99
+ Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
100
+ On: accessory.context.On ?? false,
89
101
  };
102
+ accessory.context.Switch = this.Switch as object;
103
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
104
+
105
+ this.Switch.Service
106
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
107
+ .getCharacteristic(this.hap.Characteristic.On)
108
+ .onGet(() => {
109
+ return this.Switch!.On;
110
+ })
111
+ .onSet(this.OnSet.bind(this));
112
+
113
+ // Remove other services
90
114
  this.removeFanService(accessory);
91
115
  this.removeLockService(accessory);
92
116
  this.removeDoorService(accessory);
@@ -96,21 +120,27 @@ export class Others extends irdeviceBase {
96
120
  this.removeGarageDoorService(accessory);
97
121
  this.removeWindowCoveringService(accessory);
98
122
  this.removeStatefulProgrammableSwitchService(accessory);
99
-
100
- // Add Switch Service
101
- const SwitchService = `${accessory.displayName} Switch`;
102
- (this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service
103
- || accessory.addService(this.hap.Service.Switch)), SwitchService;
104
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
105
-
106
- this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
107
- this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
108
123
  } else if (this.otherDeviceType === 'garagedoor') {
109
- // Initialize Garage Door property
124
+ // Initialize Garage Door Service
125
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
110
126
  this.GarageDoor = {
111
- Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
112
- On: accessory.context.On || false,
127
+ Name: accessory.context.GarageDoor.Name ?? `${accessory.displayName} Garage Door`,
128
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
129
+ On: accessory.context.On ?? false,
113
130
  };
131
+ accessory.context.GarageDoor = this.GarageDoor as object;
132
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
133
+
134
+ this.GarageDoor.Service
135
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
136
+ .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
137
+ .getCharacteristic(this.hap.Characteristic.TargetDoorState)
138
+ .onGet(() => {
139
+ return this.GarageDoor!.On;
140
+ })
141
+ .onSet(this.OnSet.bind(this));
142
+
143
+ // Remove other services
114
144
  this.removeFanService(accessory);
115
145
  this.removeLockService(accessory);
116
146
  this.removeDoorService(accessory);
@@ -120,40 +150,20 @@ export class Others extends irdeviceBase {
120
150
  this.removeWindowService(accessory);
121
151
  this.removeWindowCoveringService(accessory);
122
152
  this.removeStatefulProgrammableSwitchService(accessory);
123
-
124
- // Add GarageDoor Service
125
- const GarageDoorService = `${accessory.displayName} Garage Door Opener`;
126
- (this.GarageDoor!.Service = accessory.getService(this.hap.Service.GarageDoorOpener) as Service
127
- || accessory.addService(this.hap.Service.GarageDoorOpener)), GarageDoorService;
128
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
129
-
130
- this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
131
- this.GarageDoor!.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
132
- this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
133
153
  } else if (this.otherDeviceType === 'door') {
134
- // Initialize Door property
154
+ // Initialize Door Service
155
+ accessory.context.Door = accessory.context.Door ?? {};
135
156
  this.Door = {
136
- Service: accessory.getService(this.hap.Service.Door) as Service,
137
- On: accessory.context.On || false,
157
+ Name: accessory.context.Door.Name ?? `${accessory.displayName} Door`,
158
+ Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
159
+ On: accessory.context.On ?? false,
138
160
  };
139
- this.removeFanService(accessory);
140
- this.removeLockService(accessory);
141
- this.removeOutletService(accessory);
142
- this.removeFaucetService(accessory);
143
- this.removeSwitchService(accessory);
144
- this.removeWindowService(accessory);
145
- this.removeGarageDoorService(accessory);
146
- this.removeWindowCoveringService(accessory);
147
- this.removeStatefulProgrammableSwitchService(accessory);
148
-
149
- // Add Door Service
150
- const DoorService = `${accessory.displayName} Door`;
151
- (this.Door!.Service = accessory.getService(this.hap.Service.Door) as Service
152
- || accessory.addService(this.hap.Service.Door)), DoorService;
161
+ accessory.context.Door = this.Door as object;
153
162
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
154
163
 
155
- this.Door!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
156
164
  this.Door!.Service
165
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
166
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
157
167
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
158
168
  .setProps({
159
169
  validValues: [0, 100],
@@ -161,32 +171,34 @@ export class Others extends irdeviceBase {
161
171
  maxValue: 100,
162
172
  minStep: 100,
163
173
  })
174
+ .onGet(() => {
175
+ return this.GarageDoor!.On;
176
+ })
164
177
  .onSet(this.OnSet.bind(this));
165
- this.Door!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
166
- } else if (this.otherDeviceType === 'window') {
167
- // Initialize Window property
168
- this.Window = {
169
- Service: accessory.getService(this.hap.Service.Window) as Service,
170
- On: accessory.context.On || false,
171
- };
178
+
179
+ // Remove other services
172
180
  this.removeFanService(accessory);
173
181
  this.removeLockService(accessory);
174
- this.removeDoorService(accessory);
175
182
  this.removeOutletService(accessory);
176
183
  this.removeFaucetService(accessory);
177
184
  this.removeSwitchService(accessory);
185
+ this.removeWindowService(accessory);
178
186
  this.removeGarageDoorService(accessory);
179
187
  this.removeWindowCoveringService(accessory);
180
188
  this.removeStatefulProgrammableSwitchService(accessory);
181
-
182
- // Add Window Service
183
- const WindowService = `${accessory.displayName} Window`;
184
- (this.Window!.Service = accessory.getService(this.hap.Service.Window) as Service
185
- || accessory.addService(this.hap.Service.Window)), WindowService;
189
+ } else if (this.otherDeviceType === 'window') {
190
+ // Initialize Window Service
191
+ accessory.context.Window = accessory.context.Window ?? {};
192
+ this.Window = {
193
+ Name: accessory.context.Window.Name ?? `${accessory.displayName} Window`,
194
+ Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
195
+ On: accessory.context.On ?? false,
196
+ };
197
+ accessory.context.Window = this.Window as object;
186
198
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
187
199
 
188
- this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
189
- this.Window!.Service
200
+ this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
201
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
190
202
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
191
203
  .setProps({
192
204
  validValues: [0, 100],
@@ -194,32 +206,35 @@ export class Others extends irdeviceBase {
194
206
  maxValue: 100,
195
207
  minStep: 100,
196
208
  })
209
+ .onGet(() => {
210
+ return this.GarageDoor!.On;
211
+ })
197
212
  .onSet(this.OnSet.bind(this));
198
- this.Window!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
199
- } else if (this.otherDeviceType === 'windowcovering') {
200
- // Initialize WindowCovering property
201
- this.WindowCovering = {
202
- Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
203
- On: accessory.context.On || false,
204
- };
213
+
214
+ // Remove other services
205
215
  this.removeFanService(accessory);
206
216
  this.removeLockService(accessory);
207
217
  this.removeDoorService(accessory);
208
218
  this.removeOutletService(accessory);
209
219
  this.removeFaucetService(accessory);
210
220
  this.removeSwitchService(accessory);
211
- this.removeWindowService(accessory);
212
221
  this.removeGarageDoorService(accessory);
222
+ this.removeWindowCoveringService(accessory);
213
223
  this.removeStatefulProgrammableSwitchService(accessory);
214
-
215
- // Add WindowCovering Service
216
- const WindowCoveringService = `${accessory.displayName} Window Covering`;
217
- (this.WindowCovering!.Service = accessory.getService(this.hap.Service.WindowCovering) as Service
218
- || accessory.addService(this.hap.Service.WindowCovering)), WindowCoveringService;
224
+ } else if (this.otherDeviceType === 'windowcovering') {
225
+ // Initialize WindowCovering Service
226
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
227
+ this.WindowCovering = {
228
+ Name: accessory.context.WindowCovering.Name ?? `${accessory.displayName} Window Covering`,
229
+ Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
230
+ On: accessory.context.On ?? false,
231
+ };
232
+ accessory.context.WindowCovering = this.WindowCovering as object;
219
233
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
220
234
 
221
- this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
222
- this.WindowCovering!.Service
235
+ this.WindowCovering.Service
236
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
237
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
223
238
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
224
239
  .setProps({
225
240
  validValues: [0, 100],
@@ -227,14 +242,41 @@ export class Others extends irdeviceBase {
227
242
  maxValue: 100,
228
243
  minStep: 100,
229
244
  })
245
+ .onGet(() => {
246
+ return this.WindowCovering!.On;
247
+ })
230
248
  .onSet(this.OnSet.bind(this));
231
- this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
249
+
250
+ // Remove other services
251
+ this.removeFanService(accessory);
252
+ this.removeLockService(accessory);
253
+ this.removeDoorService(accessory);
254
+ this.removeOutletService(accessory);
255
+ this.removeFaucetService(accessory);
256
+ this.removeSwitchService(accessory);
257
+ this.removeWindowService(accessory);
258
+ this.removeGarageDoorService(accessory);
259
+ this.removeStatefulProgrammableSwitchService(accessory);
232
260
  } else if (this.otherDeviceType === 'lock') {
233
- // Initialize Lock property
234
- this.Lock = {
235
- Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
236
- On: accessory.context.On || false,
261
+ // Initialize LockMechanism Service
262
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
263
+ this.LockMechanism = {
264
+ Name: accessory.context.LockMechanism.Name ?? `${accessory.displayName} Lock`,
265
+ Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
266
+ On: accessory.context.On ?? false,
237
267
  };
268
+ accessory.context.LockMechanism = this.LockMechanism as object;
269
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
270
+
271
+ this.LockMechanism.Service
272
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
273
+ .getCharacteristic(this.hap.Characteristic.LockTargetState)
274
+ .onGet(() => {
275
+ return this.LockMechanism!.On;
276
+ })
277
+ .onSet(this.OnSet.bind(this));
278
+
279
+ // Remove other services
238
280
  this.removeFanService(accessory);
239
281
  this.removeDoorService(accessory);
240
282
  this.removeOutletService(accessory);
@@ -244,21 +286,26 @@ export class Others extends irdeviceBase {
244
286
  this.removeGarageDoorService(accessory);
245
287
  this.removeWindowCoveringService(accessory);
246
288
  this.removeStatefulProgrammableSwitchService(accessory);
247
-
248
- // Add Lock Service
249
- const LockService = `${accessory.displayName} Lock`;
250
- (this.Lock!.Service = accessory.getService(this.hap.Service.LockMechanism) as Service
251
- || accessory.addService(this.hap.Service.LockMechanism)), LockService;
252
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
253
-
254
- this.Lock!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
255
- this.Lock!.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
256
289
  } else if (this.otherDeviceType === 'faucet') {
257
- // Initialize Faucet property
290
+ // Initialize Faucet Service
291
+ accessory.context.Faucet = accessory.context.Faucet ?? {};
258
292
  this.Faucet = {
259
- Service: accessory.getService(this.hap.Service.Faucet) as Service,
260
- On: accessory.context.On || false,
293
+ Name: accessory.context.Faucet.Name ?? `${accessory.displayName} Faucet`,
294
+ Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
295
+ On: accessory.context.On ?? false,
261
296
  };
297
+ accessory.context.Faucet = this.Faucet as object;
298
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
299
+
300
+ this.Faucet.Service
301
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
302
+ .getCharacteristic(this.hap.Characteristic.Active)
303
+ .onGet(() => {
304
+ return this.Faucet!.On;
305
+ })
306
+ .onSet(this.OnSet.bind(this));
307
+
308
+ // Remove other services
262
309
  this.removeFanService(accessory);
263
310
  this.removeLockService(accessory);
264
311
  this.removeDoorService(accessory);
@@ -268,21 +315,26 @@ export class Others extends irdeviceBase {
268
315
  this.removeGarageDoorService(accessory);
269
316
  this.removeWindowCoveringService(accessory);
270
317
  this.removeStatefulProgrammableSwitchService(accessory);
271
-
272
- // Add Faucet Service
273
- const FaucetService = `${accessory.displayName} Faucet`;
274
- (this.Faucet!.Service = accessory.getService(this.hap.Service.Faucet) as Service
275
- || accessory.addService(this.hap.Service.Faucet)), FaucetService;
276
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
277
-
278
- this.Faucet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
279
- this.Faucet!.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
280
318
  } else if (this.otherDeviceType === 'fan') {
281
- // Initialize Fan property
319
+ // Initialize Fan Service
320
+ accessory.context.Fan = accessory.context.Fan ?? {};
282
321
  this.Fan = {
283
- Service: accessory.getService(this.hap.Service.Fanv2) as Service,
284
- On: accessory.context.On || false,
322
+ Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
323
+ Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
324
+ On: accessory.context.On ?? false,
285
325
  };
326
+ accessory.context.Fan = this.Fan as object;
327
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
328
+
329
+ this.Fan.Service
330
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
331
+ .getCharacteristic(this.hap.Characteristic.On)
332
+ .onGet(() => {
333
+ return this.Fan!.On;
334
+ })
335
+ .onSet(this.OnSet.bind(this));
336
+
337
+ // Remove other services
286
338
  this.removeLockService(accessory);
287
339
  this.removeDoorService(accessory);
288
340
  this.removeFaucetService(accessory);
@@ -292,21 +344,27 @@ export class Others extends irdeviceBase {
292
344
  this.removeGarageDoorService(accessory);
293
345
  this.removeWindowCoveringService(accessory);
294
346
  this.removeStatefulProgrammableSwitchService(accessory);
295
-
296
- // Add Fan Service
297
- const FanService = `${accessory.displayName} Fan`;
298
- (this.Fan!.Service = accessory.getService(this.hap.Service.Fanv2) as Service
299
- || accessory.addService(this.hap.Service.Fanv2)), FanService;
300
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
301
-
302
- this.Fan!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
303
- this.Fan!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
304
347
  } else if (this.otherDeviceType === 'stateful') {
305
- // Initialize StatefulProgrammableSwitch property
348
+ // Initialize StatefulProgrammableSwitch Service
349
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
306
350
  this.StatefulProgrammableSwitch = {
307
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
308
- On: accessory.context.On || false,
351
+ Name: accessory.context.StatefulProgrammableSwitch.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
352
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
353
+ ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
354
+ On: accessory.context.On ?? false,
309
355
  };
356
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
357
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
358
+
359
+ this.StatefulProgrammableSwitch.Service
360
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
361
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
362
+ .onGet(() => {
363
+ return this.StatefulProgrammableSwitch!.On;
364
+ })
365
+ .onSet(this.OnSet.bind(this));
366
+
367
+ // Remove other services
310
368
  this.removeFanService(accessory);
311
369
  this.removeLockService(accessory);
312
370
  this.removeDoorService(accessory);
@@ -316,23 +374,26 @@ export class Others extends irdeviceBase {
316
374
  this.removeWindowService(accessory);
317
375
  this.removeGarageDoorService(accessory);
318
376
  this.removeWindowCoveringService(accessory);
319
-
320
- // Add StatefulProgrammableSwitch.Service
321
- const StatefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
322
- (this.StatefulProgrammableSwitch!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service
323
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), StatefulProgrammableSwitchService;
324
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
325
-
326
- this.StatefulProgrammableSwitch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
327
- this.StatefulProgrammableSwitch!.Service
328
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
329
- .onSet(this.OnSet.bind(this));
330
377
  } else {
331
- // Initialize Outlet property
378
+ // Initialize Outlet Service
379
+ accessory.context.Outlet = accessory.context.Outlet ?? {};
332
380
  this.Outlet = {
333
- Service: accessory.getService(this.hap.Service.Outlet) as Service,
334
- On: accessory.context.On || false,
381
+ Name: accessory.context.Outlet.Name ?? `${accessory.displayName} Outlet`,
382
+ Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
383
+ On: accessory.context.On ?? false,
335
384
  };
385
+ accessory.context.Outlet = this.Outlet as object;
386
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
387
+
388
+ this.Outlet.Service
389
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
390
+ .getCharacteristic(this.hap.Characteristic.On)
391
+ .onGet(() => {
392
+ return this.Outlet!.On;
393
+ })
394
+ .onSet(this.OnSet.bind(this));
395
+
396
+ // Remove other services
336
397
  this.removeFanService(accessory);
337
398
  this.removeLockService(accessory);
338
399
  this.removeDoorService(accessory);
@@ -342,15 +403,6 @@ export class Others extends irdeviceBase {
342
403
  this.removeGarageDoorService(accessory);
343
404
  this.removeWindowCoveringService(accessory);
344
405
  this.removeStatefulProgrammableSwitchService(accessory);
345
-
346
- // Add Outlet.Service
347
- const OutletService = `${accessory.displayName} Outlet`;
348
- (this.Outlet!.Service = accessory.getService(this.hap.Service.Outlet) as Service
349
- || accessory.addService(this.hap.Service.Outlet)), OutletService;
350
- this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
351
-
352
- this.Outlet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
353
- this.Outlet!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
354
406
  }
355
407
  }
356
408
 
@@ -394,11 +446,11 @@ export class Others extends irdeviceBase {
394
446
  } else if (this.otherDeviceType === 'lock') {
395
447
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
396
448
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
397
- this.Lock!.On = false;
449
+ this.LockMechanism!.On = false;
398
450
  } else {
399
- this.Lock!.On = true;
451
+ this.LockMechanism!.On = true;
400
452
  }
401
- On = this.Lock!.On;
453
+ On = this.LockMechanism!.On;
402
454
  } else if (this.otherDeviceType === 'faucet') {
403
455
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
404
456
  if (value === this.hap.Characteristic.Active.INACTIVE) {
@@ -589,22 +641,26 @@ export class Others extends irdeviceBase {
589
641
  }
590
642
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
591
643
  } else if (this.otherDeviceType === 'lock') {
592
- if (this.Lock!.On === undefined) {
593
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Lock!.On}`);
644
+ if (this.LockMechanism?.On === undefined) {
645
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LockMechanism?.On}`);
594
646
  } else {
595
- if (this.Lock!.On) {
596
- this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
597
- this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
647
+ if (this.LockMechanism.On) {
648
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
649
+ this.hap.Characteristic.LockTargetState.UNSECURED);
650
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
651
+ this.hap.Characteristic.LockCurrentState.UNSECURED);
598
652
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
599
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
653
+ + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.LockMechanism.On})`);
600
654
  } else {
601
- this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
602
- this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
655
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
656
+ this.hap.Characteristic.LockTargetState.SECURED);
657
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
658
+ this.hap.Characteristic.LockCurrentState.SECURED);
603
659
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
604
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock!.On})`);
660
+ + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
605
661
  }
606
662
  }
607
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.Lock!.On}`);
663
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism?.On}`);
608
664
  } else if (this.otherDeviceType === 'faucet') {
609
665
  if (this.Faucet!.On === undefined) {
610
666
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Faucet!.On}`);
@@ -730,10 +786,10 @@ export class Others extends irdeviceBase {
730
786
 
731
787
  async removeLockService(accessory: PlatformAccessory): Promise<void> {
732
788
  // If Lock.Service still present, then remove first
733
- if (this.Lock?.Service) {
734
- this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
789
+ if (this.LockMechanism?.Service) {
790
+ this.LockMechanism!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
735
791
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
736
- accessory.removeService(this.Lock!.Service);
792
+ accessory.removeService(this.LockMechanism!.Service);
737
793
  }
738
794
  }
739
795