@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.31

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 (166) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/config.schema.json +147 -9
  3. package/dist/device/blindtilt.d.ts +21 -94
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +347 -756
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +25 -71
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +582 -759
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +13 -67
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +209 -587
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +13 -74
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +250 -632
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +14 -65
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +204 -531
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +17 -86
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +335 -786
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +59 -0
  28. package/dist/device/device.d.ts.map +1 -0
  29. package/dist/device/device.js +654 -0
  30. package/dist/device/device.js.map +1 -0
  31. package/dist/device/fan.d.ts +51 -0
  32. package/dist/device/fan.d.ts.map +1 -0
  33. package/dist/device/fan.js +499 -0
  34. package/dist/device/fan.js.map +1 -0
  35. package/dist/device/hub.d.ts +15 -59
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +242 -596
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +10 -65
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +207 -571
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +11 -64
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +174 -584
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +10 -68
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +252 -568
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +15 -62
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +210 -542
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +13 -63
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +170 -577
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +13 -64
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +159 -577
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +13 -69
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +136 -518
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +9 -57
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +82 -452
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +11 -62
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +140 -451
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +9 -70
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +121 -664
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/irdevice/airconditioner.d.ts +8 -48
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +309 -419
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +7 -38
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +72 -304
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts +6 -35
  89. package/dist/irdevice/camera.d.ts.map +1 -1
  90. package/dist/irdevice/camera.js +34 -278
  91. package/dist/irdevice/camera.js.map +1 -1
  92. package/dist/irdevice/fan.d.ts +6 -39
  93. package/dist/irdevice/fan.d.ts.map +1 -1
  94. package/dist/irdevice/fan.js +67 -311
  95. package/dist/irdevice/fan.js.map +1 -1
  96. package/dist/irdevice/irdevice.d.ts +40 -0
  97. package/dist/irdevice/irdevice.d.ts.map +1 -0
  98. package/dist/irdevice/irdevice.js +509 -0
  99. package/dist/irdevice/irdevice.js.map +1 -0
  100. package/dist/irdevice/light.d.ts +6 -34
  101. package/dist/irdevice/light.d.ts.map +1 -1
  102. package/dist/irdevice/light.js +23 -272
  103. package/dist/irdevice/light.js.map +1 -1
  104. package/dist/irdevice/other.d.ts +18 -47
  105. package/dist/irdevice/other.d.ts.map +1 -1
  106. package/dist/irdevice/other.js +352 -546
  107. package/dist/irdevice/other.js.map +1 -1
  108. package/dist/irdevice/tv.d.ts +7 -39
  109. package/dist/irdevice/tv.d.ts.map +1 -1
  110. package/dist/irdevice/tv.js +82 -321
  111. package/dist/irdevice/tv.js.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.d.ts +6 -35
  113. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.js +41 -284
  115. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  116. package/dist/irdevice/waterheater.d.ts +6 -35
  117. package/dist/irdevice/waterheater.d.ts.map +1 -1
  118. package/dist/irdevice/waterheater.js +42 -287
  119. package/dist/irdevice/waterheater.js.map +1 -1
  120. package/dist/platform.d.ts +14 -1
  121. package/dist/platform.d.ts.map +1 -1
  122. package/dist/platform.js +237 -94
  123. package/dist/platform.js.map +1 -1
  124. package/dist/settings.d.ts +40 -10
  125. package/dist/settings.d.ts.map +1 -1
  126. package/dist/settings.js +0 -552
  127. package/dist/settings.js.map +1 -1
  128. package/dist/utils.d.ts +77 -0
  129. package/dist/utils.d.ts.map +1 -1
  130. package/dist/utils.js +638 -1
  131. package/dist/utils.js.map +1 -1
  132. package/package.json +16 -15
  133. package/src/custom.d.ts +2 -1
  134. package/src/device/blindtilt.ts +373 -782
  135. package/src/device/bot.ts +616 -844
  136. package/src/device/ceilinglight.ts +222 -607
  137. package/src/device/colorbulb.ts +264 -656
  138. package/src/device/contact.ts +229 -553
  139. package/src/device/curtain.ts +355 -810
  140. package/src/device/device.ts +681 -0
  141. package/src/device/fan.ts +548 -0
  142. package/src/device/hub.ts +268 -623
  143. package/src/device/humidifier.ts +237 -618
  144. package/src/device/iosensor.ts +200 -610
  145. package/src/device/lightstrip.ts +273 -596
  146. package/src/device/lock.ts +247 -582
  147. package/src/device/meter.ts +196 -601
  148. package/src/device/meterplus.ts +184 -602
  149. package/src/device/motion.ts +156 -541
  150. package/src/device/plug.ts +92 -480
  151. package/src/device/robotvacuumcleaner.ts +161 -477
  152. package/src/device/waterdetector.ts +139 -689
  153. package/src/index.ts +1 -1
  154. package/src/irdevice/airconditioner.ts +330 -446
  155. package/src/irdevice/airpurifier.ts +89 -321
  156. package/src/irdevice/camera.ts +42 -293
  157. package/src/irdevice/fan.ts +78 -327
  158. package/src/irdevice/irdevice.ts +526 -0
  159. package/src/irdevice/light.ts +32 -287
  160. package/src/irdevice/other.ts +396 -615
  161. package/src/irdevice/tv.ts +100 -339
  162. package/src/irdevice/vacuumcleaner.ts +49 -305
  163. package/src/irdevice/waterheater.ts +50 -310
  164. package/src/platform.ts +247 -102
  165. package/src/settings.ts +56 -565
  166. package/src/utils.ts +642 -1
@@ -1,67 +1,90 @@
1
- import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * other.ts: @switchbot/homebridge-switchbot.
4
+ */
2
5
  import { request } from 'undici';
6
+ import { irdeviceBase } from './irdevice.js';
3
7
  import { SwitchBotPlatform } from '../platform.js';
4
- import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings.js';
8
+ import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
10
 
6
11
  /**
7
12
  * Platform Accessory
8
13
  * An instance of this class is created for each accessory your platform registers
9
14
  * Each accessory may expose multiple services of different service types.
10
15
  */
