@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.11

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 (136) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +44 -17
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -2
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +220 -397
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +3 -2
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +59 -31
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +3 -2
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +57 -29
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +47 -18
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +16 -5
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/device.d.ts +9 -0
  24. package/dist/device/device.d.ts.map +1 -1
  25. package/dist/device/device.js +30 -3
  26. package/dist/device/device.js.map +1 -1
  27. package/dist/device/fan.d.ts.map +1 -1
  28. package/dist/device/fan.js +44 -18
  29. package/dist/device/fan.js.map +1 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +46 -18
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +45 -20
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts.map +1 -1
  37. package/dist/device/iosensor.js +46 -18
  38. package/dist/device/iosensor.js.map +1 -1
  39. package/dist/device/lightstrip.d.ts +4 -3
  40. package/dist/device/lightstrip.d.ts.map +1 -1
  41. package/dist/device/lightstrip.js +60 -31
  42. package/dist/device/lightstrip.js.map +1 -1
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +48 -17
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts.map +1 -1
  47. package/dist/device/meter.js +46 -18
  48. package/dist/device/meter.js.map +1 -1
  49. package/dist/device/meterplus.d.ts.map +1 -1
  50. package/dist/device/meterplus.js +46 -18
  51. package/dist/device/meterplus.js.map +1 -1
  52. package/dist/device/motion.d.ts.map +1 -1
  53. package/dist/device/motion.js +45 -17
  54. package/dist/device/motion.js.map +1 -1
  55. package/dist/device/plug.d.ts.map +1 -1
  56. package/dist/device/plug.js +40 -18
  57. package/dist/device/plug.js.map +1 -1
  58. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  59. package/dist/device/robotvacuumcleaner.js +42 -17
  60. package/dist/device/robotvacuumcleaner.js.map +1 -1
  61. package/dist/device/waterdetector.d.ts.map +1 -1
  62. package/dist/device/waterdetector.js +41 -16
  63. package/dist/device/waterdetector.js.map +1 -1
  64. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  65. package/dist/irdevice/airconditioner.js +8 -1
  66. package/dist/irdevice/airconditioner.js.map +1 -1
  67. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  68. package/dist/irdevice/airpurifier.js +6 -0
  69. package/dist/irdevice/airpurifier.js.map +1 -1
  70. package/dist/irdevice/camera.d.ts.map +1 -1
  71. package/dist/irdevice/camera.js +3 -0
  72. package/dist/irdevice/camera.js.map +1 -1
  73. package/dist/irdevice/fan.d.ts.map +1 -1
  74. package/dist/irdevice/fan.js +3 -0
  75. package/dist/irdevice/fan.js.map +1 -1
  76. package/dist/irdevice/irdevice.d.ts +9 -0
  77. package/dist/irdevice/irdevice.d.ts.map +1 -1
  78. package/dist/irdevice/irdevice.js +29 -2
  79. package/dist/irdevice/irdevice.js.map +1 -1
  80. package/dist/irdevice/light.d.ts.map +1 -1
  81. package/dist/irdevice/light.js +9 -0
  82. package/dist/irdevice/light.js.map +1 -1
  83. package/dist/irdevice/other.d.ts +1 -0
  84. package/dist/irdevice/other.d.ts.map +1 -1
  85. package/dist/irdevice/other.js +216 -228
  86. package/dist/irdevice/other.js.map +1 -1
  87. package/dist/irdevice/tv.d.ts.map +1 -1
  88. package/dist/irdevice/tv.js +9 -0
  89. package/dist/irdevice/tv.js.map +1 -1
  90. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  91. package/dist/irdevice/vacuumcleaner.js +3 -0
  92. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  93. package/dist/irdevice/waterheater.js +1 -1
  94. package/dist/irdevice/waterheater.js.map +1 -1
  95. package/dist/platform.d.ts.map +1 -1
  96. package/dist/platform.js +11 -2
  97. package/dist/platform.js.map +1 -1
  98. package/dist/types/bledevicestatus.d.ts +1 -0
  99. package/dist/types/bledevicestatus.d.ts.map +1 -1
  100. package/dist/utils.d.ts +8 -0
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +16 -0
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +6 -6
  105. package/src/device/blindtilt.ts +44 -17
  106. package/src/device/bot.ts +224 -407
  107. package/src/device/ceilinglight.ts +57 -33
  108. package/src/device/colorbulb.ts +55 -31
  109. package/src/device/contact.ts +48 -19
  110. package/src/device/curtain.ts +19 -6
  111. package/src/device/device.ts +36 -3
  112. package/src/device/fan.ts +44 -19
  113. package/src/device/hub.ts +46 -18
  114. package/src/device/humidifier.ts +44 -20
  115. package/src/device/iosensor.ts +46 -18
  116. package/src/device/lightstrip.ts +60 -33
  117. package/src/device/lock.ts +49 -17
  118. package/src/device/meter.ts +46 -18
  119. package/src/device/meterplus.ts +46 -18
  120. package/src/device/motion.ts +46 -18
  121. package/src/device/plug.ts +38 -18
  122. package/src/device/robotvacuumcleaner.ts +41 -17
  123. package/src/device/waterdetector.ts +40 -16
  124. package/src/irdevice/airconditioner.ts +11 -2
  125. package/src/irdevice/airpurifier.ts +8 -0
  126. package/src/irdevice/camera.ts +4 -0
  127. package/src/irdevice/fan.ts +4 -0
  128. package/src/irdevice/irdevice.ts +35 -2
  129. package/src/irdevice/light.ts +12 -0
  130. package/src/irdevice/other.ts +254 -283
  131. package/src/irdevice/tv.ts +12 -0
  132. package/src/irdevice/vacuumcleaner.ts +4 -0
  133. package/src/irdevice/waterheater.ts +1 -1
  134. package/src/platform.ts +11 -2
  135. package/src/types/bledevicestatus.ts +1 -0
  136. package/src/utils.ts +15 -0
