homebridge-smartthings-oauth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.devcontainer/Dockerfile +16 -0
  2. package/.devcontainer/devcontainer.json +36 -0
  3. package/LICENSE +176 -0
  4. package/README.md +114 -0
  5. package/config.schema.json +134 -0
  6. package/dist/auth/auth.d.ts +23 -0
  7. package/dist/auth/auth.d.ts.map +1 -0
  8. package/dist/auth/auth.js +168 -0
  9. package/dist/auth/auth.js.map +1 -0
  10. package/dist/auth/tokenManager.d.ts +36 -0
  11. package/dist/auth/tokenManager.d.ts.map +1 -0
  12. package/dist/auth/tokenManager.js +180 -0
  13. package/dist/auth/tokenManager.js.map +1 -0
  14. package/dist/basePlatformAccessory.d.ts +49 -0
  15. package/dist/basePlatformAccessory.d.ts.map +1 -0
  16. package/dist/basePlatformAccessory.js +209 -0
  17. package/dist/basePlatformAccessory.js.map +1 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +7 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/keyValues.d.ts +4 -0
  23. package/dist/keyValues.d.ts.map +1 -0
  24. package/dist/keyValues.js +12 -0
  25. package/dist/keyValues.js.map +1 -0
  26. package/dist/multiServiceAccessory.d.ts +60 -0
  27. package/dist/multiServiceAccessory.d.ts.map +1 -0
  28. package/dist/multiServiceAccessory.js +398 -0
  29. package/dist/multiServiceAccessory.js.map +1 -0
  30. package/dist/platform.d.ts +42 -0
  31. package/dist/platform.d.ts.map +1 -0
  32. package/dist/platform.js +302 -0
  33. package/dist/platform.js.map +1 -0
  34. package/dist/services/airConditionerService.d.ts +52 -0
  35. package/dist/services/airConditionerService.d.ts.map +1 -0
  36. package/dist/services/airConditionerService.js +438 -0
  37. package/dist/services/airConditionerService.js.map +1 -0
  38. package/dist/services/baseService.d.ts +21 -0
  39. package/dist/services/baseService.d.ts.map +1 -0
  40. package/dist/services/baseService.js +63 -0
  41. package/dist/services/baseService.js.map +1 -0
  42. package/dist/services/batteryService.d.ts +10 -0
  43. package/dist/services/batteryService.d.ts.map +1 -0
  44. package/dist/services/batteryService.js +71 -0
  45. package/dist/services/batteryService.js.map +1 -0
  46. package/dist/services/carbonMonoxideDetector.d.ts +11 -0
  47. package/dist/services/carbonMonoxideDetector.d.ts.map +1 -0
  48. package/dist/services/carbonMonoxideDetector.js +28 -0
  49. package/dist/services/carbonMonoxideDetector.js.map +1 -0
  50. package/dist/services/contactSensorService.d.ts +10 -0
  51. package/dist/services/contactSensorService.d.ts.map +1 -0
  52. package/dist/services/contactSensorService.js +28 -0
  53. package/dist/services/contactSensorService.js.map +1 -0
  54. package/dist/services/doorService.d.ts +16 -0
  55. package/dist/services/doorService.d.ts.map +1 -0
  56. package/dist/services/doorService.js +138 -0
  57. package/dist/services/doorService.js.map +1 -0
  58. package/dist/services/fanSpeedService.d.ts +15 -0
  59. package/dist/services/fanSpeedService.d.ts.map +1 -0
  60. package/dist/services/fanSpeedService.js +153 -0
  61. package/dist/services/fanSpeedService.js.map +1 -0
  62. package/dist/services/fanSwitchLevelService.d.ts +14 -0
  63. package/dist/services/fanSwitchLevelService.d.ts.map +1 -0
  64. package/dist/services/fanSwitchLevelService.js +121 -0
  65. package/dist/services/fanSwitchLevelService.js.map +1 -0
  66. package/dist/services/humidityService.d.ts +10 -0
  67. package/dist/services/humidityService.d.ts.map +1 -0
  68. package/dist/services/humidityService.js +23 -0
  69. package/dist/services/humidityService.js.map +1 -0
  70. package/dist/services/leakDetector.d.ts +10 -0
  71. package/dist/services/leakDetector.d.ts.map +1 -0
  72. package/dist/services/leakDetector.js +27 -0
  73. package/dist/services/leakDetector.js.map +1 -0
  74. package/dist/services/lightSensorService.d.ts +10 -0
  75. package/dist/services/lightSensorService.d.ts.map +1 -0
  76. package/dist/services/lightSensorService.js +24 -0
  77. package/dist/services/lightSensorService.js.map +1 -0
  78. package/dist/services/lightService.d.ts +26 -0
  79. package/dist/services/lightService.d.ts.map +1 -0
  80. package/dist/services/lightService.js +340 -0
  81. package/dist/services/lightService.js.map +1 -0
  82. package/dist/services/lockService.d.ts +16 -0
  83. package/dist/services/lockService.d.ts.map +1 -0
  84. package/dist/services/lockService.js +128 -0
  85. package/dist/services/lockService.js.map +1 -0
  86. package/dist/services/motionService.d.ts +10 -0
  87. package/dist/services/motionService.d.ts.map +1 -0
  88. package/dist/services/motionService.js +23 -0
  89. package/dist/services/motionService.js.map +1 -0
  90. package/dist/services/occupancySensorService.d.ts +10 -0
  91. package/dist/services/occupancySensorService.d.ts.map +1 -0
  92. package/dist/services/occupancySensorService.js +23 -0
  93. package/dist/services/occupancySensorService.js.map +1 -0
  94. package/dist/services/sensorService.d.ts +15 -0
  95. package/dist/services/sensorService.d.ts.map +1 -0
  96. package/dist/services/sensorService.js +69 -0
  97. package/dist/services/sensorService.js.map +1 -0
  98. package/dist/services/smartThingsCommand.d.ts +7 -0
  99. package/dist/services/smartThingsCommand.d.ts.map +1 -0
  100. package/dist/services/smartThingsCommand.js +12 -0
  101. package/dist/services/smartThingsCommand.js.map +1 -0
  102. package/dist/services/smokeDetector.d.ts +10 -0
  103. package/dist/services/smokeDetector.d.ts.map +1 -0
  104. package/dist/services/smokeDetector.js +27 -0
  105. package/dist/services/smokeDetector.js.map +1 -0
  106. package/dist/services/statelessProgrammableSwitchService.d.ts +12 -0
  107. package/dist/services/statelessProgrammableSwitchService.d.ts.map +1 -0
  108. package/dist/services/statelessProgrammableSwitchService.js +94 -0
  109. package/dist/services/statelessProgrammableSwitchService.js.map +1 -0
  110. package/dist/services/switchService.d.ts +12 -0
  111. package/dist/services/switchService.d.ts.map +1 -0
  112. package/dist/services/switchService.js +72 -0
  113. package/dist/services/switchService.js.map +1 -0
  114. package/dist/services/temperatureService.d.ts +11 -0
  115. package/dist/services/temperatureService.d.ts.map +1 -0
  116. package/dist/services/temperatureService.js +32 -0
  117. package/dist/services/temperatureService.js.map +1 -0
  118. package/dist/services/thermostatService.d.ts +22 -0
  119. package/dist/services/thermostatService.d.ts.map +1 -0
  120. package/dist/services/thermostatService.js +273 -0
  121. package/dist/services/thermostatService.js.map +1 -0
  122. package/dist/services/valveService.d.ts +12 -0
  123. package/dist/services/valveService.d.ts.map +1 -0
  124. package/dist/services/valveService.js +59 -0
  125. package/dist/services/valveService.js.map +1 -0
  126. package/dist/services/windowCoveringService.d.ts +36 -0
  127. package/dist/services/windowCoveringService.d.ts.map +1 -0
  128. package/dist/services/windowCoveringService.js +158 -0
  129. package/dist/services/windowCoveringService.js.map +1 -0
  130. package/dist/settings.d.ts +9 -0
  131. package/dist/settings.d.ts.map +1 -0
  132. package/dist/settings.js +12 -0
  133. package/dist/settings.js.map +1 -0
  134. package/dist/webhook/subscriptionHandler.d.ts +32 -0
  135. package/dist/webhook/subscriptionHandler.d.ts.map +1 -0
  136. package/dist/webhook/subscriptionHandler.js +68 -0
  137. package/dist/webhook/subscriptionHandler.js.map +1 -0
  138. package/dist/webhook/webhookServer.d.ts +19 -0
  139. package/dist/webhook/webhookServer.d.ts.map +1 -0
  140. package/dist/webhook/webhookServer.js +125 -0
  141. package/dist/webhook/webhookServer.js.map +1 -0
  142. package/package.json +57 -0
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePlatformAccessory = void 0;
4
+ const axios = require("axios");
5
+ /**
6
+ * Platform Accessory
7
+ * An instance of this class is created for each accessory your platform registers
8
+ * Each accessory may expose multiple services of different service types.
9
+ */
10
+ class BasePlatformAccessory {
11
+ get id() {
12
+ return this.accessory.UUID;
13
+ }
14
+ constructor(platform, accessory) {
15
+ this.online = true;
16
+ this.deviceStatus = { timestamp: 0, status: undefined };
17
+ this.failureCount = 0;
18
+ this.giveUpTime = 0;
19
+ this.commandInProgress = false;
20
+ this.lastCommandCompleted = 0;
21
+ this.statusQueryInProgress = false;
22
+ this.lastStatusResult = true;
23
+ this.accessory = accessory;
24
+ this.platform = platform;
25
+ this.name = accessory.context.device.label;
26
+ this.log = platform.log;
27
+ this.baseURL = platform.config.BaseURL;
28
+ this.key = platform.config.AccessToken;
29
+ this.api = platform.api;
30
+ const headerDict = { 'Authorization': 'Bearer: ' + this.key };
31
+ this.axInstance = axios.default.create({
32
+ baseURL: this.baseURL,
33
+ headers: headerDict,
34
+ });
35
+ this.commandURL = 'devices/' + accessory.context.device.deviceId + '/commands';
36
+ this.statusURL = 'devices/' + accessory.context.device.deviceId + '/status';
37
+ this.healthURL = 'devices/' + accessory.context.device.deviceId + '/health';
38
+ this.characteristic = platform.Characteristic;
39
+ // set accessory information
40
+ accessory.getService(platform.Service.AccessoryInformation)
41
+ .setCharacteristic(platform.Characteristic.Manufacturer, accessory.context.device.manufacturerName)
42
+ .setCharacteristic(platform.Characteristic.Model, 'Default-Model')
43
+ .setCharacteristic(platform.Characteristic.SerialNumber, 'Default-Serial');
44
+ // // Find out if we are online
45
+ this.axInstance.get(this.healthURL)
46
+ .then(res => {
47
+ if (res.data.state === 'ONLINE') {
48
+ this.online = true;
49
+ }
50
+ else {
51
+ this.online = false;
52
+ }
53
+ });
54
+ // if (this.name === 'Test Lock') {
55
+ // platform.subscriptionHandler.addSubscription(this);
56
+ // }
57
+ }
58
+ // Called by subclasses to refresh the status for the device. Will only refresh if it has been more than
59
+ // 4 seconds since last refresh
60
+ //
61
+ async refreshStatus() {
62
+ return new Promise((resolve) => {
63
+ this.log.debug(`Refreshing status for ${this.name} - current timestamp is ${this.deviceStatus.timestamp}`);
64
+ if ((this.deviceStatus.status === undefined) || (Date.now() - this.deviceStatus.timestamp > 5000)) {
65
+ // If there is already a call to smartthings to update status for this device, don't issue another one until
66
+ // we return from that.
67
+ if (this.statusQueryInProgress) {
68
+ this.log.debug(`Status query already in progress for ${this.name}. Waiting...`);
69
+ this.waitFor(() => !this.statusQueryInProgress).then(() => resolve(this.lastStatusResult));
70
+ return;
71
+ }
72
+ this.log.debug(`Calling Smartthings to get an update for ${this.name}`);
73
+ this.statusQueryInProgress = true;
74
+ this.failureCount = 0;
75
+ this.waitFor(() => this.commandInProgress === false).then(() => {
76
+ this.lastStatusResult = true;
77
+ this.axInstance.get(this.statusURL).then((res) => {
78
+ if (res.data.components.main !== undefined) {
79
+ this.deviceStatus.status = res.data.components.main;
80
+ this.deviceStatus.timestamp = Date.now();
81
+ this.log.debug(`Updated status for ${this.name}: ${JSON.stringify(this.deviceStatus.status)}`);
82
+ this.statusQueryInProgress = false;
83
+ resolve(true);
84
+ }
85
+ else {
86
+ this.log.debug(`No status returned for ${this.name}`);
87
+ this.statusQueryInProgress = false;
88
+ resolve(this.lastStatusResult = false);
89
+ }
90
+ }).catch(error => {
91
+ this.failureCount++;
92
+ this.log.error(`Failed to request status from ${this.name}: ${error}. This is failure number ${this.failureCount}`);
93
+ if (this.failureCount >= 5) {
94
+ this.log.error(`Exceeded allowed failures for ${this.name}. Device is offline`);
95
+ this.giveUpTime = Date.now();
96
+ this.online = false;
97
+ }
98
+ this.statusQueryInProgress = false;
99
+ resolve(this.lastStatusResult = false);
100
+ });
101
+ });
102
+ }
103
+ else {
104
+ resolve(true);
105
+ }
106
+ });
107
+ }
108
+ startPollingState(pollSeconds, getValue, service, chracteristic, targetStateCharacteristic, getTargetState) {
109
+ if (this.platform.config.WebhookToken && this.platform.config.WebhookToken !== '') {
110
+ return; // Don't poll if we have a webhook token
111
+ }
112
+ if (pollSeconds > 0) {
113
+ return setInterval(() => {
114
+ // If we are in the middle of a commmand call, or it hasn't been at least 10 seconds, we don't want to poll.
115
+ if (this.commandInProgress || Date.now() - this.lastCommandCompleted < 20 * 1000) {
116
+ // Skip polling until command is complete
117
+ this.log.debug(`Command in progress, skipping polling for ${this.name}`);
118
+ return;
119
+ }
120
+ if (this.online) {
121
+ this.log.debug(`${this.name} polling...`);
122
+ // this.commandInProgress = true;
123
+ getValue().then((v) => {
124
+ service.updateCharacteristic(chracteristic, v);
125
+ this.log.debug(`${this.name} value updated.`);
126
+ }).catch(() => {
127
+ this.log.warn(`Poll failure on ${this.name}`);
128
+ return;
129
+ });
130
+ // Update target if we have to
131
+ if (targetStateCharacteristic && getTargetState) {
132
+ //service.updateCharacteristic(targetStateCharacteristic, getTargetState());
133
+ getTargetState().then(value => service.updateCharacteristic(targetStateCharacteristic, value));
134
+ }
135
+ }
136
+ else {
137
+ // If we failed this accessory due to errors. Reset the failure count and online status after 10 minutes.
138
+ if (this.giveUpTime > 0 && (Date.now() - this.giveUpTime > (10 * 60 * 1000))) {
139
+ this.axInstance.get(this.healthURL)
140
+ .then(res => {
141
+ if (res.data.state === 'ONLINE') {
142
+ this.online = true;
143
+ this.giveUpTime = 0;
144
+ this.failureCount = 0;
145
+ }
146
+ });
147
+ }
148
+ }
149
+ }, pollSeconds * 1000);
150
+ }
151
+ }
152
+ async sendCommand(capability, command, args) {
153
+ let cmd;
154
+ if (args) {
155
+ cmd = {
156
+ capability: capability,
157
+ command: command,
158
+ arguments: args,
159
+ };
160
+ }
161
+ else {
162
+ cmd = {
163
+ capability: capability,
164
+ command: command,
165
+ };
166
+ }
167
+ const commandBody = JSON.stringify([cmd]);
168
+ return new Promise((resolve) => {
169
+ this.waitFor(() => !this.commandInProgress).then(() => {
170
+ this.commandInProgress = true;
171
+ this.axInstance.post(this.commandURL, commandBody).then(() => {
172
+ this.log.debug(`${command} successful for ${this.name}`);
173
+ this.deviceStatus.timestamp = 0; // Force a refresh on next poll after a state change
174
+ this.commandInProgress = false;
175
+ resolve(true);
176
+ // Force a small delay so that status fetch is correct
177
+ // setTimeout(() => {
178
+ // this.log.debug(`Delay complete for ${this.name}`);
179
+ // this.commandInProgress = false;
180
+ // resolve(true);
181
+ // }, 1500);
182
+ }).catch((error) => {
183
+ this.commandInProgress = false;
184
+ this.log.error(`${command} failed for ${this.name}: ${error}`);
185
+ resolve(false);
186
+ });
187
+ });
188
+ });
189
+ }
190
+ // Wait for the condition to be true. Will check every 500 ms
191
+ async waitFor(condition) {
192
+ if (condition()) {
193
+ return;
194
+ }
195
+ this.log.debug(`${this.name} command or request is waiting...`);
196
+ return new Promise(resolve => {
197
+ const interval = setInterval(() => {
198
+ if (condition()) {
199
+ this.log.debug(`${this.name} command or request is proceeding.`);
200
+ clearInterval(interval);
201
+ resolve();
202
+ }
203
+ this.log.debug(`${this.name} still waiting...`);
204
+ }, 250);
205
+ });
206
+ }
207
+ }
208
+ exports.BasePlatformAccessory = BasePlatformAccessory;
209
+ //# sourceMappingURL=basePlatformAccessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basePlatformAccessory.js","sourceRoot":"","sources":["../src/basePlatformAccessory.ts"],"names":[],"mappings":";;;AACA,+BAAgC;AAShC;;;;GAIG;AACH,MAAsB,qBAAqB;IA8BzC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,YACE,QAAwC,EACxC,SAA4B;QAhBpB,WAAM,GAAG,IAAI,CAAC;QACd,iBAAY,GAAiB,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QACjE,iBAAY,GAAG,CAAC,CAAC;QACjB,eAAU,GAAG,CAAC,CAAC;QACf,sBAAiB,GAAG,KAAK,CAAC;QAC1B,yBAAoB,GAAG,CAAC,CAAC;QAEzB,0BAAqB,GAAG,KAAK,CAAC;QAC9B,qBAAgB,GAAG,IAAI,CAAC;QAUhC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QACvC,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,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AG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,mCAAmC,CAAC,CAAC;QAChE,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;gBAChC,IAAI,SAAS,EAAE,EAAE;oBACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,oCAAoC,CAAC,CAAC;oBACjE,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACxB,OAAO,EAAE,CAAC;iBACX;gBACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,mBAAmB,CAAC,CAAC;YAClD,CAAC,EAAE,GAAG,CAAC,CAAC;QACV,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA3OD,sDA2OC"}
@@ -0,0 +1,7 @@
1
+ import { API } from 'homebridge';
2
+ /**
3
+ * This method registers the platform with Homebridge
4
+ */
5
+ declare const _default: (api: API) => void;
6
+ export = _default;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAKjC;;GAEG;8BACY,GAAG;AAAlB,kBAEE"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ const settings_1 = require("./settings");
3
+ const platform_1 = require("./platform");
4
+ module.exports = (api) => {
5
+ api.registerPlatform(settings_1.PLATFORM_NAME, platform_1.IKHomeBridgeHomebridgePlatform);
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,yCAA2C;AAC3C,yCAA4D;AAK5D,iBAAS,CAAC,GAAQ,EAAE,EAAE;IACpB,GAAG,CAAC,gBAAgB,CAAC,wBAAa,EAAE,yCAA8B,CAAC,CAAC;AACtE,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const WEBHOOK_URL: string;
2
+ export declare const WH_CONNECT_RETRY_MINUTES = 1;
3
+ export declare function wait(seconds: any): Promise<void>;
4
+ //# sourceMappingURL=keyValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValues.d.ts","sourceRoot":"","sources":["../src/keyValues.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAA2F,CAAC;AACpH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,wBAAsB,IAAI,CAAC,OAAO,KAAA,GAAE,OAAO,CAAC,IAAI,CAAC,CAIhD"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wait = exports.WH_CONNECT_RETRY_MINUTES = exports.WEBHOOK_URL = void 0;
4
+ exports.WEBHOOK_URL = process.env.WEBHOOK_URL ? process.env.WEBHOOK_URL : 'https://stwh.kleinstudios.net/api/';
5
+ exports.WH_CONNECT_RETRY_MINUTES = 1;
6
+ async function wait(seconds) {
7
+ return new Promise(resolve => {
8
+ setTimeout(() => resolve(), seconds * 1000);
9
+ });
10
+ }
11
+ exports.wait = wait;
12
+ //# sourceMappingURL=keyValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValues.js","sourceRoot":"","sources":["../src/keyValues.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,oCAAoC,CAAC;AACvG,QAAA,wBAAwB,GAAG,CAAC,CAAC;AAEnC,KAAK,UAAU,IAAI,CAAC,OAAO;IAChC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,oBAIC"}
@@ -0,0 +1,60 @@
1
+ /// <reference types="node" />
2
+ import { PlatformAccessory, Characteristic, CharacteristicValue, Service, WithUUID, Logger, API } from 'homebridge';
3
+ import axios = require('axios');
4
+ import { IKHomeBridgeHomebridgePlatform } from './platform';
5
+ import { ShortEvent } from './webhook/subscriptionHandler';
6
+ import { Command } from './services/smartThingsCommand';
7
+ /**
8
+ * Platform Accessory
9
+ * An instance of this class is created for each accessory your platform registers
10
+ * Each accessory may expose multiple services of different service types.
11
+ */
12
+ export declare class MultiServiceAccessory {
13
+ components: {
14
+ componentId: string;
15
+ capabilities: string[];
16
+ status: Record<string, unknown>;
17
+ }[];
18
+ /**
19
+ * These are just used to create a working example
20
+ * You should implement your own code to track the state of your accessory
21
+ */
22
+ private services;
23
+ private static capabilityMap;
24
+ private static comboCapabilityMap;
25
+ protected accessory: PlatformAccessory;
26
+ protected platform: IKHomeBridgeHomebridgePlatform;
27
+ readonly name: string;
28
+ protected characteristic: typeof Characteristic;
29
+ protected log: Logger;
30
+ protected baseURL: string;
31
+ protected key: string;
32
+ protected axInstance: axios.AxiosInstance;
33
+ protected commandURL: string;
34
+ protected statusURL: string;
35
+ protected healthURL: string;
36
+ protected api: API;
37
+ protected online: boolean;
38
+ protected deviceStatusTimestamp: number;
39
+ protected failureCount: number;
40
+ protected giveUpTime: number;
41
+ protected commandInProgress: boolean;
42
+ protected lastCommandCompleted: number;
43
+ protected statusQueryInProgress: boolean;
44
+ protected lastStatusResult: boolean;
45
+ get id(): string;
46
+ constructor(platform: IKHomeBridgeHomebridgePlatform, accessory: PlatformAccessory);
47
+ private checkDeviceHealth;
48
+ private registerServiceIfMatchesCapabilities;
49
+ addComponent(componentId: string, capabilities: string[]): void;
50
+ isOnline(): boolean;
51
+ static capabilitySupported(capability: string): boolean;
52
+ refreshStatus(): Promise<boolean>;
53
+ forceNextStatusRefresh(): void;
54
+ startPollingState(pollSeconds: number, getValue: () => Promise<CharacteristicValue>, service: Service, chracteristic: WithUUID<new () => Characteristic>, targetStateCharacteristic?: WithUUID<new () => Characteristic>, getTargetState?: () => Promise<CharacteristicValue>): NodeJS.Timer | void;
55
+ sendCommand(capability: string, command: string, args?: unknown[]): Promise<boolean>;
56
+ sendCommands(commands: Command[]): Promise<boolean>;
57
+ private waitFor;
58
+ processEvent(event: ShortEvent): void;
59
+ }
60
+ //# sourceMappingURL=multiServiceAccessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiServiceAccessory.d.ts","sourceRoot":"","sources":["../src/multiServiceAccessory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,mBAAmB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACpH,OAAO,KAAK,GAAG,QAAQ,OAAO,CAAC,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAmB5D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAM3D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAOxD;;;;GAIG;AAEH,qBAAa,qBAAqB;IAGhC,UAAU,EAAE;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,EAAE,CAAM;IAET;;;OAGG;IAEH,OAAO,CAAC,QAAQ,CAAqB;IAGrC,OAAO,CAAC,MAAM,CAAC,aAAa,CAkB1B;IAGF,OAAO,CAAC,MAAM,CAAC,kBAAkB,CA6D/B;IAEF,SAAS,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACvC,SAAS,CAAC,QAAQ,EAAE,8BAA8B,CAAC;IACnD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAS,CA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