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