11
- export class Others {
12
- public readonly api: API;
13
- public readonly log: Logging;
14
- public readonly config!: SwitchBotPlatformConfig;
15
- protected readonly hap: HAP;
16
+ export class Others extends irdeviceBase {
16
17
  // Services
17
- fanService?: Service;
18
- doorService?: Service;
19
- lockService?: Service;
20
- faucetService?: Service;
21
- windowService?: Service;
22
- switchService?: Service;
23
- outletService?: Service;
24
- garageDoorService?: Service;
25
- windowCoveringService?: Service;
26
- statefulProgrammableSwitchService?: Service;
27
-
28
- // Characteristic Values
29
- On?: CharacteristicValue;
30
- FirmwareRevision!: CharacteristicValue;
18
+ private Switch?: {
19
+ Service: Service;
20
+ On: CharacteristicValue;
21
+ };
22
+
23
+ private GarageDoor?: {
24
+ Service: Service;
25
+ On: CharacteristicValue;
26
+ };
27
+
28
+ private Door?: {
29
+ Service: Service;
30
+ On: CharacteristicValue;
31
+ };
32
+
33
+ private Window?: {
34
+ Service: Service;
35
+ On: CharacteristicValue;
36
+ };
37
+
38
+ private WindowCovering?: {
39
+ Service: Service;
40
+ On: CharacteristicValue;
41
+ };
42
+
43
+ private Lock?: {
44
+ Service: Service;
45
+ On: CharacteristicValue;
46
+ };
47
+
48
+ private Faucet?: {
49
+ Service: Service;
50
+ On: CharacteristicValue;
51
+ };
52
+
53
+ private Fan?: {
54
+ Service: Service;
55
+ On: CharacteristicValue;
56
+ };
57
+
58
+ private StatefulProgrammableSwitch?: {
59
+ Service: Service;
60
+ On: CharacteristicValue;
61
+ };
62
+
63
+ private Outlet?: {
64
+ Service: Service;
65
+ On: CharacteristicValue;
66
+ };
31
67
 
32
68
  // Config
33
- deviceLogging!: string;
34
- disablePushOn?: boolean;
35
69
  otherDeviceType?: string;
36
- disablePushOff?: boolean;
37
70
 
38
71
  constructor(
39
- private readonly platform: SwitchBotPlatform,
40
- private accessory: PlatformAccessory,
41
- public device: irdevice & irDevicesConfig,
72
+ readonly platform: SwitchBotPlatform,
73
+ accessory: PlatformAccessory,
74
+ device: irdevice & irDevicesConfig,
42
75
  ) {
43
- this.api = this.platform.api;
44
- this.log = this.platform.log;
45
- this.config = this.platform.config;
46
- this.hap = this.api.hap;
47
- // default placeholders
48
- this.deviceLogs(device);
49
- this.deviceType(device);
50
- this.deviceContext();
51
- this.disablePushOnChanges(device);
52
- this.disablePushOffChanges(device);
53
- this.deviceConfig(device);
76
+ super(platform, accessory, device);
54
77
 
55
- // set accessory information
56
- accessory
57
- .getService(this.hap.Service.AccessoryInformation)!
58
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
59
- .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
60
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
61
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
78
+ // default placeholders
79
+ this.getOtherConfigSettings(device);
62
80
 
63
81
  // deviceType
64
82
  if (this.otherDeviceType === 'switch') {
83
+ // Initialize Switch property
84
+ this.Switch = {
85
+ Service: accessory.getService(this.hap.Service.Switch)!,
86
+ On: accessory.context.On || false,
87
+ };
65
88
  this.removeFanService(accessory);
66
89
  this.removeLockService(accessory);
67
90
  this.removeDoorService(accessory);
@@ -72,18 +95,20 @@ export class Others {
72
95
  this.removeWindowCoveringService(accessory);
73
96
  this.removeStatefulProgrammableSwitchService(accessory);
74
97
 
75
- // Add switchService
76
- const switchService = `${accessory.displayName} Switch`;
77
- (this.switchService = accessory.getService(this.hap.Service.Switch)
78
- || accessory.addService(this.hap.Service.Switch)), switchService;
98
+ // Add Switch Service
99
+ const SwitchService = `${accessory.displayName} Switch`;
100
+ (this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service
101
+ || accessory.addService(this.hap.Service.Switch)), SwitchService;
79
102
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
80
103
 
81
- this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
82
- if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
83
- this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
84
- }
85
- this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
104
+ this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
105
+ this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
86
106
  } else if (this.otherDeviceType === 'garagedoor') {
107
+ // Initialize Garage Door property
108
+ this.GarageDoor = {
109
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener)!,
110
+ On: accessory.context.On || false,
111
+ };
87
112
  this.removeFanService(accessory);
88
113
  this.removeLockService(accessory);
89
114
  this.removeDoorService(accessory);
@@ -94,19 +119,21 @@ export class Others {
94
119
  this.removeWindowCoveringService(accessory);
95
120
  this.removeStatefulProgrammableSwitchService(accessory);
96
121
 
97
- // Add garageDoorService
98
- const garageDoorService = `${accessory.displayName} Garage Door Opener`;
99
- (this.garageDoorService = accessory.getService(this.hap.Service.GarageDoorOpener)
100
- || accessory.addService(this.hap.Service.GarageDoorOpener)), garageDoorService;
122
+ // Add GarageDoor Service
123
+ const GarageDoorService = `${accessory.displayName} Garage Door Opener`;
124
+ (this.GarageDoor!.Service = accessory.getService(this.hap.Service.GarageDoorOpener) as Service
125
+ || accessory.addService(this.hap.Service.GarageDoorOpener)), GarageDoorService;
101
126
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
102
127
 
103
- this.garageDoorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
104
- if (!this.garageDoorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
105
- this.garageDoorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
106
- }
107
- this.garageDoorService.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
108
- this.garageDoorService.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
128
+ this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
129
+ this.GarageDoor!.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
130
+ this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
109
131
  } else if (this.otherDeviceType === 'door') {
132
+ // Initialize Door property
133
+ this.Door = {
134
+ Service: accessory.getService(this.hap.Service.Door)!,
135
+ On: accessory.context.On || false,
136
+ };
110
137
  this.removeFanService(accessory);
111
138
  this.removeLockService(accessory);
112
139
  this.removeOutletService(accessory);
@@ -117,17 +144,14 @@ export class Others {
117
144
  this.removeWindowCoveringService(accessory);
118
145
  this.removeStatefulProgrammableSwitchService(accessory);
119
146
 
120
- // Add doorService
121
- const doorService = `${accessory.displayName} Door`;
122
- (this.doorService = accessory.getService(this.hap.Service.Door)
123
- || accessory.addService(this.hap.Service.Door)), doorService;
147
+ // Add Door Service
148
+ const DoorService = `${accessory.displayName} Door`;
149
+ (this.Door!.Service = accessory.getService(this.hap.Service.Door) as Service
150
+ || accessory.addService(this.hap.Service.Door)), DoorService;
124
151
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
125
152
 
126
- this.doorService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
127
- if (!this.doorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
128
- this.doorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
129
- }
130
- this.doorService
153
+ this.Door!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
154
+ this.Door!.Service
131
155
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
132
156
  .setProps({
133
157
  validValues: [0, 100],
@@ -136,8 +160,13 @@ export class Others {
136
160
  minStep: 100,
137
161
  })
138
162
  .onSet(this.OnSet.bind(this));
139
- this.doorService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
163
+ this.Door!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
140
164
  } else if (this.otherDeviceType === 'window') {
165
+ // Initialize Window property
166
+ this.Window = {
167
+ Service: accessory.getService(this.hap.Service.Window)!,
168
+ On: accessory.context.On || false,
169
+ };
141
170
  this.removeFanService(accessory);
142
171
  this.removeLockService(accessory);
143
172
  this.removeDoorService(accessory);
@@ -148,17 +177,14 @@ export class Others {
148
177
  this.removeWindowCoveringService(accessory);
149
178
  this.removeStatefulProgrammableSwitchService(accessory);
150
179
 
151
- // Add windowService
152
- const windowService = `${accessory.displayName} Window`;
153
- (this.windowService = accessory.getService(this.hap.Service.Window)
154
- || accessory.addService(this.hap.Service.Window)), windowService;
180
+ // Add Window Service
181
+ const WindowService = `${accessory.displayName} Window`;
182
+ (this.Window!.Service = accessory.getService(this.hap.Service.Window) as Service
183
+ || accessory.addService(this.hap.Service.Window)), WindowService;
155
184
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
156
185
 
157
- this.windowService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
158
- if (!this.windowService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
159
- this.windowService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
160
- }
161
- this.windowService
186
+ this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
187
+ this.Window!.Service
162
188
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
163
189
  .setProps({
164
190
  validValues: [0, 100],
@@ -167,8 +193,13 @@ export class Others {
167
193
  minStep: 100,
168
194
  })
169
195
  .onSet(this.OnSet.bind(this));
170
- this.windowService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
196
+ this.Window!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
171
197
  } else if (this.otherDeviceType === 'windowcovering') {
198
+ // Initialize WindowCovering property
199
+ this.WindowCovering = {
200
+ Service: accessory.getService(this.hap.Service.WindowCovering)!,
201
+ On: accessory.context.On || false,
202
+ };
172
203
  this.removeFanService(accessory);
173
204
  this.removeLockService(accessory);
174
205
  this.removeDoorService(accessory);
@@ -179,17 +210,14 @@ export class Others {
179
210
  this.removeGarageDoorService(accessory);
180
211
  this.removeStatefulProgrammableSwitchService(accessory);
181
212
 
182
- // Add windowCoveringService
183
- const windowCoveringService = `${accessory.displayName} Window Covering`;
184
- (this.windowCoveringService = accessory.getService(this.hap.Service.WindowCovering)
185
- || accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
213
+ // Add WindowCovering Service
214
+ const WindowCoveringService = `${accessory.displayName} Window Covering`;
215
+ (this.WindowCovering!.Service = accessory.getService(this.hap.Service.WindowCovering) as Service
216
+ || accessory.addService(this.hap.Service.WindowCovering)), WindowCoveringService;
186
217
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
187
218
 
188
- this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
189
- if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
190
- this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
191
- }
192
- this.windowCoveringService
219
+ this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
220
+ this.WindowCovering!.Service
193
221
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
194
222
  .setProps({
195
223
  validValues: [0, 100],
@@ -198,8 +226,13 @@ export class Others {
198
226
  minStep: 100,
199
227
  })
200
228
  .onSet(this.OnSet.bind(this));
201
- this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
229
+ this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
202
230
  } else if (this.otherDeviceType === 'lock') {
231
+ // Initialize Lock property
232
+ this.Lock = {
233
+ Service: accessory.getService(this.hap.Service.LockMechanism)!,
234
+ On: accessory.context.On || false,
235
+ };
203
236
  this.removeFanService(accessory);
204
237
  this.removeDoorService(accessory);
205
238
  this.removeOutletService(accessory);
@@ -210,18 +243,20 @@ export class Others {
210
243
  this.removeWindowCoveringService(accessory);
211
244
  this.removeStatefulProgrammableSwitchService(accessory);
212
245
 
213
- // Add lockService
214
- const lockService = `${accessory.displayName} Lock`;
215
- (this.lockService = accessory.getService(this.hap.Service.LockMechanism)
216
- || accessory.addService(this.hap.Service.LockMechanism)), lockService;
246
+ // Add Lock Service
247
+ const LockService = `${accessory.displayName} Lock`;
248
+ (this.Lock!.Service = accessory.getService(this.hap.Service.LockMechanism) as Service
249
+ || accessory.addService(this.hap.Service.LockMechanism)), LockService;
217
250
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
218
251
 
219
- this.lockService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
220
- if (!this.lockService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
221
- this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
222
- }
223
- this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
252
+ this.Lock!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
253
+ this.Lock!.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
224
254
  } else if (this.otherDeviceType === 'faucet') {
255
+ // Initialize Faucet property
256
+ this.Faucet = {
257
+ Service: accessory.getService(this.hap.Service.Faucet)!,
258
+ On: accessory.context.On || false,
259
+ };
225
260
  this.removeFanService(accessory);
226
261
  this.removeLockService(accessory);
227
262
  this.removeDoorService(accessory);
@@ -232,18 +267,20 @@ export class Others {
232
267
  this.removeWindowCoveringService(accessory);
233
268
  this.removeStatefulProgrammableSwitchService(accessory);
234
269
 
235
- // Add faucetService
236
- const faucetService = `${accessory.displayName} Faucet`;
237
- (this.faucetService = accessory.getService(this.hap.Service.Faucet)
238
- || accessory.addService(this.hap.Service.Faucet)), faucetService;
270
+ // Add Faucet Service
271
+ const FaucetService = `${accessory.displayName} Faucet`;
272
+ (this.Faucet!.Service = accessory.getService(this.hap.Service.Faucet) as Service
273
+ || accessory.addService(this.hap.Service.Faucet)), FaucetService;
239
274
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
240
275
 
241
- this.faucetService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
242
- if (!this.faucetService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
243
- this.faucetService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
244
- }
245
- this.faucetService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
276
+ this.Faucet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
277
+ this.Faucet!.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
246
278
  } else if (this.otherDeviceType === 'fan') {
279
+ // Initialize Fan property
280
+ this.Fan = {
281
+ Service: accessory.getService(this.hap.Service.Fanv2)!,
282
+ On: accessory.context.On || false,
283
+ };
247
284
  this.removeLockService(accessory);
248
285
  this.removeDoorService(accessory);
249
286
  this.removeFaucetService(accessory);
@@ -254,18 +291,20 @@ export class Others {
254
291
  this.removeWindowCoveringService(accessory);
255
292
  this.removeStatefulProgrammableSwitchService(accessory);
256
293
 
257
- // Add fanService
258
- const fanService = `${accessory.displayName} Fan`;
259
- (this.fanService = accessory.getService(this.hap.Service.Fan)
260
- || accessory.addService(this.hap.Service.Fan)), fanService;
294
+ // Add Fan Service
295
+ const FanService = `${accessory.displayName} Fan`;
296
+ (this.Fan!.Service = accessory.getService(this.hap.Service.Fanv2) as Service
297
+ || accessory.addService(this.hap.Service.Fanv2)), FanService;
261
298
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
262
299
 
263
- this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
264
- if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
265
- this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
266
- }
267
- this.fanService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
300
+ this.Fan!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
301
+ this.Fan!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
268
302
  } else if (this.otherDeviceType === 'stateful') {
303
+ // Initialize StatefulProgrammableSwitch property
304
+ this.StatefulProgrammableSwitch = {
305
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)!,
306
+ On: accessory.context.On || false,
307
+ };
269
308
  this.removeFanService(accessory);
270
309
  this.removeLockService(accessory);
271
310
  this.removeDoorService(accessory);
@@ -276,20 +315,22 @@ export class Others {
276
315
  this.removeGarageDoorService(accessory);
277
316
  this.removeWindowCoveringService(accessory);
278
317
 
279
- // Add statefulProgrammableSwitchService
280
- const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
281
- (this.statefulProgrammableSwitchService = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
282
- || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService;
318
+ // Add StatefulProgrammableSwitch.Service
319
+ const StatefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
320
+ (this.StatefulProgrammableSwitch!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service
321
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), StatefulProgrammableSwitchService;
283
322
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
284
323
 
285
- this.statefulProgrammableSwitchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
286
- if (!this.statefulProgrammableSwitchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
287
- this.statefulProgrammableSwitchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
288
- }
289
- this.statefulProgrammableSwitchService
324
+ this.StatefulProgrammableSwitch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
325
+ this.StatefulProgrammableSwitch!.Service
290
326
  .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
291
327
  .onSet(this.OnSet.bind(this));
292
328
  } else {
329
+ // Initialize Outlet property
330
+ this.Outlet = {
331
+ Service: accessory.getService(this.hap.Service.Outlet)!,
332
+ On: accessory.context.On || false,
333
+ };
293
334
  this.removeFanService(accessory);
294
335
  this.removeLockService(accessory);
295
336
  this.removeDoorService(accessory);
@@ -300,17 +341,14 @@ export class Others {
300
341
  this.removeWindowCoveringService(accessory);
301
342
  this.removeStatefulProgrammableSwitchService(accessory);
302
343
 
303
- // Add outletService
304
- const outletService = `${accessory.displayName} Outlet`;
305
- (this.outletService = accessory.getService(this.hap.Service.Outlet)
306
- || accessory.addService(this.hap.Service.Outlet)), outletService;
344
+ // Add Outlet.Service
345
+ const OutletService = `${accessory.displayName} Outlet`;
346
+ (this.Outlet!.Service = accessory.getService(this.hap.Service.Outlet) as Service
347
+ || accessory.addService(this.hap.Service.Outlet)), OutletService;
307
348
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
308
349
 
309
- this.outletService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
310
- if (!this.outletService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
311
- this.outletService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
312
- }
313
- this.outletService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
350
+ this.Outlet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
351
+ this.Outlet!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
314
352
  }
315
353
  }
316
354
 
@@ -318,55 +356,75 @@ export class Others {
318
356
  * Handle requests to set the "On" characteristic
319
357
  */
320
358
  async OnSet(value: CharacteristicValue): Promise<void> {
359
+ let On: boolean;
321
360
  if (this.otherDeviceType === 'garagedoor') {
322
361
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
323
362
  if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
324
- this.On = false;
363
+ this.GarageDoor!.On = false;
364
+ } else {
365
+ this.GarageDoor!.On = true;
366
+ }
367
+ On = this.GarageDoor!.On;
368
+ } else if (this.otherDeviceType === 'door') {
369
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
370
+ if (value === 0) {
371
+ this.Door!.On = false;
372
+ } else {
373
+ this.Door!.On = true;
374
+ }
375
+ On = this.Door!.On;
376
+ } else if (this.otherDeviceType === 'window') {
377
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
378
+ if (value === 0) {
379
+ this.Window!.On = false;
325
380
  } else {
326
- this.On = true;
381
+ this.Window!.On = true;
327
382
  }
328
- } else if (
329
- this.otherDeviceType === 'door' ||
330
- this.otherDeviceType === 'window' ||
331
- this.otherDeviceType === 'windowcovering'
332
- ) {
383
+ On = this.Window!.On;
384
+ } else if (this.otherDeviceType === 'windowcovering') {
333
385
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
334
386
  if (value === 0) {
335
- this.On = false;
387
+ this.WindowCovering!.On = false;
336
388
  } else {
337
- this.On = true;
389
+ this.WindowCovering!.On = true;
338
390
  }
391
+ On = this.WindowCovering!.On;
339
392
  } else if (this.otherDeviceType === 'lock') {
340
393
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
341
394
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
342
- this.On = false;
395
+ this.Lock!.On = false;
343
396
  } else {
344
- this.On = true;
397
+ this.Lock!.On = true;
345
398
  }
399
+ On = this.Lock!.On;
346
400
  } else if (this.otherDeviceType === 'faucet') {
347
401
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
348
402
  if (value === this.hap.Characteristic.Active.INACTIVE) {
349
- this.On = false;
403
+ this.Faucet!.On = false;
350
404
  } else {
351
- this.On = true;
405
+ this.Faucet!.On = true;
352
406
  }
407
+ On = this.Faucet!.On;
353
408
  } else if (this.otherDeviceType === 'stateful') {
354
409
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
355
410
  if (value === 0) {
356
- this.On = false;
411
+ this.StatefulProgrammableSwitch!.On = false;
357
412
  } else {
358
- this.On = true;
413
+ this.StatefulProgrammableSwitch!.On = true;
359
414
  }
415
+
416
+ On = this.StatefulProgrammableSwitch!.On;
360
417
  } else {
361
418
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set On: ${value}`);
362
- this.On = value;
419
+ this.Outlet!.On = value;
420
+ On = this.Outlet!.On ? true : false;
363
421
  }
364
422
 
365
423
  //pushChanges
366
- if (this.On) {
367
- await this.pushOnChanges();
424
+ if (On === true) {
425
+ await this.pushOnChanges(On);
368
426
  } else {
369
- await this.pushOffChanges();
427
+ await this.pushOffChanges(On);
370
428
  }
371
429
  }
372
430
 
@@ -380,13 +438,11 @@ export class Others {
380
438
  * Other - "command" "channelAdd" "default" = next channel
381
439
  * Other - "command" "channelSub" "default" = previous channel
382
440
  */
383
- async pushOnChanges(): Promise<void> {
384
- this.debugLog(
385
- `${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},` +
386
- ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`,
387
- );
441
+ async pushOnChanges(On: boolean): Promise<void> {
442
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${On},`
443
+ + ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
388
444
  if (this.device.customize) {
389
- if (this.On && !this.disablePushOn) {
445
+ if (On === true && !this.disablePushOn) {
390
446
  const commandType: string = await this.commandType();
391
447
  const command: string = await this.commandOn();
392
448
  const bodyChange = JSON.stringify({
@@ -401,13 +457,11 @@ export class Others {
401
457
  }
402
458
  }
403
459
 
404
- async pushOffChanges(): Promise<void> {
405
- this.debugLog(
406
- `${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},` +
407
- ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`,
408
- );
460
+ async pushOffChanges(On: boolean): Promise<void> {
461
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${On},`
462
+ + ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
409
463
  if (this.device.customize) {
410
- if (!this.On && !this.disablePushOff) {
464
+ if (On === false && !this.disablePushOff) {
411
465
  const commandType: string = await this.commandType();
412
466
  const command: string = await this.commandOff();
413
467
  const bodyChange = JSON.stringify({
@@ -437,8 +491,10 @@ export class Others {
437
491
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
438
492
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
439
493
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
440
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
494
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
441
495
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
496
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
497
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
442
498
  this.updateHomeKitCharacteristics();
443
499
  } else {
444
500
  this.statusCode(statusCode);
@@ -446,456 +502,294 @@ export class Others {
446
502
  }
447
503
  } catch (e: any) {
448
504
  this.apiError(e);
449
- this.errorLog(
450
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
451
- ` Connection, Error Message: ${JSON.stringify(e.message)}`,
452
- );
505
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
506
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
453
507
  }
454
508
  } else {
455
- this.warnLog(
456
- `${this.device.remoteType}: ${this.accessory.displayName}` +
457
- ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
458
- );
509
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
510
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
459
511
  }
460
512
  }
461
513
 
462
514
  async updateHomeKitCharacteristics(): Promise<void> {
463
515
  if (this.otherDeviceType === 'garagedoor') {
464
- if (this.On === undefined) {
465
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
516
+ if (this.GarageDoor!.On === undefined) {
517
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.GarageDoor!.On}`);
466
518
  } else {
467
- if (this.On) {
468
- this.garageDoorService?.updateCharacteristic(
469
- this.hap.Characteristic.TargetDoorState,
470
- this.hap.Characteristic.TargetDoorState.OPEN,
471
- );
472
- this.garageDoorService?.updateCharacteristic(
473
- this.hap.Characteristic.CurrentDoorState,
474
- this.hap.Characteristic.CurrentDoorState.OPEN,
475
- );
476
- this.debugLog(
477
- `${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
478
- );
519
+ if (this.GarageDoor!.On) {
520
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
521
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
522
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
523
+ + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
479
524
  } else {
480
- this.garageDoorService?.updateCharacteristic(
481
- this.hap.Characteristic.TargetDoorState,
482
- this.hap.Characteristic.TargetDoorState.CLOSED,
483
- );
484
- this.garageDoorService?.updateCharacteristic(
485
- this.hap.Characteristic.CurrentDoorState,
486
- this.hap.Characteristic.CurrentDoorState.CLOSED,
487
- );
488
- this.debugLog(
489
- `${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
490
- );
525
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
526
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
527
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
528
+ + ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
491
529
  }
492
530
  }
493
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
531
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor!.On}`);
494
532
  } else if (this.otherDeviceType === 'door') {
495
- if (this.On === undefined) {
496
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
533
+ if (this.Door!.On === undefined) {
534
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Door!.On}`);
497
535
  } else {
498
- if (this.On) {
499
- this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
500
- this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
501
- this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
502
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
536
+ if (this.Door!.On) {
537
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
538
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
539
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
540
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
541
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
503
542
  } else {
504
- this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
505
- this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
506
- this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
507
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
543
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
544
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
545
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
546
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
547
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
508
548
  }
509
549
  }
510
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.On}`);
550
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.Door!.On}`);
511
551
  } else if (this.otherDeviceType === 'window') {
512
- if (this.On === undefined) {
513
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
552
+ if (this.Window!.On === undefined) {
553
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Window!.On}`);
514
554
  } else {
515
- if (this.On) {
516
- this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
517
- this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
518
- this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
519
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
555
+ if (this.Window!.On) {
556
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
557
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
558
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
559
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
560
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
520
561
  } else {
521
- this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
522
- this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
523
- this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
524
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
562
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
563
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
564
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
565
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
566
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
525
567
  }
526
568
  }
527
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.On}`);
569
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.Window!.On}`);
528
570
  } else if (this.otherDeviceType === 'windowcovering') {
529
- if (this.On === undefined) {
530
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
571
+ if (this.WindowCovering!.On === undefined) {
572
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.WindowCovering!.On}`);
531
573
  } else {
532
- if (this.On) {
533
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
534
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
535
- this.windowCoveringService?.updateCharacteristic(
536
- this.hap.Characteristic.PositionState,
537
- this.hap.Characteristic.PositionState.STOPPED,
538
- );
539
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
574
+ if (this.WindowCovering!.On) {
575
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
576
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
577
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
578
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
579
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
540
580
  } else {
541
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
542
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
543
- this.windowCoveringService?.updateCharacteristic(
544
- this.hap.Characteristic.PositionState,
545
- this.hap.Characteristic.PositionState.STOPPED,
546
- );
547
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
581
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
582
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
583
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
584
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
585
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
548
586
  }
549
587
  }
550
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.On}`);
588
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
551
589
  } else if (this.otherDeviceType === 'lock') {
552
- if (this.On === undefined) {
553
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
590
+ if (this.Lock!.On === undefined) {
591
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Lock!.On}`);
554
592
  } else {
555
- if (this.On) {
556
- this.lockService?.updateCharacteristic(
557
- this.hap.Characteristic.LockTargetState,
558
- this.hap.Characteristic.LockTargetState.UNSECURED,
559
- );
560
- this.lockService?.updateCharacteristic(
561
- this.hap.Characteristic.LockCurrentState,
562
- this.hap.Characteristic.LockCurrentState.UNSECURED,
563
- );
564
- this.debugLog(
565
- `${this.device.remoteType}: ` +
566
- `${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`,
567
- );
593
+ if (this.Lock!.On) {
594
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
595
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
596
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
597
+ + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
568
598
  } else {
569
- this.lockService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
570
- this.lockService?.updateCharacteristic(
571
- this.hap.Characteristic.LockCurrentState,
572
- this.hap.Characteristic.LockCurrentState.SECURED,
573
- );
574
- this.debugLog(
575
- `${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`,
576
- );
599
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
600
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
601
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
602
+ + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock!.On})`);
577
603
  }
578
604
  }
579
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.On}`);
605
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.Lock!.On}`);
580
606
  } else if (this.otherDeviceType === 'faucet') {
581
- if (this.On === undefined) {
582
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
607
+ if (this.Faucet!.On === undefined) {
608
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Faucet!.On}`);
583
609
  } else {
584
- if (this.On) {
585
- this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
586
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
610
+ if (this.Faucet!.On) {
611
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
612
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
587
613
  } else {
588
- this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
589
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
614
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
615
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
590
616
  }
591
617
  }
592
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.On}`);
618
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.Faucet!.On}`);
593
619
  } else if (this.otherDeviceType === 'fan') {
594
- if (this.On === undefined) {
595
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
620
+ if (this.Fan!.On === undefined) {
621
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Fan!.On}`);
596
622
  } else {
597
- if (this.On) {
598
- this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
599
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
623
+ if (this.Fan!.On) {
624
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
625
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
600
626
  } else {
601
- this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
602
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
627
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
628
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
603
629
  }
604
630
  }
605
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.On}`);
631
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.Fan!.On}`);
606
632
  } else if (this.otherDeviceType === 'stateful') {
607
- if (this.On === undefined) {
608
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
633
+ if (this.StatefulProgrammableSwitch!.On === undefined) {
634
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch!.On}`);
609
635
  } else {
610
- if (this.On) {
611
- this.statefulProgrammableSwitchService?.updateCharacteristic(
612
- this.hap.Characteristic.ProgrammableSwitchEvent,
613
- this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
614
- );
615
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
616
- this.debugLog(
617
- `${this.device.remoteType}: ` +
618
- `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`,
619
- );
636
+ if (this.StatefulProgrammableSwitch!.On) {
637
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
638
+ this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
639
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
640
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
641
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
620
642
  } else {
621
- this.statefulProgrammableSwitchService?.updateCharacteristic(
622
- this.hap.Characteristic.ProgrammableSwitchEvent,
623
- this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
624
- );
625
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
626
- this.debugLog(
627
- `${this.device.remoteType}: ` +
628
- `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`,
629
- );
643
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
644
+ this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
645
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
646
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
647
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
630
648
  }
631
649
  }
632
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
650
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
633
651
  } else if (this.otherDeviceType === 'switch') {
634
- if (this.On === undefined) {
635
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
652
+ if (this.Switch!.On === undefined) {
653
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch!.On}`);
636
654
  } else {
637
- this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
638
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
655
+ this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch!.On);
656
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch!.On}`);
639
657
  }
