@switchbot/homebridge-switchbot 3.5.0-beta.58 → 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 (80) hide show
  1. package/dist/device/blindtilt.d.ts +1 -1
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +101 -67
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -1
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +200 -153
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts.map +1 -1
  10. package/dist/device/ceilinglight.js +39 -34
  11. package/dist/device/ceilinglight.js.map +1 -1
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +35 -36
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts.map +1 -1
  16. package/dist/device/contact.js +71 -56
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts +1 -1
  19. package/dist/device/curtain.d.ts.map +1 -1
  20. package/dist/device/curtain.js +98 -54
  21. package/dist/device/curtain.js.map +1 -1
  22. package/dist/device/device.d.ts.map +1 -1
  23. package/dist/device/device.js +7 -9
  24. package/dist/device/device.js.map +1 -1
  25. package/dist/device/fan.d.ts.map +1 -1
  26. package/dist/device/fan.js +53 -23
  27. package/dist/device/fan.js.map +1 -1
  28. package/dist/device/hub.d.ts.map +1 -1
  29. package/dist/device/hub.js +39 -52
  30. package/dist/device/hub.js.map +1 -1
  31. package/dist/device/humidifier.d.ts.map +1 -1
  32. package/dist/device/humidifier.js +38 -38
  33. package/dist/device/humidifier.js.map +1 -1
  34. package/dist/device/iosensor.d.ts.map +1 -1
  35. package/dist/device/iosensor.js +40 -45
  36. package/dist/device/iosensor.js.map +1 -1
  37. package/dist/device/lightstrip.d.ts.map +1 -1
  38. package/dist/device/lightstrip.js +34 -31
  39. package/dist/device/lightstrip.js.map +1 -1
  40. package/dist/device/lock.d.ts.map +1 -1
  41. package/dist/device/lock.js +67 -58
  42. package/dist/device/lock.js.map +1 -1
  43. package/dist/device/meter.d.ts.map +1 -1
  44. package/dist/device/meter.js +41 -46
  45. package/dist/device/meter.js.map +1 -1
  46. package/dist/device/meterplus.d.ts.map +1 -1
  47. package/dist/device/meterplus.js +41 -46
  48. package/dist/device/meterplus.js.map +1 -1
  49. package/dist/device/motion.d.ts.map +1 -1
  50. package/dist/device/motion.js +48 -38
  51. package/dist/device/motion.js.map +1 -1
  52. package/dist/device/plug.d.ts.map +1 -1
  53. package/dist/device/plug.js +12 -12
  54. package/dist/device/plug.js.map +1 -1
  55. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  56. package/dist/device/robotvacuumcleaner.js +78 -95
  57. package/dist/device/robotvacuumcleaner.js.map +1 -1
  58. package/dist/device/waterdetector.d.ts.map +1 -1
  59. package/dist/device/waterdetector.js +38 -30
  60. package/dist/device/waterdetector.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/device/blindtilt.ts +115 -84
  63. package/src/device/bot.ts +233 -172
  64. package/src/device/ceilinglight.ts +43 -42
  65. package/src/device/colorbulb.ts +35 -40
  66. package/src/device/contact.ts +77 -60
  67. package/src/device/curtain.ts +106 -61
  68. package/src/device/device.ts +7 -9
  69. package/src/device/fan.ts +61 -26
  70. package/src/device/hub.ts +47 -57
  71. package/src/device/humidifier.ts +48 -52
  72. package/src/device/iosensor.ts +51 -53
  73. package/src/device/lightstrip.ts +37 -35
  74. package/src/device/lock.ts +74 -65
  75. package/src/device/meter.ts +47 -50
  76. package/src/device/meterplus.ts +47 -50
  77. package/src/device/motion.ts +53 -42
  78. package/src/device/plug.ts +14 -15
  79. package/src/device/robotvacuumcleaner.ts +83 -100
  80. package/src/device/waterdetector.ts +41 -31
