@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.
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/config.schema.json +347 -0
- package/lib/accessory-information.d.ts +4 -0
- package/lib/accessory-information.d.ts.map +1 -0
- package/lib/accessory-information.js +26 -0
- package/lib/accessory-information.js.map +1 -0
- package/lib/characteristics/amperes.d.ts +4 -0
- package/lib/characteristics/amperes.d.ts.map +1 -0
- package/lib/characteristics/amperes.js +15 -0
- package/lib/characteristics/amperes.js.map +1 -0
- package/lib/characteristics/default-characteristic.d.ts +3 -0
- package/lib/characteristics/default-characteristic.d.ts.map +1 -0
- package/lib/characteristics/default-characteristic.js +19 -0
- package/lib/characteristics/default-characteristic.js.map +1 -0
- package/lib/characteristics/index.d.ts +3 -0
- package/lib/characteristics/index.d.ts.map +1 -0
- package/lib/characteristics/index.js +25 -0
- package/lib/characteristics/index.js.map +1 -0
- package/lib/characteristics/kilowatt-hours.d.ts +4 -0
- package/lib/characteristics/kilowatt-hours.d.ts.map +1 -0
- package/lib/characteristics/kilowatt-hours.js +15 -0
- package/lib/characteristics/kilowatt-hours.js.map +1 -0
- package/lib/characteristics/kilowatt-volt-ampere-hour.d.ts +4 -0
- package/lib/characteristics/kilowatt-volt-ampere-hour.d.ts.map +1 -0
- package/lib/characteristics/kilowatt-volt-ampere-hour.js +16 -0
- package/lib/characteristics/kilowatt-volt-ampere-hour.js.map +1 -0
- package/lib/characteristics/types.d.ts +7 -0
- package/lib/characteristics/types.d.ts.map +1 -0
- package/lib/characteristics/types.js +4 -0
- package/lib/characteristics/types.js.map +1 -0
- package/lib/characteristics/volt-amperes.d.ts +4 -0
- package/lib/characteristics/volt-amperes.d.ts.map +1 -0
- package/lib/characteristics/volt-amperes.js +15 -0
- package/lib/characteristics/volt-amperes.js.map +1 -0
- package/lib/characteristics/volts.d.ts +4 -0
- package/lib/characteristics/volts.d.ts.map +1 -0
- package/lib/characteristics/volts.js +15 -0
- package/lib/characteristics/volts.js.map +1 -0
- package/lib/characteristics/watts.d.ts +4 -0
- package/lib/characteristics/watts.d.ts.map +1 -0
- package/lib/characteristics/watts.js +15 -0
- package/lib/characteristics/watts.js.map +1 -0
- package/lib/config.d.ts +180 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +167 -0
- package/lib/config.js.map +1 -0
- package/lib/homekit-device/bulb.d.ts +41 -0
- package/lib/homekit-device/bulb.d.ts.map +1 -0
- package/lib/homekit-device/bulb.js +307 -0
- package/lib/homekit-device/bulb.js.map +1 -0
- package/lib/homekit-device/create.d.ts +11 -0
- package/lib/homekit-device/create.d.ts.map +1 -0
- package/lib/homekit-device/create.js +18 -0
- package/lib/homekit-device/create.js.map +1 -0
- package/lib/homekit-device/index.d.ts +33 -0
- package/lib/homekit-device/index.d.ts.map +1 -0
- package/lib/homekit-device/index.js +120 -0
- package/lib/homekit-device/index.js.map +1 -0
- package/lib/homekit-device/plug.d.ts +43 -0
- package/lib/homekit-device/plug.d.ts.map +1 -0
- package/lib/homekit-device/plug.js +244 -0
- package/lib/homekit-device/plug.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/platform.d.ts +59 -0
- package/lib/platform.d.ts.map +1 -0
- package/lib/platform.js +301 -0
- package/lib/platform.js.map +1 -0
- package/lib/settings.d.ts +3 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/settings.js +6 -0
- package/lib/settings.js.map +1 -0
- package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.d.ts +3 -0
- package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.d.ts.map +1 -0
- package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.js +21 -0
- package/lib/tapo/custom-characteristics/currentConsumptionCharacteristic.js.map +1 -0
- package/lib/tapo/custom-characteristics/default-characteristic.d.ts +3 -0
- package/lib/tapo/custom-characteristics/default-characteristic.d.ts.map +1 -0
- package/lib/tapo/custom-characteristics/default-characteristic.js +19 -0
- package/lib/tapo/custom-characteristics/default-characteristic.js.map +1 -0
- package/lib/tapo/custom-characteristics/index.d.ts +3 -0
- package/lib/tapo/custom-characteristics/index.d.ts.map +1 -0
- package/lib/tapo/custom-characteristics/index.js +17 -0
- package/lib/tapo/custom-characteristics/index.js.map +1 -0
- package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.d.ts +3 -0
- package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.d.ts.map +1 -0
- package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.js +20 -0
- package/lib/tapo/custom-characteristics/resetConsumptionCharacteristic.js.map +1 -0
- package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.d.ts +3 -0
- package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.d.ts.map +1 -0
- package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.js +21 -0
- package/lib/tapo/custom-characteristics/totalConsumptionCharacteristic.js.map +1 -0
- package/lib/tapo/homekit-device/types.d.ts +30 -0
- package/lib/tapo/homekit-device/types.d.ts.map +1 -0
- package/lib/tapo/homekit-device/types.js +3 -0
- package/lib/tapo/homekit-device/types.js.map +1 -0
- package/lib/tapo/platform.d.ts +14 -0
- package/lib/tapo/platform.d.ts.map +1 -0
- package/lib/tapo/platform.js +3 -0
- package/lib/tapo/platform.js.map +1 -0
- package/lib/tapo/platformL510EAccessory.d.ts +31 -0
- package/lib/tapo/platformL510EAccessory.d.ts.map +1 -0
- package/lib/tapo/platformL510EAccessory.js +146 -0
- package/lib/tapo/platformL510EAccessory.js.map +1 -0
- package/lib/tapo/platformL520EAccessory.d.ts +42 -0
- package/lib/tapo/platformL520EAccessory.d.ts.map +1 -0
- package/lib/tapo/platformL520EAccessory.js +205 -0
- package/lib/tapo/platformL520EAccessory.js.map +1 -0
- package/lib/tapo/platformL530Accessory.d.ts +84 -0
- package/lib/tapo/platformL530Accessory.d.ts.map +1 -0
- package/lib/tapo/platformL530Accessory.js +439 -0
- package/lib/tapo/platformL530Accessory.js.map +1 -0
- package/lib/tapo/platformP100Accessory.d.ts +23 -0
- package/lib/tapo/platformP100Accessory.d.ts.map +1 -0
- package/lib/tapo/platformP100Accessory.js +72 -0
- package/lib/tapo/platformP100Accessory.js.map +1 -0
- package/lib/tapo/platformP110Accessory.d.ts +39 -0
- package/lib/tapo/platformP110Accessory.d.ts.map +1 -0
- package/lib/tapo/platformP110Accessory.js +146 -0
- package/lib/tapo/platformP110Accessory.js.map +1 -0
- package/lib/tapo/platformTPLinkAccessory.d.ts +29 -0
- package/lib/tapo/platformTPLinkAccessory.d.ts.map +1 -0
- package/lib/tapo/platformTPLinkAccessory.js +132 -0
- package/lib/tapo/platformTPLinkAccessory.js.map +1 -0
- package/lib/tapo/utils/energyUsage.d.ts +4 -0
- package/lib/tapo/utils/energyUsage.d.ts.map +1 -0
- package/lib/tapo/utils/energyUsage.js +8 -0
- package/lib/tapo/utils/energyUsage.js.map +1 -0
- package/lib/tapo/utils/l510e.d.ts +17 -0
- package/lib/tapo/utils/l510e.d.ts.map +1 -0
- package/lib/tapo/utils/l510e.js +47 -0
- package/lib/tapo/utils/l510e.js.map +1 -0
- package/lib/tapo/utils/l520e.d.ts +20 -0
- package/lib/tapo/utils/l520e.d.ts.map +1 -0
- package/lib/tapo/utils/l520e.js +65 -0
- package/lib/tapo/utils/l520e.js.map +1 -0
- package/lib/tapo/utils/l530.d.ts +22 -0
- package/lib/tapo/utils/l530.d.ts.map +1 -0
- package/lib/tapo/utils/l530.js +135 -0
- package/lib/tapo/utils/l530.js.map +1 -0
- package/lib/tapo/utils/newTpLinkCipher.d.ts +22 -0
- package/lib/tapo/utils/newTpLinkCipher.d.ts.map +1 -0
- package/lib/tapo/utils/newTpLinkCipher.js +88 -0
- package/lib/tapo/utils/newTpLinkCipher.js.map +1 -0
- package/lib/tapo/utils/p100.d.ts +117 -0
- package/lib/tapo/utils/p100.d.ts.map +1 -0
- package/lib/tapo/utils/p100.js +665 -0
- package/lib/tapo/utils/p100.js.map +1 -0
- package/lib/tapo/utils/p110.d.ts +16 -0
- package/lib/tapo/utils/p110.d.ts.map +1 -0
- package/lib/tapo/utils/p110.js +68 -0
- package/lib/tapo/utils/p110.js.map +1 -0
- package/lib/tapo/utils/powerUsage.d.ts +7 -0
- package/lib/tapo/utils/powerUsage.d.ts.map +1 -0
- package/lib/tapo/utils/powerUsage.js +10 -0
- package/lib/tapo/utils/powerUsage.js.map +1 -0
- package/lib/tapo/utils/tpLinkCipher.d.ts +12 -0
- package/lib/tapo/utils/tpLinkCipher.d.ts.map +1 -0
- package/lib/tapo/utils/tpLinkCipher.js +35 -0
- package/lib/tapo/utils/tpLinkCipher.js.map +1 -0
- package/lib/tapo/utils/tplinkAccessory.d.ts +22 -0
- package/lib/tapo/utils/tplinkAccessory.d.ts.map +1 -0
- package/lib/tapo/utils/tplinkAccessory.js +3 -0
- package/lib/tapo/utils/tplinkAccessory.js.map +1 -0
- package/lib/tapo/utils/usage.d.ts +6 -0
- package/lib/tapo/utils/usage.d.ts.map +1 -0
- package/lib/tapo/utils/usage.js +10 -0
- package/lib/tapo/utils/usage.js.map +1 -0
- package/lib/utils.d.ts +29 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +129 -0
- package/lib/utils.js.map +1 -0
- package/package.json +116 -0
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
const _1 = __importDefault(require("."));
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
class HomeKitDevicePlug extends _1.default {
|
|
9
|
+
config;
|
|
10
|
+
tplinkDevice;
|
|
11
|
+
desiredPowerState;
|
|
12
|
+
constructor(platform, config, homebridgeAccessory, tplinkDevice) {
|
|
13
|
+
super(platform, config, homebridgeAccessory, tplinkDevice, (() => {
|
|
14
|
+
if (config.switchModels &&
|
|
15
|
+
config.switchModels.findIndex((m) => tplinkDevice.model.includes(m)) !== -1) {
|
|
16
|
+
return 8 /* Categories.SWITCH */;
|
|
17
|
+
}
|
|
18
|
+
return tplinkDevice.supportsDimmer
|
|
19
|
+
? 5 /* Categories.LIGHTBULB */
|
|
20
|
+
: 7 /* Categories.OUTLET */;
|
|
21
|
+
})());
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.tplinkDevice = tplinkDevice;
|
|
24
|
+
let primaryService;
|
|
25
|
+
if (this.category === 5 /* Categories.LIGHTBULB */) {
|
|
26
|
+
primaryService = this.addLightbulbService();
|
|
27
|
+
this.removeOutletService();
|
|
28
|
+
this.removeSwitchService();
|
|
29
|
+
}
|
|
30
|
+
else if (this.category === 7 /* Categories.OUTLET */) {
|
|
31
|
+
primaryService = this.addOutletService();
|
|
32
|
+
this.removeBrightnessCharacteristic(primaryService);
|
|
33
|
+
this.removeLightbulbService();
|
|
34
|
+
this.removeSwitchService();
|
|
35
|
+
}
|
|
36
|
+
else if (this.category === 8 /* Categories.SWITCH */) {
|
|
37
|
+
primaryService = this.addSwitchService();
|
|
38
|
+
this.removeBrightnessCharacteristic(primaryService);
|
|
39
|
+
this.removeLightbulbService();
|
|
40
|
+
this.removeOutletService();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`constructor: Invalid category: ${this.category} (${this.category.toString()})`);
|
|
44
|
+
}
|
|
45
|
+
if (platform.config.addCustomCharacteristics &&
|
|
46
|
+
tplinkDevice.supportsEmeter) {
|
|
47
|
+
this.addEnergyCharacteristics(primaryService);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.removeEnergyCharacteristics(primaryService);
|
|
51
|
+
}
|
|
52
|
+
this.getSysInfo = (0, utils_1.deferAndCombine)((requestCount) => {
|
|
53
|
+
this.log.debug(`executing deferred getSysInfo count: ${requestCount}`);
|
|
54
|
+
return this.tplinkDevice.getSysInfo();
|
|
55
|
+
}, platform.config.waitTimeUpdate);
|
|
56
|
+
this.setPowerState = (0, utils_1.deferAndCombine)(async (requestCount) => {
|
|
57
|
+
this.log.debug(`executing deferred setPowerState count: ${requestCount}`);
|
|
58
|
+
if (this.desiredPowerState === undefined) {
|
|
59
|
+
this.log.warn('setPowerState called with undefined desiredPowerState');
|
|
60
|
+
return Promise.resolve(true);
|
|
61
|
+
}
|
|
62
|
+
const ret = await this.tplinkDevice.setPowerState(this.desiredPowerState);
|
|
63
|
+
this.desiredPowerState = undefined;
|
|
64
|
+
return ret;
|
|
65
|
+
}, platform.config.waitTimeUpdate, (value) => {
|
|
66
|
+
this.desiredPowerState = value;
|
|
67
|
+
});
|
|
68
|
+
this.getRealtime = (0, utils_1.deferAndCombine)((requestCount) => {
|
|
69
|
+
this.log.debug(`executing deferred getRealtime count: ${requestCount}`);
|
|
70
|
+
return this.tplinkDevice.emeter.getRealtime();
|
|
71
|
+
}, platform.config.waitTimeUpdate);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Aggregates getSysInfo requests
|
|
75
|
+
*
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
getSysInfo;
|
|
79
|
+
/**
|
|
80
|
+
* Aggregates setPowerState requests
|
|
81
|
+
*
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
setPowerState;
|
|
85
|
+
/**
|
|
86
|
+
* Aggregates getRealtime requests
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
getRealtime;
|
|
91
|
+
addOutletService() {
|
|
92
|
+
const { Outlet } = this.platform.Service;
|
|
93
|
+
const { Characteristic } = this.platform;
|
|
94
|
+
const outletService = this.homebridgeAccessory.getService(Outlet) ??
|
|
95
|
+
this.addService(Outlet, this.name);
|
|
96
|
+
this.addOnCharacteristic(outletService);
|
|
97
|
+
if (this.category === 7 /* Categories.OUTLET */) {
|
|
98
|
+
const outletInUseCharacteristic = (0, utils_1.getOrAddCharacteristic)(outletService, Characteristic.OutletInUse);
|
|
99
|
+
outletInUseCharacteristic.onGet(() => {
|
|
100
|
+
this.getSysInfo().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
101
|
+
return this.tplinkDevice.inUse; // immediately returned cached value
|
|
102
|
+
});
|
|
103
|
+
this.tplinkDevice.on('in-use-update', (value) => {
|
|
104
|
+
this.updateValue(outletService, outletInUseCharacteristic, value);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return outletService;
|
|
108
|
+
}
|
|
109
|
+
removeOutletService() {
|
|
110
|
+
this.removeServiceIfExists(this.platform.Service.Outlet);
|
|
111
|
+
}
|
|
112
|
+
addSwitchService() {
|
|
113
|
+
const { Switch } = this.platform.Service;
|
|
114
|
+
const switchService = this.homebridgeAccessory.getService(Switch) ??
|
|
115
|
+
this.addService(Switch, this.name);
|
|
116
|
+
this.addOnCharacteristic(switchService);
|
|
117
|
+
return switchService;
|
|
118
|
+
}
|
|
119
|
+
removeSwitchService() {
|
|
120
|
+
this.removeServiceIfExists(this.platform.Service.Switch);
|
|
121
|
+
}
|
|
122
|
+
addLightbulbService() {
|
|
123
|
+
const { Lightbulb } = this.platform.Service;
|
|
124
|
+
const lightbulbService = this.homebridgeAccessory.getService(Lightbulb) ??
|
|
125
|
+
this.addService(Lightbulb, this.name);
|
|
126
|
+
this.addOnCharacteristic(lightbulbService);
|
|
127
|
+
return lightbulbService;
|
|
128
|
+
}
|
|
129
|
+
removeLightbulbService() {
|
|
130
|
+
this.removeServiceIfExists(this.platform.Service.Lightbulb);
|
|
131
|
+
}
|
|
132
|
+
addOnCharacteristic(service) {
|
|
133
|
+
const onCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, this.platform.Characteristic.On);
|
|
134
|
+
onCharacteristic
|
|
135
|
+
.onGet(() => {
|
|
136
|
+
this.getSysInfo().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
137
|
+
return this.tplinkDevice.relayState; // immediately returned cached value
|
|
138
|
+
})
|
|
139
|
+
.onSet(async (value) => {
|
|
140
|
+
this.log.info(`Setting On to: ${value}`);
|
|
141
|
+
if (typeof value === 'boolean') {
|
|
142
|
+
await this.setPowerState(value);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.log.warn('setValue: Invalid On:', value);
|
|
146
|
+
throw new Error(`setValue: Invalid On: ${value}`);
|
|
147
|
+
});
|
|
148
|
+
this.tplinkDevice.on('power-update', (value) => {
|
|
149
|
+
this.updateValue(service, onCharacteristic, value);
|
|
150
|
+
});
|
|
151
|
+
this.addBrightnessCharacteristic(service);
|
|
152
|
+
return service;
|
|
153
|
+
}
|
|
154
|
+
addBrightnessCharacteristic(service) {
|
|
155
|
+
const brightnessCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, this.platform.Characteristic.Brightness);
|
|
156
|
+
brightnessCharacteristic
|
|
157
|
+
.onGet(() => {
|
|
158
|
+
this.getSysInfo().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
159
|
+
return this.tplinkDevice.dimmer.brightness; // immediately returned cached value
|
|
160
|
+
})
|
|
161
|
+
.onSet(async (value) => {
|
|
162
|
+
this.log.info(`Setting Brightness to: ${value}`);
|
|
163
|
+
if (typeof value === 'number') {
|
|
164
|
+
if (value > 0) {
|
|
165
|
+
await this.tplinkDevice.dimmer.setBrightness(value);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
await this.tplinkDevice.setPowerState(false);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.log.warn('setValue: Invalid Brightness:', value);
|
|
173
|
+
throw new Error(`setValue: Invalid Brightness: ${value}`);
|
|
174
|
+
});
|
|
175
|
+
this.tplinkDevice.on('brightness-update', (value) => {
|
|
176
|
+
this.updateValue(service, brightnessCharacteristic, value);
|
|
177
|
+
});
|
|
178
|
+
return service;
|
|
179
|
+
}
|
|
180
|
+
removeBrightnessCharacteristic(service) {
|
|
181
|
+
this.removeCharacteristicIfExists(service, this.platform.Characteristic.Brightness);
|
|
182
|
+
}
|
|
183
|
+
addEnergyCharacteristics(service) {
|
|
184
|
+
const { Amperes, KilowattHours, VoltAmperes, Volts, Watts } = this.platform.customCharacteristics;
|
|
185
|
+
const amperesCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, Amperes);
|
|
186
|
+
amperesCharacteristic.onGet(() => {
|
|
187
|
+
this.getRealtime().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
188
|
+
return this.tplinkDevice.emeter.realtime.current ?? 0; // immediately returned cached value
|
|
189
|
+
});
|
|
190
|
+
const kilowattCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, KilowattHours);
|
|
191
|
+
kilowattCharacteristic.onGet(() => {
|
|
192
|
+
this.getRealtime().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
193
|
+
return this.tplinkDevice.emeter.realtime.total ?? 0; // immediately returned cached value
|
|
194
|
+
});
|
|
195
|
+
const voltAmperesCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, VoltAmperes);
|
|
196
|
+
voltAmperesCharacteristic.onGet(() => {
|
|
197
|
+
this.getRealtime().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
198
|
+
const { realtime } = this.tplinkDevice.emeter;
|
|
199
|
+
return (realtime.voltage ?? 0) * (realtime.voltage ?? 0); // immediately returned cached value
|
|
200
|
+
});
|
|
201
|
+
const voltsCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, Volts);
|
|
202
|
+
voltsCharacteristic.onGet(() => {
|
|
203
|
+
this.getRealtime().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
204
|
+
return this.tplinkDevice.emeter.realtime.voltage ?? 0; // immediately returned cached value
|
|
205
|
+
});
|
|
206
|
+
const wattsCharacteristic = (0, utils_1.getOrAddCharacteristic)(service, Watts);
|
|
207
|
+
wattsCharacteristic.onGet(() => {
|
|
208
|
+
this.getRealtime().catch(this.logRejection.bind(this)); // this will eventually trigger update
|
|
209
|
+
return this.tplinkDevice.emeter.realtime.power ?? 0; // immediately returned cached value
|
|
210
|
+
});
|
|
211
|
+
this.tplinkDevice.on('emeter-realtime-update', (emeterRealtime) => {
|
|
212
|
+
this.updateValue(service, amperesCharacteristic, emeterRealtime.current ?? null);
|
|
213
|
+
this.updateValue(service, kilowattCharacteristic, emeterRealtime.total ?? null);
|
|
214
|
+
this.updateValue(service, voltAmperesCharacteristic, emeterRealtime.voltage != null && emeterRealtime.current != null
|
|
215
|
+
? emeterRealtime.voltage * emeterRealtime.current
|
|
216
|
+
: null);
|
|
217
|
+
this.updateValue(service, voltsCharacteristic, emeterRealtime.voltage ?? null);
|
|
218
|
+
this.updateValue(service, wattsCharacteristic, emeterRealtime.power ?? null);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
removeEnergyCharacteristics(service) {
|
|
222
|
+
const { Amperes, KilowattHours, VoltAmperes, Volts, Watts } = this.platform.customCharacteristics;
|
|
223
|
+
[Amperes, KilowattHours, VoltAmperes, Volts, Watts].forEach((characteristic) => {
|
|
224
|
+
this.removeCharacteristicIfExists(service, characteristic);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
identify() {
|
|
228
|
+
this.log.info(`identify`);
|
|
229
|
+
this.tplinkDevice
|
|
230
|
+
.blink(1, 500)
|
|
231
|
+
.then(() => {
|
|
232
|
+
return this.tplinkDevice.blink(2, 500);
|
|
233
|
+
})
|
|
234
|
+
.then(() => {
|
|
235
|
+
this.log.debug(`identify done`);
|
|
236
|
+
})
|
|
237
|
+
.catch((reason) => {
|
|
238
|
+
this.log.error(`identify complete`);
|
|
239
|
+
this.log.error(reason);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.default = HomeKitDevicePlug;
|
|
244
|
+
//# sourceMappingURL=plug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,CAAC,mBAAmB,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AA9VD,oCA8VC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;8BAKvB,GAAG,KAAG,IAAI;AAAzB,kBAEE"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const settings_1 = require("./settings");
|
|
6
|
+
const platform_1 = __importDefault(require("./platform"));
|
|
7
|
+
module.exports = (api) => {
|
|
8
|
+
api.registerPlatform(settings_1.PLATFORM_NAME, platform_1.default);
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAEA,yCAA2C;AAC3C,0DAAiD;AAEjD,iBAAS,CAAC,GAAQ,EAAQ,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,wBAAa,EAAE,kBAAuB,CAAC,CAAC;AAC/D,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Categories } from 'homebridge';
|
|
2
|
+
import type { API, Characteristic, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service, WithUUID } from 'homebridge';
|
|
3
|
+
import type { TapoDeviceConfigInput, TplinkSmarthomeConfig } from './config';
|
|
4
|
+
export type TplinkSmarthomeAccessoryContext = {
|
|
5
|
+
deviceId?: string;
|
|
6
|
+
device?: TapoDeviceConfigInput;
|
|
7
|
+
};
|
|
8
|
+
export default class TplinkSmarthomePlatform implements DynamicPlatformPlugin {
|
|
9
|
+
readonly log: Logging;
|
|
10
|
+
readonly api: API;
|
|
11
|
+
readonly Service: typeof Service;
|
|
12
|
+
readonly Characteristic: typeof Characteristic;
|
|
13
|
+
customCharacteristics: Record<string, WithUUID<new () => Characteristic>>;
|
|
14
|
+
readonly FakeGatoHistoryService: any;
|
|
15
|
+
config: TplinkSmarthomeConfig;
|
|
16
|
+
private readonly configuredAccessories;
|
|
17
|
+
private readonly homekitDevicesById;
|
|
18
|
+
private readonly categories;
|
|
19
|
+
constructor(log: Logging, config: PlatformConfig, api: API);
|
|
20
|
+
/**
|
|
21
|
+
* Return string representation of Service/Characteristic for logging
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
lsc(serviceOrCharacteristic: Service | Characteristic | {
|
|
26
|
+
UUID: string;
|
|
27
|
+
}, characteristic?: Characteristic | {
|
|
28
|
+
UUID: string;
|
|
29
|
+
}): string;
|
|
30
|
+
private get deviceAccessoriesByHost();
|
|
31
|
+
private createHomekitDevice;
|
|
32
|
+
getCategoryName(category: Categories): string | undefined;
|
|
33
|
+
getServiceName(service: {
|
|
34
|
+
UUID: string;
|
|
35
|
+
}): string | undefined;
|
|
36
|
+
getCharacteristicName(characteristic: WithUUID<{
|
|
37
|
+
name?: string;
|
|
38
|
+
displayName?: string;
|
|
39
|
+
}>): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Registers a Homebridge PlatformAccessory.
|
|
42
|
+
*
|
|
43
|
+
* Calls {@link external:homebridge.API#registerPlatformAccessories}
|
|
44
|
+
*/
|
|
45
|
+
registerPlatformAccessory(platformAccessory: PlatformAccessory<TplinkSmarthomeAccessoryContext>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Function invoked when homebridge tries to restore cached accessory
|
|
48
|
+
*/
|
|
49
|
+
configureAccessory(accessory: PlatformAccessory<TplinkSmarthomeAccessoryContext>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Adds a new or existing real device.
|
|
52
|
+
*/
|
|
53
|
+
private foundDevice;
|
|
54
|
+
private discoverTapoDevices;
|
|
55
|
+
private registerTapoDevice;
|
|
56
|
+
private createTapoAccessory;
|
|
57
|
+
private static isTapoLight;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EACV,GAAG,EACH,cAAc,EACd,qBAAqB,EACrB,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,QAAQ,EACT,MAAM,YAAY,CAAC;AAWpB,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAkB7E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,uBAAwB,YAAW,qBAAqB;aAwBzD,GAAG,EAAE,OAAO;aAEZ,GAAG,EAAE,GAAG;IAzB1B,SAAgB,OAAO,iBAAC;IAExB,SAAgB,cAAc,wBAAC;IAExB,qBAAqB,EAAE,MAAM,CAClC,MAAM,EACN,QAAQ,CAAC,UAAU,cAAc,CAAC,CACnC,CAAC;IAEF,SAAgB,sBAAsB,MAAC;IAEhC,MAAM,EAAE,qBAAqB,CAAC;IAErC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAGxB;IAEd,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAyC;IAE5E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsC;gBAG/C,GAAG,EAAE,OAAO,EAC5B,MAAM,EAAE,cAAc,EACN,GAAG,EAAE,GAAG;IA6J1B;;;;OAIG;IACI,GAAG,CACR,uBAAuB,EAAE,OAAO,GAAG,cAAc,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EACpE,cAAc,CAAC,EAAE,cAAc,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GACjD,MAAM;IA2BT,OAAO,KAAK,uBAAuB,GAYlC;IAED,OAAO,CAAC,mBAAmB;IAO3B,eAAe,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS;IAIzD,cAAc,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,SAAS;IAW7D,qBAAqB,CACnB,cAAc,EAAE,QAAQ,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAChE,MAAM,GAAG,SAAS;IAkBrB;;;;OAIG;IACH,yBAAyB,CACvB,iBAAiB,EAAE,iBAAiB,CAAC,+BAA+B,CAAC,GACpE,IAAI;IAWP;;OAEG;IACH,kBAAkB,CAChB,SAAS,EAAE,iBAAiB,CAAC,+BAA+B,CAAC,GAC5D,IAAI;IAYP;;OAEG;IACH,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,kBAAkB;IAqC1B,OAAO,CAAC,mBAAmB;IAoD3B,OAAO,CAAC,MAAM,CAAC,WAAW;CAc3B"}
|
package/lib/platform.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
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
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const fakegato_history_1 = __importDefault(require("fakegato-history"));
|
|
10
|
+
const semver_1 = require("semver");
|
|
11
|
+
const tplink_smarthome_api_1 = require("tplink-smarthome-api");
|
|
12
|
+
const config_1 = require("./config");
|
|
13
|
+
const characteristics_1 = __importDefault(require("./characteristics"));
|
|
14
|
+
const settings_1 = require("./settings");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const create_1 = __importDefault(require("./homekit-device/create"));
|
|
17
|
+
const custom_characteristics_1 = __importDefault(require("./tapo/custom-characteristics"));
|
|
18
|
+
const platformL510EAccessory_1 = require("./tapo/platformL510EAccessory");
|
|
19
|
+
const platformL520EAccessory_1 = require("./tapo/platformL520EAccessory");
|
|
20
|
+
const platformL530Accessory_1 = require("./tapo/platformL530Accessory");
|
|
21
|
+
const platformP100Accessory_1 = require("./tapo/platformP100Accessory");
|
|
22
|
+
const platformP110Accessory_1 = require("./tapo/platformP110Accessory");
|
|
23
|
+
// okay for reading json
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
|
+
const packageConfig = require('../package.json');
|
|
26
|
+
class TplinkSmarthomePlatform {
|
|
27
|
+
log;
|
|
28
|
+
api;
|
|
29
|
+
Service;
|
|
30
|
+
Characteristic;
|
|
31
|
+
customCharacteristics;
|
|
32
|
+
FakeGatoHistoryService;
|
|
33
|
+
config;
|
|
34
|
+
configuredAccessories = new Map();
|
|
35
|
+
homekitDevicesById = new Map();
|
|
36
|
+
categories = new Map();
|
|
37
|
+
constructor(log, config, api) {
|
|
38
|
+
this.log = log;
|
|
39
|
+
this.api = api;
|
|
40
|
+
this.log.info('%s v%s, node %s, homebridge v%s, api v%s', packageConfig.name, packageConfig.version, process.version, api.serverVersion, api.version);
|
|
41
|
+
if (!(0, semver_1.satisfies)(process.version, packageConfig.engines.node)) {
|
|
42
|
+
this.log.error('Error: not using minimum node version %s', packageConfig.engines.node);
|
|
43
|
+
}
|
|
44
|
+
if (api.versionGreaterOrEqual == null ||
|
|
45
|
+
!api.versionGreaterOrEqual('1.3.0')) {
|
|
46
|
+
this.log.error(`homebridge-tplink-tapo requires homebridge >= 1.3.0. Currently running: ${api.serverVersion}`);
|
|
47
|
+
throw new Error(`homebridge-tplink-tapo requires homebridge >= 1.3.0. Currently running: ${api.serverVersion}`);
|
|
48
|
+
}
|
|
49
|
+
this.Service = this.api.hap.Service;
|
|
50
|
+
this.Characteristic = this.api.hap.Characteristic;
|
|
51
|
+
this.log.debug('config.json: %j', config);
|
|
52
|
+
this.config = (0, config_1.parseConfig)(config);
|
|
53
|
+
this.log.debug('config: %j', this.config);
|
|
54
|
+
this.customCharacteristics = {
|
|
55
|
+
...(0, characteristics_1.default)(api.hap.Characteristic),
|
|
56
|
+
...(0, custom_characteristics_1.default)(api.hap.Characteristic),
|
|
57
|
+
};
|
|
58
|
+
this.FakeGatoHistoryService = (0, fakegato_history_1.default)(this.api);
|
|
59
|
+
this.categories.set(5 /* Categories.LIGHTBULB */, 'LIGHTBULB');
|
|
60
|
+
this.categories.set(7 /* Categories.OUTLET */, 'OUTLET');
|
|
61
|
+
this.categories.set(8 /* Categories.SWITCH */, 'SWITCH');
|
|
62
|
+
const tplinkApiLogger = Object.assign(() => { }, this.log, {
|
|
63
|
+
prefix: `${this.log.prefix || settings_1.PLATFORM_NAME}.API`,
|
|
64
|
+
});
|
|
65
|
+
const client = new tplink_smarthome_api_1.Client({
|
|
66
|
+
logger: tplinkApiLogger,
|
|
67
|
+
defaultSendOptions: this.config.defaultSendOptions,
|
|
68
|
+
});
|
|
69
|
+
client.on('device-new', (device) => {
|
|
70
|
+
this.log.info(`Device First Online: ${chalk_1.default.blue(`[${device.alias}]`)} %s [%s]`, device.deviceType, device.id, device.host, device.port);
|
|
71
|
+
this.foundDevice(device);
|
|
72
|
+
});
|
|
73
|
+
client.on('device-online', (device) => {
|
|
74
|
+
this.log.debug(`Device Online: ${chalk_1.default.blue(`[${device.alias}]`)} %s [%s]`, device.deviceType, device.id, device.host, device.port);
|
|
75
|
+
this.foundDevice(device);
|
|
76
|
+
});
|
|
77
|
+
client.on('device-offline', (device) => {
|
|
78
|
+
const deviceAccessory = this.homekitDevicesById.get(device.id);
|
|
79
|
+
if (deviceAccessory !== undefined) {
|
|
80
|
+
this.log.debug(`Device Offline: ${chalk_1.default.blue(`[${device.alias}]`)} %s [%s]`, deviceAccessory.homebridgeAccessory.displayName, device.deviceType, device.id, device.host, device.port);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
this.api.on("didFinishLaunching" /* APIEvent.DID_FINISH_LAUNCHING */, () => {
|
|
84
|
+
this.log.debug("didFinishLaunching" /* APIEvent.DID_FINISH_LAUNCHING */);
|
|
85
|
+
client.startDiscovery({
|
|
86
|
+
...this.config.discoveryOptions,
|
|
87
|
+
filterCallback: (si) => {
|
|
88
|
+
return si.deviceId != null && si.deviceId.length > 0;
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
this.discoverTapoDevices();
|
|
92
|
+
const refreshEmeterForAccessories = async (accessories) => {
|
|
93
|
+
for (const acc of accessories) {
|
|
94
|
+
const device = acc.tplinkDevice;
|
|
95
|
+
if (device.supportsEmeter) {
|
|
96
|
+
this.log.debug(`getEmeterRealtime ${chalk_1.default.blue(`[${device.alias}]`)}`);
|
|
97
|
+
// eslint-disable-next-line no-await-in-loop
|
|
98
|
+
await device.emeter.getRealtime().catch((reason) => {
|
|
99
|
+
this.log.error('[%s] %s', device.alias, 'emeter.getRealtime()');
|
|
100
|
+
this.log.error(reason);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const refreshEmeter = async () => {
|
|
106
|
+
this.log.debug(`${chalk_1.default.magenta('refreshEmeter()')}`);
|
|
107
|
+
if (this.config.emeterPollingInterval <= 0)
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
const deviceAccessories = this.deviceAccessoriesByHost;
|
|
111
|
+
const promises = [];
|
|
112
|
+
for (const accForHost of deviceAccessories.values()) {
|
|
113
|
+
promises.push(refreshEmeterForAccessories(accForHost));
|
|
114
|
+
}
|
|
115
|
+
await Promise.all(promises);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
this.log.error(`Error in ${chalk_1.default.magenta('refreshEmeter()')}:`);
|
|
119
|
+
this.log.error(String(err));
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
this.log.debug(`Scheduling next run of ${chalk_1.default.magenta('refreshEmeter()')} in %d(ms)`, this.config.emeterPollingInterval);
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
refreshEmeter();
|
|
125
|
+
}, this.config.emeterPollingInterval);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
if (this.config.emeterPollingInterval > 0)
|
|
129
|
+
refreshEmeter();
|
|
130
|
+
});
|
|
131
|
+
this.api.on('shutdown', () => {
|
|
132
|
+
this.log.debug('shutdown');
|
|
133
|
+
client.stopDiscovery();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Return string representation of Service/Characteristic for logging
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
lsc(serviceOrCharacteristic, characteristic) {
|
|
142
|
+
let serviceName;
|
|
143
|
+
let characteristicName;
|
|
144
|
+
if (serviceOrCharacteristic instanceof this.api.hap.Service) {
|
|
145
|
+
serviceName = this.getServiceName(serviceOrCharacteristic);
|
|
146
|
+
}
|
|
147
|
+
else if (serviceOrCharacteristic instanceof this.api.hap.Characteristic ||
|
|
148
|
+
('UUID' in serviceOrCharacteristic &&
|
|
149
|
+
typeof serviceOrCharacteristic.UUID === 'string')) {
|
|
150
|
+
characteristicName = this.getCharacteristicName(serviceOrCharacteristic);
|
|
151
|
+
}
|
|
152
|
+
if (characteristic instanceof this.api.hap.Characteristic) {
|
|
153
|
+
characteristicName = this.getCharacteristicName(characteristic);
|
|
154
|
+
}
|
|
155
|
+
if (serviceName != null && characteristicName != null) {
|
|
156
|
+
return `[${chalk_1.default.yellow(serviceName)}.${chalk_1.default.green(characteristicName)}]`;
|
|
157
|
+
}
|
|
158
|
+
if (serviceName !== undefined)
|
|
159
|
+
return `[${chalk_1.default.yellow(serviceName)}]`;
|
|
160
|
+
return `[${chalk_1.default.green(characteristicName)}]`;
|
|
161
|
+
}
|
|
162
|
+
get deviceAccessoriesByHost() {
|
|
163
|
+
const byHost = new Map();
|
|
164
|
+
for (const [, tpLinkAccessory] of this.homekitDevicesById) {
|
|
165
|
+
const { host } = tpLinkAccessory.tplinkDevice;
|
|
166
|
+
const arr = byHost.get(host);
|
|
167
|
+
if (arr != null) {
|
|
168
|
+
arr.push(tpLinkAccessory);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
byHost.set(host, [tpLinkAccessory]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return byHost;
|
|
175
|
+
}
|
|
176
|
+
createHomekitDevice(accessory, tplinkDevice) {
|
|
177
|
+
return (0, create_1.default)(this, this.config, accessory, tplinkDevice);
|
|
178
|
+
}
|
|
179
|
+
getCategoryName(category) {
|
|
180
|
+
return this.categories.get(category);
|
|
181
|
+
}
|
|
182
|
+
getServiceName(service) {
|
|
183
|
+
return (0, utils_1.lookup)(this.api.hap.Service, (thisKeyValue, value) => (0, utils_1.isObjectLike)(thisKeyValue) &&
|
|
184
|
+
'UUID' in thisKeyValue &&
|
|
185
|
+
thisKeyValue.UUID === value, service.UUID);
|
|
186
|
+
}
|
|
187
|
+
getCharacteristicName(characteristic) {
|
|
188
|
+
if ('name' in characteristic && characteristic.name !== undefined)
|
|
189
|
+
return characteristic.name;
|
|
190
|
+
if ('displayName' in characteristic &&
|
|
191
|
+
characteristic.displayName !== undefined)
|
|
192
|
+
return characteristic.displayName;
|
|
193
|
+
if ('UUID' in characteristic) {
|
|
194
|
+
return (0, utils_1.lookupCharacteristicNameByUUID)(this.api.hap.Characteristic, characteristic.UUID);
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Registers a Homebridge PlatformAccessory.
|
|
200
|
+
*
|
|
201
|
+
* Calls {@link external:homebridge.API#registerPlatformAccessories}
|
|
202
|
+
*/
|
|
203
|
+
registerPlatformAccessory(platformAccessory) {
|
|
204
|
+
this.log.debug(`registerPlatformAccessory(${chalk_1.default.blue(`[${platformAccessory.displayName}]`)})`);
|
|
205
|
+
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [
|
|
206
|
+
platformAccessory,
|
|
207
|
+
]);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Function invoked when homebridge tries to restore cached accessory
|
|
211
|
+
*/
|
|
212
|
+
configureAccessory(accessory) {
|
|
213
|
+
this.log.info(`Configuring cached accessory: ${chalk_1.default.blue(`[${accessory.displayName}]`)} UUID: ${accessory.UUID} deviceId: %s `, accessory.context?.deviceId);
|
|
214
|
+
this.log.debug('%O', accessory.context);
|
|
215
|
+
this.configuredAccessories.set(accessory.UUID, accessory);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Adds a new or existing real device.
|
|
219
|
+
*/
|
|
220
|
+
foundDevice(device) {
|
|
221
|
+
const deviceId = device.id;
|
|
222
|
+
if (deviceId == null || deviceId.length === 0) {
|
|
223
|
+
this.log.error('Missing deviceId: %s', device.host);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (this.homekitDevicesById.get(deviceId) !== undefined) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.log.info(`Adding: ${chalk_1.default.blue(`[${device.alias}]`)} %s [%s]`, device.deviceType, deviceId);
|
|
230
|
+
const uuid = this.api.hap.uuid.generate(deviceId);
|
|
231
|
+
const accessory = this.configuredAccessories.get(uuid);
|
|
232
|
+
this.homekitDevicesById.set(device.id, this.createHomekitDevice(accessory, device));
|
|
233
|
+
}
|
|
234
|
+
discoverTapoDevices() {
|
|
235
|
+
if (this.config.tapo.devices.length === 0)
|
|
236
|
+
return;
|
|
237
|
+
if (this.config.username === '' || this.config.password === '') {
|
|
238
|
+
this.log.warn('Skipping configured Tapo devices because username/password are not set');
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
for (const device of this.config.tapo.devices) {
|
|
242
|
+
this.registerTapoDevice(device);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
registerTapoDevice(device) {
|
|
246
|
+
const uuid = this.api.hap.uuid.generate(device.host + (device.name != null ? device.name : ''));
|
|
247
|
+
const displayName = device.name ?? device.host;
|
|
248
|
+
const existingAccessory = this.configuredAccessories.get(uuid);
|
|
249
|
+
const category = TplinkSmarthomePlatform.isTapoLight(device)
|
|
250
|
+
? 5 /* Categories.LIGHTBULB */
|
|
251
|
+
: 7 /* Categories.OUTLET */;
|
|
252
|
+
const PlatformAccessoryCtor = this.api.platformAccessory;
|
|
253
|
+
const accessory = existingAccessory ??
|
|
254
|
+
new PlatformAccessoryCtor(displayName, uuid, category);
|
|
255
|
+
accessory.context.device = {
|
|
256
|
+
...device,
|
|
257
|
+
name: displayName,
|
|
258
|
+
};
|
|
259
|
+
this.createTapoAccessory(accessory, device);
|
|
260
|
+
if (existingAccessory != null) {
|
|
261
|
+
this.log.info(`Restoring configured Tapo accessory: ${chalk_1.default.blue(`[${displayName}]`)}`);
|
|
262
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.log.info(`Adding configured Tapo accessory: ${chalk_1.default.blue(`[${displayName}]`)}`);
|
|
266
|
+
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [
|
|
267
|
+
accessory,
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
createTapoAccessory(accessory, device) {
|
|
271
|
+
const timeout = device.timeout ?? 2;
|
|
272
|
+
const type = device.type?.toLowerCase() ?? 'plug';
|
|
273
|
+
if (type === 'colorlight' || type === 'l530' || type === 'l530e') {
|
|
274
|
+
return new platformL530Accessory_1.L530Accessory(this.log, this, accessory, timeout, device.updateInterval);
|
|
275
|
+
}
|
|
276
|
+
if (type === 'whitelight' || type === 'l520' || type === 'l520e') {
|
|
277
|
+
return new platformL520EAccessory_1.L520EAccessory(this.log, this, accessory, timeout, device.updateInterval);
|
|
278
|
+
}
|
|
279
|
+
if (type === 'light' || type === 'l510' || type === 'l510e') {
|
|
280
|
+
return new platformL510EAccessory_1.L510EAccessory(this.log, this, accessory, timeout, device.updateInterval);
|
|
281
|
+
}
|
|
282
|
+
if (type === 'powerplug' || type === 'p110') {
|
|
283
|
+
return new platformP110Accessory_1.P110Accessory(this.log, this, accessory, timeout, device.updateInterval);
|
|
284
|
+
}
|
|
285
|
+
return new platformP100Accessory_1.P100Accessory(this.log, this, accessory, timeout, device.updateInterval);
|
|
286
|
+
}
|
|
287
|
+
static isTapoLight(device) {
|
|
288
|
+
const type = device.type?.toLowerCase();
|
|
289
|
+
return (type === 'colorlight' ||
|
|
290
|
+
type === 'whitelight' ||
|
|
291
|
+
type === 'light' ||
|
|
292
|
+
type === 'l510' ||
|
|
293
|
+
type === 'l510e' ||
|
|
294
|
+
type === 'l520' ||
|
|
295
|
+
type === 'l520e' ||
|
|
296
|
+
type === 'l530' ||
|
|
297
|
+
type === 'l530e');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.default = TplinkSmarthomePlatform;
|
|
301
|
+
//# sourceMappingURL=platform.js.map
|