@fredsocial/homebridge-tplink-tapo 0.1.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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/config.schema.json +347 -0
  4. package/lib/accessory-information.d.ts +4 -0
  5. package/lib/accessory-information.d.ts.map +1 -0
  6. package/lib/accessory-information.js +26 -0
  7. package/lib/accessory-information.js.map +1 -0
  8. package/lib/characteristics/amperes.d.ts +4 -0
  9. package/lib/characteristics/amperes.d.ts.map +1 -0
  10. package/lib/characteristics/amperes.js +15 -0
  11. package/lib/characteristics/amperes.js.map +1 -0
  12. package/lib/characteristics/default-characteristic.d.ts +3 -0
  13. package/lib/characteristics/default-characteristic.d.ts.map +1 -0
  14. package/lib/characteristics/default-characteristic.js +19 -0
  15. package/lib/characteristics/default-characteristic.js.map +1 -0
  16. package/lib/characteristics/index.d.ts +3 -0
  17. package/lib/characteristics/index.d.ts.map +1 -0
  18. package/lib/characteristics/index.js +25 -0
  19. package/lib/characteristics/index.js.map +1 -0
  20. package/lib/characteristics/kilowatt-hours.d.ts +4 -0
  21. package/lib/characteristics/kilowatt-hours.d.ts.map +1 -0
  22. package/lib/characteristics/kilowatt-hours.js +15 -0
  23. package/lib/characteristics/kilowatt-hours.js.map +1 -0
  24. package/lib/characteristics/kilowatt-volt-ampere-hour.d.ts +4 -0
  25. package/lib/characteristics/kilowatt-volt-ampere-hour.d.ts.map +1 -0
  26. package/lib/characteristics/kilowatt-volt-ampere-hour.js +16 -0
  27. package/lib/characteristics/kilowatt-volt-ampere-hour.js.map +1 -0
  28. package/lib/characteristics/types.d.ts +7 -0
  29. package/lib/characteristics/types.d.ts.map +1 -0
  30. package/lib/characteristics/types.js +4 -0
  31. package/lib/characteristics/types.js.map +1 -0
  32. package/lib/characteristics/volt-amperes.d.ts +4 -0
  33. package/lib/characteristics/volt-amperes.d.ts.map +1 -0
  34. package/lib/characteristics/volt-amperes.js +15 -0
  35. package/lib/characteristics/volt-amperes.js.map +1 -0
  36. package/lib/characteristics/volts.d.ts +4 -0
  37. package/lib/characteristics/volts.d.ts.map +1 -0
  38. package/lib/characteristics/volts.js +15 -0
  39. package/lib/characteristics/volts.js.map +1 -0
  40. package/lib/characteristics/watts.d.ts +4 -0
  41. package/lib/characteristics/watts.d.ts.map +1 -0
  42. package/lib/characteristics/watts.js +15 -0
  43. package/lib/characteristics/watts.js.map +1 -0
  44. package/lib/config.d.ts +180 -0
  45. package/lib/config.d.ts.map +1 -0
  46. package/lib/config.js +167 -0
  47. package/lib/config.js.map +1 -0
  48. package/lib/homekit-device/bulb.d.ts +41 -0
  49. package/lib/homekit-device/bulb.d.ts.map +1 -0
  50. package/lib/homekit-device/bulb.js +307 -0
  51. package/lib/homekit-device/bulb.js.map +1 -0
  52. package/lib/homekit-device/create.d.ts +11 -0
  53. package/lib/homekit-device/create.d.ts.map +1 -0
  54. package/lib/homekit-device/create.js +18 -0
  55. package/lib/homekit-device/create.js.map +1 -0
  56. package/lib/homekit-device/index.d.ts +33 -0
  57. package/lib/homekit-device/index.d.ts.map +1 -0
  58. package/lib/homekit-device/index.js +120 -0
  59. package/lib/homekit-device/index.js.map +1 -0
  60. package/lib/homekit-device/plug.d.ts +43 -0
  61. package/lib/homekit-device/plug.d.ts.map +1 -0
  62. package/lib/homekit-device/plug.js +244 -0
  63. package/lib/homekit-device/plug.js.map +1 -0
  64. package/lib/index.d.ts +4 -0
  65. package/lib/index.d.ts.map +1 -0
  66. package/lib/index.js +10 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/platform.d.ts +59 -0
  69. package/lib/platform.d.ts.map +1 -0
  70. package/lib/platform.js +301 -0
  71. package/lib/platform.js.map +1 -0
  72. package/lib/settings.d.ts +3 -0
  73. package/lib/settings.d.ts.map +1 -0
  74. package/lib/settings.js +6 -0
  75. package/lib/settings.js.map +1 -0
  76. package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.d.ts +3 -0
  77. package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.d.ts.map +1 -0
  78. package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.js +21 -0
  79. package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.js.map +1 -0
  80. package/lib/tapo/custom-characteristics/default-characteristic.d.ts +3 -0
  81. package/lib/tapo/custom-characteristics/default-characteristic.d.ts.map +1 -0
  82. package/lib/tapo/custom-characteristics/default-characteristic.js +19 -0
  83. package/lib/tapo/custom-characteristics/default-characteristic.js.map +1 -0
  84. package/lib/tapo/custom-characteristics/index.d.ts +3 -0
  85. package/lib/tapo/custom-characteristics/index.d.ts.map +1 -0
  86. package/lib/tapo/custom-characteristics/index.js +17 -0
  87. package/lib/tapo/custom-characteristics/index.js.map +1 -0
  88. package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.d.ts +3 -0
  89. package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.d.ts.map +1 -0
  90. package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.js +20 -0
  91. package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.js.map +1 -0
  92. package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.d.ts +3 -0
  93. package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.d.ts.map +1 -0
  94. package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.js +21 -0
  95. package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.js.map +1 -0
  96. package/lib/tapo/homekit-device/types.d.ts +30 -0
  97. package/lib/tapo/homekit-device/types.d.ts.map +1 -0
  98. package/lib/tapo/homekit-device/types.js +3 -0
  99. package/lib/tapo/homekit-device/types.js.map +1 -0
  100. package/lib/tapo/platform.d.ts +14 -0
  101. package/lib/tapo/platform.d.ts.map +1 -0
  102. package/lib/tapo/platform.js +3 -0
  103. package/lib/tapo/platform.js.map +1 -0
  104. package/lib/tapo/platformL510EAccessory.d.ts +31 -0
  105. package/lib/tapo/platformL510EAccessory.d.ts.map +1 -0
  106. package/lib/tapo/platformL510EAccessory.js +146 -0
  107. package/lib/tapo/platformL510EAccessory.js.map +1 -0
  108. package/lib/tapo/platformL520EAccessory.d.ts +42 -0
  109. package/lib/tapo/platformL520EAccessory.d.ts.map +1 -0
  110. package/lib/tapo/platformL520EAccessory.js +205 -0
  111. package/lib/tapo/platformL520EAccessory.js.map +1 -0
  112. package/lib/tapo/platformL530Accessory.d.ts +84 -0
  113. package/lib/tapo/platformL530Accessory.d.ts.map +1 -0
  114. package/lib/tapo/platformL530Accessory.js +439 -0
  115. package/lib/tapo/platformL530Accessory.js.map +1 -0
  116. package/lib/tapo/platformP100Accessory.d.ts +23 -0
  117. package/lib/tapo/platformP100Accessory.d.ts.map +1 -0
  118. package/lib/tapo/platformP100Accessory.js +72 -0
  119. package/lib/tapo/platformP100Accessory.js.map +1 -0
  120. package/lib/tapo/platformP110Accessory.d.ts +39 -0
  121. package/lib/tapo/platformP110Accessory.d.ts.map +1 -0
  122. package/lib/tapo/platformP110Accessory.js +146 -0
  123. package/lib/tapo/platformP110Accessory.js.map +1 -0
  124. package/lib/tapo/platformTPLinkAccessory.d.ts +29 -0
  125. package/lib/tapo/platformTPLinkAccessory.d.ts.map +1 -0
  126. package/lib/tapo/platformTPLinkAccessory.js +132 -0
  127. package/lib/tapo/platformTPLinkAccessory.js.map +1 -0
  128. package/lib/tapo/utils/energyUsage.d.ts +4 -0
  129. package/lib/tapo/utils/energyUsage.d.ts.map +1 -0
  130. package/lib/tapo/utils/energyUsage.js +8 -0
  131. package/lib/tapo/utils/energyUsage.js.map +1 -0
  132. package/lib/tapo/utils/l510e.d.ts +17 -0
  133. package/lib/tapo/utils/l510e.d.ts.map +1 -0
  134. package/lib/tapo/utils/l510e.js +47 -0
  135. package/lib/tapo/utils/l510e.js.map +1 -0
  136. package/lib/tapo/utils/l520e.d.ts +20 -0
  137. package/lib/tapo/utils/l520e.d.ts.map +1 -0
  138. package/lib/tapo/utils/l520e.js +65 -0
  139. package/lib/tapo/utils/l520e.js.map +1 -0
  140. package/lib/tapo/utils/l530.d.ts +22 -0
  141. package/lib/tapo/utils/l530.d.ts.map +1 -0
  142. package/lib/tapo/utils/l530.js +135 -0
  143. package/lib/tapo/utils/l530.js.map +1 -0
  144. package/lib/tapo/utils/newTpLinkCipher.d.ts +22 -0
  145. package/lib/tapo/utils/newTpLinkCipher.d.ts.map +1 -0
  146. package/lib/tapo/utils/newTpLinkCipher.js +88 -0
  147. package/lib/tapo/utils/newTpLinkCipher.js.map +1 -0
  148. package/lib/tapo/utils/p100.d.ts +117 -0
  149. package/lib/tapo/utils/p100.d.ts.map +1 -0
  150. package/lib/tapo/utils/p100.js +665 -0
  151. package/lib/tapo/utils/p100.js.map +1 -0
  152. package/lib/tapo/utils/p110.d.ts +16 -0
  153. package/lib/tapo/utils/p110.d.ts.map +1 -0
  154. package/lib/tapo/utils/p110.js +68 -0
  155. package/lib/tapo/utils/p110.js.map +1 -0
  156. package/lib/tapo/utils/powerUsage.d.ts +7 -0
  157. package/lib/tapo/utils/powerUsage.d.ts.map +1 -0
  158. package/lib/tapo/utils/powerUsage.js +10 -0
  159. package/lib/tapo/utils/powerUsage.js.map +1 -0
  160. package/lib/tapo/utils/tpLinkCipher.d.ts +12 -0
  161. package/lib/tapo/utils/tpLinkCipher.d.ts.map +1 -0
  162. package/lib/tapo/utils/tpLinkCipher.js +35 -0
  163. package/lib/tapo/utils/tpLinkCipher.js.map +1 -0
  164. package/lib/tapo/utils/tplinkAccessory.d.ts +22 -0
  165. package/lib/tapo/utils/tplinkAccessory.d.ts.map +1 -0
  166. package/lib/tapo/utils/tplinkAccessory.js +3 -0
  167. package/lib/tapo/utils/tplinkAccessory.js.map +1 -0
  168. package/lib/tapo/utils/usage.d.ts +6 -0
  169. package/lib/tapo/utils/usage.d.ts.map +1 -0
  170. package/lib/tapo/utils/usage.js +10 -0
  171. package/lib/tapo/utils/usage.js.map +1 -0
  172. package/lib/utils.d.ts +29 -0
  173. package/lib/utils.d.ts.map +1 -0
  174. package/lib/utils.js +129 -0
  175. package/lib/utils.js.map +1 -0
  176. package/package.json +116 -0
