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,340 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LightService = void 0;
4
+ const baseService_1 = require("./baseService");
5
+ class LightService extends baseService_1.BaseService {
6
+ constructor(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus) {
7
+ super(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus);
8
+ // There is a device that can't handle sethue and setsaturation separately and requires both
9
+ // args using setcolor.
10
+ this.currentColor = {
11
+ hue: 0,
12
+ saturation: 0,
13
+ };
14
+ this.requireSetColor = false;
15
+ this.setServiceType(platform.Service.Lightbulb);
16
+ // Set the event handlers
17
+ this.log.debug(`Adding LightService to ${this.name}`);
18
+ this.service.getCharacteristic(platform.Characteristic.On)
19
+ .onGet(this.getSwitchState.bind(this))
20
+ .onSet(this.setSwitchState.bind(this));
21
+ // if (accessory.context.device.components[0].capabilities.find(c => c.id === 'switchLevel')) {
22
+ if (this.findCapability('switchLevel')) {
23
+ this.log.debug(`${this.name} supports switchLevel`);
24
+ this.service.getCharacteristic(platform.Characteristic.Brightness)
25
+ .onSet(this.setLevel.bind(this))
26
+ .onGet(this.getLevel.bind(this));
27
+ }
28
+ // If this bulb supports colorTemperature, then add those handlers
29
+ // if (accessory.context.device.components[0].capabilities.find(c => c.id === 'colorTemperature')) {
30
+ if (this.findCapability('colorTemperature')) {
31
+ this.log.debug(`${this.name} supports colorTemperature`);
32
+ this.service.getCharacteristic(platform.Characteristic.ColorTemperature)
33
+ .onSet(this.setColorTemp.bind(this))
34
+ .onGet(this.getColorTemp.bind(this));
35
+ }
36
+ // If we support color control...
37
+ //if (accessory.context.device.components[0].capabilities.find(c => c.id === 'colorControl')) {
38
+ if (this.findCapability('colorControl')) {
39
+ this.log.debug(`${this.name} supports colorControl`);
40
+ this.service.getCharacteristic(platform.Characteristic.Hue)
41
+ .onSet(this.setHue.bind(this))
42
+ .onGet(this.getHue.bind(this));
43
+ this.service.getCharacteristic(platform.Characteristic.Saturation)
44
+ .onSet(this.setSaturation.bind(this))
45
+ .onGet(this.getSaturation.bind(this));
46
+ // Get current color setting. Sets currentColor values to start
47
+ this.getHue();
48
+ this.getSaturation();
49
+ }
50
+ let pollSwitchesAndLightsSeconds = 10; // default to 10 seconds
51
+ if (this.platform.config.PollSwitchesAndLightsSeconds !== undefined) {
52
+ pollSwitchesAndLightsSeconds = this.platform.config.PollSwitchesAndLightsSeconds;
53
+ }
54
+ if (pollSwitchesAndLightsSeconds > 0) {
55
+ multiServiceAccessory.startPollingState(pollSwitchesAndLightsSeconds, this.getSwitchState.bind(this), this.service, platform.Characteristic.On);
56
+ }
57
+ }
58
+ async setSwitchState(value) {
59
+ this.log.debug('Received setSwitchState(' + value + ') event for ' + this.name);
60
+ if (!this.multiServiceAccessory.isOnline) {
61
+ this.log.error(this.name + ' is offline');
62
+ throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
63
+ }
64
+ this.multiServiceAccessory.sendCommand('switch', value ? 'on' : 'off').then((success) => {
65
+ if (success) {
66
+ this.log.debug('onSet(' + value + ') SUCCESSFUL for ' + this.name);
67
+ this.multiServiceAccessory.forceNextStatusRefresh();
68
+ // this.deviceStatus.timestamp = 0;
69
+ }
70
+ else {
71
+ this.log.error(`Command failed for ${this.name}`);
72
+ }
73
+ });
74
+ }
75
+ async getSwitchState() {
76
+ // if you need to return an error to show the device as "Not Responding" in the Home app:
77
+ // throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
78
+ this.log.debug('Received getSwitchState() event for ' + this.name);
79
+ return new Promise((resolve, reject) => {
80
+ this.getStatus().then(success => {
81
+ if (success) {
82
+ const switchState = this.deviceStatus.status.switch.switch.value;
83
+ this.log.debug(`SwitchState value from ${this.name}: ${switchState}`);
84
+ resolve(switchState === 'on');
85
+ }
86
+ else {
87
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
88
+ }
89
+ });
90
+ });
91
+ }
92
+ async setLevel(value) {
93
+ this.log.debug('Received setLevel(' + value + ') event for ' + this.name);
94
+ return new Promise((resolve, reject) => {
95
+ if (!this.multiServiceAccessory.isOnline()) {
96
+ this.log.error(this.accessory.context.device.label + ' is offline');
97
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
98
+ }
99
+ this.multiServiceAccessory.sendCommand('switchLevel', 'setLevel', [value]).then(success => {
100
+ if (success) {
101
+ this.log.debug('setLevel(' + value + ') SUCCESSFUL for ' + this.name);
102
+ this.multiServiceAccessory.forceNextStatusRefresh();
103
+ // this.deviceStatus.timestamp = 0;
104
+ resolve();
105
+ }
106
+ else {
107
+ this.log.error(`Failed to send setLevel command for ${this.name}`);
108
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
109
+ }
110
+ });
111
+ });
112
+ }
113
+ async getLevel() {
114
+ this.log.debug('Received getLevel() event for ' + this.name);
115
+ let level = 0;
116
+ return new Promise((resolve, reject) => {
117
+ if (!this.multiServiceAccessory.isOnline()) {
118
+ this.log.error(this.accessory.context.device.label + ' is offline');
119
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
120
+ }
121
+ this.getStatus().then((success) => {
122
+ if (!success) {
123
+ this.log.error(`Could not get device status for ${this.name}`);
124
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
125
+ }
126
+ try {
127
+ if (this.deviceStatus.status.switchLevel.level.value !== undefined) {
128
+ level = this.deviceStatus.status.switchLevel.level.value;
129
+ this.log.debug('getLevel() SUCCESSFUL for ' + this.name + '. value = ' + level);
130
+ resolve(level);
131
+ }
132
+ else {
133
+ this.log.error('getLevel() FAILED for ' + this.name + '. Undefined value');
134
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
135
+ }
136
+ }
137
+ catch (e) {
138
+ this.log.error('getLevel() FAILED for ' + this.name + '. Error: ' + e);
139
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
140
+ }
141
+ });
142
+ });
143
+ }
144
+ async setColorTemp(value) {
145
+ this.log.debug(`Set Color Temperature received with value ${value}`);
146
+ return new Promise((resolve, reject) => {
147
+ if (!this.multiServiceAccessory.isOnline()) {
148
+ this.log.error(this.accessory.context.device.label + ' is offline');
149
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
150
+ }
151
+ const stValue = 6500 - Math.round((value - 140) / 360 * 6500) + 1;
152
+ this.log.debug(`Sending converted temperature value of ${stValue} to ${this.name}`);
153
+ this.multiServiceAccessory.sendCommand('colorTemperature', 'setColorTemperature', [stValue])
154
+ .then(() => resolve())
155
+ .catch((value) => reject(value));
156
+ });
157
+ }
158
+ async getColorTemp() {
159
+ return new Promise((resolve, reject) => {
160
+ this.getStatus().then((success) => {
161
+ if (!success) {
162
+ //this.online = false;
163
+ this.log.error(`Could not get device status for ${this.name}`);
164
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
165
+ }
166
+ let stTemperature;
167
+ if (this.deviceStatus.status.colorTemperature.colorTemperature.value !== undefined) {
168
+ stTemperature = Math.min(this.deviceStatus.status.colorTemperature.colorTemperature.value, 6500);
169
+ this.log.debug('getColorTemperature() SUCCESSFUL for ' + this.name + '. value = ' + stTemperature);
170
+ // Convert number to the homebridge compatible value
171
+ const hbTemperature = 500 - ((stTemperature / 6500) * 360);
172
+ resolve(hbTemperature);
173
+ }
174
+ else {
175
+ this.log.error('getColorTemperature() FAILED for ' + this.name + '. Undefined value');
176
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
177
+ }
178
+ });
179
+ });
180
+ }
181
+ //
182
+ // If we get an error setting individual hue or saturation, then use setColor to set both at once. Needed to fix #96
183
+ //
184
+ async setColor(hue, saturation) {
185
+ this.log.debug(`setColor called with hue: ${hue}, saturation: ${saturation}}`);
186
+ return new Promise((resolve) => {
187
+ this.multiServiceAccessory.sendCommand('colorControl', 'setColor', [{
188
+ hue: this.currentColor.hue,
189
+ saturation: this.currentColor.saturation,
190
+ }])
191
+ .then((success) => resolve(success));
192
+ });
193
+ }
194
+ async setHue(value) {
195
+ this.log.debug(`setHue called with value ${value}`);
196
+ const huePct = Math.round((value / 360) * 100);
197
+ this.currentColor.hue = huePct;
198
+ this.log.debug(`Hue arc value of ${value} converted to Hue Percent of ${huePct}`);
199
+ return new Promise((resolve, reject) => {
200
+ if (this.requireSetColor) { // Issue #96
201
+ this.setColor(this.currentColor.hue, this.currentColor.saturation)
202
+ .then(() => resolve())
203
+ .catch((value) => reject(value));
204
+ }
205
+ else {
206
+ this.multiServiceAccessory.sendCommand('colorControl', 'setHue', [huePct])
207
+ .then((success) => {
208
+ if (success) {
209
+ resolve();
210
+ }
211
+ else {
212
+ this.log.warn(`Received ${value} setting hue for ${this.name}, will try setting color`);
213
+ this.requireSetColor = true;
214
+ this.setColor(this.currentColor.hue, this.currentColor.saturation).then((success) => {
215
+ if (!success) {
216
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
217
+ }
218
+ else {
219
+ resolve();
220
+ }
221
+ });
222
+ }
223
+ });
224
+ }
225
+ });
226
+ }
227
+ async getHue() {
228
+ return new Promise((resolve, reject) => {
229
+ this.getStatus().then((success) => {
230
+ if (!success) {
231
+ //this.online = false;
232
+ this.log.error(`Could not get device status for ${this.name}`);
233
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
234
+ }
235
+ if (this.deviceStatus.status.colorControl.hue.value !== undefined) {
236
+ const hue = this.deviceStatus.status.colorControl.hue.value;
237
+ this.log.debug('getHue() SUCCESSFUL for ' + this.name + '. value = ' + hue);
238
+ this.currentColor.hue = hue;
239
+ const hueArc = Math.round((hue / 100) * 360);
240
+ this.log.debug(`Hue Percent of ${hue} converted to ${hueArc}.`);
241
+ resolve(hueArc);
242
+ }
243
+ else {
244
+ this.log.error('getHue() FAILED for ' + this.name + '. Undefined value');
245
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
246
+ }
247
+ });
248
+ });
249
+ }
250
+ async setSaturation(value) {
251
+ this.log.debug(`setSaturation called with value ${value}`);
252
+ this.currentColor.saturation = value;
253
+ return new Promise((resolve, reject) => {
254
+ if (this.requireSetColor) {
255
+ this.setColor(this.currentColor.hue, this.currentColor.saturation)
256
+ .then(() => resolve())
257
+ .catch((value) => reject(value));
258
+ }
259
+ else {
260
+ this.multiServiceAccessory.sendCommand('colorControl', 'setSaturation', [value])
261
+ .then((success) => {
262
+ if (success) {
263
+ resolve();
264
+ }
265
+ else {
266
+ this.log.warn(`Received ${value} setting saturation for ${this.name}, will try setting color`);
267
+ this.requireSetColor = true;
268
+ this.setColor(this.currentColor.hue, this.currentColor.saturation).then(success => {
269
+ if (success) {
270
+ resolve();
271
+ }
272
+ else {
273
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
274
+ }
275
+ });
276
+ }
277
+ });
278
+ }
279
+ });
280
+ }
281
+ async getSaturation() {
282
+ return new Promise((resolve, reject) => {
283
+ this.getStatus().then((success) => {
284
+ if (!success) {
285
+ this.log.error(`Could not get device status for ${this.name}`);
286
+ return reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
287
+ }
288
+ if (this.deviceStatus.status.colorControl.saturation.value !== undefined) {
289
+ const satPct = this.deviceStatus.status.colorControl.saturation.value;
290
+ this.currentColor.saturation = satPct;
291
+ this.log.debug('getSaturation() SUCCESSFUL for ' + this.name + '. value = ' + satPct);
292
+ // Convert saturation from percent to degrees
293
+ resolve(satPct);
294
+ }
295
+ else {
296
+ this.log.error('getSaturation() FAILED for ' + this.name + '. Undefined value');
297
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
298
+ }
299
+ }).catch(() => {
300
+ this.log.error('getSaturation() FAILED for ' + this.name + '. Comm error.');
301
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
302
+ });
303
+ });
304
+ }
305
+ processEvent(event) {
306
+ switch (event.capability) {
307
+ case 'switch': {
308
+ this.log.debug(`Event updating switch capability for ${this.name} to ${event.value}`);
309
+ this.service.updateCharacteristic(this.platform.Characteristic.On, event.value === 'on');
310
+ return;
311
+ }
312
+ case 'switchLevel': {
313
+ this.log.debug(`Event updating switchLevel capability for ${this.name} to ${event.value}`);
314
+ this.service.updateCharacteristic(this.platform.Characteristic.Brightness, event.value);
315
+ return;
316
+ }
317
+ case 'colorTemperature': {
318
+ this.log.debug(`Event updating colorTemperature capability for ${this.name} to ${event.value}`);
319
+ const stTemperature = Math.min(this.deviceStatus.status.colorTemperature.colorTemperature.value, 6500);
320
+ this.log.debug('getColorTemperature() SUCCESSFUL for ' + this.name + '. value = ' + stTemperature);
321
+ // Convert number to the homebridge compatible value
322
+ const hbTemperature = 500 - ((stTemperature / 6500) * 360);
323
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, hbTemperature);
324
+ return;
325
+ }
326
+ case 'colorControl': {
327
+ this.log.debug(`Event for colorControl, attribute is ${event.attribute}, value is ${event.value}`);
328
+ if (event.attribute === 'hue') {
329
+ const hueArc = Math.round((event.value / 100) * 360);
330
+ this.service.updateCharacteristic(this.platform.Characteristic.Hue, hueArc);
331
+ }
332
+ else if (event.attribute === 'saturation') {
333
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, event.value);
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ exports.LightService = LightService;
340
+ //# sourceMappingURL=lightService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightService.js","sourceRoot":"","sources":["../../src/services/lightService.ts"],"names":[],"mappings":";;;AAEA,+CAA4C;AAI5C,MAAa,YAAa,SAAQ,yBAAW;IAY3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AK,CAAC,CAAC;iBACzF;aACF;SAEF;IACH,CAAC;CAEF;AAtXD,oCAsXC"}
@@ -0,0 +1,16 @@
1
+ import { PlatformAccessory, CharacteristicValue } from 'homebridge';
2
+ import { IKHomeBridgeHomebridgePlatform } from '../platform';
3
+ import { BaseService } from './baseService';
4
+ import { MultiServiceAccessory } from '../multiServiceAccessory';
5
+ import { ShortEvent } from '../webhook/subscriptionHandler';
6
+ export declare class LockService extends BaseService {
7
+ private targetState;
8
+ private lockInTransitionStart;
9
+ constructor(platform: IKHomeBridgeHomebridgePlatform, accessory: PlatformAccessory, componentId: string, capabilities: string[], multiServiceAccessory: MultiServiceAccessory, name: string, deviceStatus: any);
10
+ getLockTargetState(): Promise<number>;
11
+ setLockTargetState(value: CharacteristicValue): Promise<void>;
12
+ getLockCurrentState(): Promise<CharacteristicValue>;
13
+ processEvent(event: ShortEvent): void;
14
+ mapLockState(lockState: string): CharacteristicValue;
15
+ }
16
+ //# sourceMappingURL=lockService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockService.d.ts","sourceRoot":"","sources":["../../src/services/lockService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,qBAAqB,CAAK;gBAEtB,QAAQ,EAAE,8BAA8B,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAC7H,qBAAqB,EAAE,qBAAqB,EAC5C,IAAI,EAAE,MAAM,EAAE,YAAY,KAAA;IAqCtB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAwBrC,kBAAkB,CAAC,KAAK,EAAE,mBAAmB;IAwB7C,mBAAmB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAkBlD,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAYrC,YAAY,CAAC,SAAS,EAAC,MAAM,GAAG,mBAAmB;CAe3D"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LockService = void 0;
4
+ const baseService_1 = require("./baseService");
5
+ class LockService extends baseService_1.BaseService {
6
+ constructor(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus) {
7
+ super(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus);
8
+ this.targetState = 0;
9
+ this.lockInTransitionStart = 0;
10
+ this.setServiceType(platform.Service.LockMechanism);
11
+ // Set the event handlers
12
+ this.log.debug(`Adding LockService to ${this.name}`);
13
+ this.service.getCharacteristic(platform.Characteristic.LockCurrentState)
14
+ .onGet(this.getLockCurrentState.bind(this));
15
+ this.service.getCharacteristic(platform.Characteristic.LockTargetState)
16
+ .onGet(this.getLockTargetState.bind(this))
17
+ .onSet(this.setLockTargetState.bind(this));
18
+ // Set Target State to current state to start
19
+ this.getLockCurrentState().then(currentState => {
20
+ if (currentState === platform.Characteristic.LockCurrentState.UNSECURED) {
21
+ this.targetState = platform.Characteristic.LockTargetState.UNSECURED;
22
+ }
23
+ else {
24
+ this.targetState = platform.Characteristic.LockTargetState.SECURED;
25
+ }
26
+ }).catch(() => {
27
+ this.log.error(`Failed to get current state for ${this.name} on init`);
28
+ this.targetState = platform.Characteristic.LockTargetState.SECURED;
29
+ });
30
+ let pollLocksSeconds = 10; // default to 10 seconds
31
+ if (this.platform.config.PollLocksSeconds !== undefined) {
32
+ pollLocksSeconds = this.platform.config.PollSensorsSeconds;
33
+ }
34
+ if (pollLocksSeconds > 0) {
35
+ multiServiceAccessory.startPollingState(pollLocksSeconds, this.getLockCurrentState.bind(this), this.service, platform.Characteristic.LockCurrentState, this.platform.Characteristic.LockTargetState, this.getLockTargetState.bind(this));
36
+ }
37
+ }
38
+ // Return the current target state
39
+ async getLockTargetState() {
40
+ // If it has been more than 10 seconds since we've sent a transition command,
41
+ // reset the target state to the current state.
42
+ if (Date.now() - this.lockInTransitionStart > 10000) {
43
+ return new Promise((resolve, reject) => {
44
+ this.getStatus().then(success => {
45
+ if (!success) {
46
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
47
+ return;
48
+ }
49
+ this.targetState = this.deviceStatus.status.lock.lock.value === 'locked' ?
50
+ this.platform.Characteristic.LockTargetState.SECURED :
51
+ this.platform.Characteristic.LockTargetState.UNSECURED;
52
+ this.log.debug(`Reset ${this.name} to ${this.targetState}`);
53
+ resolve(this.targetState);
54
+ });
55
+ });
56
+ }
57
+ else {
58
+ return this.targetState;
59
+ }
60
+ }
61
+ // Set the target state of the lock
62
+ async setLockTargetState(value) {
63
+ this.log.debug('Received setTargetState(' + value + ') event for ' + this.name);
64
+ this.targetState = value;
65
+ if (!this.multiServiceAccessory.isOnline) {
66
+ this.log.error(this.name + ' is offline');
67
+ throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
68
+ }
69
+ this.lockInTransitionStart = Date.now();
70
+ this.service.updateCharacteristic(this.platform.Characteristic.LockTargetState, value);
71
+ this.multiServiceAccessory.sendCommand('lock', value ? 'lock' : 'unlock').then((success) => {
72
+ if (success) {
73
+ this.log.debug('onSet(' + value + ') SUCCESSFUL for ' + this.name);
74
+ this.multiServiceAccessory.forceNextStatusRefresh();
75
+ // this.deviceStatus.timestamp = 0; // Force refresh
76
+ }
77
+ else {
78
+ this.log.error(`Command failed for ${this.name}`);
79
+ }
80
+ });
81
+ }
82
+ // Get the current state of the lock
83
+ async getLockCurrentState() {
84
+ // if you need to return an error to show the device as "Not Responding" in the Home app:
85
+ // throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
86
+ this.log.debug('Received getLockState() event for ' + this.name);
87
+ return new Promise((resolve, reject) => {
88
+ this.getStatus().then(success => {
89
+ if (success) {
90
+ const lockState = this.deviceStatus.status.lock.lock.value;
91
+ this.log.debug(`LockState value from ${this.name}: ${lockState}`);
92
+ resolve(this.mapLockState(lockState));
93
+ }
94
+ else {
95
+ reject(new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */));
96
+ }
97
+ });
98
+ });
99
+ }
100
+ processEvent(event) {
101
+ this.log.debug(`Event updating lock capability for ${this.name} to ${event.value}`);
102
+ this.service.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.mapLockState(event.value));
103
+ if (event.value === 'locked') {
104
+ this.targetState = this.platform.Characteristic.LockTargetState.SECURED;
105
+ this.service.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.targetState);
106
+ }
107
+ else {
108
+ this.targetState = this.platform.Characteristic.LockTargetState.UNSECURED;
109
+ this.service.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.targetState);
110
+ }
111
+ }
112
+ mapLockState(lockState) {
113
+ switch (lockState) {
114
+ case 'locked': {
115
+ return (this.platform.Characteristic.LockCurrentState.SECURED);
116
+ }
117
+ case 'unlocked':
118
+ case 'unlocked with timeout': {
119
+ return (this.platform.Characteristic.LockCurrentState.UNSECURED);
120
+ }
121
+ default: {
122
+ return (this.platform.Characteristic.LockCurrentState.UNKNOWN);
123
+ }
124
+ }
125
+ }
126
+ }
127
+ exports.LockService = LockService;
128
+ //# sourceMappingURL=lockService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockService.js","sourceRoot":"","sources":["../../src/services/lockService.ts"],"names":[],"mappings":";;;AAEA,+CAA4C;A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@@ -0,0 +1,10 @@
1
+ import { PlatformAccessory } from 'homebridge';
2
+ import { IKHomeBridgeHomebridgePlatform } from '../platform';
3
+ import { MultiServiceAccessory } from '../multiServiceAccessory';
4
+ import { SensorService } from './sensorService';
5
+ import { ShortEvent } from '../webhook/subscriptionHandler';
6
+ export declare class MotionService extends SensorService {
7
+ constructor(platform: IKHomeBridgeHomebridgePlatform, accessory: PlatformAccessory, componentId: string, capabilities: string[], multiServiceAccessory: MultiServiceAccessory, name: string, deviceStatus: any);
8
+ processEvent(event: ShortEvent): void;
9
+ }
10
+ //# sourceMappingURL=motionService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motionService.d.ts","sourceRoot":"","sources":["../../src/services/motionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,qBAAa,aAAc,SAAQ,aAAa;gBAElC,QAAQ,EAAE,8BAA8B,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAC7H,qBAAqB,EAAE,qBAAqB,EAC5C,IAAI,EAAE,MAAM,EAAE,YAAY,KAAA;IAcrB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAI7C"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MotionService = void 0;
4
+ const sensorService_1 = require("./sensorService");
5
+ class MotionService extends sensorService_1.SensorService {
6
+ constructor(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus) {
7
+ super(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus);
8
+ this.log.debug(`Adding MotionService to ${this.name}`);
9
+ this.initService(platform.Service.MotionSensor, platform.Characteristic.MotionDetected, (status) => {
10
+ if (status.motionSensor.motion.value === null || status.motionSensor.motion.value === undefined) {
11
+ this.log.warn(`${this.name} returned bad value for status`);
12
+ throw ('Bad Value');
13
+ }
14
+ return status.motionSensor.motion.value === 'active' ? true : false;
15
+ });
16
+ }
17
+ processEvent(event) {
18
+ this.log.debug(`Updating ${this.name} from evnent to ${event.value}`);
19
+ this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, event.value === 'active' ? true : false);
20
+ }
21
+ }
22
+ exports.MotionService = MotionService;
23
+ //# sourceMappingURL=motionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motionService.js","sourceRoot":"","sources":["../../src/services/motionService.ts"],"names":[],"mappings":";;;AAGA,mDAAgD;AAGhD,MAAa,aAAc,SAAQ,6BAAa;IAE9C,YAAY,QAAwC,EAAE,SAA4B,EAAE,WAAmB,EAAE,YAAsB,EAC7H,qBAA4C,EAC5C,IAAY,EAAE,YAAY;QAC1B,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAEjG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE;YACjG,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC/F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,gCAAgC,CAAC,CAAC;gBAC5D,MAAK,CAAC,WAAW,CAAC,CAAC;aACpB;YACD,OAAO,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,YAAY,CAAC,KAAiB;QACnC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,IAAI,mBAAmB,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1H,CAAC;CACF;AAtBD,sCAsBC"}
@@ -0,0 +1,10 @@
1
+ import { PlatformAccessory } from 'homebridge';
2
+ import { IKHomeBridgeHomebridgePlatform } from '../platform';
3
+ import { MultiServiceAccessory } from '../multiServiceAccessory';
4
+ import { SensorService } from './sensorService';
5
+ import { ShortEvent } from '../webhook/subscriptionHandler';
6
+ export declare class OccupancySensorService extends SensorService {
7
+ constructor(platform: IKHomeBridgeHomebridgePlatform, accessory: PlatformAccessory, componentId: string, capabilities: string[], multiServiceAccessory: MultiServiceAccessory, name: string, deviceStatus: any);
8
+ processEvent(event: ShortEvent): void;
9
+ }
10
+ //# sourceMappingURL=occupancySensorService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"occupancySensorService.d.ts","sourceRoot":"","sources":["../../src/services/occupancySensorService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,qBAAa,sBAAuB,SAAQ,aAAa;gBAE3C,QAAQ,EAAE,8BAA8B,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAC7H,qBAAqB,EAAE,qBAAqB,EAC5C,IAAI,EAAE,MAAM,EAAE,YAAY,KAAA;IAcrB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAM7C"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OccupancySensorService = void 0;
4
+ const sensorService_1 = require("./sensorService");
5
+ class OccupancySensorService extends sensorService_1.SensorService {
6
+ constructor(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus) {
7
+ super(platform, accessory, componentId, capabilities, multiServiceAccessory, name, deviceStatus);
8
+ this.log.debug(`Adding OccupancySensorService to ${this.name}`);
9
+ this.initService(platform.Service.OccupancySensor, platform.Characteristic.OccupancyDetected, (status) => {
10
+ if (status.presenceSensor.presence.value === null || status.presenceSensor.presence.value === undefined) {
11
+ this.log.warn(`${this.name} returned bad value for status`);
12
+ throw ('Bad Value');
13
+ }
14
+ return status.presenceSensor.presence.value === 'present' ? 1 : 0;
15
+ });
16
+ }
17
+ processEvent(event) {
18
+ this.log.debug(`Event updating occupancy (presence) for ${this.name} to ${event.value}`);
19
+ this.service.updateCharacteristic(this.platform.Characteristic.OccupancyDetected, event.value === 'present' ? 1 : 0);
20
+ }
21
+ }
22
+ exports.OccupancySensorService = OccupancySensorService;
23
+ //# sourceMappingURL=occupancySensorService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"occupancySensorService.js","sourceRoot":"","sources":["../../src/services/occupancySensorService.ts"],"names":[],"mappings":";;;AAGA,mDAAgD;AAGhD,MAAa,sBAAuB,SAAQ,6BAAa;IAEvD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