@@ -21,7 +21,7 @@ export class Bot extends deviceBase {
21
21
  Door;
22
22
  Window;
23
23
  WindowCovering;
24
- Lock;
24
+ LockMechanism;
25
25
  Faucet;
26
26
  Fan;
27
27
  StatefulProgrammableSwitch;
@@ -46,17 +46,37 @@ export class Bot extends deviceBase {
46
46
  this.botUpdateInProgress = false;
47
47
  // Initialize Battery property
48
48
  this.Battery = {
49
- Service: accessory.getService(this.hap.Service.Battery),
50
- BatteryLevel: accessory.context.BatteryLevel || 100,
51
- StatusLowBattery: accessory.context.StatusLowBattery || this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
49
+ Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
50
+ Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
51
+ BatteryLevel: accessory.context.BatteryLevel ?? 100,
52
+ StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
52
53
  };
54
+ // Initialize Battery Characteristics
55
+ this.Battery.Service
56
+ .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
57
+ .setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
58
+ .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
59
+ accessory.context.Battery.Name = this.Battery.Name;
53
60
  // deviceType
54
61
  if (this.botDeviceType === 'switch') {
55
- // Initialize Switch property
62
+ // Initialize Switch Service
56
63
  this.Switch = {
57
- Service: accessory.getService(this.hap.Service.Switch),
58
- On: accessory.context.On || false,
64
+ Name: accessory.context.Name ?? accessory.displayName,
65
+ Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch),
66
+ On: accessory.context.On ?? false,
59
67
  };
68
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
69
+ // Initialize Switch Characteristics
70
+ this.Switch.Service
71
+ .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
72
+ .setCharacteristic(this.hap.Characteristic.On, this.Switch.On)
73
+ .getCharacteristic(this.hap.Characteristic.On)
74
+ .onGet(() => {
75
+ return this.Switch.On;
76
+ })
77
+ .onSet(this.OnSet.bind(this));
78
+ accessory.context.Name = this.Switch.Name;
79
+ // Remove other services
60
80
  this.removeFanService(accessory);
61
81
  this.removeLockService(accessory);
62
82
  this.removeDoorService(accessory);
@@ -66,20 +86,31 @@ export class Bot extends deviceBase {
66
86
  this.removeGarageDoorService(accessory);
67
87
  this.removeWindowCoveringService(accessory);
68
88
  this.removeStatefulProgrammableSwitchService(accessory);
69
- // Add switchService
70
- const switchService = `${accessory.displayName} Switch`;
71
- (this.Switch.Service = accessory.getService(this.hap.Service.Switch)
72
- || accessory.addService(this.hap.Service.Switch)), switchService;
73
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
74
- this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
75
- this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
76
89
  }
77
90
  else if (this.botDeviceType === 'garagedoor') {
78
- // Initialize Switch property
91
+ // Initialize GarageDoor Service
79
92
  this.GarageDoor = {
80
- Service: accessory.getService(this.hap.Service.GarageDoorOpener),
81
- On: accessory.context.On || false,
93
+ Name: accessory.context.Name ?? accessory.displayName,
94
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener),
95
+ On: accessory.context.On ?? false,
82
96
  };
97
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
98
+ // Initialize GarageDoor Characteristics
99
+ this.GarageDoor.Service
100
+ .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
101
+ .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
102
+ .getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
103
+ validValues: [0, 100],
104
+ minValue: 0,
105
+ maxValue: 100,
106
+ minStep: 100,
107
+ })
108
+ .onGet(() => {
109
+ return this.GarageDoor.On;
110
+ })
111
+ .onSet(this.OnSet.bind(this));
112
+ accessory.context.Name = this.GarageDoor.Name;
113
+ // Remove other services
83
114
  this.removeFanService(accessory);
84
115
  this.removeLockService(accessory);
85
116
  this.removeDoorService(accessory);
@@ -89,117 +120,127 @@ export class Bot extends deviceBase {
89
120
  this.removeWindowService(accessory);
90
121
  this.removeWindowCoveringService(accessory);
91
122
  this.removeStatefulProgrammableSwitchService(accessory);
92
- // Add garageDoorService
93
- const garageDoorService = `${accessory.displayName} Garage Door Opener`;
94
- (this.GarageDoor.Service = accessory.getService(this.hap.Service.GarageDoorOpener)
95
- || accessory.addService(this.hap.Service.GarageDoorOpener)), garageDoorService;
96
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
97
- this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
98
- this.GarageDoor.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
99
- this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
100
123
  }
