@switchbot/homebridge-switchbot 3.5.0-beta.63 → 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 (108) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +7 -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 +31 -21
  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.d.ts.map +1 -1
  11. package/dist/device/colorbulb.js +1 -2
  12. package/dist/device/colorbulb.js.map +1 -1
  13. package/dist/device/contact.d.ts.map +1 -1
  14. package/dist/device/contact.js +14 -10
  15. package/dist/device/contact.js.map +1 -1
  16. package/dist/device/device.js +11 -10
  17. package/dist/device/device.js.map +1 -1
  18. package/dist/device/fan.d.ts.map +1 -1
  19. package/dist/device/fan.js +7 -5
  20. package/dist/device/fan.js.map +1 -1
  21. package/dist/device/hub.d.ts.map +1 -1
  22. package/dist/device/hub.js +9 -6
  23. package/dist/device/hub.js.map +1 -1
  24. package/dist/device/humidifier.d.ts.map +1 -1
  25. package/dist/device/humidifier.js +6 -4
  26. package/dist/device/humidifier.js.map +1 -1
  27. package/dist/device/iosensor.d.ts.map +1 -1
  28. package/dist/device/iosensor.js +10 -6
  29. package/dist/device/iosensor.js.map +1 -1
  30. package/dist/device/lightstrip.d.ts.map +1 -1
  31. package/dist/device/lightstrip.js +3 -2
  32. package/dist/device/lightstrip.js.map +1 -1
  33. package/dist/device/lock.d.ts.map +1 -1
  34. package/dist/device/lock.js +12 -8
  35. package/dist/device/lock.js.map +1 -1
  36. package/dist/device/meter.d.ts.map +1 -1
  37. package/dist/device/meter.js +8 -5
  38. package/dist/device/meter.js.map +1 -1
  39. package/dist/device/meterplus.d.ts.map +1 -1
  40. package/dist/device/meterplus.js +9 -6
  41. package/dist/device/meterplus.js.map +1 -1
  42. package/dist/device/motion.d.ts.map +1 -1
  43. package/dist/device/motion.js +9 -5
  44. package/dist/device/motion.js.map +1 -1
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +3 -2
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  49. package/dist/device/robotvacuumcleaner.js +6 -4
  50. package/dist/device/robotvacuumcleaner.js.map +1 -1
  51. package/dist/device/waterdetector.d.ts.map +1 -1
  52. package/dist/device/waterdetector.js +4 -2
  53. package/dist/device/waterdetector.js.map +1 -1
  54. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  55. package/dist/irdevice/airconditioner.js +5 -5
  56. package/dist/irdevice/airconditioner.js.map +1 -1
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +6 -10
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts.map +1 -1
  61. package/dist/irdevice/camera.js +3 -5
  62. package/dist/irdevice/camera.js.map +1 -1
  63. package/dist/irdevice/fan.d.ts.map +1 -1
  64. package/dist/irdevice/fan.js +3 -6
  65. package/dist/irdevice/fan.js.map +1 -1
  66. package/dist/irdevice/light.d.ts.map +1 -1
  67. package/dist/irdevice/light.js +7 -13
  68. package/dist/irdevice/light.js.map +1 -1
  69. package/dist/irdevice/other.d.ts.map +1 -1
  70. package/dist/irdevice/other.js +34 -55
  71. package/dist/irdevice/other.js.map +1 -1
  72. package/dist/irdevice/tv.d.ts.map +1 -1
  73. package/dist/irdevice/tv.js +4 -8
  74. package/dist/irdevice/tv.js.map +1 -1
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +3 -5
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts.map +1 -1
  79. package/dist/irdevice/waterheater.js +3 -5
  80. package/dist/irdevice/waterheater.js.map +1 -1
  81. package/package.json +1 -1
  82. package/src/device/blindtilt.ts +7 -6
  83. package/src/device/bot.ts +31 -21
  84. package/src/device/ceilinglight.ts +4 -3
  85. package/src/device/colorbulb.ts +1 -2
  86. package/src/device/contact.ts +14 -10
  87. package/src/device/device.ts +11 -11
  88. package/src/device/fan.ts +7 -5
  89. package/src/device/hub.ts +9 -6
  90. package/src/device/humidifier.ts +6 -4
  91. package/src/device/iosensor.ts +10 -6
  92. package/src/device/lightstrip.ts +3 -2
  93. package/src/device/lock.ts +12 -8
  94. package/src/device/meter.ts +8 -5
  95. package/src/device/meterplus.ts +9 -6
  96. package/src/device/motion.ts +9 -5
  97. package/src/device/plug.ts +3 -2
  98. package/src/device/robotvacuumcleaner.ts +6 -4
  99. package/src/device/waterdetector.ts +4 -2
  100. package/src/irdevice/airconditioner.ts +5 -6
  101. package/src/irdevice/airpurifier.ts +6 -11
  102. package/src/irdevice/camera.ts +3 -5
  103. package/src/irdevice/fan.ts +3 -7
  104. package/src/irdevice/light.ts +7 -15
  105. package/src/irdevice/other.ts +34 -55
  106. package/src/irdevice/tv.ts +4 -8
  107. package/src/irdevice/vacuumcleaner.ts +3 -5
  108. package/src/irdevice/waterheater.ts +3 -5