@@ -19,63 +19,55 @@ export class Others extends irdeviceBase {
19
19
  private Switch?: {
20
20
  Name: CharacteristicValue;
21
21
  Service: Service;
22
- On: CharacteristicValue;
23
22
  };
24
23
 
25
24
  private GarageDoor?: {
26
25
  Name: CharacteristicValue;
27
26
  Service: Service;
28
- On: CharacteristicValue;
29
27
  };
30
28
 
31
29
  private Door?: {
32
30
  Name: CharacteristicValue;
33
31
  Service: Service;
34
- On: CharacteristicValue;
35
32
  };
36
33
 
37
34
  private Window?: {
38
35
  Name: CharacteristicValue;
39
36
  Service: Service;
40
- On: CharacteristicValue;
41
37
  };
42
38
 
43
39
  private WindowCovering?: {
44
40
  Name: CharacteristicValue;
45
41
  Service: Service;
46
- On: CharacteristicValue;
47
42
  };
48
43
 
49
44
  private LockMechanism?: {
50
45
  Name: CharacteristicValue;
51
46
  Service: Service;
52
- On: CharacteristicValue;
53
47
  };
54
48
 
55
49
  private Faucet?: {
56
50
  Name: CharacteristicValue;
57
51
  Service: Service;
58
- On: CharacteristicValue;
59
52
  };
60
53
 
61
54
  private Fan?: {
62
55
  Name: CharacteristicValue;
63
56
  Service: Service;
64
- On: CharacteristicValue;
65
57
  };
66
58
 
67
59
  private StatefulProgrammableSwitch?: {
68
60
  Name: CharacteristicValue;
69
61
  Service: Service;
70
- On: CharacteristicValue;
71
62
  };
72
63
 
73
64
  private Outlet?: {
74
65
  Name: CharacteristicValue;
75
66
  Service: Service;
76
- On: CharacteristicValue;
77
67
  };
78
68
 
69
+ On!: boolean;
70
+
79
71
  // Config
80
72
  otherDeviceType?: string;
81
73
 
@@ -85,32 +77,31 @@ export class Others extends irdeviceBase {
85
77
  device: irdevice & irDevicesConfig,
86
78
  ) {
87
79
  super(platform, accessory, device);
88
- // Set category
89
- accessory.category = this.hap.Categories.OTHER;
90
80
 
91
81
  // default placeholders
92
82
  this.getOtherConfigSettings(device);
93
83
 
94
84
  // deviceType
95
85
  if (this.otherDeviceType === 'switch') {
86
+ // Set category
87
+ accessory.category = this.hap.Categories.SWITCH;
96
88
  // Initialize Switch Service
97
89
  accessory.context.Switch = accessory.context.Switch ?? {};
90
+ if (accessory.context.Switch.Name) {
91
+ accessory.context.Switch.Name = this.validateAndCleanString(accessory.context.Switch.Name,
92
+ 'Switch Name', accessory.context.Switch.Name);
93
+ }
98
94
  this.Switch = {
99
- Name: accessory.context.Switch.Name ?? `${accessory.displayName} Switch`,
95
+ Name: accessory.context.Switch.Name ?? accessory.displayName,
100
96
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
101
- On: accessory.context.On ?? false,
102
97
  };
103
98
  accessory.context.Switch = this.Switch as object;
104
- this.debugWarnLog('Displaying as Switch');
105
-
99
+ this.debugLog('Displaying as Switch');
100
+ // Initialize Switch Characteristics
106
101
  this.Switch.Service
107
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
102
+ .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
108
103
  .getCharacteristic(this.hap.Characteristic.On)
109
- .onGet(() => {
110
- return this.Switch!.On;
111
- })
112
104
  .onSet(this.OnSet.bind(this));
113
-
114
105
  // Remove other services
115
106
  this.removeFanService(accessory);
116
107
  this.removeLockService(accessory);
@@ -122,25 +113,32 @@ export class Others extends irdeviceBase {
122
113
  this.removeWindowCoveringService(accessory);
123
114
  this.removeStatefulProgrammableSwitchService(accessory);
124
115
  } else if (this.otherDeviceType === 'garagedoor') {
125
- // Initialize Garage Door Service
116
+ // Set category
117
+ accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER;
118
+ // Initialize GarageDoor Service
126
119
  accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
120
+ if (accessory.context.GarageDoor.Name) {
121
+ accessory.context.GarageDoor.Name = this.validateAndCleanString(accessory.context.GarageDoor.Name,
122
+ 'GarageDoor Name', accessory.context.GarageDoor.Name);
123
+ }
127
124
  this.GarageDoor = {
128
- Name: accessory.context.GarageDoor.Name ?? `${accessory.displayName} Garage Door`,
125
+ Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
129
126
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
130
- On: accessory.context.On ?? false,
131
127
  };
132
128
  accessory.context.GarageDoor = this.GarageDoor as object;
133
- this.debugWarnLog('Displaying as Garage Door Opener');
134
-
129
+ this.debugLog('Displaying as Garage Door Opener');
130
+ // Initialize GarageDoor Characteristics
135
131
  this.GarageDoor.Service
136
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
132
+ .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
137
133
  .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
138
134
  .getCharacteristic(this.hap.Characteristic.TargetDoorState)
139
- .onGet(() => {
140
- return this.GarageDoor!.On;
135
+ .setProps({
136
+ validValues: [0, 100],
137
+ minValue: 0,
138
+ maxValue: 100,
139
+ minStep: 100,
141
140
  })
142
141
  .onSet(this.OnSet.bind(this));
143
-
144
142
  // Remove other services
145
143
  this.removeFanService(accessory);
146
144
  this.removeLockService(accessory);
@@ -152,31 +150,31 @@ export class Others extends irdeviceBase {
152
150
  this.removeWindowCoveringService(accessory);
153
151
  this.removeStatefulProgrammableSwitchService(accessory);
154
152
  } else if (this.otherDeviceType === 'door') {
153
+ // Set category
154
+ accessory.category = this.hap.Categories.DOOR;
155
155
  // Initialize Door Service
156
156
  accessory.context.Door = accessory.context.Door ?? {};
157
+ if (accessory.context.Door.Name) {
158
+ accessory.context.Door.Name = this.validateAndCleanString(accessory.context.Door.Name,
159
+ 'Door Name', accessory.context.Door.Name);
160
+ }
157
161
  this.Door = {
158
- Name: accessory.context.Door.Name ?? `${accessory.displayName} Door`,
162
+ Name: accessory.context.Door.Name ?? accessory.displayName,
159
163
  Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
160
- On: accessory.context.On ?? false,
161
164
  };
162
165
  accessory.context.Door = this.Door as object;
163
- this.debugWarnLog('Displaying as Door');
164
-
165
- this.Door!.Service
166
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
166
+ this.debugLog('Displaying as Door');
167
+ // Initialize Door Characteristics
168
+ this.Door.Service
169
+ .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
167
170
  .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
168
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
169
- .setProps({
171
+ .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
170
172
  validValues: [0, 100],
171
173
  minValue: 0,
172
174
  maxValue: 100,
173
175
  minStep: 100,
174
176
  })
175
- .onGet(() => {
176
- return this.GarageDoor!.On;
177
- })
178
177
  .onSet(this.OnSet.bind(this));
179
-
180
178
  // Remove other services
181
179
  this.removeFanService(accessory);
182
180
  this.removeLockService(accessory);
@@ -188,30 +186,31 @@ export class Others extends irdeviceBase {
188
186
  this.removeWindowCoveringService(accessory);
189
187
  this.removeStatefulProgrammableSwitchService(accessory);
190
188
  } else if (this.otherDeviceType === 'window') {
189
+ // Set category
190
+ accessory.category = this.hap.Categories.WINDOW;
191
191
  // Initialize Window Service
192
192
  accessory.context.Window = accessory.context.Window ?? {};
193
+ if (accessory.context.Window.Name) {
194
+ accessory.context.Window.Name = this.validateAndCleanString(accessory.context.Window.Name,
195
+ 'Window Name', accessory.context.Window.Name);
196
+ }
193
197
  this.Window = {
194
- Name: accessory.context.Window.Name ?? `${accessory.displayName} Window`,
198
+ Name: accessory.context.Window.Name ?? accessory.displayName,
195
199
  Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
196
- On: accessory.context.On ?? false,
197
200
  };
198
201
  accessory.context.Window = this.Window as object;
199
- this.debugWarnLog('Displaying as Window');
200
-
201
- this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
202
+ this.debugLog('Displaying as Window');
203
+ // Initialize Window Characteristics
204
+ this.Window.Service
205
+ .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
202
206
  .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
203
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
204
- .setProps({
207
+ .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
205
208
  validValues: [0, 100],
206
209
  minValue: 0,
207
210
  maxValue: 100,
208
211
  minStep: 100,
209
212
  })
210
- .onGet(() => {
211
- return this.GarageDoor!.On;
212
- })
213
213
  .onSet(this.OnSet.bind(this));
214
-
215
214
  // Remove other services
216
215
  this.removeFanService(accessory);
217
216
  this.removeLockService(accessory);
@@ -223,18 +222,23 @@ export class Others extends irdeviceBase {
223
222
  this.removeWindowCoveringService(accessory);
224
223
  this.removeStatefulProgrammableSwitchService(accessory);
225
224
  } else if (this.otherDeviceType === 'windowcovering') {
225
+ // Set category
226
+ accessory.category = this.hap.Categories.WINDOW_COVERING;
226
227
  // Initialize WindowCovering Service
227
228
  accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
229
+ if (accessory.context.WindowCovering.Name) {
230
+ accessory.context.WindowCovering.Name = this.validateAndCleanString(accessory.context.WindowCovering.Name,
231
+ 'WindowCovering Name', accessory.context.WindowCovering.Name);
232
+ }
228
233
  this.WindowCovering = {
229
- Name: accessory.context.WindowCovering.Name ?? `${accessory.displayName} Window Covering`,
234
+ Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
230
235
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
231
- On: accessory.context.On ?? false,
232
236
  };
233
237
  accessory.context.WindowCovering = this.WindowCovering as object;
234
- this.debugWarnLog('Displaying as Window Covering');
235
-
238
+ this.debugLog('Displaying as Window Covering');
239
+ // Initialize WindowCovering Characteristics
236
240
  this.WindowCovering.Service
237
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
241
+ .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
238
242
  .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
239
243
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
240
244
  .setProps({
@@ -243,11 +247,7 @@ export class Others extends irdeviceBase {
243
247
  maxValue: 100,
244
248
  minStep: 100,
245
249
  })
246
- .onGet(() => {
247
- return this.WindowCovering!.On;
248
- })
249
250
  .onSet(this.OnSet.bind(this));
250
-
251
251
  // Remove other services
252
252
  this.removeFanService(accessory);
253
253
  this.removeLockService(accessory);
@@ -259,24 +259,26 @@ export class Others extends irdeviceBase {
259
259
  this.removeGarageDoorService(accessory);
260
260
  this.removeStatefulProgrammableSwitchService(accessory);
261
261
  } else if (this.otherDeviceType === 'lock') {
262
- // Initialize LockMechanism Service
262
+ // Set category
263
+ accessory.category = this.hap.Categories.DOOR_LOCK;
264
+ // Initialize Lock Service
263
265
  accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
266
+ if (accessory.context.LockMechanism.Name) {
267
+ accessory.context.LockMechanism.Name = this.validateAndCleanString(accessory.context.LockMechanism.Name,
268
+ 'LockMechanism Name', accessory.context.LockMechanism.Name);
269
+ }
264
270
  this.LockMechanism = {
265
- Name: accessory.context.LockMechanism.Name ?? `${accessory.displayName} Lock`,
271
+ Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
266
272
  Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
267
- On: accessory.context.On ?? false,
268
273
  };
269
274
  accessory.context.LockMechanism = this.LockMechanism as object;
270
- this.debugWarnLog('Displaying as Lock');
271
-
275
+ this.debugLog('Displaying as Lock');
276
+ // Initialize Lock Characteristics
272
277
  this.LockMechanism.Service
273
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
278
+ .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
279
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
274
280
  .getCharacteristic(this.hap.Characteristic.LockTargetState)
275
- .onGet(() => {
276
- return this.LockMechanism!.On;
277
- })
278
281
  .onSet(this.OnSet.bind(this));
279
-
280
282
  // Remove other services
281
283
  this.removeFanService(accessory);
282
284
  this.removeDoorService(accessory);
@@ -288,24 +290,25 @@ export class Others extends irdeviceBase {
288
290
  this.removeWindowCoveringService(accessory);
289
291
  this.removeStatefulProgrammableSwitchService(accessory);
290
292
  } else if (this.otherDeviceType === 'faucet') {
293
+ // Set category
294
+ accessory.category = this.hap.Categories.FAUCET;
291
295
  // Initialize Faucet Service
292
296
  accessory.context.Faucet = accessory.context.Faucet ?? {};
297
+ if (accessory.context.Faucet.Name) {
298
+ accessory.context.Faucet.Name = this.validateAndCleanString(accessory.context.Faucet.Name,
299
+ 'Faucet Name', accessory.context.Faucet.Name);
300
+ }
293
301
  this.Faucet = {
294
- Name: accessory.context.Faucet.Name ?? `${accessory.displayName} Faucet`,
302
+ Name: accessory.context.Faucet.Name ?? accessory.displayName,
295
303
  Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
296
- On: accessory.context.On ?? false,
297
304
  };
298
305
  accessory.context.Faucet = this.Faucet as object;
299
- this.debugWarnLog('Displaying as Faucet');
300
-
306
+ this.debugLog('Displaying as Faucet');
307
+ // Initialize Faucet Characteristics
301
308
  this.Faucet.Service
302
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
309
+ .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
303
310
  .getCharacteristic(this.hap.Characteristic.Active)
304
- .onGet(() => {
305
- return this.Faucet!.On;
306
- })
307
311
  .onSet(this.OnSet.bind(this));
308
-
309
312
  // Remove other services
310
313
  this.removeFanService(accessory);
311
314
  this.removeLockService(accessory);
@@ -317,24 +320,25 @@ export class Others extends irdeviceBase {
317
320
  this.removeWindowCoveringService(accessory);
318
321
  this.removeStatefulProgrammableSwitchService(accessory);
319
322
  } else if (this.otherDeviceType === 'fan') {
323
+ // Set category
324
+ accessory.category = this.hap.Categories.FAN;
320
325
  // Initialize Fan Service
321
326
  accessory.context.Fan = accessory.context.Fan ?? {};
327
+ if (accessory.context.Fan.Name) {
328
+ accessory.context.Fan.Name = this.validateAndCleanString(accessory.context.Fan.Name,
329
+ 'Fan Name', accessory.context.Fan.Name);
330
+ }
322
331
  this.Fan = {
323
- Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
332
+ Name: accessory.context.Fan.Name ?? accessory.displayName,
324
333
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
325
- On: accessory.context.On ?? false,
326
334
  };
327
335
  accessory.context.Fan = this.Fan as object;
328
- this.debugWarnLog('Displaying as Fan');
329
-
336
+ this.debugLog('Displaying as Fan');
337
+ // Initialize Fan Characteristics
330
338
  this.Fan.Service
331
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
332
- .getCharacteristic(this.hap.Characteristic.On)
333
- .onGet(() => {
334
- return this.Fan!.On;
335
- })
339
+ .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
340
+ .getCharacteristic(this.hap.Characteristic.Active)
336
341
  .onSet(this.OnSet.bind(this));
337
-
338
342
  // Remove other services
339
343
  this.removeLockService(accessory);
340
344
  this.removeDoorService(accessory);
@@ -346,25 +350,26 @@ export class Others extends irdeviceBase {
346
350
  this.removeWindowCoveringService(accessory);
347
351
  this.removeStatefulProgrammableSwitchService(accessory);
348
352
  } else if (this.otherDeviceType === 'stateful') {
353
+ // Set category
354
+ accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH;
349
355
  // Initialize StatefulProgrammableSwitch Service
350
356
  accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
357
+ if (accessory.context.StatefulProgrammableSwitch.Name) {
358
+ accessory.context.StatefulProgrammableSwitch.Name = this.validateAndCleanString(accessory.context.StatefulProgrammableSwitch.Name,
359
+ 'StatefulProgrammableSwitch Name', accessory.context.StatefulProgrammableSwitch.Name);
360
+ }
351
361
  this.StatefulProgrammableSwitch = {
352
- Name: accessory.context.StatefulProgrammableSwitch.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
362
+ Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
353
363
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
354
- ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
355
- On: accessory.context.On ?? false,
364
+ ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
356
365
  };
357
366
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
358
- this.debugWarnLog('Displaying as Stateful Programmable Switch');
359
-
367
+ this.debugLog('Displaying as Stateful Programmable Switch');
368
+ // Initialize StatefulProgrammableSwitch Characteristics
360
369
  this.StatefulProgrammableSwitch.Service
361
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
370
+ .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
362
371
  .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
363
- .onGet(() => {
364
- return this.StatefulProgrammableSwitch!.On;
365
- })
366
372
  .onSet(this.OnSet.bind(this));
367
-
368
373
  // Remove other services
369
374
  this.removeFanService(accessory);
370
375
  this.removeLockService(accessory);
@@ -375,25 +380,26 @@ export class Others extends irdeviceBase {
375
380
  this.removeWindowService(accessory);
376
381
  this.removeGarageDoorService(accessory);
377
382
  this.removeWindowCoveringService(accessory);
378
- } else {
379
- // Initialize Outlet Service
383
+ } else if (this.otherDeviceType === 'outlet') {
384
+ // Set category
385
+ accessory.category = this.hap.Categories.OUTLET;
386
+ // Initialize Switch property
380
387
  accessory.context.Outlet = accessory.context.Outlet ?? {};
388
+ if (accessory.context.Outlet.Name) {
389
+ accessory.context.Outlet.Name = this.validateAndCleanString(accessory.context.Outlet.Name,
390
+ 'Outlet Name', accessory.context.Outlet.Name);
391
+ }
381
392
  this.Outlet = {
382
- Name: accessory.context.Outlet.Name ?? `${accessory.displayName} Outlet`,
393
+ Name: accessory.context.Outlet.Name ?? accessory.displayName,
383
394
  Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
384
- On: accessory.context.On ?? false,
385
395
  };
386
396
  accessory.context.Outlet = this.Outlet as object;
387
- this.debugWarnLog('Displaying as Outlet');
388
-
397
+ this.debugLog('Displaying as Outlet');
398
+ // Initialize Outlet Characteristics
389
399
  this.Outlet.Service
390
- .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
400
+ .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
391
401
  .getCharacteristic(this.hap.Characteristic.On)
392
- .onGet(() => {
393
- return this.Outlet!.On;
394
- })
395
402
  .onSet(this.OnSet.bind(this));
396
-
397
403
  // Remove other services
398
404
  this.removeFanService(accessory);
399
405
  this.removeLockService(accessory);
@@ -404,6 +410,8 @@ export class Others extends irdeviceBase {
404
410
  this.removeGarageDoorService(accessory);
405
411
  this.removeWindowCoveringService(accessory);
406
412
  this.removeStatefulProgrammableSwitchService(accessory);
413
+ } else {
414
+ this.errorLog('Device Type not set');
407
415
  }
408
416
  }
409
417
 
@@ -411,75 +419,57 @@ export class Others extends irdeviceBase {
411
419
  * Handle requests to set the "On" characteristic
412
420
  */
413
421
  async OnSet(value: CharacteristicValue): Promise<void> {
414
- let On: boolean;
415
- if (this.otherDeviceType === 'garagedoor') {
416
- this.infoLog(`Set TargetDoorState: ${value}`);
417
- if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
418
- this.GarageDoor!.On = false;
419
- } else {
420
- this.GarageDoor!.On = true;
422
+ if (this.otherDeviceType === 'switch') {
423
+ if (this.Switch) {
424
+ await this.debugLog(`Set On: ${value}`);
425
+ this.On = value === false ? false : true;
426
+ }
427
+ } else if (this.otherDeviceType === 'garagedoor') {
428
+ if (this.GarageDoor) {
429
+ await this.debugLog(`Set TargetDoorState: ${value}`);
430
+ this.On = value === this.hap.Characteristic.TargetDoorState.CLOSED ? false : true;
421
431
  }
422
- On = this.GarageDoor!.On;
423
432
  } else if (this.otherDeviceType === 'door') {
424
- this.infoLog(`Set TargetPosition: ${value}`);
425
- if (value === 0) {
426
- this.Door!.On = false;
427
- } else {
428
- this.Door!.On = true;
433
+ if (this.Door) {
434
+ await this.debugLog(`Set TargetPosition: ${value}`);
435
+ this.On = value === 0 ? false : true;
429
436
  }
430
- On = this.Door!.On;
431
437
  } else if (this.otherDeviceType === 'window') {
432
- this.infoLog(`Set TargetPosition: ${value}`);
433
- if (value === 0) {
434
- this.Window!.On = false;
435
- } else {
436
- this.Window!.On = true;
438
+ if (this.Window) {
439
+ await this.debugLog(`Set TargetPosition: ${value}`);
440
+ this.On = value === 0 ? false : true;
437
441
  }
438
- On = this.Window!.On;
439
442
  } else if (this.otherDeviceType === 'windowcovering') {
440
- this.infoLog(`Set TargetPosition: ${value}`);
441
- if (value === 0) {
442
- this.WindowCovering!.On = false;
443
- } else {
444
- this.WindowCovering!.On = true;
443
+ if (this.WindowCovering) {
444
+ await this.debugLog(`Set TargetPosition: ${value}`);
445
+ this.On = value === 0 ? false : true;
445
446
  }
446
- On = this.WindowCovering!.On;
447
447
  } else if (this.otherDeviceType === 'lock') {
448
- this.infoLog(`Set LockTargetState: ${value}`);
449
- if (value === this.hap.Characteristic.LockTargetState.SECURED) {
450
- this.LockMechanism!.On = false;
451
- } else {
452
- this.LockMechanism!.On = true;
448
+ if (this.LockMechanism) {
449
+ await this.debugLog(`Set LockTargetState: ${value}`);
450
+ this.On = value === this.hap.Characteristic.LockTargetState.SECURED ? false : true;
453
451
  }
454
- On = this.LockMechanism!.On;
455
452
  } else if (this.otherDeviceType === 'faucet') {
456
- this.infoLog(`Set Active: ${value}`);
457
- if (value === this.hap.Characteristic.Active.INACTIVE) {
458
- this.Faucet!.On = false;
459
- } else {
460
- this.Faucet!.On = true;
453
+ if (this.Faucet) {
454
+ await this.debugLog(`Set Active: ${value}`);
455
+ this.On = value === this.hap.Characteristic.Active.INACTIVE ? false : true;
461
456
  }
462
- On = this.Faucet!.On;
463
457
  } else if (this.otherDeviceType === 'stateful') {
464
- this.infoLog(`Set ProgrammableSwitchOutputState: ${value}`);
465
- if (value === 0) {
466
- this.StatefulProgrammableSwitch!.On = false;
467
- } else {
468
- this.StatefulProgrammableSwitch!.On = true;
458
+ if (this.StatefulProgrammableSwitch) {
459
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
460
+ this.On = value === 0 ? false : true;
469
461
  }
470
-
471
- On = this.StatefulProgrammableSwitch!.On;
472
462
  } else {
473
- this.infoLog(`Set On: ${value}`);
474
- this.Outlet!.On = value;
475
- On = this.Outlet!.On ? true : false;
463
+ if (this.Outlet) {
464
+ await this.debugLog(`Set On: ${value}`);
465
+ this.On = value === false ? false : true;
466
+ }
476
467
  }
477
-
478
468
  //pushChanges
479
- if (On === true) {
480
- await this.pushOnChanges(On);
469
+ if (this.On === true) {
470
+ await this.pushOnChanges(this.On);
481
471
  } else {
482
- await this.pushOffChanges(On);
472
+ await this.pushOffChanges(this.On);
483
473
  }
484
474
  }
485
475
 
@@ -557,160 +547,151 @@ export class Others extends irdeviceBase {
557
547
 
558
548
  async updateHomeKitCharacteristics(): Promise<void> {
559
549
  await this.debugLog('updateHomeKitCharacteristics');
560
- if (this.otherDeviceType === 'garagedoor') {
561
- if (this.GarageDoor!.On === undefined) {
562
- await this.debugLog(`On: ${this.GarageDoor!.On}`);
550
+ // State
551
+ if (this.otherDeviceType === 'switch' && this.Switch) {
552
+ if (this.On === undefined) {
553
+ await this.debugLog(`On: ${this.On}`);
554
+ } else {
555
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
556
+ await this.debugLog(`updateCharacteristic On: ${this.On}`);
557
+ }
558
+ } else if (this.otherDeviceType === 'garagedoor' && this.GarageDoor) {
559
+ if (this.On === undefined) {
560
+ await this.debugLog(`On: ${this.On}`);
563
561
  } else {
564
- if (this.GarageDoor!.On) {
565
- this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
566
- this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
567
- await this.debugLog('updateCharacteristic'
568
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
562
+ if (this.On) {
563
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
564
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
565
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`);
569
566
  } else {
570
- this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
571
- this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
572
- await this.debugLog('updateCharacteristic'
573
- + ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
567
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
568
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
569
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`);
574
570
  }
575
571
  }
576
- await this.debugLog(`Garage Door On: ${this.GarageDoor!.On}`);
577
- } else if (this.otherDeviceType === 'door') {
578
- if (this.Door!.On === undefined) {
579
- await this.debugLog(`On: ${this.Door!.On}`);
572
+ await this.debugLog(`Garage Door On: ${this.On}`);
573
+ } else if (this.otherDeviceType === 'door' && this.Door) {
574
+ if (this.On === undefined) {
575
+ await this.debugLog(`On: ${this.On}`);
580
576
  } else {
581
- if (this.Door!.On) {
582
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
583
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
584
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
585
- await this.debugLog('updateCharacteristic'
586
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
577
+ if (this.On) {
578
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
579
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
580
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
581
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
587
582
  } else {
588
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
589
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
590
- this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
591
- await this.debugLog('updateCharacteristic'
592
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
583
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
584
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
585
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
586
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
593
587
  }
594
588
  }
595
- await this.debugLog(`Door On: ${this.Door!.On}`);
596
- } else if (this.otherDeviceType === 'window') {
597
- if (this.Window!.On === undefined) {
598
- await this.debugLog(`On: ${this.Window!.On}`);
589
+ await this.debugLog(`Door On: ${this.On}`);
590
+ } else if (this.otherDeviceType === 'window' && this.Window) {
591
+ if (this.On === undefined) {
592
+ await this.debugLog(`On: ${this.On}`);
599
593
  } else {
600
- if (this.Window!.On) {
601
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
602
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
603
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
604
- await this.debugLog('updateCharacteristic'
605
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
594
+ if (this.On) {
595
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
596
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
597
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
598
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
606
599
  } else {
607
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
608
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
609
- this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
610
- await this.debugLog('updateCharacteristic'
611
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
600
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
601
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
602
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
603
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
612
604
  }
613
605
  }
614
- await this.debugLog(`Window On: ${this.Window!.On}`);
615
- } else if (this.otherDeviceType === 'windowcovering') {
616
- if (this.WindowCovering!.On === undefined) {
617
- await this.debugLog(`On: ${this.WindowCovering!.On}`);
606
+ await this.debugLog(`Window On: ${this.On}`);
607
+ } else if (this.otherDeviceType === 'windowcovering' && this.WindowCovering) {
608
+ if (this.On === undefined) {
609
+ await this.debugLog(`On: ${this.On}`);
618
610
  } else {
619
- if (this.WindowCovering!.On) {
620
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
621
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
622
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
623
- await this.debugLog('updateCharacteristic'
624
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
611
+ if (this.On) {
612
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
613
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
614
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
615
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
625
616
  } else {
626
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
627
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
628
- this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
629
- await this.debugLog('updateCharacteristic'
630
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
617
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
618
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
619
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
620
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
631
621
  }
632
622
  }
633
- await this.debugLog(`Window Covering On: ${this.WindowCovering!.On}`);
634
- } else if (this.otherDeviceType === 'lock') {
635
- if (this.LockMechanism?.On === undefined) {
636
- await this.debugLog(`On: ${this.LockMechanism?.On}`);
623
+ await this.debugLog(`Window Covering On: ${this.On}`);
624
+ } else if (this.otherDeviceType === 'lock' && this.LockMechanism) {
625
+ if (this.On === undefined) {
626
+ await this.debugLog(`On: ${this.On}`);
637
627
  } else {
638
- if (this.LockMechanism.On) {
628
+ if (this.On) {
639
629
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
640
630
  this.hap.Characteristic.LockTargetState.UNSECURED);
641
631
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
642
632
  this.hap.Characteristic.LockCurrentState.UNSECURED);
643
- await this.debugLog('updateCharacteristic'
644
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.LockMechanism.On})`);
633
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
645
634
  } else {
646
635
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
647
636
  this.hap.Characteristic.LockTargetState.SECURED);
648
637
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
649
638
  this.hap.Characteristic.LockCurrentState.SECURED);
650
- await this.debugLog('updateCharacteristic'
651
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
639
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
652
640
  }
653
641
  }
654
- await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
655
- } else if (this.otherDeviceType === 'faucet') {
656
- if (this.Faucet!.On === undefined) {
657
- await this.debugLog(`On: ${this.Faucet!.On}`);
642
+ await this.debugLog(`Lock On: ${this.On}`);
643
+ } else if (this.otherDeviceType === 'faucet' && this.Faucet) {
644
+ if (this.On === undefined) {
645
+ await this.debugLog(`On: ${this.On}`);
658
646
  } else {
659
- if (this.Faucet!.On) {
660
- this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
661
- await this.debugLog(`updateCharacteristic Active: ${this.Faucet!.On}`);
647
+ if (this.On) {
648
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
649
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
662
650
  } else {
663
- this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
664
- await this.debugLog(`updateCharacteristic Active: ${this.Faucet!.On}`);
651
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
652
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
665
653
  }
666
654
  }
667
- await this.debugLog(`Faucet On: ${this.Faucet!.On}`);
668
- } else if (this.otherDeviceType === 'fan') {
669
- if (this.Fan!.On === undefined) {
670
- await this.debugLog(`On: ${this.Fan!.On}`);
655
+ await this.debugLog(`Faucet On: ${this.On}`);
656
+ } else if (this.otherDeviceType === 'fan' && this.Fan) {
657
+ if (this.On === undefined) {
658
+ await this.debugLog(`On: ${this.On}`);
671
659
  } else {
672
- if (this.Fan!.On) {
673
- this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
674
- await this.debugLog(`updateCharacteristic On: ${this.Fan!.On}`);
660
+ if (this.On) {
661
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
662
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
675
663
  } else {
676
- this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
677
- await this.debugLog(`updateCharacteristic On: ${this.Fan!.On}`);
664
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
665
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
678
666
  }
679
667
  }
680
- await this.debugLog(`Fan On: ${this.Fan!.On}`);
681
- } else if (this.otherDeviceType === 'stateful') {
682
- if (this.StatefulProgrammableSwitch!.On === undefined) {
683
- await this.debugLog(`On: ${this.StatefulProgrammableSwitch!.On}`);
668
+ await this.debugLog(`Fan On: ${this.On}`);
669
+ } else if (this.otherDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
670
+ if (this.On === undefined) {
671
+ await this.debugLog(`On: ${this.On}`);
684
672
  } else {
685
- if (this.StatefulProgrammableSwitch!.On) {
686
- this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
673
+ if (this.On) {
674
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
687
675
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
688
- this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
689
- await this.debugLog('updateCharacteristic'
690
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
676
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
677
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
691
678
  } else {
692
- this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
679
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
693
680
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
694
- this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
695
- await this.debugLog('updateCharacteristic'
696
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
681
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
682
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
697
683
  }
698
684
  }
699
- await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
700
- } else if (this.otherDeviceType === 'switch') {
701
- if (this.Switch!.On === undefined) {
702
- await this.debugLog(`On: ${this.Switch!.On}`);
685
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`);
686
+ } else if (this.otherDeviceType === 'outlet' && this.Outlet) {
687
+ if (this.On === undefined) {
688
+ await this.debugLog(`On: ${this.On}`);
703
689
  } else {
704
- this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch!.On);
705
- await this.debugLog(`updateCharacteristic On: ${this.Switch!.On}`);
690
+ this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
691
+ await this.debugLog(`updateCharacteristic On: ${this.On}`);
706
692
  }
707
693
  } else {
708
- if (this.Outlet!.On === undefined) {
709
- await this.debugLog(`On: ${this.Outlet!.On}`);
710
- } else {
711
- this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet!.On);
712
- await this.debugLog(`updateCharacteristic On: ${this.Outlet!.On}`);
713
- }
694
+ await this.errorLog(`otherDeviceType: ${this.otherDeviceType}, On: ${this.On}`);
714
695
  }
715
696
  }
716
697
 
@@ -774,7 +755,6 @@ export class Others extends irdeviceBase {
774
755
  this.Outlet = {
775
756
  Name: accessory.context.Outlet.Name ?? `${accessory.displayName} Outlet`,
776
757
  Service: accessory.getService(this.hap.Service.Outlet) as Service,
777
- On: accessory.context.On ?? false,
778
758
  };
779
759
  accessory.context.Outlet = this.Outlet as object;
780
760
  this.warnLog('Removing any leftover Outlet Service');
@@ -787,7 +767,6 @@ export class Others extends irdeviceBase {
787
767
  this.GarageDoor = {
788
768
  Name: accessory.context.GarageDoor.Name ?? `${accessory.displayName} Garage Door`,
789
769
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
790
- On: accessory.context.On ?? false,
791
770
  };
792
771
  accessory.context.GarageDoor = this.GarageDoor as object;
793
772
  this.warnLog('Removing any leftover Garage Door Service');
@@ -800,7 +779,6 @@ export class Others extends irdeviceBase {
800
779
  this.Door = {
801
780
  Name: accessory.context.Door.Name ?? `${accessory.displayName} Door`,
802
781
  Service: accessory.getService(this.hap.Service.Door) as Service,
803
- On: accessory.context.On ?? false,
804
782
  };
805
783
  accessory.context.Door = this.Door as object;
806
784
  this.warnLog('Removing any leftover Door Service');
@@ -813,7 +791,6 @@ export class Others extends irdeviceBase {
813
791
  this.LockMechanism = {
814
792
  Name: accessory.context.LockMechanism.Name ?? `${accessory.displayName} Lock`,
815
793
  Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
816
- On: accessory.context.On ?? false,
817
794
  };
818
795
  accessory.context.LockMechanism = this.LockMechanism as object;
819
796
  this.warnLog('Removing any leftover Lock Service');
@@ -826,7 +803,6 @@ export class Others extends irdeviceBase {
826
803
  this.Faucet = {
827
804
  Name: accessory.context.Faucet.Name ?? `${accessory.displayName} Faucet`,
828
805
  Service: accessory.getService(this.hap.Service.Faucet) as Service,
829
- On: accessory.context.On ?? false,
830
806
  };
831
807
  accessory.context.Faucet = this.Faucet as object;
832
808
  this.warnLog('Removing any leftover Faucet Service');
@@ -839,7 +815,6 @@ export class Others extends irdeviceBase {
839
815
  this.Fan = {
840
816
  Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
841
817
  Service: accessory.getService(this.hap.Service.Fanv2) as Service,
842
- On: accessory.context.On ?? false,
843
818
  };
844
819
  accessory.context.Fan = this.Fan as object;
845
820
  this.warnLog('Removing any leftover Fan Service');
@@ -852,7 +827,6 @@ export class Others extends irdeviceBase {
852
827
  this.Window = {
853
828
  Name: accessory.context.Window.Name ?? `${accessory.displayName} Window`,
854
829
  Service: accessory.getService(this.hap.Service.Window) as Service,
855
- On: accessory.context.On ?? false,
856
830
  };
857
831
  accessory.context.Window = this.Window as object;
858
832
  this.warnLog('Removing any leftover Window Service');
@@ -865,7 +839,6 @@ export class Others extends irdeviceBase {
865
839
  this.WindowCovering = {
866
840
  Name: accessory.context.WindowCovering.Name ?? `${accessory.displayName} Window Covering`,
867
841
  Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
868
- On: accessory.context.On ?? false,
869
842
  };
870
843
  accessory.context.WindowCovering = this.WindowCovering as object;
871
844
  this.warnLog('Removing any leftover Window Covering Service');
@@ -878,7 +851,6 @@ export class Others extends irdeviceBase {
878
851
  this.StatefulProgrammableSwitch = {
879
852
  Name: accessory.context.StatefulProgrammableSwitch.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
880
853
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
881
- On: accessory.context.On ?? false,
882
854
  };
883
855
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
884
856
  this.warnLog('Removing any leftover Stateful Programmable Switch Service');
@@ -891,7 +863,6 @@ export class Others extends irdeviceBase {
891
863
  this.Switch = {
892
864
  Name: accessory.context.Switch.Name ?? `${accessory.displayName} Switch`,
893
865
  Service: accessory.getService(this.hap.Service.Switch) as Service,
894
- On: accessory.context.On ?? false,
895
866
  };
896
867
  accessory.context.Switch = this.Switch as object;
897
868
  this.warnLog('Removing any leftover Switch Service');