iobroker.panasonic-comfort-cloud 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/main.js CHANGED
@@ -1,430 +1,544 @@
1
1
  "use strict";
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 };
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;
30
15
  };
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"));
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"));
38
24
  const REFRESH_INTERVAL_IN_MINUTES_DEFAULT = 5;
39
25
  class PanasonicComfortCloud extends utils.Adapter {
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));
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;
53
49
  }
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
- }
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
+ } else if (((_k = this.config) == null ? void 0 : _k.appVersion) != "") {
57
+ this.log.debug(`Use configured AppVersion ${(_l = this.config) == null ? void 0 : _l.appVersion}.`);
58
+ this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient((_m = this.config) == null ? void 0 : _m.appVersion);
59
+ } else {
60
+ this.log.debug(`Use default AppVersion.`);
61
+ this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient();
62
+ }
63
+ try {
64
+ this.log.debug(`Try to login with username ${this.config.username}.`);
65
+ await this.comfortCloudClient.login(
66
+ this.config.username,
67
+ this.config.password
68
+ );
69
+ this.log.info("Login successful.");
70
+ this.setState("info.connection", true, true);
71
+ this.log.debug("Create devices.");
72
+ const groups = await this.comfortCloudClient.getGroups();
73
+ await this.createDevices(groups);
74
+ this.setupRefreshTimeout();
75
+ } catch (error) {
76
+ await this.handleClientError(error);
77
+ }
97
78
  }
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.`);
79
+ }
80
+ async refreshDeviceStates(device) {
81
+ this.log.debug(`Refresh device ${device.name} (${device.guid}).`);
82
+ this.log.debug(`${device.name}: guid => ${device.guid}.`);
83
+ this.log.debug(`${device.name}: operate => ${device.operate}.`);
84
+ await this.setStateChangedAsync(
85
+ `${device.name}.operate`,
86
+ device.operate,
87
+ true
88
+ );
89
+ this.log.debug(`${device.name}: temperatureSet => ${device.temperatureSet}.`);
90
+ await this.setStateChangedAsync(
91
+ `${device.name}.temperatureSet`,
92
+ device.temperatureSet,
93
+ true
94
+ );
95
+ this.log.debug(`${device.name}: insideTemperature => ${device.insideTemperature}.`);
96
+ await this.setStateChangedAsync(
97
+ `${device.name}.insideTemperature`,
98
+ device.insideTemperature,
99
+ true
100
+ );
101
+ this.log.debug(`${device.name}: outTemperature => ${device.outTemperature}.`);
102
+ await this.setStateChangedAsync(
103
+ `${device.name}.outTemperature`,
104
+ device.outTemperature,
105
+ true
106
+ );
107
+ this.log.debug(`${device.name}: airSwingLR => ${device.airSwingLR}.`);
108
+ await this.setStateChangedAsync(
109
+ `${device.name}.airSwingLR`,
110
+ device.airSwingLR,
111
+ true
112
+ );
113
+ this.log.debug(`${device.name}: airSwingUD => ${device.airSwingUD}.`);
114
+ await this.setStateChangedAsync(
115
+ `${device.name}.airSwingUD`,
116
+ device.airSwingUD,
117
+ true
118
+ );
119
+ this.log.debug(`${device.name}: fanAutoMode => ${device.fanAutoMode}.`);
120
+ await this.setStateChangedAsync(
121
+ `${device.name}.fanAutoMode`,
122
+ device.fanAutoMode,
123
+ true
124
+ );
125
+ this.log.debug(`${device.name}: ecoMode => ${device.ecoMode}.`);
126
+ await this.setStateChangedAsync(
127
+ `${device.name}.ecoMode`,
128
+ device.ecoMode,
129
+ true
130
+ );
131
+ this.log.debug(`${device.name}: operationMode => ${device.operationMode}.`);
132
+ await this.setStateChangedAsync(
133
+ `${device.name}.operationMode`,
134
+ device.operationMode,
135
+ true
136
+ );
137
+ this.log.debug(`${device.name}: fanSpeed => ${device.fanSpeed}.`);
138
+ await this.setStateChangedAsync(
139
+ `${device.name}.fanSpeed`,
140
+ device.fanSpeed,
141
+ true
142
+ );
143
+ this.log.debug(`${device.name}: actualNanoe => ${device.actualNanoe}.`);
144
+ await this.setStateChangedAsync(
145
+ `${device.name}.actualNanoe`,
146
+ device.actualNanoe,
147
+ true
148
+ );
149
+ await this.setStateChangedAsync(
150
+ `${device.name}.connected`,
151
+ true,
152
+ true
153
+ );
154
+ this.log.debug(`Refresh device ${device.name} finished.`);
155
+ }
156
+ async refreshDevice(guid, deviceName) {
157
+ try {
158
+ const device = await this.comfortCloudClient.getDevice(guid, deviceName);
159
+ if (!device) {
160
+ return;
161
+ }
162
+ if (!device.name) {
163
+ device.name = deviceName;
164
+ }
165
+ await this.refreshDeviceStates(device);
166
+ } catch (error) {
167
+ await this.handleDeviceError(deviceName, error);
124
168
  }
125
- async refreshDevice(guid, deviceName) {
169
+ }
170
+ async refreshDevices() {
171
+ try {
172
+ this.log.debug("Refresh all devices.");
173
+ const groups = await this.comfortCloudClient.getGroups();
174
+ this.setState("info.connection", true, true);
175
+ const devices = _.flatMap(groups, (g) => g.devices);
176
+ const deviceInfos = _.map(devices, (d) => {
177
+ return { guid: d.guid, name: d.name };
178
+ });
179
+ await Promise.all(deviceInfos.map(async (deviceInfo) => {
126
180
  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
- }
181
+ const device = await this.comfortCloudClient.getDevice(deviceInfo.guid, deviceInfo.name);
182
+ if (device != null) {
183
+ device.name = deviceInfo.name;
184
+ device.guid = deviceInfo.guid;
134
185
  await this.refreshDeviceStates(device);
186
+ }
187
+ } catch (error) {
188
+ await this.handleDeviceError(deviceInfo.name, error);
135
189
  }
136
- catch (error) {
137
- await this.handleClientError(error);
138
- }
139
- }
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);
158
- }
159
- }
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.');
299
- }
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
- }
190
+ }));
191
+ } catch (error) {
192
+ await this.handleClientError(error);
327
193
  }
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
- }
194
+ }
195
+ async createDevices(groups) {
196
+ const devicesFromService = _.flatMap(groups, (g) => g.devices);
197
+ const deviceInfos = _.map(devicesFromService, (d) => {
198
+ return { guid: d.guid, name: d.name };
199
+ });
200
+ await Promise.all(deviceInfos.map(async (deviceInfo) => {
201
+ this.log.debug(`Device info from group ${deviceInfo.guid}, ${deviceInfo.name}.`);
202
+ let device = null;
203
+ try {
204
+ device = await this.comfortCloudClient.getDevice(deviceInfo.guid, deviceInfo.name);
205
+ } catch (error) {
206
+ await this.handleDeviceError(deviceInfo.name, error);
207
+ return;
208
+ }
209
+ if (device != null) {
210
+ this.createDevice(deviceInfo.name);
211
+ this.createState(
212
+ deviceInfo.name,
213
+ "",
214
+ "guid",
215
+ { role: "info.address", write: false, def: deviceInfo.guid, type: "string" },
216
+ void 0
217
+ );
218
+ this.readonlyStateNames.push("guid");
219
+ this.createState(
220
+ deviceInfo.name,
221
+ "",
222
+ "operate",
223
+ {
224
+ role: "switch.power",
225
+ states: { 0: import_panasonic_comfort_cloud_client.Power[0], 1: import_panasonic_comfort_cloud_client.Power[1] },
226
+ write: true,
227
+ def: device.operate,
228
+ type: "number"
229
+ },
230
+ void 0
231
+ );
232
+ this.createState(
233
+ deviceInfo.name,
234
+ "",
235
+ "temperatureSet",
236
+ {
237
+ role: "level.temperature",
238
+ write: true,
239
+ def: device.temperatureSet,
240
+ type: "number"
241
+ },
242
+ void 0
243
+ );
244
+ this.createState(
245
+ deviceInfo.name,
246
+ "",
247
+ "insideTemperature",
248
+ {
249
+ role: "level.temperature",
250
+ write: false,
251
+ def: device.insideTemperature,
252
+ type: "number"
253
+ },
254
+ void 0
255
+ );
256
+ this.readonlyStateNames.push("insideTemperature");
257
+ this.createState(
258
+ deviceInfo.name,
259
+ "",
260
+ "outTemperature",
261
+ {
262
+ role: "level.temperature",
263
+ write: false,
264
+ def: device.outTemperature,
265
+ type: "number"
266
+ },
267
+ void 0
268
+ );
269
+ this.readonlyStateNames.push("outTemperature");
270
+ this.createState(
271
+ deviceInfo.name,
272
+ "",
273
+ "airSwingLR",
274
+ {
275
+ role: "state",
276
+ states: {
277
+ 0: import_panasonic_comfort_cloud_client.AirSwingLR[0],
278
+ 1: import_panasonic_comfort_cloud_client.AirSwingLR[1],
279
+ 2: import_panasonic_comfort_cloud_client.AirSwingLR[2],
280
+ 3: import_panasonic_comfort_cloud_client.AirSwingLR[3],
281
+ 4: import_panasonic_comfort_cloud_client.AirSwingLR[4]
282
+ },
283
+ write: true,
284
+ def: device.airSwingLR,
285
+ type: "number"
286
+ },
287
+ void 0
288
+ );
289
+ this.createState(
290
+ deviceInfo.name,
291
+ "",
292
+ "airSwingUD",
293
+ {
294
+ role: "state",
295
+ states: {
296
+ 0: import_panasonic_comfort_cloud_client.AirSwingUD[0],
297
+ 1: import_panasonic_comfort_cloud_client.AirSwingUD[1],
298
+ 2: import_panasonic_comfort_cloud_client.AirSwingUD[2],
299
+ 3: import_panasonic_comfort_cloud_client.AirSwingUD[3],
300
+ 4: import_panasonic_comfort_cloud_client.AirSwingUD[4]
301
+ },
302
+ write: true,
303
+ def: device.airSwingUD,
304
+ type: "number"
305
+ },
306
+ void 0
307
+ );
308
+ this.createState(
309
+ deviceInfo.name,
310
+ "",
311
+ "fanAutoMode",
312
+ {
313
+ role: "state",
314
+ states: {
315
+ 0: import_panasonic_comfort_cloud_client.FanAutoMode[0],
316
+ 1: import_panasonic_comfort_cloud_client.FanAutoMode[1],
317
+ 2: import_panasonic_comfort_cloud_client.FanAutoMode[2],
318
+ 3: import_panasonic_comfort_cloud_client.FanAutoMode[3]
319
+ },
320
+ write: true,
321
+ def: device.fanAutoMode,
322
+ type: "number"
323
+ },
324
+ void 0
325
+ );
326
+ this.createState(
327
+ deviceInfo.name,
328
+ "",
329
+ "ecoMode",
330
+ {
331
+ role: "state",
332
+ 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] },
333
+ write: true,
334
+ def: device.ecoMode,
335
+ type: "number"
336
+ },
337
+ void 0
338
+ );
339
+ this.createState(
340
+ deviceInfo.name,
341
+ "",
342
+ "operationMode",
343
+ {
344
+ role: "state",
345
+ states: {
346
+ 0: import_panasonic_comfort_cloud_client.OperationMode[0],
347
+ 1: import_panasonic_comfort_cloud_client.OperationMode[1],
348
+ 2: import_panasonic_comfort_cloud_client.OperationMode[2],
349
+ 3: import_panasonic_comfort_cloud_client.OperationMode[3],
350
+ 4: import_panasonic_comfort_cloud_client.OperationMode[4]
351
+ },
352
+ write: true,
353
+ def: device.operationMode,
354
+ type: "number"
355
+ },
356
+ void 0
357
+ );
358
+ this.createState(
359
+ deviceInfo.name,
360
+ "",
361
+ "fanSpeed",
362
+ {
363
+ role: "state",
364
+ states: {
365
+ 0: import_panasonic_comfort_cloud_client.FanSpeed[0],
366
+ 1: import_panasonic_comfort_cloud_client.FanSpeed[1],
367
+ 2: import_panasonic_comfort_cloud_client.FanSpeed[2],
368
+ 3: import_panasonic_comfort_cloud_client.FanSpeed[3],
369
+ 4: import_panasonic_comfort_cloud_client.FanSpeed[4],
370
+ 5: import_panasonic_comfort_cloud_client.FanSpeed[5]
371
+ },
372
+ write: true,
373
+ def: device.fanSpeed,
374
+ type: "number"
375
+ },
376
+ void 0
377
+ );
378
+ this.createState(
379
+ deviceInfo.name,
380
+ "",
381
+ "actualNanoe",
382
+ {
383
+ role: "state",
384
+ states: {
385
+ 0: import_panasonic_comfort_cloud_client.NanoeMode[0],
386
+ 1: import_panasonic_comfort_cloud_client.NanoeMode[1],
387
+ 2: import_panasonic_comfort_cloud_client.NanoeMode[2],
388
+ 3: import_panasonic_comfort_cloud_client.NanoeMode[3],
389
+ 4: import_panasonic_comfort_cloud_client.NanoeMode[4]
390
+ },
391
+ write: true,
392
+ def: device.actualNanoe,
393
+ type: "number"
394
+ },
395
+ void 0
396
+ );
397
+ this.createState(
398
+ deviceInfo.name,
399
+ "",
400
+ "connected",
401
+ { role: "state", read: true, write: false, def: false, type: "boolean" },
402
+ void 0
403
+ );
404
+ this.log.info(`Device ${deviceInfo.name} created.`);
405
+ }
406
+ }));
407
+ this.log.debug("Device creation completed.");
408
+ }
409
+ async updateDevice(deviceName, stateName, state) {
410
+ if (this.readonlyStateNames.includes(stateName)) {
411
+ return;
341
412
  }
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
- }
413
+ if (!state.ack) {
414
+ const stateObj = await this.getObjectAsync(`${deviceName}.${stateName}`);
415
+ const stateCommon = stateObj == null ? void 0 : stateObj.common;
416
+ if ((stateCommon == null ? void 0 : stateCommon.write) == false) {
417
+ return;
418
+ }
419
+ const guidState = await this.getStateAsync(`${deviceName}.guid`);
420
+ this.log.debug(
421
+ `Update device guid=${guidState == null ? void 0 : guidState.val} state=${stateName}`
422
+ );
423
+ const parameters = {};
424
+ parameters[stateName] = state.val;
425
+ if (!(guidState == null ? void 0 : guidState.val)) {
426
+ return;
427
+ }
428
+ try {
429
+ this.log.debug(`Set device parameter ${JSON.stringify(parameters)} for device ${guidState == null ? void 0 : guidState.val}`);
430
+ await this.comfortCloudClient.setParameters(
431
+ guidState == null ? void 0 : guidState.val,
432
+ parameters
433
+ );
434
+ this.log.debug(`Refresh device ${deviceName}`);
435
+ await this.refreshDevice(guidState == null ? void 0 : guidState.val, deviceName);
436
+ } catch (error) {
437
+ await this.handleClientError(error);
438
+ }
354
439
  }
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
- }
440
+ }
441
+ onUnload(callback) {
442
+ try {
443
+ if (this.refreshTimeout)
444
+ clearTimeout(this.refreshTimeout);
445
+ this.log.info("cleaned everything up...");
446
+ callback();
447
+ } catch (e) {
448
+ callback();
376
449
  }
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;
450
+ }
451
+ onObjectChange(id, obj) {
452
+ if (obj) {
453
+ this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
454
+ } else {
455
+ this.log.info(`object ${id} deleted`);
383
456
  }
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
- }
457
+ }
458
+ async onStateChange(id, state) {
459
+ if (state) {
460
+ const elements = id.split(".");
461
+ const deviceName = elements[elements.length - 2];
462
+ const stateName = elements[elements.length - 1];
463
+ try {
464
+ await this.updateDevice(deviceName, stateName, state);
465
+ } catch (error) {
466
+ await this.handleClientError(error);
467
+ }
468
+ this.log.info(
469
+ `state ${id} changed: ${state.val} (ack = ${state.ack})`
470
+ );
471
+ } else {
472
+ this.log.info(`state ${id} deleted`);
400
473
  }
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);
474
+ }
475
+ async getCurrentAppVersion() {
476
+ const response = await import_axios.default.get("https://raw.githubusercontent.com/marc2016/ioBroker.panasonic-comfort-cloud/master/.currentAppVersion");
477
+ if (response.status !== 200)
478
+ return "";
479
+ const text = await response.data;
480
+ return text;
481
+ }
482
+ async handleDeviceError(deviceName, error) {
483
+ this.log.debug(`Try to handle device error for ${deviceName}.`);
484
+ await this.setStateChangedAsync(
485
+ `${deviceName}.connected`,
486
+ false,
487
+ true
488
+ );
489
+ if (error instanceof import_panasonic_comfort_cloud_client.ServiceError) {
490
+ this.log.error(
491
+ `Service error when connecting to device ${deviceName}: ${error.message}. Code=${error.code}. Stack: ${error.stack}`
492
+ );
493
+ } else if (error instanceof Error) {
494
+ this.log.error(`Unknown error when connecting to device ${deviceName}: ${error}. Stack: ${error.stack}`);
406
495
  }
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
- }
496
+ }
497
+ async handleClientError(error) {
498
+ this.log.debug("Try to handle error.");
499
+ if (error instanceof import_panasonic_comfort_cloud_client.TokenExpiredError) {
500
+ this.log.info(
501
+ `Token of comfort cloud client expired. Trying to login again. Code=${error.code}. Stack: ${error.stack}`
502
+ );
503
+ this.setState("info.connection", false, true);
504
+ await this.comfortCloudClient.login(
505
+ this.config.username,
506
+ this.config.password
507
+ );
508
+ this.setState("info.connection", true, true);
509
+ this.log.info("Login successful.");
510
+ } else if (error instanceof import_panasonic_comfort_cloud_client.ServiceError) {
511
+ this.setState("info.connection", false, true);
512
+ this.log.error(
513
+ `Service error: ${error.message}. Code=${error.code}. Stack: ${error.stack}`
514
+ );
515
+ } else if (error instanceof Error) {
516
+ this.log.error(`Unknown error: ${error}. Stack: ${error.stack}`);
416
517
  }
417
- trimAll(text) {
418
- const newText = text.trim().replace(/(\r\n|\n|\r)/gm, '');
419
- return newText;
518
+ }
519
+ setupRefreshTimeout() {
520
+ this.log.debug("setupRefreshTimeout");
521
+ const refreshIntervalInMilliseconds = this.refreshIntervalInMinutes * 60 * 1e3;
522
+ this.log.debug(`refreshIntervalInMilliseconds=${refreshIntervalInMilliseconds}`);
523
+ this.refreshTimeout = setTimeout(this.refreshTimeoutFunc.bind(this), refreshIntervalInMilliseconds);
524
+ }
525
+ async refreshTimeoutFunc() {
526
+ this.log.debug(`refreshTimeoutFunc started.`);
527
+ try {
528
+ await this.refreshDevices();
529
+ this.setupRefreshTimeout();
530
+ } catch (error) {
531
+ await this.handleClientError(error);
420
532
  }
533
+ }
534
+ trimAll(text) {
535
+ const newText = text.trim().replace(/(\r\n|\n|\r)/gm, "");
536
+ return newText;
537
+ }
421
538
  }
422
539
  if (module.parent) {
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())();
540
+ module.exports = (options) => new PanasonicComfortCloud(options);
541
+ } else {
542
+ (() => new PanasonicComfortCloud())();
429
543
  }
430
- //# sourceMappingURL=main.js.map
544
+ //# sourceMappingURL=main.js.map