101
124
  else if (this.botDeviceType === 'door') {
102
- // Initialize Switch property
125
+ // Initialize Door Service
103
126
  this.Door = {
104
- Service: accessory.getService(this.hap.Service.Door),
105
- On: accessory.context.On || false,
127
+ Name: accessory.context.Name ?? accessory.displayName,
128
+ Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door),
129
+ On: accessory.context.On ?? false,
106
130
  };
107
- this.removeFanService(accessory);
108
- this.removeLockService(accessory);
109
- this.removeOutletService(accessory);
110
- this.removeFaucetService(accessory);
111
- this.removeSwitchService(accessory);
112
- this.removeWindowService(accessory);
113
- this.removeGarageDoorService(accessory);
114
- this.removeWindowCoveringService(accessory);
115
- this.removeStatefulProgrammableSwitchService(accessory);
116
- // Add doorService
117
- const doorService = `${accessory.displayName} Door`;
118
- (this.Door.Service = accessory.getService(this.hap.Service.Door)
119
- || accessory.addService(this.hap.Service.Door)), doorService;
120
131
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
121
- this.Door.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
132
+ // Initialize Door Characteristics
122
133
  this.Door.Service
123
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
124
- .setProps({
134
+ .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
135
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
136
+ .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
125
137
  validValues: [0, 100],
126
138
  minValue: 0,
127
139
  maxValue: 100,
128
140
  minStep: 100,
141
+ })
142
+ .onGet(() => {
143
+ return this.Door.On;
129
144
  })
130
145
  .onSet(this.OnSet.bind(this));
131
- this.Door.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
132
- }
133
- else if (this.botDeviceType === 'window') {
134
- // Initialize Switch property
135
- this.Window = {
136
- Service: accessory.getService(this.hap.Service.Window),
137
- On: accessory.context.On || false,
138
- };
146
+ accessory.context.Name = this.Door.Name;
147
+ // Remove other services
139
148
  this.removeFanService(accessory);
140
149
  this.removeLockService(accessory);
141
- this.removeDoorService(accessory);
142
150
  this.removeOutletService(accessory);
143
151
  this.removeFaucetService(accessory);
144
152
  this.removeSwitchService(accessory);
153
+ this.removeWindowService(accessory);
145
154
  this.removeGarageDoorService(accessory);
146
155
  this.removeWindowCoveringService(accessory);
147
156
  this.removeStatefulProgrammableSwitchService(accessory);
148
- // Add windowService
149
- const windowService = `${accessory.displayName} Window`;
150
- (this.Window.Service = accessory.getService(this.hap.Service.Window)
151
- || accessory.addService(this.hap.Service.Window)), windowService;
157
+ }
158
+ else if (this.botDeviceType === 'window') {
159
+ // Initialize Window Service
160
+ this.Window = {
161
+ Name: accessory.context.Name ?? accessory.displayName,
162
+ Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window),
163
+ On: accessory.context.On ?? false,
164
+ };
152
165
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
153
- this.Window.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
166
+ // Initialize Window Characteristics
154
167
  this.Window.Service
155
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
156
- .setProps({
168
+ .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
169
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
170
+ .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
157
171
  validValues: [0, 100],
158
172
  minValue: 0,
159
173
  maxValue: 100,
160
174
  minStep: 100,
175
+ })
176
+ .onGet(() => {
177
+ return this.Window.On;
161
178
  })
162
179
  .onSet(this.OnSet.bind(this));