@@ -0,0 +1,439 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.L530Accessory = void 0;
7
+ const l530_1 = __importDefault(require("./utils/l530"));
8
+ const platformTPLinkAccessory_1 = require("./platformTPLinkAccessory");
9
+ /**
10
+ * L530 Accessory
11
+ * An instance of this class is created for each accessory your platform registers
12
+ * Each accessory may expose multiple services of different service types.
13
+ */
14
+ class L530Accessory extends platformTPLinkAccessory_1.TPLinkPlatformAccessory {
15
+ log;
16
+ platform;
17
+ accessory;
18
+ timeout;
19
+ updateInterval;
20
+ adaptiveLightingController;
21
+ fakeGatoHistoryService;
22
+ constructor(log, platform, accessory, timeout, updateInterval) {
23
+ super(log, platform, accessory, timeout, updateInterval);
24
+ this.log = log;
25
+ this.platform = platform;
26
+ this.accessory = accessory;
27
+ this.timeout = timeout;
28
+ this.updateInterval = updateInterval;
29
+ this.tpLinkAccessory = new l530_1.default(this.log, accessory.context.device.host, platform.config.username, platform.config.password, this.timeout);
30
+ this.fakeGatoHistoryService = new this.platform.FakeGatoHistoryService('energy', accessory, {
31
+ log: this.log,
32
+ size: 4096,
33
+ storage: 'fs',
34
+ });
35
+ this.initialise(platform, updateInterval);
36
+ // get the Outlet service if it exists, otherwise create a new Outlet service
37
+ this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);
38
+ // set the service name, this is what is displayed as the default name on the Home app
39
+ // we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
40
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
41
+ }
42
+ init(platform, updateInterval) {
43
+ this.log.debug('init called');
44
+ this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
45
+ this.log.debug('SysInfo: ', sysInfo);
46
+ // set accessory information
47
+ this.accessory.getService(this.platform.Service.AccessoryInformation)
48
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
49
+ .setCharacteristic(this.platform.Characteristic.Model, 'Tapo L530')
50
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, sysInfo.hw_id);
51
+ // each service must implement at-minimum the "required characteristics" for the given service type
52
+ // see https://developers.homebridge.io/#/service/Outlet
53
+ // register handlers for the On/Off Characteristic
54
+ this.service.getCharacteristic(this.platform.Characteristic.On)
55
+ .on('set', this.setOn.bind(this)) // SET - bind to the `setOn` method below
56
+ .on('get', this.getOn.bind(this)); // GET - bind to the `getOn` method below
57
+ // register handlers for the Brightness Characteristic
58
+ this.service.getCharacteristic(this.platform.Characteristic.Brightness)
59
+ .on('set', this.setBrightness.bind(this)) // SET - bind to the `setBrightness` method below
60
+ .on('get', this.getBrightness.bind(this)); // GET - bind to the `getBrightness` method below
61
+ // register handlers for the ColorTemperature Characteristic
62
+ this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature)
63
+ .on('set', this.setColorTemp.bind(this)) // SET - bind to the `setColorTemp` method below
64
+ .on('get', this.getColorTemp.bind(this))
65
+ .setProps({
66
+ minValue: 140,
67
+ maxValue: 400,
68
+ minStep: 1,
69
+ }); // GET - bind to the `getColorTemp` method below
70
+ // register handlers for the Hue Characteristic
71
+ this.service.getCharacteristic(this.platform.Characteristic.Hue)
72
+ .on('set', this.setHue.bind(this)) // SET - bind to the `setHue` method below
73
+ .on('get', this.getHue.bind(this)); // GET - bind to the `getHue` method below
74
+ // register handlers for the Saturation Characteristic
75
+ this.service.getCharacteristic(this.platform.Characteristic.Saturation)
76
+ .on('set', this.setSaturation.bind(this)) // SET - bind to the `setSaturation` method below
77
+ .on('get', this.getSaturation.bind(this)); // GET - bind to the `getSaturation` method below
78
+ this.service.addOptionalCharacteristic(this.platform.customCharacteristics.CurrentConsumptionCharacteristic);
79
+ this.service.getCharacteristic(this.platform.customCharacteristics.CurrentConsumptionCharacteristic)
80
+ .on('get', this.getCurrentConsumption.bind(this));
81
+ this.service.addOptionalCharacteristic(this.platform.customCharacteristics.TotalConsumptionCharacteristic);
82
+ this.service.getCharacteristic(this.platform.customCharacteristics.TotalConsumptionCharacteristic)
83
+ .on('get', this.getTotalConsumption.bind(this));
84
+ /* this.service.addOptionalCharacteristic(this.platform.customCharacteristics.ResetConsumptionCharacteristic);
85
+ this.service.getCharacteristic(this.platform.customCharacteristics.ResetConsumptionCharacteristic)
86
+ .on('set', this.resetConsumption.bind(this));*/
87
+ // Setup the adaptive lighting controller if available
88
+ if (this.platform.api.versionGreaterOrEqual && this.platform.api.versionGreaterOrEqual('1.3.0-beta.23')) {
89
+ this.log.debug('Enabling Adaptvie Lightning');
90
+ this.adaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
91
+ controllerMode: 1 /* this.platform.api.hap.AdaptiveLightingControllerMode.AUTOMATIC */,
92
+ });
93
+ this.accessory.configureController(this.adaptiveLightingController);
94
+ }
95
+ this.updateConsumption();
96
+ const interval = updateInterval ? updateInterval * 1000 : 10000;
97
+ setTimeout(() => {
98
+ this.updateState(interval);
99
+ }, interval);
100
+ }).catch(() => {
101
+ if (!this.tpLinkAccessory.is_klap) {
102
+ this.setNoResponse();
103
+ this.log.error('100 - Get Device Info failed');
104
+ }
105
+ });
106
+ }
107
+ /**
108
+ * Handle "SET" requests from HomeKit
109
+ * These are sent when the user changes the state of an accessory.
110
+ */
111
+ setBrightness(value, callback) {
112
+ if (this.tpLinkAccessory.getSysInfo().device_on) {
113
+ this.tpLinkAccessory.setBrightness(value).then((result) => {
114
+ if (result) {
115
+ this.platform.log.debug('Set Characteristic Brightness ->', value);
116
+ this.tpLinkAccessory.getSysInfo().brightness = value;
117
+ // you must call the callback function
118
+ callback(null);
119
+ }
120
+ else {
121
+ callback(new Error('unreachable'), false);
122
+ }
123
+ }).catch((error) => {
124
+ this.log.error('Failed to set brightness: ' + error);
125
+ callback(new Error('unreachable'), false);
126
+ });
127
+ }
128
+ else {
129
+ callback(null);
130
+ }
131
+ }
132
+ /**
133
+ * Handle the "GET" requests from HomeKit
134
+ * These are sent when HomeKit wants to know the current state of the accessory.
135
+ *
136
+ */
137
+ getBrightness(callback) {
138
+ this.tpLinkAccessory.getDeviceInfo().then((response) => {
139
+ this.log.debug('getBritness: ' + JSON.stringify(response));
140
+ if (response) {
141
+ const brightness = response.brightness;
142
+ if (brightness !== undefined) {
143
+ this.platform.log.debug('Get Characteristic Brightness ->', brightness);
144
+ // you must call the callback function
145
+ // the first argument should be null if there were no errors
146
+ // the second argument should be the value to return
147
+ // you must call the callback function
148
+ callback(null, brightness);
149
+ }
150
+ else {
151
+ this.log.debug('getBritness: ' + 167);
152
+ callback(new Error('unreachable'), 0);
153
+ }
154
+ }
155
+ else {
156
+ this.log.debug('getBritness: ' + 171);
157
+ callback(new Error('unreachable'), 0);
158
+ }
159
+ }).catch(() => {
160
+ this.log.debug('getBritness: ' + 175);
161
+ callback(new Error('unreachable'), 0);
162
+ });
163
+ }
164
+ /**
165
+ * Handle "SET" requests from HomeKit
166
+ * These are sent when the user changes the state of an accessory.
167
+ */
168
+ setColorTemp(value, callback) {
169
+ this.log.debug('Color Temp Homekit :' + value);
170
+ if (this.tpLinkAccessory.getSysInfo().device_on) {
171
+ this.tpLinkAccessory.setColorTemp(value).then((result) => {
172
+ if (result) {
173
+ this.tpLinkAccessory.getSysInfo().color_temp = value;
174
+ this.platform.log.debug('Set Characteristic Color Temperature ->', value);
175
+ // you must call the callback function
176
+ callback(null);
177
+ }
178
+ else {
179
+ callback(new Error('unreachable'), false);
180
+ }
181
+ }).catch((error) => {
182
+ this.log.error('Failed to set color temperature: ' + error);
183
+ callback(new Error('unreachable'), false);
184
+ });
185
+ }
186
+ else {
187
+ // you must call the callback function
188
+ callback(null);
189
+ }
190
+ }
191
+ /**
192
+ * Handle the "GET" requests from HomeKit
193
+ * These are sent when HomeKit wants to know the current state of the accessory.
194
+ *
195
+ */
196
+ getColorTemp(callback) {
197
+ this.tpLinkAccessory.getColorTemp().then((response) => {
198
+ this.log.debug('getColorTemp: ' + JSON.stringify(response));
199
+ if (response !== undefined) {
200
+ const color_temp = response;
201
+ this.platform.log.debug('Get Characteristic Color Temperature ->', color_temp);
202
+ // you must call the callback function
203
+ // the first argument should be null if there were no errors
204
+ // the second argument should be the value to return
205
+ // you must call the callback function
206
+ callback(null, color_temp);
207
+ }
208
+ else {
209
+ this.log.debug('getColorTemp: ' + 224);
210
+ callback(new Error('unreachable'), 0);
211
+ }
212
+ }).catch((error) => {
213
+ this.log.debug('getColorTemp: ' + 229);
214
+ this.log.debug('error: ' + error);
215
+ callback(new Error('unreachable'), 0);
216
+ });
217
+ }
218
+ /**
219
+ * Handle "SET" requests from HomeKit
220
+ * These are sent when the user changes the state of an accessory.
221
+ */
222
+ setHue(value, callback) {
223
+ if (this.tpLinkAccessory.getSysInfo().device_on) {
224
+ this.log.debug('Homekit Hue: ' + value);
225
+ this.tpLinkAccessory.setColor(Math.round(value), this.tpLinkAccessory.getSysInfo().saturation).then((result) => {
226
+ if (result) {
227
+ this.tpLinkAccessory.getSysInfo().hue = Math.round(value);
228
+ this.platform.log.debug('Set Characteristic Hue ->', Math.round(value));
229
+ this.platform.log.debug('With Characteristic Saturation ->', this.tpLinkAccessory.getSysInfo().saturation);
230
+ // you must call the callback function
231
+ callback(null);
232
+ }
233
+ else {
234
+ callback(new Error('unreachable'), false);
235
+ }
236
+ }).catch((error) => {
237
+ this.log.error('Failed to set hue: ' + error);
238
+ callback(new Error('unreachable'), false);
239
+ });
240
+ }
241
+ else {
242
+ callback(null);
243
+ }
244
+ }
245
+ /**
246
+ * Handle the "GET" requests from HomeKit
247
+ * These are sent when HomeKit wants to know the current state of the accessory.
248
+ *
249
+ */
250
+ getHue(callback) {
251
+ this.tpLinkAccessory.getDeviceInfo().then((response) => {
252
+ this.log.debug('getHue: ' + JSON.stringify(response));
253
+ if (response) {
254
+ let hue = response.hue;
255
+ this.platform.log.debug('Get Characteristic Hue ->', hue);
256
+ //Tapo only returns the hue value when a color has been set. So we need to hanle the cases when an color is not set
257
+ if (!hue) {
258
+ hue = 0;
259
+ }
260
+ // you must call the callback function
261
+ // the first argument should be null if there were no errors
262
+ // the second argument should be the value to return
263
+ // you must call the callback function
264
+ callback(null, hue);
265
+ }
266
+ else {
267
+ this.log.debug('getHue: ' + 282);
268
+ callback(new Error('unreachable'), 0);
269
+ }
270
+ }).catch((error) => {
271
+ this.log.debug('Unreachable');
272
+ this.log.debug('getHue: ' + 288);
273
+ this.log.debug('error: ' + error);
274
+ callback(new Error('unreachable'), 0);
275
+ });
276
+ }
277
+ /**
278
+ * Handle "SET" requests from HomeKit
279
+ * These are sent when the user changes the state of an accessory.
280
+ */
281
+ setSaturation(value, callback) {
282
+ if (this.tpLinkAccessory.getSysInfo().device_on) {
283
+ this.log.debug('Homekit Saturation: ' + value);
284
+ this.tpLinkAccessory.setColor(this.tpLinkAccessory.getSysInfo().hue, Math.round(value)).then((result) => {
285
+ if (result) {
286
+ this.tpLinkAccessory.getSysInfo().saturation = Math.round(value);
287
+ this.platform.log.debug('Set Characteristic Saturation ->', Math.round(value));
288
+ this.platform.log.debug('With Characteristic Hue ->', this.tpLinkAccessory.getSysInfo().hue);
289
+ // you must call the callback function
290
+ callback(null);
291
+ }
292
+ else {
293
+ callback(new Error('unreachable'), false);
294
+ }
295
+ }).catch((error) => {
296
+ this.log.error('Failed to set saturation: ' + error);
297
+ callback(new Error('unreachable'), false);
298
+ });
299
+ }
300
+ else {
301
+ callback(null);
302
+ }
303
+ }
304
+ /**
305
+ * Handle the "GET" requests from HomeKit
306
+ * These are sent when HomeKit wants to know the current state of the accessory.
307
+ *
308
+ */
309
+ getSaturation(callback) {
310
+ this.tpLinkAccessory.getDeviceInfo().then((response) => {
311
+ this.log.debug('getSaturation: ' + JSON.stringify(response));
312
+ if (response) {
313
+ let saturation = response.saturation;
314
+ this.platform.log.debug('Get Characteristic Saturation ->', saturation);
315
+ //Tapo only returns the saturation value when a color has been set. So we need to hanle the cases when an color is not set
316
+ if (!saturation) {
317
+ saturation = 0;
318
+ }
319
+ // you must call the callback function
320
+ // the first argument should be null if there were no errors
321
+ // the second argument should be the value to return
322
+ // you must call the callback function
323
+ callback(null, saturation);
324
+ }
325
+ else {
326
+ this.log.debug('getSaturation: ' + 341);
327
+ callback(new Error('unreachable'), 0);
328
+ }
329
+ }).catch((error) => {
330
+ this.log.debug('getSaturation: ' + 346);
331
+ this.log.debug('error: ' + error);
332
+ callback(new Error('unreachable'), 0);
333
+ });
334
+ }
335
+ updateConsumption() {
336
+ this.log.debug('updateConsumption called');
337
+ this.tpLinkAccessory.getEnergyUsage().then((response) => {
338
+ this.log.debug('Get Characteristic Power consumption ->', JSON.stringify(response));
339
+ if (response && response.power_usage) {
340
+ this.log.debug('Get Characteristic Power consumption ->', JSON.stringify(response));
341
+ if (this.fakeGatoHistoryService) {
342
+ this.fakeGatoHistoryService.addEntry({
343
+ time: new Date().getTime() / 1000,
344
+ power: this.tpLinkAccessory.getPowerConsumption().current,
345
+ });
346
+ }
347
+ }
348
+ }).catch((error) => {
349
+ this.log.error('Failed to get energy usage: ' + error);
350
+ });
351
+ setTimeout(() => {
352
+ this.updateConsumption();
353
+ }, 600000);
354
+ }
355
+ /**
356
+ * Handle the "GET" requests from HomeKit
357
+ * These are sent when HomeKit wants to know the current state of the accessory.
358
+ *
359
+ */
360
+ getCurrentConsumption(callback) {
361
+ const consumption = this.tpLinkAccessory.getPowerConsumption();
362
+ // you must call the callback function
363
+ // the first argument should be null if there were no errors
364
+ // the second argument should be the value to return
365
+ // you must call the callback function
366
+ callback(null, consumption.current);
367
+ }
368
+ /**
369
+ * Handle the "GET" requests from HomeKit
370
+ * These are sent when HomeKit wants to know the current state of the accessory.
371
+ *
372
+ */
373
+ getTotalConsumption(callback) {
374
+ const consumption = this.tpLinkAccessory.getPowerConsumption();
375
+ // you must call the callback function
376
+ // the first argument should be null if there were no errors
377
+ // the second argument should be the value to return
378
+ // you must call the callback function
379
+ callback(null, consumption.total);
380
+ }
381
+ /**
382
+ * Handle the "SET" requests from HomeKit
383
+ *
384
+ */
385
+ resetConsumption(value, callback) {
386
+ const now = Math.round(new Date().valueOf() / 1000);
387
+ const epoch = Math.round(new Date('2001-01-01T00:00:00Z').valueOf() / 1000);
388
+ this.service.updateCharacteristic(this.platform.customCharacteristics.ResetConsumptionCharacteristic, now - epoch);
389
+ this.service.updateCharacteristic(this.platform.customCharacteristics.TotalConsumptionCharacteristic, 0);
390
+ // you must call the callback function
391
+ // the first argument should be null if there were no errors
392
+ // the second argument should be the value to return
393
+ // you must call the callback function
394
+ callback(null);
395
+ }
396
+ updateState(interval) {
397
+ this.log.debug('updateState called');
398
+ this.tpLinkAccessory.getDeviceInfo(true).then((response) => {
399
+ if (response) {
400
+ this.log.debug('Device Info: ' + JSON.stringify(response));
401
+ const isOn = response.device_on;
402
+ const saturation = response.saturation;
403
+ const hue = response.hue;
404
+ const color_temp = response.color_temp;
405
+ const brightness = response.brightness;
406
+ this.platform.log.debug('Get Device Info ->', JSON.stringify(response));
407
+ if (isOn !== undefined) {
408
+ this.service.updateCharacteristic(this.platform.Characteristic.On, isOn);
409
+ }
410
+ else {
411
+ this.setNoResponse();
412
+ interval += 300000;
413
+ }
414
+ if (saturation) {
415
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, saturation);
416
+ }
417
+ if (hue) {
418
+ this.service.updateCharacteristic(this.platform.Characteristic.Hue, hue);
419
+ }
420
+ if (color_temp) {
421
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.tpLinkAccessory.calculateColorTemp(color_temp));
422
+ }
423
+ if (brightness) {
424
+ this.service.updateCharacteristic(this.platform.Characteristic.Brightness, brightness);
425
+ }
426
+ }
427
+ setTimeout(() => {
428
+ this.updateState(interval);
429
+ }, interval);
430
+ }).catch(() => {
431
+ this.setNoResponse();
432
+ setTimeout(() => {
433
+ this.updateState(interval + 300000);
434
+ }, interval);
435
+ });
436
+ }
437
+ }
438
+ exports.L530Accessory = L530Accessory;
439
+ //# sourceMappingURL=platformL530Accessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformL530Accessory.js","sourceRoot":"","sources":["../../src/tapo/platformL530Accessory.ts"],"names":[],"mappings":";;;;;;AAGA,wDAAgC;AAChC,uEAAoE;AAEpE;;;;GAIG;AACH,MAAa,aAAc,SAAQ,iDAA6B;IAK5C;IACG;IACA;IACA;IACA;IARb,0BAA0B,CAA8B;IAC/C,sBAAsB,CAAE;IAEzC,YACkB,GAAW,EACR,QAAsB,EACtB,SAA4B,EAC5B,OAAe,EACf,cAAuB;QAE1C,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;QANzC,QAAG,GAAH,GAAG,CAAQ;QACR,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAmB;QAC5B,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAS;QAI1C,IAAI,CAAC,eAAe,GAAG,IAAI,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EACzH,IAAI,CAAC,OAAO,CAAC,CAAC;QAEhB,IAAI,CAAC,sBAAsB,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE;YAC1F,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAC,IAAI;YACT,OAAO,EAAC,IAAI;SACb,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE1C,6EAA6E;QAC7E,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC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AC,CAAC,CAAC;IAGL,CAAC;CACF;AAzdD,sCAydC"}
@@ -0,0 +1,23 @@
1
+ import { PlatformAccessory, CharacteristicGetCallback, Logger } from 'homebridge';
2
+ import type { TapoPlatform } from './platform';
3
+ import P100 from './utils/p100';
4
+ import { TPLinkPlatformAccessory } from './platformTPLinkAccessory';
5
+ /**
6
+ * P100 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
+ export declare class P100Accessory extends TPLinkPlatformAccessory<P100> {
11
+ readonly log: Logger;
12
+ protected readonly platform: TapoPlatform;
13
+ protected readonly accessory: PlatformAccessory;
14
+ protected readonly timeout: number;
15
+ protected readonly updateInterval?: number | undefined;
16
+ constructor(log: Logger, platform: TapoPlatform, accessory: PlatformAccessory, timeout: number, updateInterval?: number | undefined);
17
+ protected init(platform: TapoPlatform, updateInterval?: number): void;
18
+ /**
19
+ * Handle requests to get the current value of the "Outlet In Use" characteristic
20
+ */
21
+ handleOutletInUseGet(callback: CharacteristicGetCallback): void;
22
+ }
23
+ //# sourceMappingURL=platformP100Accessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformP100Accessory.d.ts","sourceRoot":"","sources":["../../src/tapo/platformP100Accessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,IAAI,MAAM,cAAc,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,uBAAuB,CAAC,IAAI,CAAC;aAG5C,GAAG,EAAE,MAAM;IAC3B,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY;IACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iBAAiB;IAC/C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAClC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAJlB,GAAG,EAAE,MAAM,EACR,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,oBAAQ;IAkB5C,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE,MAAM;IAgC9D;;OAEG;IACH,oBAAoB,CAAC,QAAQ,EAAE,yBAAyB;CAQzD"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.P100Accessory = void 0;
7
+ const p100_1 = __importDefault(require("./utils/p100"));
8
+ const platformTPLinkAccessory_1 = require("./platformTPLinkAccessory");
9
+ /**
10
+ * P100 Accessory
11
+ * An instance of this class is created for each accessory your platform registers
12
+ * Each accessory may expose multiple services of different service types.
13
+ */
14
+ class P100Accessory extends platformTPLinkAccessory_1.TPLinkPlatformAccessory {
15
+ log;
16
+ platform;
17
+ accessory;
18
+ timeout;
19
+ updateInterval;
20
+ constructor(log, platform, accessory, timeout, updateInterval) {
21
+ super(log, platform, accessory, timeout, updateInterval);
22
+ this.log = log;
23
+ this.platform = platform;
24
+ this.accessory = accessory;
25
+ this.timeout = timeout;
26
+ this.updateInterval = updateInterval;
27
+ this.tpLinkAccessory = new p100_1.default(this.log, accessory.context.device.host, platform.config.username, platform.config.password, this.timeout);
28
+ this.initialise(platform, updateInterval);
29
+ // get the Outlet service if it exists, otherwise create a new Outlet service
30
+ this.service = this.accessory.getService(this.platform.Service.Outlet) || this.accessory.addService(this.platform.Service.Outlet);
31
+ // set the service name, this is what is displayed as the default name on the Home app
32
+ // we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
33
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
34
+ }
35
+ init(platform, updateInterval) {
36
+ this.tpLinkAccessory.getDeviceInfo(true).then((sysInfo) => {
37
+ // set accessory information
38
+ this.accessory.getService(this.platform.Service.AccessoryInformation)
39
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'TP-Link')
40
+ .setCharacteristic(this.platform.Characteristic.Model, 'Tapo P100')
41
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, sysInfo.hw_id);
42
+ // each service must implement at-minimum the "required characteristics" for the given service type
43
+ // see https://developers.homebridge.io/#/service/Outlet
44
+ // register handlers for the On/Off Characteristic
45
+ this.service.getCharacteristic(this.platform.Characteristic.On)
46
+ .on('set', this.setOn.bind(this)) // SET - bind to the `setOn` method below
47
+ .on('get', this.getOn.bind(this)); // GET - bind to the `getOn` method below
48
+ // register handlers for the OutletInUse Characteristic
49
+ this.service.getCharacteristic(this.platform.Characteristic.OutletInUse)
50
+ .on('get', this.handleOutletInUseGet.bind(this));
51
+ const interval = updateInterval ? updateInterval * 1000 : 10000;
52
+ this.log.debug('interval: ' + interval);
53
+ setTimeout(() => {
54
+ this.updateState(interval);
55
+ }, interval);
56
+ }).catch(() => {
57
+ this.setNoResponse();
58
+ this.log.error('52 - Get Device Info failed');
59
+ });
60
+ }
61
+ /**
62
+ * Handle requests to get the current value of the "Outlet In Use" characteristic
63
+ */
64
+ handleOutletInUseGet(callback) {
65
+ this.log.debug('Triggered GET OutletInUse');
66
+ //P100 does not expose this info so we assume it is always in use
67
+ const currentValue = 1;
68
+ callback(null, currentValue);
69
+ }
70
+ }
71
+ exports.P100Accessory = P100Accessory;
72
+ //# sourceMappingURL=platformP100Accessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformP100Accessory.js","sourceRoot":"","sources":["../../src/tapo/platformP100Accessory.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAgC;AAChC,uEAAoE;AAEpE;;;;GAIG;AACH,MAAa,aAAc,SAAQ,iDA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I,CAAC,aAAa,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,QAAmC;QACtD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE5C,iEAAiE;QACjE,MAAM,YAAY,GAAG,CAAC,CAAC;QAEvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC/B,CAAC;CACF;AApED,sCAoEC"}
@@ -0,0 +1,39 @@
1
+ import { PlatformAccessory, CharacteristicValue, CharacteristicGetCallback, Logger } from 'homebridge';
2
+ import type { TapoPlatform } from './platform';
3
+ import P110 from './utils/p110';
4
+ import { TPLinkPlatformAccessory } from './platformTPLinkAccessory';
5
+ /**
6
+ * P110 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
+ export declare class P110Accessory extends TPLinkPlatformAccessory<P110> {
11
+ readonly log: Logger;
12
+ protected readonly platform: TapoPlatform;
13
+ protected readonly accessory: PlatformAccessory;
14
+ protected readonly timeout: number;
15
+ protected readonly updateInterval?: number | undefined;
16
+ private readonly fakeGatoHistoryService?;
17
+ constructor(log: Logger, platform: TapoPlatform, accessory: PlatformAccessory, timeout: number, updateInterval?: number | undefined);
18
+ protected init(platform: TapoPlatform, updateInterval?: number): void;
19
+ private updateConsumption;
20
+ /**
21
+ * Handle the "GET" requests from HomeKit
22
+ * These are sent when HomeKit wants to know the current state of the accessory.
23
+ *
24
+ */
25
+ getCurrentConsumption(callback: CharacteristicGetCallback): void;
26
+ /**
27
+ * Handle the "GET" requests from HomeKit
28
+ * These are sent when HomeKit wants to know the current state of the accessory.
29
+ *
30
+ */
31
+ getTotalConsumption(callback: CharacteristicGetCallback): void;
32
+ /**
33
+ * Handle the "SET" requests from HomeKit
34
+ *
35
+ */
36
+ resetConsumption(value: CharacteristicValue, callback: CharacteristicGetCallback): void;
37
+ protected updateState(interval: number): void;
38
+ }
39
+ //# sourceMappingURL=platformP110Accessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformP110Accessory.d.ts","sourceRoot":"","sources":["../../src/tapo/platformP110Accessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,yBAAyB,EACxE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,IAAI,MAAM,cAAc,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,uBAAuB,CAAC,IAAI,CAAC;aAI5C,GAAG,EAAE,MAAM;IAC3B,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY;IACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,iBAAiB;IAC/C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAClC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC;IAPpC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;gBAGvB,GAAG,EAAE,MAAM,EACR,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,oBAAQ;IAuB5C,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE,MAAM;IAoC9D,OAAO,CAAC,iBAAiB;IAqBzB;;;;OAIG;IACH,qBAAqB,CAAC,QAAQ,EAAE,yBAAyB;IAczD;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,yBAAyB;IAcvD;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,yBAAyB;IAchF,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAC,MAAM;CAItC"}