@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24

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