163
- this.Window.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
164
- }
165
- else if (this.botDeviceType === 'windowcovering') {
166
- // Initialize Switch property
167
- this.WindowCovering = {
168
- Service: accessory.getService(this.hap.Service.WindowCovering),
169
- On: accessory.context.On || false,
170
- };
180
+ accessory.context.Name = this.Window.Name;
181
+ // Remove other services
171
182
  this.removeFanService(accessory);
172
183
  this.removeLockService(accessory);
173
184
  this.removeDoorService(accessory);
174
185
  this.removeOutletService(accessory);
175
186
  this.removeFaucetService(accessory);
176
187
  this.removeSwitchService(accessory);
177
- this.removeWindowService(accessory);
178
188
  this.removeGarageDoorService(accessory);
189
+ this.removeWindowCoveringService(accessory);
179
190
  this.removeStatefulProgrammableSwitchService(accessory);
180
- // Add windowCoveringService
181
- const windowCoveringService = `${accessory.displayName} Window Covering`;
182
- (this.WindowCovering.Service = accessory.getService(this.hap.Service.WindowCovering)
183
- || accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
191
+ }
192
+ else if (this.botDeviceType === 'windowcovering') {
193
+ // Initialize WindowCovering Service
194
+ this.WindowCovering = {
195
+ Name: accessory.context.Name ?? accessory.displayName,
196
+ Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering),
197
+ On: accessory.context.On ?? false,
198
+ };
184
199
  this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
185
- this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
200
+ // Initialize WindowCovering Characteristics
186
201
  this.WindowCovering.Service
187
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
188
- .setProps({
202
+ .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
203
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
204
+ .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
189
205
  validValues: [0, 100],
190
206
  minValue: 0,
191
207
  maxValue: 100,
192
208
  minStep: 100,
209
+ })
210
+ .onGet(() => {
211
+ return this.WindowCovering.On;
193
212
  })
194
213
  .onSet(this.OnSet.bind(this));
195
- this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
214
+ accessory.context.Name = this.WindowCovering.Name;
215
+ // Remove other services
216
+ this.removeFanService(accessory);
217
+ this.removeLockService(accessory);
218
+ this.removeDoorService(accessory);
219
+ this.removeOutletService(accessory);
220
+ this.removeFaucetService(accessory);
221
+ this.removeSwitchService(accessory);
222
+ this.removeWindowService(accessory);
223
+ this.removeGarageDoorService(accessory);
224
+ this.removeStatefulProgrammableSwitchService(accessory);
196
225
  }
