@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.60

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 (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +408 -779
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +696 -822
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +237 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +279 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +242 -544
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +402 -805
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +684 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +535 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +246 -613
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +232 -593
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +185 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +277 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +241 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +181 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +170 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +178 -531
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +92 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +197 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -65
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +139 -495
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +9 -49
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +309 -419
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +72 -304
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +34 -278
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +100 -338
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +330 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +87 -357
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +352 -546
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +82 -321
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +41 -284
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +42 -287
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -169
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +442 -814
  143. package/src/device/bot.ts +754 -915
  144. package/src/device/ceilinglight.ts +255 -633
  145. package/src/device/colorbulb.ts +294 -685
  146. package/src/device/contact.ts +277 -571
  147. package/src/device/curtain.ts +431 -835
  148. package/src/device/device.ts +709 -0
  149. package/src/device/fan.ts +591 -0
  150. package/src/device/hub.ts +286 -644
  151. package/src/device/humidifier.ts +266 -646
  152. package/src/device/iosensor.ts +220 -625
  153. package/src/device/lightstrip.ts +305 -620
  154. package/src/device/lock.ts +280 -600
  155. package/src/device/meter.ts +216 -617
  156. package/src/device/meterplus.ts +205 -619
  157. package/src/device/motion.ts +206 -556
  158. package/src/device/plug.ts +107 -490
  159. package/src/device/robotvacuumcleaner.ts +223 -550
  160. package/src/device/waterdetector.ts +160 -519
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +333 -447
  165. package/src/irdevice/airpurifier.ts +92 -322
  166. package/src/irdevice/camera.ts +45 -294
  167. package/src/irdevice/fan.ts +115 -353
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +110 -385
  170. package/src/irdevice/other.ts +399 -616
  171. package/src/irdevice/tv.ts +103 -340
  172. package/src/irdevice/vacuumcleaner.ts +52 -306
  173. package/src/irdevice/waterheater.ts +53 -311
  174. package/src/platform.ts +355 -216
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. package/src/device/waterdetector.json +0 -11
@@ -1,67 +1,92 @@
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';
3
- import { SwitchBotPlatform } from '../platform.js';
4
- import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings.js';
6
+ import { Devices } from '../settings.js';
7
+ import { irdeviceBase } from './irdevice.js';
8
+
9
+ import type { SwitchBotPlatform } from '../platform.js';
10
+ import type { irDevicesConfig, irdevice } from '../settings.js';
11
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
12
 
6
13
  /**
7
14
  * Platform Accessory
8
15
  * An instance of this class is created for each accessory your platform registers
9
16
  * Each accessory may expose multiple services of different service types.
10
17
  */
11
- export class Others {
12
- public readonly api: API;
13
- public readonly log: Logging;
14
- public readonly config!: SwitchBotPlatformConfig;
15
- protected readonly hap: HAP;
18
+ export class Others extends irdeviceBase {
16
19
  // 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;
20
+ private Switch?: {
21
+ Service: Service;
22
+ On: CharacteristicValue;
23
+ };
24
+
25
+ private GarageDoor?: {
26
+ Service: Service;
27
+ On: CharacteristicValue;
28
+ };
29
+
30
+ private Door?: {
31
+ Service: Service;
32
+ On: CharacteristicValue;
33
+ };
34
+
35
+ private Window?: {
36
+ Service: Service;
37
+ On: CharacteristicValue;
38
+ };
39
+
40
+ private WindowCovering?: {
41
+ Service: Service;
42
+ On: CharacteristicValue;
43
+ };
44
+
45
+ private Lock?: {
46
+ Service: Service;
47
+ On: CharacteristicValue;
48
+ };
49
+
50
+ private Faucet?: {
51
+ Service: Service;
52
+ On: CharacteristicValue;
53
+ };
54
+
55
+ private Fan?: {
56
+ Service: Service;
57
+ On: CharacteristicValue;
58
+ };
59
+
60
+ private StatefulProgrammableSwitch?: {
61
+ Service: Service;
62
+ On: CharacteristicValue;
63
+ };
64
+
65
+ private Outlet?: {
66
+ Service: Service;
67
+ On: CharacteristicValue;
68
+ };
31
69
 
32
70
  // Config
33
- deviceLogging!: string;
34
- disablePushOn?: boolean;
35
71
  otherDeviceType?: string;
36
- disablePushOff?: boolean;
37
72
 
38
73
  constructor(
39
- private readonly platform: SwitchBotPlatform,
40
- private accessory: PlatformAccessory,
41
- public device: irdevice & irDevicesConfig,
74
+ readonly platform: SwitchBotPlatform,
75
+ accessory: PlatformAccessory,
76
+ device: irdevice & irDevicesConfig,
42
77
  ) {
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);
78
+ super(platform, accessory, device);
54
79
 
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);
80
+ // default placeholders
81
+ this.getOtherConfigSettings(device);
62
82
 
63
83
  // deviceType
64
84
  if (this.otherDeviceType === 'switch') {
85
+ // Initialize Switch property
86
+ this.Switch = {
87
+ Service: accessory.getService(this.hap.Service.Switch) as Service,
88
+ On: accessory.context.On || false,
89
+ };
65
90
  this.removeFanService(accessory);
66
91
  this.removeLockService(accessory);
67
92
  this.removeDoorService(accessory);
@@ -72,18 +97,20 @@ export class Others {
72
97
  this.removeWindowCoveringService(accessory);
73
98
  this.removeStatefulProgrammableSwitchService(accessory);
74
99
 
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;
100
+ // Add Switch Service
101
+ const SwitchService = `${accessory.displayName} Switch`;
102
+ (this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service
103
+ || accessory.addService(this.hap.Service.Switch)), SwitchService;
79
104
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
80
105
 
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));
106
+ this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
107
+ this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
86
108
  } else if (this.otherDeviceType === 'garagedoor') {
109
+ // Initialize Garage Door property
110
+ this.GarageDoor = {
111
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
112
+ On: accessory.context.On || false,
113
+ };
87
114
  this.removeFanService(accessory);
88
115
  this.removeLockService(accessory);
89
116
  this.removeDoorService(accessory);
@@ -94,19 +121,21 @@ export class Others {
94
121
  this.removeWindowCoveringService(accessory);
95
122
  this.removeStatefulProgrammableSwitchService(accessory);
96
123
 
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;
124
+ // Add GarageDoor Service
125
+ const GarageDoorService = `${accessory.displayName} Garage Door Opener`;
126
+ (this.GarageDoor!.Service = accessory.getService(this.hap.Service.GarageDoorOpener) as Service
127
+ || accessory.addService(this.hap.Service.GarageDoorOpener)), GarageDoorService;
101
128
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
102
129
 
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);
130
+ this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
131
+ this.GarageDoor!.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
132
+ this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
109
133
  } else if (this.otherDeviceType === 'door') {
134
+ // Initialize Door property
135
+ this.Door = {
136
+ Service: accessory.getService(this.hap.Service.Door) as Service,
137
+ On: accessory.context.On || false,
138
+ };
110
139
  this.removeFanService(accessory);
111
140
  this.removeLockService(accessory);
112
141
  this.removeOutletService(accessory);
@@ -117,17 +146,14 @@ export class Others {
117
146
  this.removeWindowCoveringService(accessory);
118
147
  this.removeStatefulProgrammableSwitchService(accessory);
119
148
 
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;
149
+ // Add Door Service
150
+ const DoorService = `${accessory.displayName} Door`;
151
+ (this.Door!.Service = accessory.getService(this.hap.Service.Door) as Service
152
+ || accessory.addService(this.hap.Service.Door)), DoorService;
124
153
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
125
154
 
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
155
+ this.Door!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
156
+ this.Door!.Service
131
157
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
132
158
  .setProps({
133
159
  validValues: [0, 100],
@@ -136,8 +162,13 @@ export class Others {
136
162
  minStep: 100,
137
163
  })
138
164
  .onSet(this.OnSet.bind(this));
139
- this.doorService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
165
+ this.Door!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
140
166
  } else if (this.otherDeviceType === 'window') {
167
+ // Initialize Window property
168
+ this.Window = {
169
+ Service: accessory.getService(this.hap.Service.Window) as Service,
170
+ On: accessory.context.On || false,
171
+ };
141
172
  this.removeFanService(accessory);
142
173
  this.removeLockService(accessory);
143
174
  this.removeDoorService(accessory);
@@ -148,17 +179,14 @@ export class Others {
148
179
  this.removeWindowCoveringService(accessory);
149
180
  this.removeStatefulProgrammableSwitchService(accessory);
150
181
 
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;
182
+ // Add Window Service
183
+ const WindowService = `${accessory.displayName} Window`;
184
+ (this.Window!.Service = accessory.getService(this.hap.Service.Window) as Service
185
+ || accessory.addService(this.hap.Service.Window)), WindowService;
155
186
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
156
187
 
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
188
+ this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
189
+ this.Window!.Service
162
190
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
163
191
  .setProps({
164
192
  validValues: [0, 100],
@@ -167,8 +195,13 @@ export class Others {
167
195
  minStep: 100,
168
196
  })
169
197
  .onSet(this.OnSet.bind(this));
170
- this.windowService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
198
+ this.Window!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
171
199
  } else if (this.otherDeviceType === 'windowcovering') {
200
+ // Initialize WindowCovering property
201
+ this.WindowCovering = {
202
+ Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
203
+ On: accessory.context.On || false,
204
+ };
172
205
  this.removeFanService(accessory);
173
206
  this.removeLockService(accessory);
174
207
  this.removeDoorService(accessory);
@@ -179,17 +212,14 @@ export class Others {
179
212
  this.removeGarageDoorService(accessory);
180
213
  this.removeStatefulProgrammableSwitchService(accessory);
181
214
 
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;
215
+ // Add WindowCovering Service
216
+ const WindowCoveringService = `${accessory.displayName} Window Covering`;
217
+ (this.WindowCovering!.Service = accessory.getService(this.hap.Service.WindowCovering) as Service
218
+ || accessory.addService(this.hap.Service.WindowCovering)), WindowCoveringService;
186
219
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
187
220
 
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
221
+ this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
222
+ this.WindowCovering!.Service
193
223
  .getCharacteristic(this.hap.Characteristic.TargetPosition)
194
224
  .setProps({
195
225
  validValues: [0, 100],
@@ -198,8 +228,13 @@ export class Others {
198
228
  minStep: 100,
199
229
  })
200
230
  .onSet(this.OnSet.bind(this));
201
- this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
231
+ this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
202
232
  } else if (this.otherDeviceType === 'lock') {
233
+ // Initialize Lock property
234
+ this.Lock = {
235
+ Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
236
+ On: accessory.context.On || false,
237
+ };
203
238
  this.removeFanService(accessory);
204
239
  this.removeDoorService(accessory);
205
240
  this.removeOutletService(accessory);
@@ -210,18 +245,20 @@ export class Others {
210
245
  this.removeWindowCoveringService(accessory);
211
246
  this.removeStatefulProgrammableSwitchService(accessory);
212
247
 
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;
248
+ // Add Lock Service
249
+ const LockService = `${accessory.displayName} Lock`;
250
+ (this.Lock!.Service = accessory.getService(this.hap.Service.LockMechanism) as Service
251
+ || accessory.addService(this.hap.Service.LockMechanism)), LockService;
217
252
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
218
253
 
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));
254
+ this.Lock!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
255
+ this.Lock!.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
224
256
  } else if (this.otherDeviceType === 'faucet') {
257
+ // Initialize Faucet property
258
+ this.Faucet = {
259
+ Service: accessory.getService(this.hap.Service.Faucet) as Service,
260
+ On: accessory.context.On || false,
261
+ };
225
262
  this.removeFanService(accessory);
226
263
  this.removeLockService(accessory);
227
264
  this.removeDoorService(accessory);
@@ -232,18 +269,20 @@ export class Others {
232
269
  this.removeWindowCoveringService(accessory);
233
270
  this.removeStatefulProgrammableSwitchService(accessory);
234
271
 
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;
272
+ // Add Faucet Service
273
+ const FaucetService = `${accessory.displayName} Faucet`;
274
+ (this.Faucet!.Service = accessory.getService(this.hap.Service.Faucet) as Service
275
+ || accessory.addService(this.hap.Service.Faucet)), FaucetService;
239
276
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
240
277
 
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));
278
+ this.Faucet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
279
+ this.Faucet!.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
246
280
  } else if (this.otherDeviceType === 'fan') {
281
+ // Initialize Fan property
282
+ this.Fan = {
283
+ Service: accessory.getService(this.hap.Service.Fanv2) as Service,
284
+ On: accessory.context.On || false,
285
+ };
247
286
  this.removeLockService(accessory);
248
287
  this.removeDoorService(accessory);
249
288
  this.removeFaucetService(accessory);
@@ -254,18 +293,20 @@ export class Others {
254
293
  this.removeWindowCoveringService(accessory);
255
294
  this.removeStatefulProgrammableSwitchService(accessory);
256
295
 
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;
296
+ // Add Fan Service
297
+ const FanService = `${accessory.displayName} Fan`;
298
+ (this.Fan!.Service = accessory.getService(this.hap.Service.Fanv2) as Service
299
+ || accessory.addService(this.hap.Service.Fanv2)), FanService;
261
300
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
262
301
 
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));
302
+ this.Fan!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
303
+ this.Fan!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
268
304
  } else if (this.otherDeviceType === 'stateful') {
305
+ // Initialize StatefulProgrammableSwitch property
306
+ this.StatefulProgrammableSwitch = {
307
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
308
+ On: accessory.context.On || false,
309
+ };
269
310
  this.removeFanService(accessory);
270
311
  this.removeLockService(accessory);
271
312
  this.removeDoorService(accessory);
@@ -276,20 +317,22 @@ export class Others {
276
317
  this.removeGarageDoorService(accessory);
277
318
  this.removeWindowCoveringService(accessory);
278
319
 
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;
320
+ // Add StatefulProgrammableSwitch.Service
321
+ const StatefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
322
+ (this.StatefulProgrammableSwitch!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service
323
+ || accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), StatefulProgrammableSwitchService;
283
324
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
284
325
 
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
326
+ this.StatefulProgrammableSwitch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
327
+ this.StatefulProgrammableSwitch!.Service
290
328
  .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
291
329
  .onSet(this.OnSet.bind(this));
292
330
  } else {
331
+ // Initialize Outlet property
332
+ this.Outlet = {
333
+ Service: accessory.getService(this.hap.Service.Outlet) as Service,
334
+ On: accessory.context.On || false,
335
+ };
293
336
  this.removeFanService(accessory);
294
337
  this.removeLockService(accessory);
295
338
  this.removeDoorService(accessory);
@@ -300,17 +343,14 @@ export class Others {
300
343
  this.removeWindowCoveringService(accessory);
301
344
  this.removeStatefulProgrammableSwitchService(accessory);
302
345
 
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;
346
+ // Add Outlet.Service
347
+ const OutletService = `${accessory.displayName} Outlet`;
348
+ (this.Outlet!.Service = accessory.getService(this.hap.Service.Outlet) as Service
349
+ || accessory.addService(this.hap.Service.Outlet)), OutletService;
307
350
  this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
308
351
 
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));
352
+ this.Outlet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
353
+ this.Outlet!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
314
354
  }
315
355
  }
316
356
 
@@ -318,55 +358,75 @@ export class Others {
318
358
  * Handle requests to set the "On" characteristic
319
359
  */
320
360
  async OnSet(value: CharacteristicValue): Promise<void> {
361
+ let On: boolean;
321
362
  if (this.otherDeviceType === 'garagedoor') {
322
363
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
323
364
  if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
324
- this.On = false;
365
+ this.GarageDoor!.On = false;
366
+ } else {
367
+ this.GarageDoor!.On = true;
368
+ }
369
+ On = this.GarageDoor!.On;
370
+ } else if (this.otherDeviceType === 'door') {
371
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
372
+ if (value === 0) {
373
+ this.Door!.On = false;
325
374
  } else {
326
- this.On = true;
375
+ this.Door!.On = true;
327
376
  }
328
- } else if (
329
- this.otherDeviceType === 'door' ||
330
- this.otherDeviceType === 'window' ||
331
- this.otherDeviceType === 'windowcovering'
332
- ) {
377
+ On = this.Door!.On;
378
+ } else if (this.otherDeviceType === 'window') {
333
379
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
334
380
  if (value === 0) {
335
- this.On = false;
381
+ this.Window!.On = false;
336
382
  } else {
337
- this.On = true;
383
+ this.Window!.On = true;
338
384
  }
385
+ On = this.Window!.On;
386
+ } else if (this.otherDeviceType === 'windowcovering') {
387
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
388
+ if (value === 0) {
389
+ this.WindowCovering!.On = false;
390
+ } else {
391
+ this.WindowCovering!.On = true;
392
+ }
393
+ On = this.WindowCovering!.On;
339
394
  } else if (this.otherDeviceType === 'lock') {
340
395
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
341
396
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
342
- this.On = false;
397
+ this.Lock!.On = false;
343
398
  } else {
344
- this.On = true;
399
+ this.Lock!.On = true;
345
400
  }
401
+ On = this.Lock!.On;
346
402
  } else if (this.otherDeviceType === 'faucet') {
347
403
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
348
404
  if (value === this.hap.Characteristic.Active.INACTIVE) {
349
- this.On = false;
405
+ this.Faucet!.On = false;
350
406
  } else {
351
- this.On = true;
407
+ this.Faucet!.On = true;
352
408
  }
409
+ On = this.Faucet!.On;
353
410
  } else if (this.otherDeviceType === 'stateful') {
354
411
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
355
412
  if (value === 0) {
356
- this.On = false;
413
+ this.StatefulProgrammableSwitch!.On = false;
357
414
  } else {
358
- this.On = true;
415
+ this.StatefulProgrammableSwitch!.On = true;
359
416
  }
417
+
418
+ On = this.StatefulProgrammableSwitch!.On;
360
419
  } else {
361
420
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set On: ${value}`);
362
- this.On = value;
421
+ this.Outlet!.On = value;
422
+ On = this.Outlet!.On ? true : false;
363
423
  }
364
424
 
365
425
  //pushChanges
366
- if (this.On) {
367
- await this.pushOnChanges();
426
+ if (On === true) {
427
+ await this.pushOnChanges(On);
368
428
  } else {
369
- await this.pushOffChanges();
429
+ await this.pushOffChanges(On);
370
430
  }
371
431
  }
372
432
 
@@ -380,13 +440,11 @@ export class Others {
380
440
  * Other - "command" "channelAdd" "default" = next channel
381
441
  * Other - "command" "channelSub" "default" = previous channel
382
442
  */
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
- );
443
+ async pushOnChanges(On: boolean): Promise<void> {
444
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${On},`
445
+ + ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
388
446
  if (this.device.customize) {
389
- if (this.On && !this.disablePushOn) {
447
+ if (On === true && !this.disablePushOn) {
390
448
  const commandType: string = await this.commandType();
391
449
  const command: string = await this.commandOn();
392
450
  const bodyChange = JSON.stringify({
@@ -401,13 +459,11 @@ export class Others {
401
459
  }
402
460
  }
403
461
 
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
- );
462
+ async pushOffChanges(On: boolean): Promise<void> {
463
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${On},`
464
+ + ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
409
465
  if (this.device.customize) {
410
- if (!this.On && !this.disablePushOff) {
466
+ if (On === false && !this.disablePushOff) {
411
467
  const commandType: string = await this.commandType();
412
468
  const command: string = await this.commandOff();
413
469
  const bodyChange = JSON.stringify({
@@ -437,8 +493,10 @@ export class Others {
437
493
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
438
494
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
439
495
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
440
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
496
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
441
497
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
498
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
499
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
442
500
  this.updateHomeKitCharacteristics();
443
501
  } else {
444
502
  this.statusCode(statusCode);
@@ -446,456 +504,294 @@ export class Others {
446
504
  }
447
505
  } catch (e: any) {
448
506
  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
- );
507
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
508
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
453
509
  }
454
510
  } 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
- );
511
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
512
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
459
513
  }
460
514
  }
461
515
 
462
516
  async updateHomeKitCharacteristics(): Promise<void> {
463
517
  if (this.otherDeviceType === 'garagedoor') {
464
- if (this.On === undefined) {
465
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
518
+ if (this.GarageDoor!.On === undefined) {
519
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.GarageDoor!.On}`);
466
520
  } 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
- );
521
+ if (this.GarageDoor!.On) {
522
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
523
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
524
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
525
+ + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
479
526
  } 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
- );
527
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
528
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
529
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
530
+ + ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
491
531
  }
492
532
  }
493
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
533
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor!.On}`);
494
534
  } else if (this.otherDeviceType === 'door') {
495
- if (this.On === undefined) {
496
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
535
+ if (this.Door!.On === undefined) {
536
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Door!.On}`);
497
537
  } 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`);
538
+ if (this.Door!.On) {
539
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
540
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
541
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
542
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
543
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
503
544
  } 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`);
