@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.40

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