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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +9 -6
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +33 -22
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts.map +1 -1
  8. package/dist/device/ceilinglight.js +4 -3
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.js +3 -2
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -10
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +11 -8
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/device.js +11 -10
  19. package/dist/device/device.js.map +1 -1
  20. package/dist/device/fan.d.ts.map +1 -1
  21. package/dist/device/fan.js +7 -5
  22. package/dist/device/fan.js.map +1 -1
  23. package/dist/device/hub.d.ts.map +1 -1
  24. package/dist/device/hub.js +9 -6
  25. package/dist/device/hub.js.map +1 -1
  26. package/dist/device/humidifier.d.ts.map +1 -1
  27. package/dist/device/humidifier.js +6 -4
  28. package/dist/device/humidifier.js.map +1 -1
  29. package/dist/device/iosensor.d.ts.map +1 -1
  30. package/dist/device/iosensor.js +10 -6
  31. package/dist/device/iosensor.js.map +1 -1
  32. package/dist/device/lightstrip.d.ts.map +1 -1
  33. package/dist/device/lightstrip.js +3 -2
  34. package/dist/device/lightstrip.js.map +1 -1
  35. package/dist/device/lock.d.ts.map +1 -1
  36. package/dist/device/lock.js +12 -8
  37. package/dist/device/lock.js.map +1 -1
  38. package/dist/device/meter.d.ts.map +1 -1
  39. package/dist/device/meter.js +8 -5
  40. package/dist/device/meter.js.map +1 -1
  41. package/dist/device/meterplus.d.ts.map +1 -1
  42. package/dist/device/meterplus.js +9 -6
  43. package/dist/device/meterplus.js.map +1 -1
  44. package/dist/device/motion.d.ts.map +1 -1
  45. package/dist/device/motion.js +10 -6
  46. package/dist/device/motion.js.map +1 -1
  47. package/dist/device/plug.d.ts.map +1 -1
  48. package/dist/device/plug.js +3 -2
  49. package/dist/device/plug.js.map +1 -1
  50. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  51. package/dist/device/robotvacuumcleaner.js +6 -4
  52. package/dist/device/robotvacuumcleaner.js.map +1 -1
  53. package/dist/device/waterdetector.d.ts.map +1 -1
  54. package/dist/device/waterdetector.js +6 -4
  55. package/dist/device/waterdetector.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts +1 -1
  57. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  58. package/dist/irdevice/airconditioner.js +65 -83
  59. package/dist/irdevice/airconditioner.js.map +1 -1
  60. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  61. package/dist/irdevice/airpurifier.js +37 -19
  62. package/dist/irdevice/airpurifier.js.map +1 -1
  63. package/dist/irdevice/camera.d.ts.map +1 -1
  64. package/dist/irdevice/camera.js +13 -11
  65. package/dist/irdevice/camera.js.map +1 -1
  66. package/dist/irdevice/fan.d.ts.map +1 -1
  67. package/dist/irdevice/fan.js +25 -15
  68. package/dist/irdevice/fan.js.map +1 -1
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +50 -24
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +1 -1
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +180 -138
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts.map +1 -1
  77. package/dist/irdevice/tv.js +50 -59
  78. package/dist/irdevice/tv.js.map +1 -1
  79. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.js +13 -10
  81. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  82. package/dist/irdevice/waterheater.d.ts.map +1 -1
  83. package/dist/irdevice/waterheater.js +14 -13
  84. package/dist/irdevice/waterheater.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/blindtilt.ts +9 -6
  87. package/src/device/bot.ts +33 -22
  88. package/src/device/ceilinglight.ts +4 -3
  89. package/src/device/colorbulb.ts +3 -3
  90. package/src/device/contact.ts +14 -10
  91. package/src/device/curtain.ts +11 -8
  92. package/src/device/device.ts +11 -11
  93. package/src/device/fan.ts +7 -5
  94. package/src/device/hub.ts +9 -6
  95. package/src/device/humidifier.ts +6 -4
  96. package/src/device/iosensor.ts +10 -6
  97. package/src/device/lightstrip.ts +3 -2
  98. package/src/device/lock.ts +12 -8
  99. package/src/device/meter.ts +8 -5
  100. package/src/device/meterplus.ts +9 -6
  101. package/src/device/motion.ts +10 -6
  102. package/src/device/plug.ts +3 -2
  103. package/src/device/robotvacuumcleaner.ts +6 -4
  104. package/src/device/waterdetector.ts +6 -4
  105. package/src/irdevice/airconditioner.ts +73 -86
  106. package/src/irdevice/airpurifier.ts +43 -23
  107. package/src/irdevice/camera.ts +14 -13
  108. package/src/irdevice/fan.ts +26 -18
  109. package/src/irdevice/light.ts +65 -45
  110. package/src/irdevice/other.ts +210 -154
  111. package/src/irdevice/tv.ts +57 -70
  112. package/src/irdevice/vacuumcleaner.ts +14 -12
  113. package/src/irdevice/waterheater.ts +15 -16