545
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
546
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
547
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
548
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
549
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
508
550
  }
509
551
  }
510
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.On}`);
552
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.Door!.On}`);
511
553
  } else if (this.otherDeviceType === 'window') {
512
- if (this.On === undefined) {
513
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
554
+ if (this.Window!.On === undefined) {
555
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Window!.On}`);
514
556
  } 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`);
557
+ if (this.Window!.On) {
558
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
559
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
560
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
561
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
562
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
520
563
  } 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`);
564
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
565
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
566
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
567
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
568
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
525
569
  }
526
570
  }
527
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.On}`);
571
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.Window!.On}`);
528
572
  } else if (this.otherDeviceType === 'windowcovering') {
529
- if (this.On === undefined) {
530
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
573
+ if (this.WindowCovering!.On === undefined) {
574
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.WindowCovering!.On}`);
531
575
  } 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`);
576
+ if (this.WindowCovering!.On) {
577
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
578
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
579
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
580
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
581
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
540
582
  } 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`);
583
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
584
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
585
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
586
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
587
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
548
588
  }
549
589
  }
550
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.On}`);
590
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
551
591
  } else if (this.otherDeviceType === 'lock') {
552
- if (this.On === undefined) {
553
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
592
+ if (this.Lock!.On === undefined) {
593
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Lock!.On}`);
554
594
  } 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