197
226
  else if (this.botDeviceType === 'lock') {
198
- // Initialize Switch property
199
- this.Lock = {
200
- Service: accessory.getService(this.hap.Service.LockMechanism),
201
- On: accessory.context.On || false,
227
+ // Initialize Lock Service
228
+ this.LockMechanism = {
229
+ Name: accessory.context.Name ?? accessory.displayName,
230
+ Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism),
231
+ On: accessory.context.On ?? false,
202
232
  };
233
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
234
+ // Initialize Lock Characteristics
235
+ this.LockMechanism.Service
236
+ .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
237
+ .getCharacteristic(this.hap.Characteristic.LockTargetState)
238
+ .onGet(() => {
239
+ return this.LockMechanism.On;
240
+ })
241
+ .onSet(this.OnSet.bind(this));
242
+ accessory.context.Name = this.LockMechanism.Name;
243
+ // Remove other services
203
244
  this.removeFanService(accessory);
204
245
  this.removeDoorService(accessory);
205
246
  this.removeOutletService(accessory);
@@ -209,20 +250,25 @@ export class Bot extends deviceBase {
209
250
  this.removeGarageDoorService(accessory);
210
251
  this.removeWindowCoveringService(accessory);
211
252
  this.removeStatefulProgrammableSwitchService(accessory);
212
- // Add lockService
213
- const lockService = `${accessory.displayName} Lock`;
214
- (this.Lock.Service = accessory.getService(this.hap.Service.LockMechanism)
215
- || accessory.addService(this.hap.Service.LockMechanism)), lockService;
216
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
217
- this.Lock.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
218
- this.Lock.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
219
253
  }
220
254
  else if (this.botDeviceType === 'faucet') {
221
- // Initialize Switch property
255
+ // Initialize Faucet Service
222
256
  this.Faucet = {
223
- Service: accessory.getService(this.hap.Service.Faucet),
224
- On: accessory.context.On || false,
257
+ Name: accessory.context.Name ?? accessory.displayName,
258
+ Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet),
259
+ On: accessory.context.On ?? false,
225
260
  };
261
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
262
+ // Initialize Faucet Characteristics
263
+ this.Faucet.Service
264
+ .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
265
+ .getCharacteristic(this.hap.Characteristic.Active)
266
+ .onGet(() => {
267
+ return this.Faucet.On;
268
+ })
269
+ .onSet(this.OnSet.bind(this));
270
+ accessory.context.Name = this.Faucet.Name;
271
+ // Remove other services
226
272
  this.removeFanService(accessory);
227
273
  this.removeLockService(accessory);
228
274
  this.removeDoorService(accessory);
@@ -232,20 +278,25 @@ export class Bot extends deviceBase {
232
278
  this.removeGarageDoorService(accessory);
233
279
  this.removeWindowCoveringService(accessory);
234
280
  this.removeStatefulProgrammableSwitchService(accessory);
235
- // Add faucetService
236
- const faucetService = `${accessory.displayName} Faucet`;
237
- (this.Faucet.Service = accessory.getService(this.hap.Service.Faucet)
238
- || accessory.addService(this.hap.Service.Faucet)), faucetService;
239
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
240
- this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
241
- this.Faucet.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
242
281
  }
243
282
  else if (this.botDeviceType === 'fan') {
244
- // Initialize Switch property
283
+ // Initialize Fan Service
245
284
  this.Fan = {
246
- Service: accessory.getService(this.hap.Service.Fanv2),
247
- On: accessory.context.On || false,
285
+ Name: accessory.context.Name ?? accessory.displayName,
286
+ Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2),
287
+ On: accessory.context.On ?? false,
248
288
  };
289
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
290
+ // Initialize Fan Characteristics
291
+ this.Fan.Service
292
+ .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
293
+ .getCharacteristic(this.hap.Characteristic.On)
294
+ .onGet(() => {
295
+ return this.Fan.On;
296
+ })
297
+ .onSet(this.OnSet.bind(this));
298
+ accessory.context.Name = this.Fan.Name;
299
+ // Remove other services
249
300
  this.removeLockService(accessory);
250
301
  this.removeDoorService(accessory);
251
302
  this.removeFaucetService(accessory);
@@ -255,20 +306,26 @@ export class Bot extends deviceBase {
255
306
  this.removeGarageDoorService(accessory);
256
307
  this.removeWindowCoveringService(accessory);
257
308
  this.removeStatefulProgrammableSwitchService(accessory);
258
- // Add fanService
259
- const fanService = `${accessory.displayName} Fan`;
260
- (this.Fan.Service = accessory.getService(this.hap.Service.Fanv2)
261
- || accessory.addService(this.hap.Service.Fanv2)), fanService;
262
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
263
- this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
264
- this.Fan.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
265
309
  }
266
310
  else if (this.botDeviceType === 'stateful') {
267
- // Initialize Switch property
311
+ // Initialize StatefulProgrammableSwitch Service
268
312
  this.StatefulProgrammableSwitch = {
269
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch),
270
- On: accessory.context.On || false,
313
+ Name: accessory.context.Name ?? accessory.displayName,
314
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
315
+ ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
316
+ On: accessory.context.On ?? false,
271
317
  };
318
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
319
+ // Initialize StatefulProgrammableSwitch Characteristics
320
+ this.StatefulProgrammableSwitch.Service
321
+ .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
322
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
323
+ .onGet(() => {
324
+ return this.StatefulProgrammableSwitch.On;
325
+ })
326
+ .onSet(this.OnSet.bind(this));
327
+ accessory.context.Name = this.StatefulProgrammableSwitch.Name;
328
+ // Remove other services
272
329
  this.removeFanService(accessory);
273
330
  this.removeLockService(accessory);
274
331
  this.removeDoorService(accessory);
@@ -278,22 +335,25 @@ export class Bot extends deviceBase {
278
335
  this.removeWindowService(accessory);
279
336
  this.removeGarageDoorService(accessory);
280
337
  this.removeWindowCoveringService(accessory);
281
- // Add statefulProgrammableSwitchService
282
- const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
283
- (this.StatefulProgrammableSwitch.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ||
284
- accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
285
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
286
- this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
287
- this.StatefulProgrammableSwitch.Service
288
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
289
- .onSet(this.OnSet.bind(this));
290
338
  }
291
339
  else {
292
340
  // Initialize Switch property
293
341
  this.Outlet = {
294
- Service: accessory.getService(this.hap.Service.Outlet),
295
- On: accessory.context.On || false,
342
+ Name: accessory.context.Name ?? accessory.displayName,
343
+ Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet),
344
+ On: accessory.context.On ?? false,
296
345
  };
346
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
347
+ // Initialize Outlet Characteristics
348
+ this.Outlet.Service
349
+ .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
350
+ .getCharacteristic(this.hap.Characteristic.On)
351
+ .onGet(() => {
352
+ return this.Outlet.On;
353
+ })
354
+ .onSet(this.OnSet.bind(this));
355
+ accessory.context.Name = this.Outlet.Name;
356
+ // Remove other services
297
357
  this.removeFanService(accessory);
298
358
  this.removeLockService(accessory);
299
359
  this.removeDoorService(accessory);
@@ -303,22 +363,9 @@ export class Bot extends deviceBase {
303
363
  this.removeGarageDoorService(accessory);
304
364
  this.removeWindowCoveringService(accessory);
305
365
  this.removeStatefulProgrammableSwitchService(accessory);
306
- // Add outletService
307
- const outletService = `${accessory.displayName} Outlet`;
308
- (this.Outlet.Service = accessory.getService(this.hap.Service.Outlet)
309
- || accessory.addService(this.hap.Service.Outlet)), outletService;
310
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
311
- this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
312
- this.Outlet.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
313
366
  }
314
367
  // Retrieve initial values and updateHomekit
315
368
  this.refreshStatus();
316
- // batteryService
317
- const batteryService = `${accessory.displayName} Battery`;
318
- (this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
319
- || accessory.addService(this.hap.Service.Battery)), batteryService;
320
- this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
321
- this.Battery.Service.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
322
369
  // Retrieve initial values and updateHomekit
323
370
  this.updateHomeKitCharacteristics();
324
371
  // Start an update interval
@@ -769,11 +816,11 @@ export class Bot extends deviceBase {
769
816
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
770
817
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
771
818
  await this.setOn(false);
772
- this.Lock.On = false;
819
+ this.LockMechanism.On = false;
773
820
  }
774
821
  else {
775
822
  await this.setOn(true);
776
- this.Lock.On = true;
823
+ this.LockMechanism.On = true;
777
824
  }
778
825
  }
779
826
  else if (this.botDeviceType === 'faucet') {
@@ -918,25 +965,25 @@ export class Bot extends deviceBase {
918
965
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering.On}`);
919
966
  }
920
967
  else if (this.botDeviceType === 'lock') {
921
- if (this.Lock.On === undefined) {
922
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Lock.On}`);
968
+ if (this.LockMechanism.On === undefined) {
969
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockMechanism.On}`);
923
970
  }
924
971
  else {
925
- if (this.Lock.On) {
926
- this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
927
- this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
972
+ if (this.LockMechanism.On) {
973
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
974
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
928
975
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
929
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.Lock.On})`);
976
+ + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
930
977
  }