640
658
  } else {
641
- if (this.On === undefined) {
642
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
659
+ if (this.Outlet!.On === undefined) {
660
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Outlet!.On}`);
643
661
  } else {
644
- this.outletService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
645
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
662
+ this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet!.On);
663
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet!.On}`);
646
664
  }
647
665
  }
648
666
  }
649
667
 
650
- async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
651
- if (device.disablePushOn === undefined) {
652
- this.disablePushOn = false;
653
- } else {
654
- this.disablePushOn = device.disablePushOn;
655
- }
656
- }
657
-
658
- async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
659
- if (device.disablePushOff === undefined) {
660
- this.disablePushOff = false;
661
- } else {
662
- this.disablePushOff = device.disablePushOff;
663
- }
664
- }
665
-
666
- async commandType(): Promise<string> {
667
- let commandType: string;
668
- if (this.device.commandType && this.device.customize) {
669
- commandType = this.device.commandType;
670
- } else if (this.device.customize) {
671
- commandType = 'customize';
672
- } else {
673
- commandType = 'command';
674
- }
675
- return commandType;
676
- }
677
-
678
- async commandOn(): Promise<string> {
679
- let command: string;
680
- if (this.device.customize && this.device.customOn) {
681
- command = this.device.customOn;
682
- } else {
683
- command = 'turnOn';
684
- }
685
- return command;
686
- }
687
-
688
- async commandOff(): Promise<string> {
689
- let command: string;
690
- if (this.device.customize && this.device.customOff) {
691
- command = this.device.customOff;
692
- } else {
693
- command = 'turnOff';
694
- }
695
- return command;
696
- }
697
-
698
- async statusCode(statusCode: number): Promise<void> {
699
- switch (statusCode) {
700
- case 151:
701
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
702
- break;
703
- case 152:
704
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
705
- break;
706
- case 160:
707
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
708
- break;
709
- case 161:
710
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
711
- break;
712
- case 171:
713
- this.errorLog(
714
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
715
- `Hub: ${this.device.hubDeviceId}`,
716
- );
717
- break;
718
- case 190:
719
- this.errorLog(
720
- `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
721
- ` Or command format is invalid, statusCode: ${statusCode}`,
722
- );
723
- break;
724
- case 100:
725
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
726
- break;
727
- case 200:
728
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
729
- break;
730
- case 400:
731
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
732
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
733
- break;
734
- case 401:
735
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
736
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
737
- break;
738
- case 403:
739
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
740
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
741
- break;
742
- case 404:
743
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
744
- + `statusCode: ${statusCode}`);
745
- break;
746
- case 406:
747
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
748
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
749
- break;
750
- case 415:
751
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
752
- + `header that is not supported by the server, statusCode: ${statusCode}`);
753
- break;
754
- case 422:
755
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
756
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
757
- break;
758
- case 429:
759
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
760
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
761
- break;
762
- case 500:
763
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
764
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
765
- break;
766
- default:
767
- this.infoLog(
768
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
769
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
770
- );
771
- }
772
- }
773
-
774
668
  async apiError(e: any): Promise<void> {
775
669
  if (this.otherDeviceType === 'garagedoor') {
776
- this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
777
- this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
778
- this.garageDoorService?.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
670
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
671
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
672
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
779
673
  } else if (this.otherDeviceType === 'door') {
780
- this.doorService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
781
- this.doorService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
782
- this.doorService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
674
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
675
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
676
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
783
677
  } else if (this.otherDeviceType === 'window') {
784
- this.windowService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
785
- this.windowService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
786
- this.windowService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
678
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
679
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
680
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
787
681
  } else if (this.otherDeviceType === 'windowcovering') {
788
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
789
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
790
- this.windowCoveringService?.updateCharacteristic(this.hap.Characteristic.PositionState, e);
682
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
683
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
684
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
791
685
  } else if (this.otherDeviceType === 'lock') {
792
- this.doorService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
793
- this.doorService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
686
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
687
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
794
688
  } else if (this.otherDeviceType === 'faucet') {
795
- this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, e);
689
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
796
690
  } else if (this.otherDeviceType === 'fan') {
797
- this.fanService?.updateCharacteristic(this.hap.Characteristic.On, e);
691
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
798
692
  } else if (this.otherDeviceType === 'stateful') {
799
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
800
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
693
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
694
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
801
695
  } else if (this.otherDeviceType === 'switch') {
802
- this.switchService?.updateCharacteristic(this.hap.Characteristic.On, e);
696
+ this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
803
697
  } else {
804
- this.outletService?.updateCharacteristic(this.hap.Characteristic.On, e);
698
+ this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
805
699
  }
806
700
  }
807
701
 
808
702
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
809
- // If outletService still present, then remove first
810
- this.outletService = this.accessory.getService(this.hap.Service.Outlet);
811
- if (this.outletService) {
703
+ // If Outlet.Service still present, then remove first
704
+ if (this.Outlet?.Service) {
705
+ this.Outlet!.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
812
706
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
707
+ accessory.removeService(this.Outlet!.Service);
813
708
  }
814
- accessory.removeService(this.outletService!);
815
709
  }
816
710
 
817
711
  async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
818
- // If garageDoorService still present, then remove first
819
- this.garageDoorService = this.accessory.getService(this.hap.Service.GarageDoorOpener);
820
- if (this.garageDoorService) {
712
+ // If GarageDoor.Service still present, then remove first
713
+ if (this.GarageDoor?.Service) {
714
+ this.GarageDoor!.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
821
715
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
716
+ accessory.removeService(this.GarageDoor!.Service);
822
717
  }
823
- accessory.removeService(this.garageDoorService!);
824
718
  }
825
719
 
826
720
  async removeDoorService(accessory: PlatformAccessory): Promise<void> {
827
- // If doorService still present, then remove first
828
- this.doorService = this.accessory.getService(this.hap.Service.Door);
829
- if (this.doorService) {
721
+ // If Door.Service still present, then remove first
722
+ if (this.Door?.Service) {
723
+ this.Door!.Service = this.accessory.getService(this.hap.Service.Door) as Service;
830
724
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
725
+ accessory.removeService(this.Door!.Service);
831
726
  }
832
- accessory.removeService(this.doorService!);
833
727
  }
834
728
 
835
729
  async removeLockService(accessory: PlatformAccessory): Promise<void> {
836
- // If lockService still present, then remove first
837
- this.lockService = this.accessory.getService(this.hap.Service.LockMechanism);
838
- if (this.lockService) {
730
+ // If Lock.Service still present, then remove first
731
+ if (this.Lock?.Service) {
732
+ this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
839
733
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
734
+ accessory.removeService(this.Lock!.Service);
840
735
  }
841
- accessory.removeService(this.lockService!);
842
736
  }
843
737
 
844
738
  async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
845
- // If faucetService still present, then remove first
846
- this.faucetService = this.accessory.getService(this.hap.Service.Faucet);
847
- if (this.faucetService) {
739
+ // If Faucet.Service still present, then remove first
740
+ if (this.Faucet?.Service) {
741
+ this.Faucet!.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
848
742
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
743
+ accessory.removeService(this.Faucet!.Service);
849
744
  }
850
- accessory.removeService(this.faucetService!);
851
745
  }
852
746
 
853
747
  async removeFanService(accessory: PlatformAccessory): Promise<void> {
854
- // If fanService still present, then remove first
855
- this.fanService = this.accessory.getService(this.hap.Service.Fan);
856
- if (this.fanService) {
748
+ // If Fan Service still present, then remove first
749
+ if (this.Fan?.Service) {
750
+ this.Fan!.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
857
751
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
752
+ accessory.removeService(this.Fan!.Service);
858
753
  }
859
- accessory.removeService(this.fanService!);
860
754
  }
861
755
 
862
756
  async removeWindowService(accessory: PlatformAccessory): Promise<void> {
863
- // If windowService still present, then remove first
864
- this.windowService = this.accessory.getService(this.hap.Service.Window);
865
- if (this.windowService) {
757
+ // If Window.Service still present, then remove first
758
+ if (this.Window?.Service) {
759
+ this.Window!.Service = this.accessory.getService(this.hap.Service.Window) as Service;
866
760
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
761
+ accessory.removeService(this.Window!.Service);
867
762
  }
868
- accessory.removeService(this.windowService!);
869
763
  }
870
764
 
871
765
  async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
872
- // If windowCoveringService still present, then remove first
873
- this.windowCoveringService = this.accessory.getService(this.hap.Service.WindowCovering);
874
- if (this.windowCoveringService) {
766
+ // If WindowCovering.Service still present, then remove first
767
+ if (this.WindowCovering?.Service) {
768
+ this.WindowCovering!.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
875
769
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
770
+ accessory.removeService(this.WindowCovering!.Service);
876
771
  }
877
- accessory.removeService(this.windowCoveringService!);
878
772
  }
879
773
 
880
774
  async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
881
- // If statefulProgrammableSwitchService still present, then remove first
882
- this.statefulProgrammableSwitchService = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
883
- if (this.statefulProgrammableSwitchService) {
775
+ // If StatefulProgrammableSwitch.Service still present, then remove first
776
+ if (this.StatefulProgrammableSwitch?.Service) {
777
+ this.StatefulProgrammableSwitch!.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
884
778
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
779
+ accessory.removeService(this.StatefulProgrammableSwitch!.Service);
885
780
  }
886
- accessory.removeService(this.statefulProgrammableSwitchService!);
887
781
  }
888
782
 
889
783
  async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
890
- // If switchService still present, then remove first
891
- this.switchService = this.accessory.getService(this.hap.Service.Switch);
892
- if (this.switchService) {
784
+ // If Switch.Service still present, then remove first
785
+ if (this.Switch?.Service) {
786
+ this.Switch!.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
893
787
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
788
+ accessory.removeService(this.Switch!.Service);
894
789
  }
895
- accessory.removeService(this.switchService!);
896
790
  }
897
791
 
898
- async deviceType(device: irdevice & irDevicesConfig): Promise<void> {
792
+ async getOtherConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
899
793
  if (!device.other?.deviceType && this.accessory.context.deviceType) {
900
794
  this.otherDeviceType = this.accessory.context.deviceType;
901
795
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from Accessory Cache.`);
@@ -909,117 +803,4 @@ export class Others {
909
803
  this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} no deviceType set, using default deviceType: ${this.otherDeviceType}`);
910
804
  }
911
805
  }
912
-
913
- async deviceContext() {
914
- if (this.On === undefined) {
915
- this.On = true;
916
- } else {
917
- this.On = this.accessory.context.On;
918
- }
919
- if (this.FirmwareRevision === undefined) {
920
- this.FirmwareRevision = this.platform.version;
921
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
922
- }
923
- }
924
-
925
- async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
926
- let config = {};
927
- if (device.other) {
928
- config = device.other;
929
- }
930
- if (device.logging !== undefined) {
931
- config['logging'] = device.logging;
932
- }
933
- if (device.connectionType !== undefined) {
934
- config['connectionType'] = device.connectionType;
935
- }
936
- if (device.external !== undefined) {
937
- config['external'] = device.external;
938
- }
939
- if (device.customOn !== undefined) {
940
- config['customOn'] = device.customOn;
941
- }
942
- if (device.customOff !== undefined) {
943
- config['customOff'] = device.customOff;
944
- }
945
- if (device.customize !== undefined) {
946
- config['customize'] = device.customize;
947
- }
948
- if (device.disablePushOn !== undefined) {
949
- config['disablePushOn'] = device.disablePushOn;
950
- }
951
- if (device.disablePushOff !== undefined) {
952
- config['disablePushOff'] = device.disablePushOff;
953
- }
954
- if (Object.entries(config).length !== 0) {
955
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
956
- }
957
- }
958
-
959
- async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
960
- if (this.platform.debugMode) {
961
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
962
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
963
- } else if (device.logging) {
964
- this.deviceLogging = this.accessory.context.logging = device.logging;
965
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
966
- } else if (this.platform.config.options?.logging) {
967
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
968
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
969
- } else {
970
- this.deviceLogging = this.accessory.context.logging = 'standard';
971
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
972
- }
973
- }
974
-
975
- /**
976
- * Logging for Device
977
- */
978
- infoLog(...log: any[]): void {
979
- if (this.enablingDeviceLogging()) {
980
- this.platform.log.info(String(...log));
981
- }
982
- }
983
-
984
- warnLog(...log: any[]): void {
985
- if (this.enablingDeviceLogging()) {
986
- this.platform.log.warn(String(...log));
987
- }
988
- }
989
-
990
- debugWarnLog(...log: any[]): void {
991
- if (this.enablingDeviceLogging()) {
992
- if (this.deviceLogging?.includes('debug')) {
993
- this.platform.log.warn('[DEBUG]', String(...log));
994
- }
995
- }
996
- }
997
-
998
- errorLog(...log: any[]): void {
999
- if (this.enablingDeviceLogging()) {
1000
- this.platform.log.error(String(...log));
1001
- }
1002
- }
1003
-
1004
- debugErrorLog(...log: any[]): void {
1005
- if (this.enablingDeviceLogging()) {
1006
- if (this.deviceLogging?.includes('debug')) {
1007
- this.platform.log.error('[DEBUG]', String(...log));
1008
- }
1009
- }
1010
- }
1011
-
1012
- debugLog(...log: any[]): void {
1013
- if (this.enablingDeviceLogging()) {
1014
- if (this.deviceLogging === 'debug') {
1015
- this.platform.log.info('[DEBUG]', String(...log));
1016
- } else {
1017
- this.platform.log.debug(String(...log));
1018
- }
1019
- }
1020
- }
1021
-
1022
- enablingDeviceLogging(): boolean {
1023
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
1024
- }
1025
806
  }