tsvesync 1.0.11
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 +227 -0
- package/api/vesync/VeSync.yaml +33 -0
- package/api/vesyncbulb/ESL100.yaml +74 -0
- package/api/vesyncbulb/ESL100CW.yaml +123 -0
- package/api/vesyncbulb/ESL100MC.yaml +169 -0
- package/api/vesyncbulb/XYD0001.yaml +193 -0
- package/api/vesyncfan/Classic200S.yaml +280 -0
- package/api/vesyncfan/Classic300S.yaml +278 -0
- package/api/vesyncfan/Core200S.yaml +256 -0
- package/api/vesyncfan/Core300S.yaml +281 -0
- package/api/vesyncfan/Core400S.yaml +281 -0
- package/api/vesyncfan/Core600S.yaml +281 -0
- package/api/vesyncfan/Dual200S.yaml +278 -0
- package/api/vesyncfan/LAP-C201S-AUSR.yaml +256 -0
- package/api/vesyncfan/LAP-C202S-WUSR.yaml +256 -0
- package/api/vesyncfan/LAP-C301S-WAAA.yaml +281 -0
- package/api/vesyncfan/LAP-C301S-WJP.yaml +281 -0
- package/api/vesyncfan/LAP-C302S-WUSB.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WAAA.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WJP.yaml +281 -0
- package/api/vesyncfan/LAP-C401S-WUSR.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WEU.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WUS.yaml +281 -0
- package/api/vesyncfan/LAP-C601S-WUSR.yaml +281 -0
- package/api/vesyncfan/LAP-EL551S-AEUR.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-AUS.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-EL551S-WUS.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-AASR.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WJP.yaml +167 -0
- package/api/vesyncfan/LAP-V102S-WUS.yaml +167 -0
- package/api/vesyncfan/LAP-V201-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AASR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AEUR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-AUSR.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WEU.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WJP.yaml +167 -0
- package/api/vesyncfan/LAP-V201S-WUS.yaml +167 -0
- package/api/vesyncfan/LEH-S601S-WUS.yaml +303 -0
- package/api/vesyncfan/LEH-S601S-WUSR.yaml +82 -0
- package/api/vesyncfan/LTF-F422S-KEU.yaml +165 -0
- package/api/vesyncfan/LTF-F422S-WUS.yaml +165 -0
- package/api/vesyncfan/LTF-F422S-WUSR.yaml +167 -0
- package/api/vesyncfan/LTF-F422_WJP.yaml +165 -0
- package/api/vesyncfan/LUH-A601S-AUSW.yaml +82 -0
- package/api/vesyncfan/LUH-A601S-WUSB.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WEU.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WEUR.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WJP.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUS.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUSC.yaml +305 -0
- package/api/vesyncfan/LUH-A602S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WEU.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WJP.yaml +305 -0
- package/api/vesyncfan/LUH-D301S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-M101S-WUS.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WEU.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WUS.yaml +278 -0
- package/api/vesyncfan/LUH-O451S-WUSR.yaml +305 -0
- package/api/vesyncfan/LUH-O601S-KUS.yaml +305 -0
- package/api/vesyncfan/LUH-O601S-WUS.yaml +305 -0
- package/api/vesyncfan/LV-PUR131S.yaml +108 -0
- package/api/vesyncfan/LV-RH131S.yaml +108 -0
- package/api/vesyncoutlet/ESO15-TB.yaml +124 -0
- package/api/vesyncoutlet/ESW01-EU.yaml +122 -0
- package/api/vesyncoutlet/ESW03-USA.yaml +122 -0
- package/api/vesyncoutlet/ESW15-USA.yaml +156 -0
- package/api/vesyncoutlet/wifi-switch-1.3.yaml +60 -0
- package/api/vesyncswitch/ESWD16.yaml +128 -0
- package/api/vesyncswitch/ESWL01.yaml +56 -0
- package/api/vesyncswitch/ESWL03.yaml +56 -0
- package/dist/lib/helpers.d.ts +87 -0
- package/dist/lib/helpers.js +222 -0
- package/dist/lib/helpers.js.map +1 -0
- package/dist/lib/vesync.d.ts +47 -0
- package/dist/lib/vesync.js +309 -0
- package/dist/lib/vesync.js.map +1 -0
- package/dist/lib/vesyncBaseDevice.d.ts +68 -0
- package/dist/lib/vesyncBaseDevice.js +116 -0
- package/dist/lib/vesyncBaseDevice.js.map +1 -0
- package/dist/lib/vesyncBulb.d.ts +0 -0
- package/dist/lib/vesyncBulb.js +2 -0
- package/dist/lib/vesyncBulb.js.map +1 -0
- package/dist/lib/vesyncFan.d.ts +92 -0
- package/dist/lib/vesyncFan.js +265 -0
- package/dist/lib/vesyncFan.js.map +1 -0
- package/dist/lib/vesyncKitchen.d.ts +0 -0
- package/dist/lib/vesyncKitchen.js +2 -0
- package/dist/lib/vesyncKitchen.js.map +1 -0
- package/dist/lib/vesyncOutlet.d.ts +0 -0
- package/dist/lib/vesyncOutlet.js +2 -0
- package/dist/lib/vesyncOutlet.js.map +1 -0
- package/dist/lib/vesyncSwitch.d.ts +0 -0
- package/dist/lib/vesyncSwitch.js +2 -0
- package/dist/lib/vesyncSwitch.js.map +1 -0
- package/dist/src/lib/helpers.d.ts +88 -0
- package/dist/src/lib/helpers.js +244 -0
- package/dist/src/lib/vesync.d.ts +89 -0
- package/dist/src/lib/vesync.js +430 -0
- package/dist/src/lib/vesyncBaseDevice.d.ts +43 -0
- package/dist/src/lib/vesyncBaseDevice.js +87 -0
- package/dist/src/lib/vesyncBulb.d.ts +79 -0
- package/dist/src/lib/vesyncBulb.js +198 -0
- package/dist/src/lib/vesyncBulbImpl.d.ts +38 -0
- package/dist/src/lib/vesyncBulbImpl.js +161 -0
- package/dist/src/lib/vesyncFan.d.ts +80 -0
- package/dist/src/lib/vesyncFan.js +406 -0
- package/dist/src/lib/vesyncFanImpl.d.ts +137 -0
- package/dist/src/lib/vesyncFanImpl.js +643 -0
- package/dist/src/lib/vesyncOutlet.d.ts +53 -0
- package/dist/src/lib/vesyncOutlet.js +98 -0
- package/dist/src/lib/vesyncOutletImpl.d.ts +70 -0
- package/dist/src/lib/vesyncOutletImpl.js +206 -0
- package/dist/src/lib/vesyncSwitch.d.ts +169 -0
- package/dist/src/lib/vesyncSwitch.js +414 -0
- package/dist/src/lib/vesyncSwitchImpl.d.ts +82 -0
- package/dist/src/lib/vesyncSwitchImpl.js +290 -0
- package/dist/test/testFeatures.d.ts +4 -0
- package/dist/test/testFeatures.js +394 -0
- package/dist/test/testService.d.ts +62 -0
- package/dist/test/testService.js +540 -0
- package/dist/test/testSpecial.d.ts +5 -0
- package/dist/test/testSpecial.js +227 -0
- package/package.json +53 -0
- package/src/lib/helpers.ts +290 -0
- package/src/lib/vesync.ts +530 -0
- package/src/lib/vesyncBaseDevice.ts +114 -0
- package/src/lib/vesyncBulb.ts +252 -0
- package/src/lib/vesyncBulbImpl.ts +215 -0
- package/src/lib/vesyncFan.ts +447 -0
- package/src/lib/vesyncFanImpl.ts +848 -0
- package/src/lib/vesyncOutlet.ts +148 -0
- package/src/lib/vesyncOutletImpl.ts +284 -0
- package/src/lib/vesyncSwitch.ts +546 -0
- package/src/lib/vesyncSwitchImpl.ts +408 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var _a;
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.VeSync = void 0;
|
|
38
|
+
/**
|
|
39
|
+
* VeSync API Device Library
|
|
40
|
+
*/
|
|
41
|
+
const helpers_1 = require("./helpers");
|
|
42
|
+
const bulbMods = __importStar(require("./vesyncBulb"));
|
|
43
|
+
const fanMods = __importStar(require("./vesyncFan"));
|
|
44
|
+
const outletMods = __importStar(require("./vesyncOutlet"));
|
|
45
|
+
const switchMods = __importStar(require("./vesyncSwitch"));
|
|
46
|
+
const kitchenMods = __importStar(require("./vesyncKitchen"));
|
|
47
|
+
const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
|
|
48
|
+
function objectFactory(devType, config, manager) {
|
|
49
|
+
const fans = (devType, config, manager) => {
|
|
50
|
+
const fanCls = fanMods.fanModules[devType];
|
|
51
|
+
return ['fans', new fanCls(config, manager)];
|
|
52
|
+
};
|
|
53
|
+
const outlets = (devType, config, manager) => {
|
|
54
|
+
const outletCls = outletMods.outletModules[devType];
|
|
55
|
+
return ['outlets', new outletCls(config, manager)];
|
|
56
|
+
};
|
|
57
|
+
const switches = (devType, config, manager) => {
|
|
58
|
+
const switchCls = switchMods.switchModules[devType];
|
|
59
|
+
return ['switches', new switchCls(config, manager)];
|
|
60
|
+
};
|
|
61
|
+
const bulbs = (devType, config, manager) => {
|
|
62
|
+
const bulbCls = bulbMods.bulbModules[devType];
|
|
63
|
+
return ['bulbs', new bulbCls(config, manager)];
|
|
64
|
+
};
|
|
65
|
+
const kitchen = (devType, config, manager) => {
|
|
66
|
+
const kitchenCls = kitchenMods.kitchenModules[devType];
|
|
67
|
+
return ['kitchen', new kitchenCls(config, manager)];
|
|
68
|
+
};
|
|
69
|
+
if (devType in fanMods.fanModules) {
|
|
70
|
+
return fans(devType, config, manager);
|
|
71
|
+
}
|
|
72
|
+
else if (devType in outletMods.outletModules) {
|
|
73
|
+
return outlets(devType, config, manager);
|
|
74
|
+
}
|
|
75
|
+
else if (devType in switchMods.switchModules) {
|
|
76
|
+
return switches(devType, config, manager);
|
|
77
|
+
}
|
|
78
|
+
else if (devType in bulbMods.bulbModules) {
|
|
79
|
+
return bulbs(devType, config, manager);
|
|
80
|
+
}
|
|
81
|
+
else if (devType in kitchenMods.kitchenModules) {
|
|
82
|
+
return kitchen(devType, config, manager);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.debug('Unknown device named %s model %s', config.deviceName || '', config.deviceType || '');
|
|
86
|
+
return ['unknown', null];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class VeSync {
|
|
90
|
+
constructor(username, password, timeZone = helpers_1.DEFAULT_TZ, debug = false, redact = true) {
|
|
91
|
+
this.body = helpers_1.Helpers.reqBody(this, 'devicelist');
|
|
92
|
+
this[_a] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/devices', 'post', body, helpers_1.Helpers.reqHeaders(this));
|
|
93
|
+
this._debug = debug;
|
|
94
|
+
if (debug) {
|
|
95
|
+
// Set debug logging levels
|
|
96
|
+
console.debug('Debug logging enabled');
|
|
97
|
+
}
|
|
98
|
+
this._redact = redact;
|
|
99
|
+
if (redact) {
|
|
100
|
+
helpers_1.Helpers.redact = redact;
|
|
101
|
+
}
|
|
102
|
+
this.username = username;
|
|
103
|
+
this.password = password;
|
|
104
|
+
this.token = null;
|
|
105
|
+
this.accountId = null;
|
|
106
|
+
this.countryCode = null;
|
|
107
|
+
this.devices = null;
|
|
108
|
+
this.enabled = false;
|
|
109
|
+
this.updateInterval = helpers_1.API_RATE_LIMIT;
|
|
110
|
+
this.lastUpdateTs = null;
|
|
111
|
+
this.inProcess = false;
|
|
112
|
+
this._energyUpdateInterval = DEFAULT_ENERGY_UPDATE_INTERVAL;
|
|
113
|
+
this._energyCheck = true;
|
|
114
|
+
this.fans = [];
|
|
115
|
+
this.outlets = [];
|
|
116
|
+
this.switches = [];
|
|
117
|
+
this.bulbs = [];
|
|
118
|
+
this.scales = [];
|
|
119
|
+
this.kitchen = [];
|
|
120
|
+
this._devList = {
|
|
121
|
+
fans: this.fans,
|
|
122
|
+
outlets: this.outlets,
|
|
123
|
+
switches: this.switches,
|
|
124
|
+
bulbs: this.bulbs,
|
|
125
|
+
kitchen: this.kitchen,
|
|
126
|
+
unknown: []
|
|
127
|
+
};
|
|
128
|
+
if (typeof timeZone === 'string' && timeZone) {
|
|
129
|
+
const regTest = /[^a-zA-Z/_]/;
|
|
130
|
+
if (regTest.test(timeZone)) {
|
|
131
|
+
this.timeZone = helpers_1.DEFAULT_TZ;
|
|
132
|
+
console.debug('Invalid characters in time zone - %s', timeZone);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.timeZone = timeZone;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.timeZone = helpers_1.DEFAULT_TZ;
|
|
140
|
+
console.debug('Time zone is not a string');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
get debug() {
|
|
144
|
+
return this._debug;
|
|
145
|
+
}
|
|
146
|
+
set debug(newFlag) {
|
|
147
|
+
this._debug = newFlag;
|
|
148
|
+
// Set logging levels based on debug flag
|
|
149
|
+
if (newFlag) {
|
|
150
|
+
console.debug('Debug logging enabled');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
get redact() {
|
|
154
|
+
return this._redact;
|
|
155
|
+
}
|
|
156
|
+
set redact(newFlag) {
|
|
157
|
+
if (newFlag) {
|
|
158
|
+
helpers_1.Helpers.redact = true;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
helpers_1.Helpers.redact = false;
|
|
162
|
+
}
|
|
163
|
+
this._redact = newFlag;
|
|
164
|
+
}
|
|
165
|
+
get energyUpdateInterval() {
|
|
166
|
+
return this._energyUpdateInterval;
|
|
167
|
+
}
|
|
168
|
+
set energyUpdateInterval(newEnergyUpdate) {
|
|
169
|
+
if (newEnergyUpdate > 0) {
|
|
170
|
+
this._energyUpdateInterval = newEnergyUpdate;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Test if device should be removed - false = Remove
|
|
175
|
+
*/
|
|
176
|
+
static removeDevTest(device, newList) {
|
|
177
|
+
if (Array.isArray(newList) && device.cid) {
|
|
178
|
+
for (const item of newList) {
|
|
179
|
+
if ('cid' in item && device.cid === item.cid) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Login to VeSync server
|
|
188
|
+
*/
|
|
189
|
+
async login() {
|
|
190
|
+
const body = helpers_1.Helpers.reqBody(this, 'login');
|
|
191
|
+
const [response] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body);
|
|
192
|
+
if (!response || response.code !== 0 || !response.result) {
|
|
193
|
+
console.error('Error logging in to VeSync');
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
this.token = response.result.token;
|
|
197
|
+
this.accountId = response.result.accountID;
|
|
198
|
+
this.countryCode = response.result.countryCode;
|
|
199
|
+
this.enabled = true;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get list of VeSync devices
|
|
204
|
+
*/
|
|
205
|
+
async getDevices() {
|
|
206
|
+
if (!this.enabled)
|
|
207
|
+
: console.error('Not logged in');
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
if(, response) { }
|
|
211
|
+
}
|
|
212
|
+
exports.VeSync = VeSync;
|
|
213
|
+
_a = response;
|
|
214
|
+
|| response.code !== 0;
|
|
215
|
+
{
|
|
216
|
+
console.error('Error getting device list');
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
this.devices = response.result.list || [];
|
|
220
|
+
return true;
|
|
221
|
+
/**
|
|
222
|
+
* Process devices after getting list of devices
|
|
223
|
+
*/
|
|
224
|
+
processDevices();
|
|
225
|
+
void {
|
|
226
|
+
: .devices
|
|
227
|
+
};
|
|
228
|
+
{
|
|
229
|
+
console.error('Device list not fetched');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const deviceList = [...this.devices];
|
|
233
|
+
const toRemove = [];
|
|
234
|
+
// Build list of devices to remove
|
|
235
|
+
for (const devList of Object.values(this._devList)) {
|
|
236
|
+
for (const device of devList) {
|
|
237
|
+
if (!VeSync.removeDevTest(device, deviceList)) {
|
|
238
|
+
toRemove.push(device);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Remove devices not in device list
|
|
243
|
+
for (const device of toRemove) {
|
|
244
|
+
for (const [key, devList] of Object.entries(this._devList)) {
|
|
245
|
+
const index = devList.indexOf(device);
|
|
246
|
+
if (index > -1) {
|
|
247
|
+
this._devList[key].splice(index, 1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Add new devices
|
|
252
|
+
for (const device of deviceList) {
|
|
253
|
+
let foundDevice = false;
|
|
254
|
+
// Look for existing devices
|
|
255
|
+
for (const devList of Object.values(this._devList)) {
|
|
256
|
+
if (devList.some(dev => dev.cid === device.cid)) {
|
|
257
|
+
foundDevice = true;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// If device not found, add it
|
|
262
|
+
if (!foundDevice) {
|
|
263
|
+
const [deviceType, deviceObj] = objectFactory(device.deviceType, device, this);
|
|
264
|
+
if (deviceObj) {
|
|
265
|
+
this._devList[deviceType].push(deviceObj);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Update all devices
|
|
271
|
+
*/
|
|
272
|
+
async;
|
|
273
|
+
update();
|
|
274
|
+
Promise < void > {
|
|
275
|
+
: .enabled
|
|
276
|
+
};
|
|
277
|
+
{
|
|
278
|
+
console.error('Not logged in');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (this.inProcess) {
|
|
282
|
+
console.debug('Update already in process');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const currentTime = Date.now();
|
|
286
|
+
if (this.lastUpdateTs &&
|
|
287
|
+
currentTime - this.lastUpdateTs < this.updateInterval * 1000) {
|
|
288
|
+
console.debug('Update rate limit - waiting %d seconds', this.updateInterval - (currentTime - this.lastUpdateTs) / 1000);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
this.inProcess = true;
|
|
292
|
+
this.lastUpdateTs = currentTime;
|
|
293
|
+
try {
|
|
294
|
+
await this.getDevices();
|
|
295
|
+
this.processDevices();
|
|
296
|
+
const updatePromises = [];
|
|
297
|
+
for (const deviceList of Object.values(this._devList)) {
|
|
298
|
+
for (const device of deviceList) {
|
|
299
|
+
if ('update' in device && typeof device.update === 'function') {
|
|
300
|
+
updatePromises.push(device.update());
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
await Promise.all(updatePromises);
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
this.inProcess = false;
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=vesync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vesync.js","sourceRoot":"","sources":["../../src/lib/vesync.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,uCAAgE;AAGhE,uDAAyC;AACzC,qDAAuC;AACvC,2DAA6C;AAC7C,2DAA6C;AAC7C,6DAA+C;AAE/C,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAQ7C,SAAS,aAAa,CAClB,OAAe,EACf,MAAoB,EACpB,OAAe;IAEf,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,MAAoB,EAAE,OAAe,EAAkC,EAAE;QACpG,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,MAAoB,EAAE,OAAe,EAAkC,EAAE;QACvG,MAAM,SAAS,GAAG,UAAU,CAAC,a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tB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;AAEhC,IAAI,CAAC;IACD,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IACxB,IAAI,CAAC,cAAc,EAAE,CAAC;IAEtB,MAAM,cAAc,GAAoB,EAAE,CAAC;IAC3C,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;YAC9B,IAAI,QAAQ,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBAC5D,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YACzC,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACtC,CAAC;QAAS,CAAC;IACP,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all VeSync devices
|
|
3
|
+
*/
|
|
4
|
+
import { VeSync } from './vesync';
|
|
5
|
+
export interface DeviceDetails {
|
|
6
|
+
deviceName: string;
|
|
7
|
+
deviceImg?: string;
|
|
8
|
+
cid: string;
|
|
9
|
+
connectionStatus: string;
|
|
10
|
+
connectionType?: string;
|
|
11
|
+
deviceType: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
uuid?: string;
|
|
14
|
+
configModule: string;
|
|
15
|
+
macID?: string;
|
|
16
|
+
mode?: string;
|
|
17
|
+
speed?: number | string;
|
|
18
|
+
extension?: any;
|
|
19
|
+
currentFirmVersion?: string;
|
|
20
|
+
deviceRegion?: string;
|
|
21
|
+
deviceStatus?: string;
|
|
22
|
+
subDeviceNo?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class VeSyncBaseDevice {
|
|
25
|
+
protected manager: VeSync;
|
|
26
|
+
deviceName: string;
|
|
27
|
+
deviceImage: string | null;
|
|
28
|
+
cid: string;
|
|
29
|
+
connectionStatus: string;
|
|
30
|
+
connectionType: string | null;
|
|
31
|
+
deviceType: string;
|
|
32
|
+
type: string | null;
|
|
33
|
+
uuid: string | null;
|
|
34
|
+
configModule: string;
|
|
35
|
+
macId: string | null;
|
|
36
|
+
mode: string | null;
|
|
37
|
+
speed: number | null;
|
|
38
|
+
extension: any;
|
|
39
|
+
currentFirmVersion: string | null;
|
|
40
|
+
deviceRegion: string | null;
|
|
41
|
+
pid: string | null;
|
|
42
|
+
subDeviceNo: number;
|
|
43
|
+
config: {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
};
|
|
46
|
+
deviceStatus: string | null;
|
|
47
|
+
constructor(details: DeviceDetails, manager: VeSync);
|
|
48
|
+
/**
|
|
49
|
+
* Return true if device is on
|
|
50
|
+
*/
|
|
51
|
+
get isOn(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Return true if firmware update available
|
|
54
|
+
*/
|
|
55
|
+
get firmwareUpdate(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get managed device configuration
|
|
58
|
+
*/
|
|
59
|
+
getPid(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Display device details
|
|
62
|
+
*/
|
|
63
|
+
display(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Return device details as JSON string
|
|
66
|
+
*/
|
|
67
|
+
displayJSON(): string;
|
|
68
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VeSyncBaseDevice = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
class VeSyncBaseDevice {
|
|
6
|
+
constructor(details, manager) {
|
|
7
|
+
this.manager = manager;
|
|
8
|
+
if (details.cid) {
|
|
9
|
+
this.deviceName = details.deviceName;
|
|
10
|
+
this.deviceImage = details.deviceImg || null;
|
|
11
|
+
this.cid = details.cid;
|
|
12
|
+
this.connectionStatus = details.connectionStatus;
|
|
13
|
+
this.connectionType = details.connectionType || null;
|
|
14
|
+
this.deviceType = details.deviceType;
|
|
15
|
+
this.type = details.type || null;
|
|
16
|
+
this.uuid = details.uuid || null;
|
|
17
|
+
this.configModule = details.configModule;
|
|
18
|
+
this.macId = details.macID || null;
|
|
19
|
+
this.mode = details.mode || null;
|
|
20
|
+
this.speed = typeof details.speed === 'string' && details.speed !== ''
|
|
21
|
+
? parseInt(details.speed)
|
|
22
|
+
: (typeof details.speed === 'number' ? details.speed : null);
|
|
23
|
+
this.extension = details.extension;
|
|
24
|
+
this.currentFirmVersion = details.currentFirmVersion || null;
|
|
25
|
+
this.deviceRegion = details.deviceRegion || null;
|
|
26
|
+
this.pid = null;
|
|
27
|
+
this.subDeviceNo = details.subDeviceNo || 0;
|
|
28
|
+
this.config = {};
|
|
29
|
+
if (typeof details.extension === 'object' && details.extension !== null) {
|
|
30
|
+
const ext = details.extension;
|
|
31
|
+
this.speed = ext.fanSpeedLevel;
|
|
32
|
+
this.mode = ext.mode;
|
|
33
|
+
}
|
|
34
|
+
if (this.connectionStatus !== 'online') {
|
|
35
|
+
this.deviceStatus = 'off';
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.deviceStatus = details.deviceStatus || null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error(`No cid found for ${this.constructor.name}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return true if device is on
|
|
47
|
+
*/
|
|
48
|
+
get isOn() {
|
|
49
|
+
return this.deviceStatus === 'on';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Return true if firmware update available
|
|
53
|
+
*/
|
|
54
|
+
get firmwareUpdate() {
|
|
55
|
+
const cfv = this.config?.current_firmware_version;
|
|
56
|
+
const lfv = this.config?.latest_firmware_version;
|
|
57
|
+
if (cfv !== undefined && lfv !== undefined) {
|
|
58
|
+
return cfv !== lfv;
|
|
59
|
+
}
|
|
60
|
+
console.debug('Call device.getConfig() to get firmware versions');
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get managed device configuration
|
|
65
|
+
*/
|
|
66
|
+
async getPid() {
|
|
67
|
+
const body = helpers_1.Helpers.reqBody(this.manager, 'devicedetail');
|
|
68
|
+
body.configModule = this.configModule;
|
|
69
|
+
body.region = this.deviceRegion;
|
|
70
|
+
body.method = 'configInfo';
|
|
71
|
+
const [response] = await helpers_1.Helpers.callApi('/cloud/v1/deviceManaged/configInfo', 'post', body);
|
|
72
|
+
if (typeof response !== 'object' ||
|
|
73
|
+
response.code !== 0 ||
|
|
74
|
+
!response.result) {
|
|
75
|
+
console.error(`Error getting config info for ${this.deviceName}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.pid = response.result?.pid;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Display device details
|
|
82
|
+
*/
|
|
83
|
+
display() {
|
|
84
|
+
const disp = [
|
|
85
|
+
['Device Name:', this.deviceName],
|
|
86
|
+
['Model:', this.deviceType],
|
|
87
|
+
['Subdevice No:', this.subDeviceNo.toString()],
|
|
88
|
+
['Status:', this.deviceStatus],
|
|
89
|
+
['Online:', this.connectionStatus],
|
|
90
|
+
['Type:', this.type],
|
|
91
|
+
['CID:', this.cid],
|
|
92
|
+
];
|
|
93
|
+
if (this.uuid) {
|
|
94
|
+
disp.push(['UUID:', this.uuid]);
|
|
95
|
+
}
|
|
96
|
+
for (const line of disp) {
|
|
97
|
+
console.log(`${line[0].padEnd(30, '.')} ${line[1]}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Return device details as JSON string
|
|
102
|
+
*/
|
|
103
|
+
displayJSON() {
|
|
104
|
+
return JSON.stringify({
|
|
105
|
+
'Device Name': this.deviceName,
|
|
106
|
+
'Model': this.deviceType,
|
|
107
|
+
'Subdevice No': this.subDeviceNo.toString(),
|
|
108
|
+
'Status': this.deviceStatus,
|
|
109
|
+
'Online': this.connectionStatus,
|
|
110
|
+
'Type': this.type,
|
|
111
|
+
'CID': this.cid,
|
|
112
|
+
}, null, 4);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.VeSyncBaseDevice = VeSyncBaseDevice;
|
|
116
|
+
//# sourceMappingURL=vesyncBaseDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vesyncBaseDevice.js","sourceRoot":"","sources":["../../src/lib/vesyncBaseDevice.ts"],"names":[],"mappings":";;;AAIA,uCAAoC;AAsBpC,MAAa,gBAAgB;IAsBzB,YAAY,OAAsB,EAAE,OAAe;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACrC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;YAC7C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;YACvB,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YACjD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC;YACrD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;YACjC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;YACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;YACnC,IAAI,CAAC,IAAI,GAAG,OA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ib/vesyncBulb.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeSync API for controlling fans and purifiers
|
|
3
|
+
*/
|
|
4
|
+
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
5
|
+
import { Timer } from './helpers';
|
|
6
|
+
interface HumidFeatures {
|
|
7
|
+
module: string;
|
|
8
|
+
models: string[];
|
|
9
|
+
features: string[];
|
|
10
|
+
mist_modes: string[];
|
|
11
|
+
mist_levels: number[];
|
|
12
|
+
warm_mist_levels?: number[];
|
|
13
|
+
}
|
|
14
|
+
interface AirFeatures {
|
|
15
|
+
module: string;
|
|
16
|
+
models: string[];
|
|
17
|
+
modes?: string[];
|
|
18
|
+
features: string[];
|
|
19
|
+
levels?: number[];
|
|
20
|
+
set_mode_method?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const humidFeatures: {
|
|
23
|
+
[key: string]: HumidFeatures;
|
|
24
|
+
};
|
|
25
|
+
export declare const airFeatures: {
|
|
26
|
+
[key: string]: AirFeatures;
|
|
27
|
+
};
|
|
28
|
+
export declare function modelDict(): {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function modelFeatures(devType: string): AirFeatures | HumidFeatures;
|
|
32
|
+
export declare const fanClasses: Set<string>;
|
|
33
|
+
export declare const fanModules: {
|
|
34
|
+
[key: string]: string;
|
|
35
|
+
};
|
|
36
|
+
interface AirDetails {
|
|
37
|
+
filter_life: number;
|
|
38
|
+
mode: string;
|
|
39
|
+
level: number;
|
|
40
|
+
display: boolean;
|
|
41
|
+
child_lock: boolean;
|
|
42
|
+
night_light: string;
|
|
43
|
+
air_quality?: number;
|
|
44
|
+
air_quality_value?: number;
|
|
45
|
+
display_forever?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare class VeSyncAirBypass extends VeSyncBaseDevice {
|
|
48
|
+
private _configDict;
|
|
49
|
+
private _features;
|
|
50
|
+
details: AirDetails;
|
|
51
|
+
timer: Timer | null;
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
constructor(details: any, manager: any);
|
|
54
|
+
/**
|
|
55
|
+
* Get configuration and details for air purifier
|
|
56
|
+
*/
|
|
57
|
+
getConfig(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Build bypass body for air purifier
|
|
60
|
+
*/
|
|
61
|
+
buildBypassBody(method: string): any;
|
|
62
|
+
/**
|
|
63
|
+
* Turn air purifier on/off
|
|
64
|
+
*/
|
|
65
|
+
turnOn(toggle?: boolean): Promise<boolean>;
|
|
66
|
+
turnOff(): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Set mode for air purifier
|
|
69
|
+
*/
|
|
70
|
+
setMode(mode: string): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Set fan speed for air purifier
|
|
73
|
+
*/
|
|
74
|
+
setLevel(level: number): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Set child lock for air purifier
|
|
77
|
+
*/
|
|
78
|
+
setChildLock(toggle?: boolean): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Set display for air purifier
|
|
81
|
+
*/
|
|
82
|
+
setDisplay(toggle?: boolean): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Update air purifier details
|
|
85
|
+
*/
|
|
86
|
+
update(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Display air purifier details
|
|
89
|
+
*/
|
|
90
|
+
display(): void;
|
|
91
|
+
}
|
|
92
|
+
export {};
|