931
978
  else {
932
- this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
933
- this.Lock.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
979
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
980
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
934
981
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
935
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock.On})`);
982
+ + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
936
983
  }
937
984
  }
938
- await this.setOn(Boolean(this.Lock.On));
939
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.Lock.On}`);
985
+ await this.setOn(Boolean(this.LockMechanism.On));
986
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism.On}`);
940
987
  }
941
988
  else if (this.botDeviceType === 'faucet') {
942
989
  if (this.Faucet.On === undefined) {
@@ -1060,10 +1107,10 @@ export class Bot extends deviceBase {
1060
1107
  }
1061
1108
  async removeLockService(accessory) {
1062
1109
  // If lockService still present, then remove first
1063
- if (this.Lock?.Service) {
1064
- this.Lock.Service = this.accessory.getService(this.hap.Service.LockMechanism);
1110
+ if (this.LockMechanism?.Service) {
1111
+ this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism);
1065
1112
  this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
1066
- accessory.removeService(this.Lock.Service);
1113
+ accessory.removeService(this.LockMechanism.Service);
1067
1114
  }
1068
1115
  }
1069
1116
  async removeFaucetService(accessory) {
@@ -1129,7 +1176,7 @@ export class Bot extends deviceBase {
1129
1176
  On = this.WindowCovering.On ? true : false;
1130
1177
  }
1131
1178
  else if (this.botDeviceType === 'lock') {
1132
- On = this.Lock.On ? true : false;
1179
+ On = this.LockMechanism.On ? true : false;
1133
1180
  }
1134
1181
  else if (this.botDeviceType === 'faucet') {
1135
1182
  On = this.Faucet.On ? true : false;
@@ -1162,7 +1209,7 @@ export class Bot extends deviceBase {
1162
1209
  this.WindowCovering.On = On;
1163
1210
  }
1164
1211
  else if (this.botDeviceType === 'lock') {
1165
- this.Lock.On = On;
1212
+ this.LockMechanism.On = On;
1166
1213
  }
1167
1214
  else if (this.botDeviceType === 'faucet') {
1168
1215
  this.Faucet.On = On;