@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.0

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