iobroker.panasonic-comfort-cloud 2.0.4 → 2.0.6
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/README.md +7 -1
- package/build/lib/tools.js +54 -52
- package/build/lib/tools.js.map +7 -0
- package/build/main.js +474 -381
- package/build/main.js.map +7 -0
- package/io-package.json +76 -77
- package/package.json +5 -3
package/build/main.js
CHANGED
|
@@ -1,398 +1,491 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var utils = __toESM(require("@iobroker/adapter-core"));
|
|
21
|
+
var import_panasonic_comfort_cloud_client = require("panasonic-comfort-cloud-client");
|
|
22
|
+
var _ = __toESM(require("lodash"));
|
|
20
23
|
const REFRESH_INTERVAL_IN_MINUTES_DEFAULT = 5;
|
|
21
|
-
const comfortCloudClient = new
|
|
24
|
+
const comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient();
|
|
22
25
|
class PanasonicComfortCloud extends utils.Adapter {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
refreshDeviceStates(device) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
this.log.debug(`Refresh device ${device.name} (${device.guid}).`);
|
|
65
|
-
this.log.debug(`${device.name}: guid => ${device.guid}.`);
|
|
66
|
-
this.log.debug(`${device.name}: operate => ${device.operate}.`);
|
|
67
|
-
yield this.setStateChangedAsync(`${device.name}.operate`, device.operate, true);
|
|
68
|
-
this.log.debug(`${device.name}: temperatureSet => ${device.temperatureSet}.`);
|
|
69
|
-
yield this.setStateChangedAsync(`${device.name}.temperatureSet`, device.temperatureSet, true);
|
|
70
|
-
this.log.debug(`${device.name}: insideTemperature => ${device.insideTemperature}.`);
|
|
71
|
-
yield this.setStateChangedAsync(`${device.name}.insideTemperature`, device.insideTemperature, true);
|
|
72
|
-
this.log.debug(`${device.name}: outTemperature => ${device.outTemperature}.`);
|
|
73
|
-
yield this.setStateChangedAsync(`${device.name}.outTemperature`, device.outTemperature, true);
|
|
74
|
-
this.log.debug(`${device.name}: airSwingLR => ${device.airSwingLR}.`);
|
|
75
|
-
yield this.setStateChangedAsync(`${device.name}.airSwingLR`, device.airSwingLR, true);
|
|
76
|
-
this.log.debug(`${device.name}: airSwingUD => ${device.airSwingUD}.`);
|
|
77
|
-
yield this.setStateChangedAsync(`${device.name}.airSwingUD`, device.airSwingUD, true);
|
|
78
|
-
this.log.debug(`${device.name}: fanAutoMode => ${device.fanAutoMode}.`);
|
|
79
|
-
yield this.setStateChangedAsync(`${device.name}.fanAutoMode`, device.fanAutoMode, true);
|
|
80
|
-
this.log.debug(`${device.name}: ecoMode => ${device.ecoMode}.`);
|
|
81
|
-
yield this.setStateChangedAsync(`${device.name}.ecoMode`, device.ecoMode, true);
|
|
82
|
-
this.log.debug(`${device.name}: operationMode => ${device.operationMode}.`);
|
|
83
|
-
yield this.setStateChangedAsync(`${device.name}.operationMode`, device.operationMode, true);
|
|
84
|
-
this.log.debug(`${device.name}: fanSpeed => ${device.fanSpeed}.`);
|
|
85
|
-
yield this.setStateChangedAsync(`${device.name}.fanSpeed`, device.fanSpeed, true);
|
|
86
|
-
this.log.debug(`${device.name}: actualNanoe => ${device.actualNanoe}.`);
|
|
87
|
-
yield this.setStateChangedAsync(`${device.name}.actualNanoe`, device.actualNanoe, true);
|
|
88
|
-
this.log.debug(`Refresh device ${device.name} finished.`);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
refreshDevice(guid, deviceName) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
try {
|
|
94
|
-
const device = yield comfortCloudClient.getDevice(guid);
|
|
95
|
-
if (!device) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (!device.name) {
|
|
99
|
-
device.name = deviceName;
|
|
100
|
-
}
|
|
101
|
-
yield this.refreshDeviceStates(device);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
yield this.handleClientError(error);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
refreshDevices() {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
try {
|
|
111
|
-
this.log.debug('Refresh all devices.');
|
|
112
|
-
const groups = yield comfortCloudClient.getGroups();
|
|
113
|
-
this.setState('info.connection', true, true);
|
|
114
|
-
const devices = _.flatMap(groups, g => g.devices);
|
|
115
|
-
const deviceInfos = _.map(devices, d => { return { guid: d.guid, name: d.name }; });
|
|
116
|
-
yield Promise.all(deviceInfos.map((deviceInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const device = yield comfortCloudClient.getDevice(deviceInfo.guid);
|
|
118
|
-
if (device != null) {
|
|
119
|
-
device.name = deviceInfo.name;
|
|
120
|
-
device.guid = deviceInfo.guid;
|
|
121
|
-
yield this.refreshDeviceStates(device);
|
|
122
|
-
}
|
|
123
|
-
})));
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
yield this.handleClientError(error);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
createDevices(groups) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
const devices = yield this.getDevicesAsync();
|
|
133
|
-
const names = _.map(devices, (value) => {
|
|
134
|
-
return value.common.name;
|
|
135
|
-
});
|
|
136
|
-
const devicesFromService = _.flatMap(groups, g => g.devices);
|
|
137
|
-
const deviceInfos = _.map(devicesFromService, d => { return { guid: d.guid, name: d.name }; });
|
|
138
|
-
yield Promise.all(deviceInfos.map((deviceInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
this.log.debug(`Device info from group ${deviceInfo.guid}, ${deviceInfo.name}.`);
|
|
140
|
-
let device = null;
|
|
141
|
-
try {
|
|
142
|
-
device = yield comfortCloudClient.getDevice(deviceInfo.guid);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
yield this.handleClientError(error);
|
|
146
|
-
}
|
|
147
|
-
if (device != null) {
|
|
148
|
-
if (_.includes(names, deviceInfo.name)) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this.createDevice(deviceInfo.name);
|
|
152
|
-
this.createState(deviceInfo.name, '', 'guid', { role: 'info.address', write: false, def: deviceInfo.guid, type: 'string' }, undefined);
|
|
153
|
-
this.readonlyStateNames.push('guid');
|
|
154
|
-
this.createState(deviceInfo.name, '', 'operate', {
|
|
155
|
-
role: 'switch.power',
|
|
156
|
-
states: { 0: panasonic_comfort_cloud_client_1.Power[0], 1: panasonic_comfort_cloud_client_1.Power[1] },
|
|
157
|
-
write: true,
|
|
158
|
-
def: device.operate,
|
|
159
|
-
type: 'number',
|
|
160
|
-
}, undefined);
|
|
161
|
-
this.createState(deviceInfo.name, '', 'temperatureSet', {
|
|
162
|
-
role: 'level.temperature',
|
|
163
|
-
write: true,
|
|
164
|
-
def: device.temperatureSet,
|
|
165
|
-
type: 'number',
|
|
166
|
-
}, undefined);
|
|
167
|
-
this.createState(deviceInfo.name, '', 'insideTemperature', {
|
|
168
|
-
role: 'level.temperature',
|
|
169
|
-
write: false,
|
|
170
|
-
def: device.insideTemperature,
|
|
171
|
-
type: 'number',
|
|
172
|
-
}, undefined);
|
|
173
|
-
this.readonlyStateNames.push('insideTemperature');
|
|
174
|
-
this.createState(deviceInfo.name, '', 'outTemperature', {
|
|
175
|
-
role: 'level.temperature',
|
|
176
|
-
write: false,
|
|
177
|
-
def: device.outTemperature,
|
|
178
|
-
type: 'number',
|
|
179
|
-
}, undefined);
|
|
180
|
-
this.readonlyStateNames.push('outTemperature');
|
|
181
|
-
this.createState(deviceInfo.name, '', 'airSwingLR', {
|
|
182
|
-
role: 'state',
|
|
183
|
-
states: {
|
|
184
|
-
0: panasonic_comfort_cloud_client_1.AirSwingLR[0],
|
|
185
|
-
1: panasonic_comfort_cloud_client_1.AirSwingLR[1],
|
|
186
|
-
2: panasonic_comfort_cloud_client_1.AirSwingLR[2],
|
|
187
|
-
3: panasonic_comfort_cloud_client_1.AirSwingLR[3],
|
|
188
|
-
4: panasonic_comfort_cloud_client_1.AirSwingLR[4],
|
|
189
|
-
},
|
|
190
|
-
write: true,
|
|
191
|
-
def: device.airSwingLR,
|
|
192
|
-
type: 'number',
|
|
193
|
-
}, undefined);
|
|
194
|
-
this.createState(deviceInfo.name, '', 'airSwingUD', {
|
|
195
|
-
role: 'state',
|
|
196
|
-
states: {
|
|
197
|
-
0: panasonic_comfort_cloud_client_1.AirSwingUD[0],
|
|
198
|
-
1: panasonic_comfort_cloud_client_1.AirSwingUD[1],
|
|
199
|
-
2: panasonic_comfort_cloud_client_1.AirSwingUD[2],
|
|
200
|
-
3: panasonic_comfort_cloud_client_1.AirSwingUD[3],
|
|
201
|
-
4: panasonic_comfort_cloud_client_1.AirSwingUD[4],
|
|
202
|
-
},
|
|
203
|
-
write: true,
|
|
204
|
-
def: device.airSwingUD,
|
|
205
|
-
type: 'number',
|
|
206
|
-
}, undefined);
|
|
207
|
-
this.createState(deviceInfo.name, '', 'fanAutoMode', {
|
|
208
|
-
role: 'state',
|
|
209
|
-
states: {
|
|
210
|
-
0: panasonic_comfort_cloud_client_1.FanAutoMode[0],
|
|
211
|
-
1: panasonic_comfort_cloud_client_1.FanAutoMode[1],
|
|
212
|
-
2: panasonic_comfort_cloud_client_1.FanAutoMode[2],
|
|
213
|
-
3: panasonic_comfort_cloud_client_1.FanAutoMode[3],
|
|
214
|
-
},
|
|
215
|
-
write: true,
|
|
216
|
-
def: device.fanAutoMode,
|
|
217
|
-
type: 'number',
|
|
218
|
-
}, undefined);
|
|
219
|
-
this.createState(deviceInfo.name, '', 'ecoMode', {
|
|
220
|
-
role: 'state',
|
|
221
|
-
states: { 0: panasonic_comfort_cloud_client_1.EcoMode[0], 1: panasonic_comfort_cloud_client_1.EcoMode[1], 2: panasonic_comfort_cloud_client_1.EcoMode[2] },
|
|
222
|
-
write: true,
|
|
223
|
-
def: device.ecoMode,
|
|
224
|
-
type: 'number',
|
|
225
|
-
}, undefined);
|
|
226
|
-
this.createState(deviceInfo.name, '', 'operationMode', {
|
|
227
|
-
role: 'state',
|
|
228
|
-
states: {
|
|
229
|
-
0: panasonic_comfort_cloud_client_1.OperationMode[0],
|
|
230
|
-
1: panasonic_comfort_cloud_client_1.OperationMode[1],
|
|
231
|
-
2: panasonic_comfort_cloud_client_1.OperationMode[2],
|
|
232
|
-
3: panasonic_comfort_cloud_client_1.OperationMode[3],
|
|
233
|
-
4: panasonic_comfort_cloud_client_1.OperationMode[4],
|
|
234
|
-
},
|
|
235
|
-
write: true,
|
|
236
|
-
def: device.operationMode,
|
|
237
|
-
type: 'number',
|
|
238
|
-
}, undefined);
|
|
239
|
-
this.createState(deviceInfo.name, '', 'fanSpeed', {
|
|
240
|
-
role: 'state',
|
|
241
|
-
states: {
|
|
242
|
-
0: panasonic_comfort_cloud_client_1.FanSpeed[0],
|
|
243
|
-
1: panasonic_comfort_cloud_client_1.FanSpeed[1],
|
|
244
|
-
2: panasonic_comfort_cloud_client_1.FanSpeed[2],
|
|
245
|
-
3: panasonic_comfort_cloud_client_1.FanSpeed[3],
|
|
246
|
-
4: panasonic_comfort_cloud_client_1.FanSpeed[4],
|
|
247
|
-
5: panasonic_comfort_cloud_client_1.FanSpeed[5],
|
|
248
|
-
},
|
|
249
|
-
write: true,
|
|
250
|
-
def: device.fanSpeed,
|
|
251
|
-
type: 'number',
|
|
252
|
-
}, undefined);
|
|
253
|
-
this.createState(deviceInfo.name, '', 'actualNanoe', {
|
|
254
|
-
role: 'state',
|
|
255
|
-
states: {
|
|
256
|
-
0: panasonic_comfort_cloud_client_1.NanoeMode[0],
|
|
257
|
-
1: panasonic_comfort_cloud_client_1.NanoeMode[1],
|
|
258
|
-
2: panasonic_comfort_cloud_client_1.NanoeMode[2],
|
|
259
|
-
3: panasonic_comfort_cloud_client_1.NanoeMode[3],
|
|
260
|
-
4: panasonic_comfort_cloud_client_1.NanoeMode[4],
|
|
261
|
-
},
|
|
262
|
-
write: true,
|
|
263
|
-
def: device.actualNanoe,
|
|
264
|
-
type: 'number',
|
|
265
|
-
}, undefined);
|
|
266
|
-
this.log.info(`Device ${deviceInfo.name} created.`);
|
|
267
|
-
}
|
|
268
|
-
})));
|
|
269
|
-
this.log.debug('Device creation completed.');
|
|
270
|
-
});
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
super({
|
|
28
|
+
...options,
|
|
29
|
+
name: "panasonic-comfort-cloud"
|
|
30
|
+
});
|
|
31
|
+
this.refreshIntervalInMinutes = REFRESH_INTERVAL_IN_MINUTES_DEFAULT;
|
|
32
|
+
this.readonlyStateNames = [];
|
|
33
|
+
this.on("ready", this.onReady.bind(this));
|
|
34
|
+
this.on("objectChange", this.onObjectChange.bind(this));
|
|
35
|
+
this.on("stateChange", this.onStateChange.bind(this));
|
|
36
|
+
this.on("unload", this.onUnload.bind(this));
|
|
37
|
+
}
|
|
38
|
+
async onReady() {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
this.refreshIntervalInMinutes = (_b = (_a = this.config) == null ? void 0 : _a.refreshInterval) != null ? _b : REFRESH_INTERVAL_IN_MINUTES_DEFAULT;
|
|
41
|
+
this.subscribeStates("*");
|
|
42
|
+
this.setState("info.connection", false, true);
|
|
43
|
+
if (!((_c = this.config) == null ? void 0 : _c.username) || !((_d = this.config) == null ? void 0 : _d.password)) {
|
|
44
|
+
this.log.error("Can not start without username or password. Please open config.");
|
|
45
|
+
} else {
|
|
46
|
+
try {
|
|
47
|
+
this.log.debug(`Try to login with username ${this.config.username}.`);
|
|
48
|
+
await comfortCloudClient.login(
|
|
49
|
+
this.config.username,
|
|
50
|
+
this.config.password
|
|
51
|
+
);
|
|
52
|
+
this.log.info("Login successful.");
|
|
53
|
+
this.setState("info.connection", true, true);
|
|
54
|
+
this.log.debug("Create devices.");
|
|
55
|
+
const groups = await comfortCloudClient.getGroups();
|
|
56
|
+
await this.createDevices(groups);
|
|
57
|
+
this.setupRefreshTimeout();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
await this.handleClientError(error);
|
|
60
|
+
}
|
|
271
61
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
62
|
+
}
|
|
63
|
+
async refreshDeviceStates(device) {
|
|
64
|
+
this.log.debug(`Refresh device ${device.name} (${device.guid}).`);
|
|
65
|
+
this.log.debug(`${device.name}: guid => ${device.guid}.`);
|
|
66
|
+
this.log.debug(`${device.name}: operate => ${device.operate}.`);
|
|
67
|
+
await this.setStateChangedAsync(
|
|
68
|
+
`${device.name}.operate`,
|
|
69
|
+
device.operate,
|
|
70
|
+
true
|
|
71
|
+
);
|
|
72
|
+
this.log.debug(`${device.name}: temperatureSet => ${device.temperatureSet}.`);
|
|
73
|
+
await this.setStateChangedAsync(
|
|
74
|
+
`${device.name}.temperatureSet`,
|
|
75
|
+
device.temperatureSet,
|
|
76
|
+
true
|
|
77
|
+
);
|
|
78
|
+
this.log.debug(`${device.name}: insideTemperature => ${device.insideTemperature}.`);
|
|
79
|
+
await this.setStateChangedAsync(
|
|
80
|
+
`${device.name}.insideTemperature`,
|
|
81
|
+
device.insideTemperature,
|
|
82
|
+
true
|
|
83
|
+
);
|
|
84
|
+
this.log.debug(`${device.name}: outTemperature => ${device.outTemperature}.`);
|
|
85
|
+
await this.setStateChangedAsync(
|
|
86
|
+
`${device.name}.outTemperature`,
|
|
87
|
+
device.outTemperature,
|
|
88
|
+
true
|
|
89
|
+
);
|
|
90
|
+
this.log.debug(`${device.name}: airSwingLR => ${device.airSwingLR}.`);
|
|
91
|
+
await this.setStateChangedAsync(
|
|
92
|
+
`${device.name}.airSwingLR`,
|
|
93
|
+
device.airSwingLR,
|
|
94
|
+
true
|
|
95
|
+
);
|
|
96
|
+
this.log.debug(`${device.name}: airSwingUD => ${device.airSwingUD}.`);
|
|
97
|
+
await this.setStateChangedAsync(
|
|
98
|
+
`${device.name}.airSwingUD`,
|
|
99
|
+
device.airSwingUD,
|
|
100
|
+
true
|
|
101
|
+
);
|
|
102
|
+
this.log.debug(`${device.name}: fanAutoMode => ${device.fanAutoMode}.`);
|
|
103
|
+
await this.setStateChangedAsync(
|
|
104
|
+
`${device.name}.fanAutoMode`,
|
|
105
|
+
device.fanAutoMode,
|
|
106
|
+
true
|
|
107
|
+
);
|
|
108
|
+
this.log.debug(`${device.name}: ecoMode => ${device.ecoMode}.`);
|
|
109
|
+
await this.setStateChangedAsync(
|
|
110
|
+
`${device.name}.ecoMode`,
|
|
111
|
+
device.ecoMode,
|
|
112
|
+
true
|
|
113
|
+
);
|
|
114
|
+
this.log.debug(`${device.name}: operationMode => ${device.operationMode}.`);
|
|
115
|
+
await this.setStateChangedAsync(
|
|
116
|
+
`${device.name}.operationMode`,
|
|
117
|
+
device.operationMode,
|
|
118
|
+
true
|
|
119
|
+
);
|
|
120
|
+
this.log.debug(`${device.name}: fanSpeed => ${device.fanSpeed}.`);
|
|
121
|
+
await this.setStateChangedAsync(
|
|
122
|
+
`${device.name}.fanSpeed`,
|
|
123
|
+
device.fanSpeed,
|
|
124
|
+
true
|
|
125
|
+
);
|
|
126
|
+
this.log.debug(`${device.name}: actualNanoe => ${device.actualNanoe}.`);
|
|
127
|
+
await this.setStateChangedAsync(
|
|
128
|
+
`${device.name}.actualNanoe`,
|
|
129
|
+
device.actualNanoe,
|
|
130
|
+
true
|
|
131
|
+
);
|
|
132
|
+
this.log.debug(`Refresh device ${device.name} finished.`);
|
|
133
|
+
}
|
|
134
|
+
async refreshDevice(guid, deviceName) {
|
|
135
|
+
try {
|
|
136
|
+
const device = await comfortCloudClient.getDevice(guid);
|
|
137
|
+
if (!device) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (!device.name) {
|
|
141
|
+
device.name = deviceName;
|
|
142
|
+
}
|
|
143
|
+
await this.refreshDeviceStates(device);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
await this.handleClientError(error);
|
|
301
146
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
147
|
+
}
|
|
148
|
+
async refreshDevices() {
|
|
149
|
+
try {
|
|
150
|
+
this.log.debug("Refresh all devices.");
|
|
151
|
+
const groups = await comfortCloudClient.getGroups();
|
|
152
|
+
this.setState("info.connection", true, true);
|
|
153
|
+
const devices = _.flatMap(groups, (g) => g.devices);
|
|
154
|
+
const deviceInfos = _.map(devices, (d) => {
|
|
155
|
+
return { guid: d.guid, name: d.name };
|
|
156
|
+
});
|
|
157
|
+
await Promise.all(deviceInfos.map(async (deviceInfo) => {
|
|
158
|
+
const device = await comfortCloudClient.getDevice(deviceInfo.guid);
|
|
159
|
+
if (device != null) {
|
|
160
|
+
device.name = deviceInfo.name;
|
|
161
|
+
device.guid = deviceInfo.guid;
|
|
162
|
+
await this.refreshDeviceStates(device);
|
|
314
163
|
}
|
|
164
|
+
}));
|
|
165
|
+
} catch (error) {
|
|
166
|
+
await this.handleClientError(error);
|
|
315
167
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
168
|
+
}
|
|
169
|
+
async createDevices(groups) {
|
|
170
|
+
const devices = await this.getDevicesAsync();
|
|
171
|
+
const names = _.map(devices, (value) => {
|
|
172
|
+
return value.common.name;
|
|
173
|
+
});
|
|
174
|
+
const devicesFromService = _.flatMap(groups, (g) => g.devices);
|
|
175
|
+
const deviceInfos = _.map(devicesFromService, (d) => {
|
|
176
|
+
return { guid: d.guid, name: d.name };
|
|
177
|
+
});
|
|
178
|
+
await Promise.all(deviceInfos.map(async (deviceInfo) => {
|
|
179
|
+
this.log.debug(`Device info from group ${deviceInfo.guid}, ${deviceInfo.name}.`);
|
|
180
|
+
let device = null;
|
|
181
|
+
try {
|
|
182
|
+
device = await comfortCloudClient.getDevice(deviceInfo.guid);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
await this.handleClientError(error);
|
|
185
|
+
}
|
|
186
|
+
if (device != null) {
|
|
187
|
+
if (_.includes(names, deviceInfo.name)) {
|
|
188
|
+
return;
|
|
327
189
|
}
|
|
190
|
+
this.createDevice(deviceInfo.name);
|
|
191
|
+
this.createState(
|
|
192
|
+
deviceInfo.name,
|
|
193
|
+
"",
|
|
194
|
+
"guid",
|
|
195
|
+
{ role: "info.address", write: false, def: deviceInfo.guid, type: "string" },
|
|
196
|
+
void 0
|
|
197
|
+
);
|
|
198
|
+
this.readonlyStateNames.push("guid");
|
|
199
|
+
this.createState(
|
|
200
|
+
deviceInfo.name,
|
|
201
|
+
"",
|
|
202
|
+
"operate",
|
|
203
|
+
{
|
|
204
|
+
role: "switch.power",
|
|
205
|
+
states: { 0: import_panasonic_comfort_cloud_client.Power[0], 1: import_panasonic_comfort_cloud_client.Power[1] },
|
|
206
|
+
write: true,
|
|
207
|
+
def: device.operate,
|
|
208
|
+
type: "number"
|
|
209
|
+
},
|
|
210
|
+
void 0
|
|
211
|
+
);
|
|
212
|
+
this.createState(
|
|
213
|
+
deviceInfo.name,
|
|
214
|
+
"",
|
|
215
|
+
"temperatureSet",
|
|
216
|
+
{
|
|
217
|
+
role: "level.temperature",
|
|
218
|
+
write: true,
|
|
219
|
+
def: device.temperatureSet,
|
|
220
|
+
type: "number"
|
|
221
|
+
},
|
|
222
|
+
void 0
|
|
223
|
+
);
|
|
224
|
+
this.createState(
|
|
225
|
+
deviceInfo.name,
|
|
226
|
+
"",
|
|
227
|
+
"insideTemperature",
|
|
228
|
+
{
|
|
229
|
+
role: "level.temperature",
|
|
230
|
+
write: false,
|
|
231
|
+
def: device.insideTemperature,
|
|
232
|
+
type: "number"
|
|
233
|
+
},
|
|
234
|
+
void 0
|
|
235
|
+
);
|
|
236
|
+
this.readonlyStateNames.push("insideTemperature");
|
|
237
|
+
this.createState(
|
|
238
|
+
deviceInfo.name,
|
|
239
|
+
"",
|
|
240
|
+
"outTemperature",
|
|
241
|
+
{
|
|
242
|
+
role: "level.temperature",
|
|
243
|
+
write: false,
|
|
244
|
+
def: device.outTemperature,
|
|
245
|
+
type: "number"
|
|
246
|
+
},
|
|
247
|
+
void 0
|
|
248
|
+
);
|
|
249
|
+
this.readonlyStateNames.push("outTemperature");
|
|
250
|
+
this.createState(
|
|
251
|
+
deviceInfo.name,
|
|
252
|
+
"",
|
|
253
|
+
"airSwingLR",
|
|
254
|
+
{
|
|
255
|
+
role: "state",
|
|
256
|
+
states: {
|
|
257
|
+
0: import_panasonic_comfort_cloud_client.AirSwingLR[0],
|
|
258
|
+
1: import_panasonic_comfort_cloud_client.AirSwingLR[1],
|
|
259
|
+
2: import_panasonic_comfort_cloud_client.AirSwingLR[2],
|
|
260
|
+
3: import_panasonic_comfort_cloud_client.AirSwingLR[3],
|
|
261
|
+
4: import_panasonic_comfort_cloud_client.AirSwingLR[4]
|
|
262
|
+
},
|
|
263
|
+
write: true,
|
|
264
|
+
def: device.airSwingLR,
|
|
265
|
+
type: "number"
|
|
266
|
+
},
|
|
267
|
+
void 0
|
|
268
|
+
);
|
|
269
|
+
this.createState(
|
|
270
|
+
deviceInfo.name,
|
|
271
|
+
"",
|
|
272
|
+
"airSwingUD",
|
|
273
|
+
{
|
|
274
|
+
role: "state",
|
|
275
|
+
states: {
|
|
276
|
+
0: import_panasonic_comfort_cloud_client.AirSwingUD[0],
|
|
277
|
+
1: import_panasonic_comfort_cloud_client.AirSwingUD[1],
|
|
278
|
+
2: import_panasonic_comfort_cloud_client.AirSwingUD[2],
|
|
279
|
+
3: import_panasonic_comfort_cloud_client.AirSwingUD[3],
|
|
280
|
+
4: import_panasonic_comfort_cloud_client.AirSwingUD[4]
|
|
281
|
+
},
|
|
282
|
+
write: true,
|
|
283
|
+
def: device.airSwingUD,
|
|
284
|
+
type: "number"
|
|
285
|
+
},
|
|
286
|
+
void 0
|
|
287
|
+
);
|
|
288
|
+
this.createState(
|
|
289
|
+
deviceInfo.name,
|
|
290
|
+
"",
|
|
291
|
+
"fanAutoMode",
|
|
292
|
+
{
|
|
293
|
+
role: "state",
|
|
294
|
+
states: {
|
|
295
|
+
0: import_panasonic_comfort_cloud_client.FanAutoMode[0],
|
|
296
|
+
1: import_panasonic_comfort_cloud_client.FanAutoMode[1],
|
|
297
|
+
2: import_panasonic_comfort_cloud_client.FanAutoMode[2],
|
|
298
|
+
3: import_panasonic_comfort_cloud_client.FanAutoMode[3]
|
|
299
|
+
},
|
|
300
|
+
write: true,
|
|
301
|
+
def: device.fanAutoMode,
|
|
302
|
+
type: "number"
|
|
303
|
+
},
|
|
304
|
+
void 0
|
|
305
|
+
);
|
|
306
|
+
this.createState(
|
|
307
|
+
deviceInfo.name,
|
|
308
|
+
"",
|
|
309
|
+
"ecoMode",
|
|
310
|
+
{
|
|
311
|
+
role: "state",
|
|
312
|
+
states: { 0: import_panasonic_comfort_cloud_client.EcoMode[0], 1: import_panasonic_comfort_cloud_client.EcoMode[1], 2: import_panasonic_comfort_cloud_client.EcoMode[2] },
|
|
313
|
+
write: true,
|
|
314
|
+
def: device.ecoMode,
|
|
315
|
+
type: "number"
|
|
316
|
+
},
|
|
317
|
+
void 0
|
|
318
|
+
);
|
|
319
|
+
this.createState(
|
|
320
|
+
deviceInfo.name,
|
|
321
|
+
"",
|
|
322
|
+
"operationMode",
|
|
323
|
+
{
|
|
324
|
+
role: "state",
|
|
325
|
+
states: {
|
|
326
|
+
0: import_panasonic_comfort_cloud_client.OperationMode[0],
|
|
327
|
+
1: import_panasonic_comfort_cloud_client.OperationMode[1],
|
|
328
|
+
2: import_panasonic_comfort_cloud_client.OperationMode[2],
|
|
329
|
+
3: import_panasonic_comfort_cloud_client.OperationMode[3],
|
|
330
|
+
4: import_panasonic_comfort_cloud_client.OperationMode[4]
|
|
331
|
+
},
|
|
332
|
+
write: true,
|
|
333
|
+
def: device.operationMode,
|
|
334
|
+
type: "number"
|
|
335
|
+
},
|
|
336
|
+
void 0
|
|
337
|
+
);
|
|
338
|
+
this.createState(
|
|
339
|
+
deviceInfo.name,
|
|
340
|
+
"",
|
|
341
|
+
"fanSpeed",
|
|
342
|
+
{
|
|
343
|
+
role: "state",
|
|
344
|
+
states: {
|
|
345
|
+
0: import_panasonic_comfort_cloud_client.FanSpeed[0],
|
|
346
|
+
1: import_panasonic_comfort_cloud_client.FanSpeed[1],
|
|
347
|
+
2: import_panasonic_comfort_cloud_client.FanSpeed[2],
|
|
348
|
+
3: import_panasonic_comfort_cloud_client.FanSpeed[3],
|
|
349
|
+
4: import_panasonic_comfort_cloud_client.FanSpeed[4],
|
|
350
|
+
5: import_panasonic_comfort_cloud_client.FanSpeed[5]
|
|
351
|
+
},
|
|
352
|
+
write: true,
|
|
353
|
+
def: device.fanSpeed,
|
|
354
|
+
type: "number"
|
|
355
|
+
},
|
|
356
|
+
void 0
|
|
357
|
+
);
|
|
358
|
+
this.createState(
|
|
359
|
+
deviceInfo.name,
|
|
360
|
+
"",
|
|
361
|
+
"actualNanoe",
|
|
362
|
+
{
|
|
363
|
+
role: "state",
|
|
364
|
+
states: {
|
|
365
|
+
0: import_panasonic_comfort_cloud_client.NanoeMode[0],
|
|
366
|
+
1: import_panasonic_comfort_cloud_client.NanoeMode[1],
|
|
367
|
+
2: import_panasonic_comfort_cloud_client.NanoeMode[2],
|
|
368
|
+
3: import_panasonic_comfort_cloud_client.NanoeMode[3],
|
|
369
|
+
4: import_panasonic_comfort_cloud_client.NanoeMode[4]
|
|
370
|
+
},
|
|
371
|
+
write: true,
|
|
372
|
+
def: device.actualNanoe,
|
|
373
|
+
type: "number"
|
|
374
|
+
},
|
|
375
|
+
void 0
|
|
376
|
+
);
|
|
377
|
+
this.log.info(`Device ${deviceInfo.name} created.`);
|
|
378
|
+
}
|
|
379
|
+
}));
|
|
380
|
+
this.log.debug("Device creation completed.");
|
|
381
|
+
}
|
|
382
|
+
async updateDevice(deviceName, stateName, state) {
|
|
383
|
+
if (this.readonlyStateNames.includes(stateName)) {
|
|
384
|
+
return;
|
|
328
385
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
386
|
+
if (!state.ack) {
|
|
387
|
+
const stateObj = await this.getObjectAsync(`${deviceName}.${stateName}`);
|
|
388
|
+
const stateCommon = stateObj == null ? void 0 : stateObj.common;
|
|
389
|
+
if ((stateCommon == null ? void 0 : stateCommon.write) == false) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const guidState = await this.getStateAsync(`${deviceName}.guid`);
|
|
393
|
+
this.log.debug(
|
|
394
|
+
`Update device guid=${guidState == null ? void 0 : guidState.val} state=${stateName}`
|
|
395
|
+
);
|
|
396
|
+
const parameters = {};
|
|
397
|
+
parameters[stateName] = state.val;
|
|
398
|
+
if (!(guidState == null ? void 0 : guidState.val)) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
this.log.debug(`Set device parameter ${JSON.stringify(parameters)} for device ${guidState == null ? void 0 : guidState.val}`);
|
|
403
|
+
await comfortCloudClient.setParameters(
|
|
404
|
+
guidState == null ? void 0 : guidState.val,
|
|
405
|
+
parameters
|
|
406
|
+
);
|
|
407
|
+
this.log.debug(`Refresh device ${deviceName}`);
|
|
408
|
+
await this.refreshDevice(guidState == null ? void 0 : guidState.val, deviceName);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
await this.handleClientError(error);
|
|
411
|
+
}
|
|
352
412
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
else if (error instanceof panasonic_comfort_cloud_client_1.ServiceError) {
|
|
364
|
-
this.setState('info.connection', false, true);
|
|
365
|
-
this.log.error(`Service error: ${error.message}. Code=${error.code}. Stack: ${error.stack}`);
|
|
366
|
-
}
|
|
367
|
-
else if (error instanceof Error) {
|
|
368
|
-
this.log.error(`Unknown error: ${error}. Stack: ${error.stack}`);
|
|
369
|
-
}
|
|
370
|
-
});
|
|
413
|
+
}
|
|
414
|
+
onUnload(callback) {
|
|
415
|
+
try {
|
|
416
|
+
if (this.refreshTimeout)
|
|
417
|
+
clearTimeout(this.refreshTimeout);
|
|
418
|
+
this.log.info("cleaned everything up...");
|
|
419
|
+
callback();
|
|
420
|
+
} catch (e) {
|
|
421
|
+
callback();
|
|
371
422
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
423
|
+
}
|
|
424
|
+
onObjectChange(id, obj) {
|
|
425
|
+
if (obj) {
|
|
426
|
+
this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
|
|
427
|
+
} else {
|
|
428
|
+
this.log.info(`object ${id} deleted`);
|
|
377
429
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
430
|
+
}
|
|
431
|
+
async onStateChange(id, state) {
|
|
432
|
+
if (state) {
|
|
433
|
+
const elements = id.split(".");
|
|
434
|
+
const deviceName = elements[elements.length - 2];
|
|
435
|
+
const stateName = elements[elements.length - 1];
|
|
436
|
+
try {
|
|
437
|
+
await this.updateDevice(deviceName, stateName, state);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
await this.handleClientError(error);
|
|
440
|
+
}
|
|
441
|
+
this.log.info(
|
|
442
|
+
`state ${id} changed: ${state.val} (ack = ${state.ack})`
|
|
443
|
+
);
|
|
444
|
+
} else {
|
|
445
|
+
this.log.info(`state ${id} deleted`);
|
|
389
446
|
}
|
|
447
|
+
}
|
|
448
|
+
async handleClientError(error) {
|
|
449
|
+
this.log.debug("Try to handle error.");
|
|
450
|
+
if (error instanceof import_panasonic_comfort_cloud_client.TokenExpiredError) {
|
|
451
|
+
this.log.info(
|
|
452
|
+
`Token of comfort cloud client expired. Trying to login again. Code=${error.code}. Stack: ${error.stack}`
|
|
453
|
+
);
|
|
454
|
+
this.setState("info.connection", false, true);
|
|
455
|
+
await comfortCloudClient.login(
|
|
456
|
+
this.config.username,
|
|
457
|
+
this.config.password
|
|
458
|
+
);
|
|
459
|
+
this.setState("info.connection", true, true);
|
|
460
|
+
this.log.info("Login successful.");
|
|
461
|
+
} else if (error instanceof import_panasonic_comfort_cloud_client.ServiceError) {
|
|
462
|
+
this.setState("info.connection", false, true);
|
|
463
|
+
this.log.error(
|
|
464
|
+
`Service error: ${error.message}. Code=${error.code}. Stack: ${error.stack}`
|
|
465
|
+
);
|
|
466
|
+
} else if (error instanceof Error) {
|
|
467
|
+
this.log.error(`Unknown error: ${error}. Stack: ${error.stack}`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
setupRefreshTimeout() {
|
|
471
|
+
this.log.debug("setupRefreshTimeout");
|
|
472
|
+
const refreshIntervalInMilliseconds = this.refreshIntervalInMinutes * 60 * 1e3;
|
|
473
|
+
this.log.debug(`refreshIntervalInMilliseconds=${refreshIntervalInMilliseconds}`);
|
|
474
|
+
this.refreshTimeout = setTimeout(this.refreshTimeoutFunc.bind(this), refreshIntervalInMilliseconds);
|
|
475
|
+
}
|
|
476
|
+
async refreshTimeoutFunc() {
|
|
477
|
+
this.log.debug(`refreshTimeoutFunc started.`);
|
|
478
|
+
try {
|
|
479
|
+
await this.refreshDevices();
|
|
480
|
+
this.setupRefreshTimeout();
|
|
481
|
+
} catch (error) {
|
|
482
|
+
await this.handleClientError(error);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
390
485
|
}
|
|
391
486
|
if (module.parent) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
else {
|
|
396
|
-
// otherwise start the instance directly
|
|
397
|
-
(() => new PanasonicComfortCloud())();
|
|
487
|
+
module.exports = (options) => new PanasonicComfortCloud(options);
|
|
488
|
+
} else {
|
|
489
|
+
(() => new PanasonicComfortCloud())();
|
|
398
490
|
}
|
|
491
|
+
//# sourceMappingURL=main.js.map
|