@@ -18,6 +18,7 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class AirConditioner extends irdeviceBase {
19
19
  // Services
20
20
  private HeaterCooler: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  Active: CharacteristicValue;
23
24
  CurrentHeaterCoolerState: CharacteristicValue;
@@ -27,7 +28,9 @@ export class AirConditioner extends irdeviceBase {
27
28
  RotationSpeed: CharacteristicValue;
28
29
  };
29
30
 
31
+ meter?: PlatformAccessory;
30
32
  private HumiditySensor?: {
33
+ Name: CharacteristicValue;
31
34
  Service: Service;
32
35
  CurrentRelativeHumidity: CharacteristicValue;
33
36
  };
@@ -46,7 +49,6 @@ export class AirConditioner extends irdeviceBase {
46
49
  set_min_heat?: number;
47
50
  set_max_cool?: number;
48
51
  set_min_cool?: number;
49
- meter?: PlatformAccessory;
50
52
 
51
53
  constructor(
52
54
  readonly platform: SwitchBotPlatform,
@@ -58,64 +60,52 @@ export class AirConditioner extends irdeviceBase {
58
60
  // default placeholders
59
61
  this.getAirConditionerConfigSettings(accessory, device);
60
62
 
61
- // Initialize HeaterCooler property
62
- this.HeaterCooler = {
63
- Service: accessory.getService(this.hap.Service.Switch) as Service,
64
- Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
65
- CurrentHeaterCoolerState: accessory.context.CurrentHeaterCoolerState || this.hap.Characteristic.CurrentHeaterCoolerState.IDLE,
66
- TargetHeaterCoolerState: accessory.context.TargetHeaterCoolerState || this.hap.Characteristic.TargetHeaterCoolerState.AUTO,
67
- CurrentTemperature: accessory.context.CurrentTemperature || 24,
68
- ThresholdTemperature: accessory.context.ThresholdTemperature || 24,
69
- RotationSpeed: accessory.context.RotationSpeed || 4,
70
- };
71
-
72
- // Initialize HumiditySensor property
73
- if (this.device.irair?.meterType && this.device.irair?.meterId) {
74
- const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`);
75
- this.meter = this.platform.accessories.find((accessory) => accessory.UUID === meterUuid);
76
- this.HumiditySensor = {
77
- Service: this.meter!.getService(this.hap.Service.HumiditySensor) as Service,
78
- CurrentRelativeHumidity: this.meter!.context.CurrentRelativeHumidity || 0,
79
- };
80
- }
63
+ this.ValidValues = this.hide_automode ? [1, 2] : [0, 1, 2];
81
64
 
82
- // get the Television service if it exists, otherwise create a new Television service
83
- // you can create multiple services for each accessory
84
- const HeaterCoolerService = `${accessory.displayName} ${device.remoteType}`;
85
- (this.HeaterCooler.Service = accessory.getService(this.hap.Service.HeaterCooler)
86
- || accessory.addService(this.hap.Service.HeaterCooler)), HeaterCoolerService;
87
65
 
88
- this.HeaterCooler.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
66
+ // Initialize HeaterCooler Service
67
+ accessory.context.HeaterCooler = accessory.context.HeaterCooler ?? {};
68
+ this.HeaterCooler = {
69
+ Name: accessory.context.HeaterCooler.Name ?? `${accessory.displayName} ${device.remoteType}`,
70
+ Service: accessory.getService(this.hap.Service.HeaterCooler) ?? accessory.addService(this.hap.Service.HeaterCooler) as Service,
71
+ Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
72
+ CurrentHeaterCoolerState: accessory.context.CurrentHeaterCoolerState ?? this.hap.Characteristic.CurrentHeaterCoolerState.IDLE,
73
+ TargetHeaterCoolerState: accessory.context.TargetHeaterCoolerState ?? this.hap.Characteristic.TargetHeaterCoolerState.AUTO,
74
+ CurrentTemperature: accessory.context.CurrentTemperature ?? 24,
75
+ ThresholdTemperature: accessory.context.ThresholdTemperature ?? 24,
76
+ RotationSpeed: accessory.context.RotationSpeed ?? 4,
77
+ };
78
+ accessory.context.HeaterCooler = this.HeaterCooler as object;
89
79
 
90
- // handle on / off events using the Active characteristic
91
- this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.Active)
80
+ this.HeaterCooler.Service
81
+ .setCharacteristic(this.hap.Characteristic.Name, this.HeaterCooler.Name)
82
+ .getCharacteristic(this.hap.Characteristic.Active)
83
+ .onGet(() => {
84
+ return this.HeaterCooler.Active;
85
+ })
92
86
  .onSet(this.ActiveSet.bind(this));
93
87
 
94
- this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
95
- .onGet(this.CurrentTemperatureGet.bind(this));
96
-
97
- this.ValidValues = this.hide_automode ? [1, 2] : [0, 1, 2];
98
-
99
- if (this.device.irair?.meterType && this.device.irair?.meterId) {
100
- const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`);
101
- this.meter = this.platform.accessories.find((accessory) => accessory.UUID === meterUuid);
102
- }
103
-
104
- if (this.meter) {
105
- this.HumiditySensor!.Service.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
106
- .onGet(this.CurrentRelativeHumidityGet.bind(this));
107
- }
88
+ this.HeaterCooler.Service
89
+ .getCharacteristic(this.hap.Characteristic.CurrentTemperature)
90
+ .onGet(async () => {
91
+ return await this.CurrentTemperatureGet();
92
+ });
108
93
 
109
94
  this.HeaterCooler.Service
110
95
  .getCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState)
111
96
  .setProps({
112
97
  validValues: this.ValidValues,
113
98
  })
114
- .onGet(this.TargetHeaterCoolerStateGet.bind(this))
99
+ .onGet(async () => {
100
+ return await this.TargetHeaterCoolerStateGet();
101
+ })
115
102
  .onSet(this.TargetHeaterCoolerStateSet.bind(this));
116
103
 
117
- this.HeaterCooler.Service.getCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState)
118
- .onGet(this.CurrentHeaterCoolerStateGet.bind(this));
104
+ this.HeaterCooler.Service
105
+ .getCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState)
106
+ .onGet(async () => {
107
+ return await this.CurrentHeaterCoolerStateGet();
108
+ });
119
109
 
