iobroker.panasonic-comfort-cloud 2.2.2 → 2.2.3

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