- );
595
+ if (this.Lock!.On) {
596
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
597
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
598
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
599
+ + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
568
600
  } 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
- );
601
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
602
+ this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
603
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
604
+ + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock!.On})`);
577
605
  }
578
606
  }
579
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.On}`);
607
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.Lock!.On}`);
580
608
  } else if (this.otherDeviceType === 'faucet') {
581
- if (this.On === undefined) {
582
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
609
+ if (this.Faucet!.On === undefined) {
610
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Faucet!.On}`);
583
611
  } 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}`);
612
+ if (this.Faucet!.On) {
613
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
614
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
587
615
  } 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}`);
616
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
617
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
590
618
  }
591
619
  }
592
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.On}`);
620
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.Faucet!.On}`);
593
621
  } else if (this.otherDeviceType === 'fan') {
594
- if (this.On === undefined) {
595
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
622
+ if (this.Fan!.On === undefined) {
623
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Fan!.On}`);
596
624
  } 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}`);
625
+ if (this.Fan!.On) {
626
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
627
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
600
628
  } else {
601
- this.fanService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
602
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
629
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
630
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
603
631
  }
604
632
  }
605
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.On}`);
633
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.Fan!.On}`);
606
634
  } else if (this.otherDeviceType === 'stateful') {
607
- if (this.On === undefined) {
608
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
635
+ if (this.StatefulProgrammableSwitch!.On === undefined) {
636
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch!.On}`);
609
637
  } 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
- );
638
+ if (this.StatefulProgrammableSwitch!.On) {
639
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
640
+ this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
641
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
642
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
643
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
620
644
  } 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
- );
645
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
646
+ this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
647
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
648
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
649
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
630
650
  }
631
651
  }
632
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
652
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
633
653
  } else if (this.otherDeviceType === 'switch') {
634
- if (this.On === undefined) {
635
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
654
+ if (this.Switch!.On === undefined) {
655
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch!.On}`);
636
656
  } else {
637
- this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
638
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
657
+ this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch!.On);
658
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch!.On}`);
639
659
  }
640
660
  } else {
641
- if (this.On === undefined) {
642
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
661
+ if (this.Outlet!.On === undefined) {
662
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Outlet!.On}`);
643
663
  } else {
644
- this.outletService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
645
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
664
+ this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet!.On);
665
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet!.On}`);
646
666
  }
647
667
  }
648
668
  }
649
669
 
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
670
  async apiError(e: any): Promise<void> {
775
671
  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);
672
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
673
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
674
+ this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
779
675
  } 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);
676
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
677
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
678
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
783
679
  } 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);
680
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
681
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
682
+ this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
787
683
  } 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);
684
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
685
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
686
+ this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
791
687
  } else if (this.otherDeviceType === 'lock') {
792
- this.doorService?.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
793
- this.doorService?.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
688
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
689
+ this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
794
690
  } else if (this.otherDeviceType === 'faucet') {
795
- this.faucetService?.updateCharacteristic(this.hap.Characteristic.Active, e);
691
+ this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
796
692
  } else if (this.otherDeviceType === 'fan') {
797
- this.fanService?.updateCharacteristic(this.hap.Characteristic.On, e);
693
+ this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
798
694
  } else if (this.otherDeviceType === 'stateful') {
799
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
800
- this.statefulProgrammableSwitchService?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
695
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
696
+ this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
801
697
  } else if (this.otherDeviceType === 'switch') {
802
- this.switchService?.updateCharacteristic(this.hap.Characteristic.On, e);
698
+ this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
803
699
  } else {
804
- this.outletService?.updateCharacteristic(this.hap.Characteristic.On, e);
700
+ this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
805
701
  }
806
702
  }
807
703
 
808
704
  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) {
705
+ // If Outlet.Service still present, then remove first
706
+ if (this.Outlet?.Service) {
707
+ this.Outlet!.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
812
708
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
709
+ accessory.removeService(this.Outlet!.Service);
813
710
  }
814
- accessory.removeService(this.outletService!);
815
711
  }
816
712
 
817
713
  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) {
714
+ // If GarageDoor.Service still present, then remove first
715
+ if (this.GarageDoor?.Service) {
716
+ this.GarageDoor!.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
821
717
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
718
+ accessory.removeService(this.GarageDoor!.Service);
822
719
  }
823
- accessory.removeService(this.garageDoorService!);
824
720
  }
825
721
 
826
722
  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) {
723
+ // If Door.Service still present, then remove first
724
+ if (this.Door?.Service) {
725
+ this.Door!.Service = this.accessory.getService(this.hap.Service.Door) as Service;
830
726
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
727
+ accessory.removeService(this.Door!.Service);
831
728
  }
832
- accessory.removeService(this.doorService!);
833
729
  }
834
730
 
835
731
  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) {
732
+ // If Lock.Service still present, then remove first
733
+ if (this.Lock?.Service) {
734
+ this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
839
735
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
736
+ accessory.removeService(this.Lock!.Service);
840
737
  }
841
- accessory.removeService(this.lockService!);
842
738
  }
843
739
 
844
740
  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) {
741
+ // If Faucet.Service still present, then remove first
742
+ if (this.Faucet?.Service) {
743
+ this.Faucet!.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
848
744
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
745
+ accessory.removeService(this.Faucet!.Service);
849
746
  }
850
- accessory.removeService(this.faucetService!);
851
747
  }
852
748
 
853
749
  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) {
750
+ // If Fan Service still present, then remove first
751
+ if (this.Fan?.Service) {
752
+ this.Fan!.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
857
753
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
754
+ accessory.removeService(this.Fan!.Service);
858
755
  }
859
- accessory.removeService(this.fanService!);
860
756
  }
861
757
 
862
758
  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) {
759
+ // If Window.Service still present, then remove first
760
+ if (this.Window?.Service) {
761
+ this.Window!.Service = this.accessory.getService(this.hap.Service.Window) as Service;
866
762
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
763
+ accessory.removeService(this.Window!.Service);
867
764
  }
868
- accessory.removeService(this.windowService!);
869
765
  }
870
766
 
871
767
  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) {
768
+ // If WindowCovering.Service still present, then remove first
769
+ if (this.WindowCovering?.Service) {
770
+ this.WindowCovering!.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
875
771
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
772
+ accessory.removeService(this.WindowCovering!.Service);
876
773
  }
877
- accessory.removeService(this.windowCoveringService!);
878
774
  }
879
775
 
880
776
  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) {
777
+ // If StatefulProgrammableSwitch.Service still present, then remove first
778
+ if (this.StatefulProgrammableSwitch?.Service) {
779
+ this.StatefulProgrammableSwitch!.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
884
780
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
781
+ accessory.removeService(this.StatefulProgrammableSwitch!.Service);
885
782
  }
886
- accessory.removeService(this.statefulProgrammableSwitchService!);
887
783
  }
888
784
 
889
785
  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) {
786
+ // If Switch.Service still present, then remove first
787
+ if (this.Switch?.Service) {
788
+ this.Switch!.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
893
789
  this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
790
+ accessory.removeService(this.Switch!.Service);
894
791
  }
895
- accessory.removeService(this.switchService!);
896
792
  }
897
793
 
898
- async deviceType(device: irdevice & irDevicesConfig): Promise<void> {
794
+ async getOtherConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
899
795
  if (!device.other?.deviceType && this.accessory.context.deviceType) {
900
796
  this.otherDeviceType = this.accessory.context.deviceType;
901
797
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from Accessory Cache.`);
@@ -909,117 +805,4 @@ export class Others {
909
805
  this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} no deviceType set, using default deviceType: ${this.otherDeviceType}`);
910
806
  }
911
807
  }
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
808
  }