120
110
  this.HeaterCooler.Service
121
111
  .getCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature)
@@ -124,7 +114,9 @@ export class AirConditioner extends irdeviceBase {
124
114
  maxValue: this.set_max_heat,
125
115
  minStep: 0.5,
126
116
  })
127
- .onGet(this.ThresholdTemperatureGet.bind(this))
117
+ .onGet(async () => {
118
+ return await this.ThresholdTemperatureGet();
119
+ })
128
120
  .onSet(this.ThresholdTemperatureSet.bind(this));
129
121
 
130
122
  this.HeaterCooler.Service
@@ -134,7 +126,9 @@ export class AirConditioner extends irdeviceBase {
134
126
  maxValue: this.set_max_cool,
135
127
  minStep: 0.5,
136
128
  })
137
- .onGet(this.ThresholdTemperatureGet.bind(this))
129
+ .onGet(async () => {
130
+ return await this.ThresholdTemperatureGet();
131
+ })
138
132
  .onSet(this.ThresholdTemperatureSet.bind(this));
139
133
 
140
134
  this.HeaterCooler.Service
@@ -145,8 +139,37 @@ export class AirConditioner extends irdeviceBase {
145
139
  minValue: 1,
146
140
  maxValue: 4,
147
141
  })
148
- .onGet(this.RotationSpeedGet.bind(this))
142
+ .onGet(async () => {
143
+ return await this.RotationSpeedGet();
144
+ })
149
145
  .onSet(this.RotationSpeedSet.bind(this));