@@ -56,11 +56,8 @@ export class AirPurifier extends irdeviceBase {
56
56
  ) {
57
57
  super(platform, accessory, device);
58
58
 
59
- if (!accessory.context.AirPurifier) {
60
- accessory.context.AirPurifier = {};
61
- }
62
-
63
- // Initialize AirPurifier property
59
+ // Initialize AirPurifier Service
60
+ accessory.context.AirPurifier = accessory.context.AirPurifier ?? {};
64
61
  this.AirPurifier = {
65
62
  Name: accessory.context.AirPurifier.Name ?? `${accessory.displayName} Air Purifier`,
66
63
  Service: accessory.getService(this.hap.Service.AirPurifier) ?? accessory.addService(this.hap.Service.AirPurifier) as Service,
@@ -69,6 +66,7 @@ export class AirPurifier extends irdeviceBase {
69
66
  CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
70
67
  TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
71
68
  };
69
+ accessory.context.AirPurifier = this.AirPurifier as object;
72
70
 
73
71
  this.AirPurifier.Service
74
72
  .setCharacteristic(this.hap.Characteristic.Name, this.AirPurifier.Name)
@@ -90,17 +88,15 @@ export class AirPurifier extends irdeviceBase {
90
88
  return this.AirPurifier.TargetAirPurifierState;
91
89
  })
92
90
  .onSet(this.TargetAirPurifierStateSet.bind(this));
93
- accessory.context.AirPurifier.Name = this.AirPurifier.Name;
94
91
 
95
- if (!accessory.context.TemperatureSensor) {
96
- accessory.context.TemperatureSensor = {};
97
- }
98
- // Initialize TemperatureSensor property
92
+ // Initialize TemperatureSensor Service
93
+ accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {};
99
94
  this.TemperatureSensor = {
100
95
  Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
101
96
  Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? accessory.addService(this.hap.Service.TemperatureSensor) as Service,
102
97
  CurrentTemperature: accessory.context.CurrentTemperature || 24,
103
98
  };
99
+ accessory.context.TemperatureSensor = this.TemperatureSensor as object;
104
100
 
105
101
  this.TemperatureSensor.Service
106
102
  .setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
@@ -108,7 +104,6 @@ export class AirPurifier extends irdeviceBase {
108
104
  .onGet(() => {
109
105
  return this.TemperatureSensor.CurrentTemperature;
110
106
  });
111
- accessory.context.TemperatureSensor.Name = this.TemperatureSensor.Name;
112
107
  }
113
108
 
114
109
  async ActiveSet(value: CharacteristicValue): Promise<void> {
@@ -30,15 +30,14 @@ export class Camera extends irdeviceBase {
30
30
  ) {
31
31
  super(platform, accessory, device);
32
32
 
33
- if (!accessory.context.Switch) {
34
- accessory.context.Switch = {};
35
- }
36
- // Initialize Switch property
33
+ // Initialize Switch Service
34
+ accessory.context.Switch = accessory.context.Switch ?? {};
37
35
  this.Switch = {
38
36
  Name: accessory.context.Switch.Name ?? `${accessory.displayName} Camera`,
39
37
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
40
38
  On: accessory.context.On ?? false,
41
39
  };
40
+ accessory.context.Switch = this.Switch as object;
42
41
 
43
42
  this.Switch.Service
44
43
  .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
@@ -47,7 +46,6 @@ export class Camera extends irdeviceBase {
47
46
  return this.Switch.On;
48
47
  })
49
48
  .onSet(this.OnSet.bind(this));
50
- accessory.context.Switch.Name = this.Switch.Name;
51
49
  }
52
50
 
53
51
  async OnSet(value: CharacteristicValue): Promise<void> {
@@ -33,11 +33,8 @@ export class IRFan extends irdeviceBase {
33
33
  ) {
34
34
  super(platform, accessory, device);
35
35
 
36
- if (!accessory.context.Fan) {
37
- accessory.context.Fan = {};
38
- }
39
-
40
- // Initialize Switch property
36
+ // Initialize Switch Service
37
+ accessory.context.Fan = accessory.context.Fan ?? {};
41
38
  this.Fan = {
42
39
  Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
43
40
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
@@ -46,6 +43,7 @@ export class IRFan extends irdeviceBase {
46
43
  RotationSpeed: accessory.context.RotationSpeed ?? 0,
47
44
  RotationDirection: accessory.context.RotationDirection ?? this.hap.Characteristic.RotationDirection.CLOCKWISE,
48
45
  };
46
+ accessory.context.Fan = this.Fan as object;
49
47
 
50
48
  this.Fan.Service
51
49
  .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
@@ -54,7 +52,6 @@ export class IRFan extends irdeviceBase {
54
52
  return this.Fan.Active;
55
53
  })
56
54
  .onSet(this.ActiveSet.bind(this));
57
- accessory.context.Fan.Name = this.Fan.Name;
58
55
 
59
56
  if (device.irfan?.rotation_speed) {
60
57
  // handle Rotation Speed events using the RotationSpeed characteristic
@@ -98,7 +95,6 @@ export class IRFan extends irdeviceBase {
98
95
  `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`,
99
96
  );
100
97
  }
101
- accessory.context.Fan.Name = this.Fan.Name;
102
98
  }
103
99
 
104
100
  async minStep(device: irdevice & irDevicesConfig): Promise<number> {
@@ -44,18 +44,15 @@ export class Light extends irdeviceBase {
44
44
  ) {
45
45
  super(platform, accessory, device);
46
46
 
47
-
48
-
49
47
  if (!device.irlight?.stateless) {
50
- if (!accessory.context.LightBulb) {
51
- accessory.context.LightBulb = {};
52
- }
53
- // Initialize LightBulb property
48
+ // Initialize LightBulb Service
49
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {};
54
50
  this.LightBulb = {
55
51
  Name: accessory.context.LightBulb.Name ?? `${accessory.displayName} ${device.remoteType}`,
56
52
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
57
53
  On: accessory.context.On || false,
58
54
  };
55
+ accessory.context.LightBulb = this.LightBulb as object;
59
56
 
60
57
  this.LightBulb.Service
61
58
  .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
@@ -64,12 +61,9 @@ export class Light extends irdeviceBase {
64
61
  return this.LightBulb!.On;
65
62
  })
66
63
  .onSet(this.OnSet.bind(this));
67
- accessory.context.LightBulb.Name = this.LightBulb.Name;
68
64
  } else {
69
65
  // Initialize ProgrammableSwitchOn Service
70
- if (!accessory.context.ProgrammableSwitchOn) {
71
- accessory.context.ProgrammableSwitchOn = {};
72
- }
66
+ accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
73
67
  this.ProgrammableSwitchOn = {
74
68
  Name: accessory.context.ProgrammableSwitchOn.Name ?? `${accessory.displayName} ${device.remoteType} On`,
75
69
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
@@ -77,6 +71,7 @@ export class Light extends irdeviceBase {
77
71
  ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
78
72
  ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
79
73
  };
74
+ accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object;
80
75
 
81
76
  // Initialize ProgrammableSwitchOn Characteristics
82
77
  this.ProgrammableSwitchOn?.Service
@@ -97,12 +92,9 @@ export class Light extends irdeviceBase {
97
92
  return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState;
98
93
  })
99
94
  .onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
100
- accessory.context.ProgrammableSwitchOn.Name = this.ProgrammableSwitchOn.Name;
101
95
 
102
96
  // Initialize ProgrammableSwitchOff Service
103
- if (!accessory.context.ProgrammableSwitchOff) {
104
- accessory.context.ProgrammableSwitchOff = {};
105
- }
97
+ accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
106
98
  this.ProgrammableSwitchOff = {
107
99
  Name: accessory.context.ProgrammableSwitchOff.Name ?? `${accessory.displayName} ${device.remoteType} Off`,
108
100
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
@@ -110,6 +102,7 @@ export class Light extends irdeviceBase {
110
102
  ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
111
103
  ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
112
104
  };
105
+ accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object;
113
106
 
114
107
  // Initialize ProgrammableSwitchOff Characteristics
115
108
  this.ProgrammableSwitchOff?.Service
@@ -130,7 +123,6 @@ export class Light extends irdeviceBase {
130
123
  return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState;
131
124
  })
132
125
  .onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
133
- accessory.context.ProgrammableSwitchOff.Name = this.ProgrammableSwitchOff.Name;
134
126
  }
135
127
 
136
128
  }
@@ -93,14 +93,13 @@ export class Others extends irdeviceBase {
93
93
  // deviceType
94
94
  if (this.otherDeviceType === 'switch') {
95
95
  // Initialize Switch Service
96
- if (!accessory.context.Switch) {
97
- accessory.context.Switch = {};
98
- }
96
+ accessory.context.Switch = accessory.context.Switch ?? {};
99
97
  this.Switch = {
100
- Name: accessory.context.Name ?? `${accessory.displayName} Switch`,
98
+ Name: accessory.context.Switch.Name ?? `${accessory.displayName} Switch`,
101
99
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
102
100
  On: accessory.context.On ?? false,
103
101
  };
102
+ accessory.context.Switch = this.Switch as object;
104
103
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
105
104
 
106
105
  this.Switch.Service
@@ -110,7 +109,6 @@ export class Others extends irdeviceBase {
110
109
  return this.Switch!.On;
111
110
  })
112
111
  .onSet(this.OnSet.bind(this));
113
- accessory.context.Name = this.Switch.Name;
114
112
 
115
113
  // Remove other services
116
114
  this.removeFanService(accessory);
@@ -124,14 +122,13 @@ export class Others extends irdeviceBase {
124
122
  this.removeStatefulProgrammableSwitchService(accessory);
125
123
  } else if (this.otherDeviceType === 'garagedoor') {
126
124
  // Initialize Garage Door Service
127
- if (!accessory.context.GarageDoor) {
128
- accessory.context.GarageDoor = {};
129
- }
125
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
130
126
  this.GarageDoor = {
131
- Name: accessory.context.Name ?? `${accessory.displayName} Garage Door`,
127
+ Name: accessory.context.GarageDoor.Name ?? `${accessory.displayName} Garage Door`,
132
128
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
133
129
  On: accessory.context.On ?? false,
134
130
  };
131
+ accessory.context.GarageDoor = this.GarageDoor as object;
135
132
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
136
133
 
137
134
  this.GarageDoor.Service
@@ -142,7 +139,6 @@ export class Others extends irdeviceBase {
142
139
  return this.GarageDoor!.On;
143
140
  })
144
141
  .onSet(this.OnSet.bind(this));
145
- accessory.context.Name = this.GarageDoor.Name;
146
142
 
147
143
  // Remove other services
148
144
  this.removeFanService(accessory);
@@ -156,14 +152,13 @@ export class Others extends irdeviceBase {
156
152
  this.removeStatefulProgrammableSwitchService(accessory);
157
153
  } else if (this.otherDeviceType === 'door') {
158
154
  // Initialize Door Service
159
- if (!accessory.context.Door) {
160
- accessory.context.Door = {};
161
- }
155
+ accessory.context.Door = accessory.context.Door ?? {};
162
156
  this.Door = {
163
- Name: accessory.context.Name ?? `${accessory.displayName} Door`,
157
+ Name: accessory.context.Door.Name ?? `${accessory.displayName} Door`,
164
158
  Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
165
159
  On: accessory.context.On ?? false,
166
160
  };
161
+ accessory.context.Door = this.Door as object;
167
162
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
168
163
 
169
164
  this.Door!.Service
@@ -180,7 +175,6 @@ export class Others extends irdeviceBase {
180
175
  return this.GarageDoor!.On;
181
176
  })
182
177
  .onSet(this.OnSet.bind(this));
183
- accessory.context.Name = this.Door.Name;
184
178
 
185
179
  // Remove other services
186
180
  this.removeFanService(accessory);
@@ -194,14 +188,13 @@ export class Others extends irdeviceBase {
194
188
  this.removeStatefulProgrammableSwitchService(accessory);
195
189
  } else if (this.otherDeviceType === 'window') {
196
190
  // Initialize Window Service
197
- if (!accessory.context.Window) {
198
- accessory.context.Window = {};
199
- }
191
+ accessory.context.Window = accessory.context.Window ?? {};
200
192
  this.Window = {
201
- Name: accessory.context.Name ?? `${accessory.displayName} Window`,
193
+ Name: accessory.context.Window.Name ?? `${accessory.displayName} Window`,
202
194
  Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
203
195
  On: accessory.context.On ?? false,
204
196
  };
197
+ accessory.context.Window = this.Window as object;
205
198
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
206
199
 
207
200
  this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
@@ -217,7 +210,6 @@ export class Others extends irdeviceBase {
217
210
  return this.GarageDoor!.On;
218
211
  })
219
212
  .onSet(this.OnSet.bind(this));
220
- accessory.context.Name = this.Window.Name;
221
213
 
222
214
  // Remove other services
223
215
  this.removeFanService(accessory);
@@ -231,18 +223,18 @@ export class Others extends irdeviceBase {
231
223
  this.removeStatefulProgrammableSwitchService(accessory);
232
224
  } else if (this.otherDeviceType === 'windowcovering') {
233
225
  // Initialize WindowCovering Service
234
- if (!accessory.context.WindowCovering) {
235
- accessory.context.WindowCovering = {};
236
- }
226
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
237
227
  this.WindowCovering = {
238
- Name: accessory.context.Name ?? `${accessory.displayName} Window Covering`,
228
+ Name: accessory.context.WindowCovering.Name ?? `${accessory.displayName} Window Covering`,
239
229
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
240
230
  On: accessory.context.On ?? false,
241
231
  };
232
+ accessory.context.WindowCovering = this.WindowCovering as object;
242
233
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
243
234
 
244
- this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
245
235
  this.WindowCovering.Service
236
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
237
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
246
238
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
247
239
  .setProps({
248
240
  validValues: [0, 100],
@@ -254,8 +246,6 @@ export class Others extends irdeviceBase {
254
246
  return this.WindowCovering!.On;
255
247
  })
256
248
  .onSet(this.OnSet.bind(this));
257
- this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
258
- accessory.context.Name = this.WindowCovering.Name;
259
249
 
260
250
  // Remove other services
261
251
  this.removeFanService(accessory);
@@ -268,15 +258,14 @@ export class Others extends irdeviceBase {
268
258
  this.removeGarageDoorService(accessory);
269
259
  this.removeStatefulProgrammableSwitchService(accessory);
270
260
  } else if (this.otherDeviceType === 'lock') {
271
- // Initialize Lock Service
272
- if (!accessory.context.LockMechanism) {
273
- accessory.context.LockMechanism = {};
274
- }
261
+ // Initialize LockMechanism Service
262
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
275
263
  this.LockMechanism = {
276
- Name: accessory.context.Name ?? `${accessory.displayName} Lock`,
264
+ Name: accessory.context.LockMechanism.Name ?? `${accessory.displayName} Lock`,
277
265
  Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
278
266
  On: accessory.context.On ?? false,
279
267
  };
268
+ accessory.context.LockMechanism = this.LockMechanism as object;
280
269
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
281
270
 
282
271
  this.LockMechanism.Service
@@ -286,7 +275,6 @@ export class Others extends irdeviceBase {
286
275
  return this.LockMechanism!.On;
287
276
  })
288
277
  .onSet(this.OnSet.bind(this));
289
- accessory.context.Name = this.LockMechanism.Name;
290
278
 
291
279
  // Remove other services
292
280
  this.removeFanService(accessory);
@@ -300,14 +288,13 @@ export class Others extends irdeviceBase {
300
288
  this.removeStatefulProgrammableSwitchService(accessory);
301
289
  } else if (this.otherDeviceType === 'faucet') {
302
290
  // Initialize Faucet Service
303
- if (!accessory.context.Faucet) {
304
- accessory.context.Faucet = {};
305
- }
291
+ accessory.context.Faucet = accessory.context.Faucet ?? {};
306
292
  this.Faucet = {
307
- Name: accessory.context.Name ?? `${accessory.displayName} Faucet`,
293
+ Name: accessory.context.Faucet.Name ?? `${accessory.displayName} Faucet`,
308
294
  Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
309
295
  On: accessory.context.On ?? false,
310
296
  };
297
+ accessory.context.Faucet = this.Faucet as object;
311
298
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
312
299
 
313
300
  this.Faucet.Service
@@ -317,7 +304,6 @@ export class Others extends irdeviceBase {
317
304
  return this.Faucet!.On;
318
305
  })
319
306
  .onSet(this.OnSet.bind(this));
320
- accessory.context.Name = this.Faucet.Name;
321
307
 
322
308
  // Remove other services
323
309
  this.removeFanService(accessory);
@@ -331,14 +317,13 @@ export class Others extends irdeviceBase {
331
317
  this.removeStatefulProgrammableSwitchService(accessory);
332
318
  } else if (this.otherDeviceType === 'fan') {
333
319
  // Initialize Fan Service
334
- if (!accessory.context.Fan) {
335
- accessory.context.Fan = {};
336
- }
320
+ accessory.context.Fan = accessory.context.Fan ?? {};
337
321
  this.Fan = {
338
- Name: accessory.context.Name ?? `${accessory.displayName} Fan`,
322
+ Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
339
323
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
340
324
  On: accessory.context.On ?? false,
341
325
  };
326
+ accessory.context.Fan = this.Fan as object;
342
327
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
343
328
 
344
329
  this.Fan.Service
@@ -348,7 +333,6 @@ export class Others extends irdeviceBase {
348
333
  return this.Fan!.On;
349
334
  })
350
335
  .onSet(this.OnSet.bind(this));
351
- accessory.context.Name = this.Fan.Name;
352
336
 
353
337
  // Remove other services
354
338
  this.removeLockService(accessory);
@@ -361,17 +345,15 @@ export class Others extends irdeviceBase {
361
345
  this.removeWindowCoveringService(accessory);
362
346
  this.removeStatefulProgrammableSwitchService(accessory);
363
347
  } else if (this.otherDeviceType === 'stateful') {
364
- // Initialize Lock Service
365
- if (!accessory.context.StatefulProgrammableSwitch) {
366
- accessory.context.StatefulProgrammableSwitch = {};
367
- }
368
- // Initialize StatefulProgrammableSwitch property
348
+ // Initialize StatefulProgrammableSwitch Service
349
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
369
350
  this.StatefulProgrammableSwitch = {
370
- Name: accessory.context.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
351
+ Name: accessory.context.StatefulProgrammableSwitch.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
371
352
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
372
353
  ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
373
354
  On: accessory.context.On ?? false,
374
355
  };
356
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
375
357
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
376
358
 
377
359
  this.StatefulProgrammableSwitch.Service
@@ -381,7 +363,6 @@ export class Others extends irdeviceBase {
381
363
  return this.StatefulProgrammableSwitch!.On;
382
364
  })
383
365
  .onSet(this.OnSet.bind(this));
384
- accessory.context.Name = this.StatefulProgrammableSwitch.Name;
385
366
 
386
367
  // Remove other services
387
368
  this.removeFanService(accessory);
@@ -395,14 +376,13 @@ export class Others extends irdeviceBase {
395
376
  this.removeWindowCoveringService(accessory);
396
377
  } else {
397
378
  // Initialize Outlet Service
398
- if (!accessory.context.Outlet) {
399
- accessory.context.Outlet = {};
400
- }
379
+ accessory.context.Outlet = accessory.context.Outlet ?? {};
401
380
  this.Outlet = {
402
- Name: accessory.context.Name ?? `${accessory.displayName} Outlet`,
381
+ Name: accessory.context.Outlet.Name ?? `${accessory.displayName} Outlet`,
403
382
  Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
404
383
  On: accessory.context.On ?? false,
405
384
  };
385
+ accessory.context.Outlet = this.Outlet as object;
406
386
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
407
387
 
408
388
  this.Outlet.Service
@@ -412,7 +392,6 @@ export class Others extends irdeviceBase {
412
392
  return this.Outlet!.On;
413
393
  })
414
394
  .onSet(this.OnSet.bind(this));
415
- accessory.context.Name = this.Outlet.Name;
416
395
 
417
396
  // Remove other services
418
397
  this.removeFanService(accessory);
@@ -45,9 +45,7 @@ export class TV extends irdeviceBase {
45
45
  super(platform, accessory, device);
46
46
 
47
47
  // Initialize Television Service
48
- if (!accessory.context.Television) {
49
- accessory.context.Television = {};
50
- }
48
+ accessory.context.Television = accessory.context.Television ?? {};
51
49
  this.Television = {
52
50
  Name: accessory.context.Television.Name ?? `${accessory.displayName} ${device.remoteType}`,
53
51
  ConfiguredName: accessory.context.Television.ConfiguredName ?? `${accessory.displayName} ${device.remoteType}`,
@@ -57,6 +55,7 @@ export class TV extends irdeviceBase {
57
55
  SleepDiscoveryMode: accessory.context.SleepDiscoveryMode ?? this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
58
56
  RemoteKey: accessory.context.RemoteKey ?? this.hap.Characteristic.RemoteKey.EXIT,
59
57
  };
58
+ accessory.context.Television = this.Television as object;
60
59
 
61
60
  switch (device.remoteType) {
62
61
  case 'Speaker':
@@ -103,12 +102,9 @@ export class TV extends irdeviceBase {
103
102
  return this.Television.RemoteKey;
104
103
  })
105
104
  .onSet(this.RemoteKeySet.bind(this));
106
- accessory.context.Television.Name = this.Television.Name;
107
105
 
108
106
  // Initialize TelevisionSpeaker Service
109
- if (!accessory.context.TelevisionSpeaker) {
110
- accessory.context.TelevisionSpeaker = {};
111
- }
107
+ accessory.context.TelevisionSpeaker = accessory.context.TelevisionSpeaker ?? {};
112
108
  this.TelevisionSpeaker = {
113
109
  Name: accessory.context.TelevisionSpeaker.Name ?? `${accessory.displayName} ${device.remoteType} Speaker`,
114
110
  Service: accessory.getService(this.hap.Service.TelevisionSpeaker) ?? accessory.addService(this.hap.Service.TelevisionSpeaker) as Service,
@@ -116,6 +112,7 @@ export class TV extends irdeviceBase {
116
112
  VolumeControlType: accessory.context.VolumeControlType ?? this.hap.Characteristic.VolumeControlType.ABSOLUTE,
117
113
  VolumeSelector: accessory.context.VolumeSelector ?? this.hap.Characteristic.VolumeSelector.INCREMENT,
118
114
  };
115
+ accessory.context.TelevisionSpeaker = this.TelevisionSpeaker as object;
119
116
 
120
117
  this.TelevisionSpeaker.Service
121
118
  .setCharacteristic(this.hap.Characteristic.Name, this.TelevisionSpeaker.Name)
@@ -126,7 +123,6 @@ export class TV extends irdeviceBase {
126
123
  return this.TelevisionSpeaker.VolumeSelector;
127
124
  })
128
125
  .onSet(this.VolumeSelectorSet.bind(this));
129
- accessory.context.TelevisionSpeaker.Name = this.TelevisionSpeaker.Name;
130
126
  }
131
127
 
132
128
  async VolumeSelectorSet(value: CharacteristicValue): Promise<void> {
@@ -31,14 +31,13 @@ export class VacuumCleaner extends irdeviceBase {
31
31
  super(platform, accessory, device);
32
32
 
33
33
  // Initialize Switch Service
34
- if (!accessory.context.Switch) {
35
- accessory.context.Switch = {};
36
- }
34
+ accessory.context.Switch = accessory.context.Switch ?? {};
37
35
  this.Switch = {
38
- Name: accessory.context.Name ?? `${accessory.displayName} ${device.remoteType}`,
36
+ Name: accessory.context.Switch.Name ?? `${accessory.displayName} ${device.remoteType}`,
39
37
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
40
38
  On: accessory.context.On ?? false,
41
39
  };
40
+ accessory.context.Switch = this.Switch as object;
42
41
 
43
42
  this.Switch.Service
44
43
  .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
@@ -47,7 +46,6 @@ export class VacuumCleaner extends irdeviceBase {
47
46
  return this.Switch.On;
48
47
  })
49
48
  .onSet(this.OnSet.bind(this));
50
- accessory.context.Switch.Name = this.Switch.Name;
51
49
  }
52
50
 
53
51
  async OnSet(value: CharacteristicValue): Promise<void> {
@@ -31,14 +31,13 @@ export class WaterHeater extends irdeviceBase {
31
31
  super(platform, accessory, device);
32
32
 
33
33
  // Initialize Switch Service
34
- if (!accessory.context.Valve) {
35
- accessory.context.Valve = {};
36
- }
34
+ accessory.context.Valve = accessory.context.Valve ?? {};
37
35
  this.Valve = {
38
- Name: accessory.context.Name ?? `${accessory.displayName} ${device.remoteType}`,
36
+ Name: accessory.context.Valve.Name ?? `${accessory.displayName} ${device.remoteType}`,
39
37
  Service: accessory.getService(this.hap.Service.Valve) ?? accessory.addService(this.hap.Service.Valve) as Service,
40
38
  Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
41
39
  };
40
+ accessory.context.Valve = this.Valve as object;
42
41
 
43
42
  this.Valve.Service
44
43
  .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
@@ -48,7 +47,6 @@ export class WaterHeater extends irdeviceBase {
48
47
  return this.Valve.Active;
49
48
  })
50
49
  .onSet(this.ActiveSet.bind(this));
51
- accessory.context.Valve.Name = this.Valve.Name;
52
50
  }
53
51
 
54
52
  async ActiveSet(value: CharacteristicValue): Promise<void> {