146
+
147
+ // Initialize HumiditySensor property
148
+
149
+ if (this.device.irair?.meterType && this.device.irair?.meterId) {
150
+ const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`);
151
+ this.meter = this.platform.accessories.find((accessory) => accessory.UUID === meterUuid);
152
+ accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {};
153
+ this.HumiditySensor = {
154
+ Name: accessory.context.HumiditySensor ?? this.meter!.displayName,
155
+ Service: this.meter!.getService(this.hap.Service.HumiditySensor) ?? this.meter!.addService(this.hap.Service.HumiditySensor) as Service,
156
+ CurrentRelativeHumidity: this.meter!.context.CurrentRelativeHumidity || 0,
157
+ };
158
+ accessory.context.HumiditySensor = this.HumiditySensor as object;
159
+ }
160
+
161
+ if (this.device.irair?.meterType && this.device.irair?.meterId) {
162
+ const meterUuid = this.platform.api.hap.uuid.generate(`${this.device.irair.meterId}-${this.device.irair.meterType}`);
163
+ this.meter = this.platform.accessories.find((accessory) => accessory.UUID === meterUuid);
164
+ }
165
+
166
+ if (this.meter) {
167
+ this.HumiditySensor!.Service
168
+ .getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
169
+ .onGet(async () => {
170
+ return await this.CurrentRelativeHumidityGet();
171
+ });
172
+ }
150
173
  }
151
174
 
152
175
  /**
@@ -545,43 +568,7 @@ export class AirConditioner extends irdeviceBase {
545
568
  this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed;
546
569
  }
547
570
 
548
- if (this.device.irair?.hide_automode) {
549
- this.hide_automode = this.device.irair?.hide_automode;
550
- this.accessory.context.hide_automode = this.hide_automode;
551
- } else {
552
- this.hide_automode = this.device.irair?.hide_automode;
553
- this.accessory.context.hide_automode = this.hide_automode;
554
- }
555
-
556
- if (this.device.irair?.set_max_heat) {
557
- this.set_max_heat = this.device.irair?.set_max_heat;
558
- this.accessory.context.set_max_heat = this.set_max_heat;
559
- } else {
560
- this.set_max_heat = 35;
561
- this.accessory.context.set_max_heat = this.set_max_heat;
562
- }
563
- if (this.device.irair?.set_min_heat) {
564
- this.set_min_heat = this.device.irair?.set_min_heat;
565
- this.accessory.context.set_min_heat = this.set_min_heat;
566
- } else {
567
- this.set_min_heat = 0;
568
- this.accessory.context.set_min_heat = this.set_min_heat;
569
- }
570
-
571
- if (this.device.irair?.set_max_cool) {
572
- this.set_max_cool = this.device.irair?.set_max_cool;
573
- this.accessory.context.set_max_cool = this.set_max_cool;
574
- } else {
575
- this.set_max_cool = 35;
576
- this.accessory.context.set_max_cool = this.set_max_cool;
577
- }
578
- if (this.device.irair?.set_min_cool) {
579
- this.set_min_cool = this.device.irair?.set_min_cool;
580
- this.accessory.context.set_min_cool = this.set_min_cool;
581
- } else {
582
- this.set_min_cool = 0;
583
- this.accessory.context.set_min_cool = this.set_min_cool;
584
- }
571
+ await this.getAirConditionerConfigSettings(this.accessory, this.device);
585
572
 
586
573
  if (this.meter) {
587
574
  if (this.HumiditySensor!.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
@@ -18,6 +18,7 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class AirPurifier extends irdeviceBase {
19
19
  // Services
20
20
  private AirPurifier: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  Active: CharacteristicValue;
23
24
  RotationSpeed: CharacteristicValue;
@@ -26,6 +27,7 @@ export class AirPurifier extends irdeviceBase {
26
27
  };
27
28
 
28
29
  private TemperatureSensor: {
30
+ Name: CharacteristicValue;
29
31
  Service: Service;
30
32
  CurrentTemperature: CharacteristicValue;
31
33
  };
@@ -54,36 +56,54 @@ export class AirPurifier extends irdeviceBase {
54
56
  ) {
55
57
  super(platform, accessory, device);
56
58
 
57
- // Initialize AirPurifier property
59
+ // Initialize AirPurifier Service
60
+ accessory.context.AirPurifier = accessory.context.AirPurifier ?? {};
58
61
  this.AirPurifier = {
59
- Service: accessory.getService(this.hap.Service.Switch) as Service,
60
- Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
61
- RotationSpeed: accessory.context.RotationSpeed || 0,
62
- CurrentAirPurifierState: accessory.context.CurrentAirPurifierState || this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
63
- TargetAirPurifierState: accessory.context.TargetAirPurifierState || this.hap.Characteristic.TargetAirPurifierState.AUTO,
62
+ Name: accessory.context.AirPurifier.Name ?? `${accessory.displayName} Air Purifier`,
63
+ Service: accessory.getService(this.hap.Service.AirPurifier) ?? accessory.addService(this.hap.Service.AirPurifier) as Service,
64
+ Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
65
+ RotationSpeed: accessory.context.RotationSpeed ?? 0,
66
+ CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
67
+ TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
64
68
  };
69
+ accessory.context.AirPurifier = this.AirPurifier as object;
65
70
 
66
- // Initialize TemperatureSensor property
67
- this.TemperatureSensor = {
68
- Service: accessory.getService(this.hap.Service.TemperatureSensor) as Service,
69
- CurrentTemperature: accessory.context.CurrentTemperature || 24,
70
- };
71
+ this.AirPurifier.Service
72
+ .setCharacteristic(this.hap.Characteristic.Name, this.AirPurifier.Name)
73
+ .getCharacteristic(this.hap.Characteristic.Active)
74
+ .onGet(() => {
75
+ return this.AirPurifier.Active;
76
+ })
77
+ .onSet(this.ActiveSet.bind(this));
71
78
 
72
- // get the Television service if it exists, otherwise create a new Television service
73
- // you can create multiple services for each accessory
74
- const AirPurifierService = `${accessory.displayName} Air Purifier`;
75
- (this.AirPurifier.Service = accessory.getService(this.hap.Service.AirPurifier)
76
- || accessory.addService(this.hap.Service.AirPurifier)), AirPurifierService;
79
+ this.AirPurifier.Service
80
+ .getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState)
81
+ .onGet(() => {
82
+ return this.CurrentAirPurifierStateGet();
83
+ });
77
84
 
78
- this.AirPurifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
79
- // handle on / off events using the Active characteristic
80
- this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
85
+ this.AirPurifier.Service
86
+ .getCharacteristic(this.hap.Characteristic.TargetAirPurifierState)
87
+ .onGet(() => {
88
+ return this.AirPurifier.TargetAirPurifierState;
89
+ })
90
+ .onSet(this.TargetAirPurifierStateSet.bind(this));
81
91
 
82
- this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState).onGet(() => {
83
- return this.CurrentAirPurifierStateGet();
84
- });
92
+ // Initialize TemperatureSensor Service
93
+ accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {};
94
+ this.TemperatureSensor = {
95
+ Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
96
+ Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? accessory.addService(this.hap.Service.TemperatureSensor) as Service,
97
+ CurrentTemperature: accessory.context.CurrentTemperature || 24,
98
+ };
99
+ accessory.context.TemperatureSensor = this.TemperatureSensor as object;
85
100
 
86
- this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
101
+ this.TemperatureSensor.Service
102
+ .setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
103
+ .getCharacteristic(this.hap.Characteristic.CurrentTemperature)
104
+ .onGet(() => {
105
+ return this.TemperatureSensor.CurrentTemperature;
106
+ });
87
107
  }
88
108
 
89
109
  async ActiveSet(value: CharacteristicValue): Promise<void> {
@@ -18,6 +18,7 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class Camera extends irdeviceBase {
19
19
  // Services
20
20
  private Switch: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  On: CharacteristicValue;
23
24
  };
@@ -29,22 +30,22 @@ export class Camera extends irdeviceBase {
29
30
  ) {
30
31
  super(platform, accessory, device);
31
32
 
32
- // Initialize Switch property
33
+ // Initialize Switch Service
34
+ accessory.context.Switch = accessory.context.Switch ?? {};
33
35
  this.Switch = {
34
- Service: accessory.getService(this.hap.Service.Switch) as Service,
35
- On: accessory.context.On || false,
36
+ Name: accessory.context.Switch.Name ?? `${accessory.displayName} Camera`,
37
+ Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
38
+ On: accessory.context.On ?? false,
36
39
  };
40
+ accessory.context.Switch = this.Switch as object;
37
41
 
38
- // get the Television service if it exists, otherwise create a new Television service
39
- // you can create multiple services for each accessory
40
- const SwitchService = `${accessory.displayName} Camera`;
41
- (this.Switch.Service = accessory.getService(this.hap.Service.Switch)
42
- || accessory.addService(this.hap.Service.Switch)), SwitchService;
43
-
44
- this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, SwitchService);
45
-
46
- // handle on / off events using the On characteristic
47
- this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
42
+ this.Switch.Service
43
+ .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
44
+ .getCharacteristic(this.hap.Characteristic.On)
45
+ .onGet(() => {
46
+ return this.Switch.On;
47
+ })
48
+ .onSet(this.OnSet.bind(this));
48
49
  }
49
50
 
50
51
  async OnSet(value: CharacteristicValue): Promise<void> {
@@ -18,6 +18,7 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class IRFan extends irdeviceBase {
19
19
  // Services
20
20
  private Fan: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  Active: CharacteristicValue;
23
24
  SwingMode: CharacteristicValue;
@@ -32,26 +33,25 @@ export class IRFan extends irdeviceBase {
32
33
  ) {
33
34
  super(platform, accessory, device);
34
35
 
35
- // Initialize Switch property
36
+ // Initialize Switch Service
37
+ accessory.context.Fan = accessory.context.Fan ?? {};
36
38
  this.Fan = {
37
- Service: accessory.getService(this.hap.Service.Lightbulb) as Service,
38
- Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
39
- SwingMode: accessory.context.SwingMode || this.hap.Characteristic.SwingMode.SWING_DISABLED,
40
- RotationSpeed: accessory.context.RotationSpeed || 0,
41
- RotationDirection: accessory.context.On || this.hap.Characteristic.RotationDirection.CLOCKWISE,
39
+ Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
40
+ Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
41
+ Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
42
+ SwingMode: accessory.context.SwingMode ?? this.hap.Characteristic.SwingMode.SWING_DISABLED,
43
+ RotationSpeed: accessory.context.RotationSpeed ?? 0,
44
+ RotationDirection: accessory.context.RotationDirection ?? this.hap.Characteristic.RotationDirection.CLOCKWISE,
42
45
  };
46
+ accessory.context.Fan = this.Fan as object;
43
47
 
44
- // get the Television service if it exists, otherwise create a new Television service
45
- // you can create multiple services for each accessory
46
- const FanService = `${accessory.displayName} Fan`;
47
- (this.Fan.Service = accessory.getService(this.hap.Service.Fanv2)
48
- || accessory.addService(this.hap.Service.Fanv2)), FanService;
49
-
50
- this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
51
-
52
- // handle on / off events using the Active characteristic
53
- this.Fan.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
54
-
48
+ this.Fan.Service
49
+ .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
50
+ .getCharacteristic(this.hap.Characteristic.Active)
51
+ .onGet(() => {
52
+ return this.Fan.Active;
53
+ })
54
+ .onSet(this.ActiveSet.bind(this));
55
55
 
56
56
  if (device.irfan?.rotation_speed) {
57
57
  // handle Rotation Speed events using the RotationSpeed characteristic
@@ -62,6 +62,9 @@ export class IRFan extends irdeviceBase {
62
62
  minValue: Number(this.minValue(device)),
63
63
  maxValue: Number(this.maxValue(device)),
64
64
  })
65
+ .onGet(() => {
66
+ return this.Fan.RotationSpeed;
67
+ })
65
68
  .onSet(this.RotationSpeedSet.bind(this));
66
69
  } else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
67
70
  const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed);
@@ -76,7 +79,12 @@ export class IRFan extends irdeviceBase {
76
79
 
77
80
  if (device.irfan?.swing_mode) {
78
81
  // handle Osolcation events using the SwingMode characteristic
79
- this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
82
+ this.Fan.Service
83
+ .getCharacteristic(this.hap.Characteristic.SwingMode)
84
+ .onGet(() => {
85
+ return this.Fan.SwingMode;
86
+ })
87
+ .onSet(this.SwingModeSet.bind(this));
80
88
  } else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
81
89
  const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode);
82
90
  this.Fan.Service.removeCharacteristic(characteristic);
@@ -18,17 +18,20 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
18
18
  export class Light extends irdeviceBase {
19
19
  // Services
20
20
  private LightBulb?: {
21
+ Name: CharacteristicValue;
21
22
  Service: Service;
22
23
  On: CharacteristicValue;
23
24
  };
24
25
 
25
26
  private ProgrammableSwitchOn?: {
27
+ Name: CharacteristicValue;
26
28
  Service: Service;
27
29
  ProgrammableSwitchEvent: CharacteristicValue;
28
30
  ProgrammableSwitchOutputState: CharacteristicValue;
29
31
  };
30
32
 
31
33
  private ProgrammableSwitchOff?: {
34
+ Name: CharacteristicValue;
32
35
  Service: Service;
33
36
  ProgrammableSwitchEvent: CharacteristicValue;
34
37
  ProgrammableSwitchOutputState: CharacteristicValue;
@@ -42,66 +45,83 @@ export class Light extends irdeviceBase {
42
45
  super(platform, accessory, device);
43
46
 
44
47
  if (!device.irlight?.stateless) {
45
- // Initialize LightBulb property
48
+ // Initialize LightBulb Service
49
+ accessory.context.LightBulb = accessory.context.LightBulb ?? {};
46
50
  this.LightBulb = {
47
- Service: accessory.getService(this.hap.Service.Lightbulb)! as Service,
51
+ Name: accessory.context.LightBulb.Name ?? `${accessory.displayName} ${device.remoteType}`,
52
+ Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
48
53
  On: accessory.context.On || false,
49
54
  };
50
- // get the Light service if it exists, otherwise create a new Light service
51
- // you can create multiple services for each accessory
52
- const LightBulbService = `${accessory.displayName} ${device.remoteType}`;
53
- (this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
54
- || accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
55
+ accessory.context.LightBulb = this.LightBulb as object;
55
56
 
56
-
57
- this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
58
-
59
- // handle on / off events using the On characteristic
60
- this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
57
+ this.LightBulb.Service
58
+ .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
59
+ .getCharacteristic(this.hap.Characteristic.On)
60
+ .onGet(() => {
61
+ return this.LightBulb!.On;
62
+ })
63
+ .onSet(this.OnSet.bind(this));
61
64
  } else {
62
-
63
- // create a new Stateful Programmable Switch On service
64
- const ProgrammableSwitchOn = `${accessory.displayName} ${device.remoteType} On`;
65
- (this.ProgrammableSwitchOn!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
66
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOn;
67
-
68
-
69
- this.ProgrammableSwitchOn?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
70
-
71
- this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
72
- validValueRanges: [0, 0],
73
- minValue: 0,
74
- maxValue: 0,
75
- validValues: [0],
76
- })
65
+ // Initialize ProgrammableSwitchOn Service
66
+ accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
67
+ this.ProgrammableSwitchOn = {
68
+ Name: accessory.context.ProgrammableSwitchOn.Name ?? `${accessory.displayName} ${device.remoteType} On`,
69
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
70
+ ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
71
+ ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
72
+ ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
73
+ };
74
+ accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object;
75
+
76
+ // Initialize ProgrammableSwitchOn Characteristics
77
+ this.ProgrammableSwitchOn?.Service
78
+ .setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name)
79
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
80
+ validValueRanges: [0, 0],
81
+ minValue: 0,
82
+ maxValue: 0,
83
+ validValues: [0],
84
+ })
77
85
  .onGet(() => {
78
86
  return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent;
79
87
  });
80
88
 
81
- this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
89
+ this.ProgrammableSwitchOn?.Service
90
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
91
+ .onGet(() => {
92
+ return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState;
93
+ })
82
94
  .onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
83
95
 
84
-
85
-
86
- // create a new Stateful Programmable Switch Off service
87
- const ProgrammableSwitchOff = `${accessory.displayName} ${device.remoteType} Off`;
88
- (this.ProgrammableSwitchOff!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
89
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchOff;
90
-
91
-
92
- this.ProgrammableSwitchOff?.Service.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
93
-
94
- this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
95
- validValueRanges: [0, 0],
96
- minValue: 0,
97
- maxValue: 0,
98
- validValues: [0],
99
- })
96
+ // Initialize ProgrammableSwitchOff Service
97
+ accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
98
+ this.ProgrammableSwitchOff = {
99
+ Name: accessory.context.ProgrammableSwitchOff.Name ?? `${accessory.displayName} ${device.remoteType} Off`,
100
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
101
+ ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
102
+ ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
103
+ ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
104
+ };
105
+ accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object;
106
+
107
+ // Initialize ProgrammableSwitchOff Characteristics
108
+ this.ProgrammableSwitchOff?.Service
109
+ .setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name)
110
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
111
+ validValueRanges: [0, 0],
112
+ minValue: 0,
113
+ maxValue: 0,
114
+ validValues: [0],
115
+ })
100
116
  .onGet(() => {
101
117
  return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent;
102
118
  });
103
119
 
104
- this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
120
+ this.ProgrammableSwitchOff?.Service
121
+ .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
122
+ .onGet(() => {
123
+ return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState;
124
+ })
105
125
  .onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
106
126
  }
107
127