iobroker.panasonic-comfort-cloud 3.0.3 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +20 -4
- package/admin/i18n/de/translations.json +4 -3
- package/admin/i18n/en/translations.json +4 -3
- package/admin/i18n/es/translations.json +3 -3
- package/admin/i18n/fr/translations.json +3 -3
- package/admin/i18n/it/translations.json +3 -3
- package/admin/i18n/nl/translations.json +3 -3
- package/admin/i18n/pl/translations.json +3 -3
- package/admin/i18n/pt/translations.json +3 -3
- package/admin/i18n/ru/translations.json +3 -3
- package/admin/i18n/uk/translations.json +3 -3
- package/admin/i18n/zh-cn/translations.json +3 -3
- package/admin/jsonConfig.json +41 -11
- package/build/lib/state-definitions.js +181 -0
- package/build/lib/state-definitions.js.map +7 -0
- package/build/main.js +151 -287
- package/build/main.js.map +2 -2
- package/io-package.json +57 -43
- package/package.json +17 -11
- package/admin/words.js +0 -18
package/build/main.js
CHANGED
|
@@ -19,8 +19,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
));
|
|
20
20
|
var utils = __toESM(require("@iobroker/adapter-core"));
|
|
21
21
|
var import_panasonic_comfort_cloud_client = require("panasonic-comfort-cloud-client");
|
|
22
|
-
var _ = __toESM(require("lodash"));
|
|
23
22
|
var import_axios = __toESM(require("axios"));
|
|
23
|
+
var import_state_definitions = require("./lib/state-definitions");
|
|
24
24
|
const REFRESH_INTERVAL_IN_MINUTES_DEFAULT = 5;
|
|
25
25
|
class PanasonicComfortCloud extends utils.Adapter {
|
|
26
26
|
constructor(options = {}) {
|
|
@@ -30,29 +30,29 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
30
30
|
});
|
|
31
31
|
this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient();
|
|
32
32
|
this.refreshIntervalInMinutes = REFRESH_INTERVAL_IN_MINUTES_DEFAULT;
|
|
33
|
-
this.
|
|
33
|
+
this.historyRefreshIntervalInMinutes = 60;
|
|
34
34
|
this.on("ready", this.onReady.bind(this));
|
|
35
35
|
this.on("objectChange", this.onObjectChange.bind(this));
|
|
36
36
|
this.on("stateChange", this.onStateChange.bind(this));
|
|
37
37
|
this.on("unload", this.onUnload.bind(this));
|
|
38
38
|
}
|
|
39
39
|
async onReady() {
|
|
40
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
41
41
|
this.refreshIntervalInMinutes = (_b = (_a = this.config) == null ? void 0 : _a.refreshInterval) != null ? _b : REFRESH_INTERVAL_IN_MINUTES_DEFAULT;
|
|
42
42
|
this.subscribeStates("*");
|
|
43
|
-
this.
|
|
43
|
+
await this.setStateAsync("info.connection", false, true);
|
|
44
44
|
const loadedAppVersion = await this.getCurrentAppVersion();
|
|
45
|
-
this.log.info(`Loaded app version from
|
|
46
|
-
if (loadedAppVersion && this.trimAll((_c = this.config) == null ? void 0 : _c.
|
|
47
|
-
this.updateConfig({
|
|
45
|
+
this.log.info(`Loaded app version from App store: ${loadedAppVersion}`);
|
|
46
|
+
if (loadedAppVersion && this.trimAll((_c = this.config) == null ? void 0 : _c.appVersionFromAppStore) != this.trimAll(loadedAppVersion)) {
|
|
47
|
+
this.updateConfig({ appVersionFromAppStore: this.trimAll(loadedAppVersion), password: this.encrypt((_d = this.config) == null ? void 0 : _d.password) });
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
if (!((_e = this.config) == null ? void 0 : _e.username) || !((_f = this.config) == null ? void 0 : _f.password)) {
|
|
51
51
|
this.log.error("Can not start without username or password. Please open config.");
|
|
52
52
|
} else {
|
|
53
|
-
if (((_g = this.config) == null ? void 0 : _g.
|
|
54
|
-
this.log.debug(`Use AppVersion from
|
|
55
|
-
this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient((_j = this.config) == null ? void 0 : _j.
|
|
53
|
+
if (((_g = this.config) == null ? void 0 : _g.appVersionFromAppStore) != "" && ((_h = this.config) == null ? void 0 : _h.useAppVersionFromAppStore)) {
|
|
54
|
+
this.log.debug(`Use AppVersion from App Store ${(_i = this.config) == null ? void 0 : _i.appVersionFromAppStore}.`);
|
|
55
|
+
this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient((_j = this.config) == null ? void 0 : _j.appVersionFromAppStore);
|
|
56
56
|
} else if (((_k = this.config) == null ? void 0 : _k.appVersion) != "") {
|
|
57
57
|
this.log.debug(`Use configured AppVersion ${(_l = this.config) == null ? void 0 : _l.appVersion}.`);
|
|
58
58
|
this.comfortCloudClient = new import_panasonic_comfort_cloud_client.ComfortCloudClient((_m = this.config) == null ? void 0 : _m.appVersion);
|
|
@@ -67,7 +67,7 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
67
67
|
this.config.password
|
|
68
68
|
);
|
|
69
69
|
this.log.info("Login successful.");
|
|
70
|
-
this.
|
|
70
|
+
await this.setStateAsync("info.connection", true, true);
|
|
71
71
|
this.log.debug("Create devices.");
|
|
72
72
|
const groups = await this.comfortCloudClient.getGroups();
|
|
73
73
|
await this.createDevices(groups);
|
|
@@ -75,85 +75,72 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
75
75
|
if ((_o = this.config) == null ? void 0 : _o.automaticRefreshEnabled) {
|
|
76
76
|
this.setupRefreshTimeout();
|
|
77
77
|
}
|
|
78
|
+
if ((_p = this.config) == null ? void 0 : _p.historyEnabled) {
|
|
79
|
+
this.log.debug(`History enabled. Refreshing history.`);
|
|
80
|
+
await this.refreshHistory(groups);
|
|
81
|
+
this.setupHistoryRefreshTimeout();
|
|
82
|
+
}
|
|
78
83
|
} catch (error) {
|
|
79
84
|
await this.handleClientError(error);
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
}
|
|
88
|
+
async refreshHistory(groups) {
|
|
89
|
+
const devicesFromService = groups.flatMap((g) => g.devices);
|
|
90
|
+
const deviceInfos = devicesFromService.map((d) => {
|
|
91
|
+
return { guid: d.guid, name: d.name };
|
|
92
|
+
});
|
|
93
|
+
for (const deviceInfo of deviceInfos) {
|
|
94
|
+
const modes = {
|
|
95
|
+
"day": import_panasonic_comfort_cloud_client.DataMode.Day
|
|
96
|
+
};
|
|
97
|
+
for (const [modeName, dataMode] of Object.entries(modes)) {
|
|
98
|
+
try {
|
|
99
|
+
this.log.debug(`Fetching ${modeName} history for ${deviceInfo.name}`);
|
|
100
|
+
const history = await this.comfortCloudClient.getDeviceHistoryData(deviceInfo.guid, new Date(), dataMode);
|
|
101
|
+
if (history && history.historyDataList) {
|
|
102
|
+
for (let i = 0; i < history.historyDataList.length; i++) {
|
|
103
|
+
const data = history.historyDataList[i];
|
|
104
|
+
const index = i.toString().padStart(2, "0");
|
|
105
|
+
const prefix = `${deviceInfo.name}.history.${modeName}.${index}`;
|
|
106
|
+
await this.setStateChangedAsync(`${prefix}.dataTime`, data.dataTime, true);
|
|
107
|
+
await this.setStateChangedAsync(`${prefix}.averageSettingTemp`, data.averageSettingTemp, true);
|
|
108
|
+
await this.setStateChangedAsync(`${prefix}.averageInsideTemp`, data.averageInsideTemp, true);
|
|
109
|
+
await this.setStateChangedAsync(`${prefix}.averageOutsideTemp`, data.averageOutsideTemp, true);
|
|
110
|
+
await this.setStateChangedAsync(`${prefix}.consumption`, data.consumption, true);
|
|
111
|
+
await this.setStateChangedAsync(`${prefix}.cost`, data.cost, true);
|
|
112
|
+
await this.setStateChangedAsync(`${prefix}.heatConsumptionRate`, data.heatConsumptionRate, true);
|
|
113
|
+
await this.setStateChangedAsync(`${prefix}.coolConsumptionRate`, data.coolConsumptionRate, true);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
this.log.warn(`Failed to fetch history ${modeName} for ${deviceInfo.name}: ${e}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
83
122
|
async refreshDeviceStates(device) {
|
|
84
123
|
this.log.debug(`Refresh device ${device.name} (${device.guid}).`);
|
|
85
124
|
this.log.debug(`${device.name}: guid => ${device.guid}.`);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
device.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await this.setStateChangedAsync(
|
|
106
|
-
`${device.name}.outTemperature`,
|
|
107
|
-
device.outTemperature,
|
|
108
|
-
true
|
|
109
|
-
);
|
|
110
|
-
this.log.debug(`${device.name}: airSwingLR => ${device.airSwingLR}.`);
|
|
111
|
-
await this.setStateChangedAsync(
|
|
112
|
-
`${device.name}.airSwingLR`,
|
|
113
|
-
device.airSwingLR,
|
|
114
|
-
true
|
|
115
|
-
);
|
|
116
|
-
this.log.debug(`${device.name}: airSwingUD => ${device.airSwingUD}.`);
|
|
117
|
-
await this.setStateChangedAsync(
|
|
118
|
-
`${device.name}.airSwingUD`,
|
|
119
|
-
device.airSwingUD,
|
|
120
|
-
true
|
|
121
|
-
);
|
|
122
|
-
this.log.debug(`${device.name}: fanAutoMode => ${device.fanAutoMode}.`);
|
|
123
|
-
await this.setStateChangedAsync(
|
|
124
|
-
`${device.name}.fanAutoMode`,
|
|
125
|
-
device.fanAutoMode,
|
|
126
|
-
true
|
|
127
|
-
);
|
|
128
|
-
this.log.debug(`${device.name}: ecoMode => ${device.ecoMode}.`);
|
|
129
|
-
await this.setStateChangedAsync(
|
|
130
|
-
`${device.name}.ecoMode`,
|
|
131
|
-
device.ecoMode,
|
|
132
|
-
true
|
|
133
|
-
);
|
|
134
|
-
this.log.debug(`${device.name}: operationMode => ${device.operationMode}.`);
|
|
135
|
-
await this.setStateChangedAsync(
|
|
136
|
-
`${device.name}.operationMode`,
|
|
137
|
-
device.operationMode,
|
|
138
|
-
true
|
|
139
|
-
);
|
|
140
|
-
this.log.debug(`${device.name}: fanSpeed => ${device.fanSpeed}.`);
|
|
141
|
-
await this.setStateChangedAsync(
|
|
142
|
-
`${device.name}.fanSpeed`,
|
|
143
|
-
device.fanSpeed,
|
|
144
|
-
true
|
|
145
|
-
);
|
|
146
|
-
this.log.debug(`${device.name}: actualNanoe => ${device.actualNanoe}.`);
|
|
147
|
-
await this.setStateChangedAsync(
|
|
148
|
-
`${device.name}.actualNanoe`,
|
|
149
|
-
device.actualNanoe,
|
|
150
|
-
true
|
|
151
|
-
);
|
|
152
|
-
await this.setStateChangedAsync(
|
|
153
|
-
`${device.name}.connected`,
|
|
154
|
-
true,
|
|
155
|
-
true
|
|
156
|
-
);
|
|
125
|
+
for (const stateDef of import_state_definitions.deviceStates) {
|
|
126
|
+
if (stateDef.id === "guid")
|
|
127
|
+
continue;
|
|
128
|
+
const value = device[stateDef.id];
|
|
129
|
+
this.log.debug(`${device.name}: ${stateDef.id} => ${value}.`);
|
|
130
|
+
if (value !== void 0) {
|
|
131
|
+
await this.setStateChangedAsync(
|
|
132
|
+
`${device.name}.${stateDef.id}`,
|
|
133
|
+
value,
|
|
134
|
+
true
|
|
135
|
+
);
|
|
136
|
+
} else if (stateDef.id === "connected") {
|
|
137
|
+
await this.setStateChangedAsync(
|
|
138
|
+
`${device.name}.connected`,
|
|
139
|
+
true,
|
|
140
|
+
true
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
157
144
|
this.log.debug(`Refresh device ${device.name} finished.`);
|
|
158
145
|
}
|
|
159
146
|
async refreshDevice(guid, deviceName) {
|
|
@@ -174,9 +161,9 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
174
161
|
try {
|
|
175
162
|
this.log.debug("Refresh all devices.");
|
|
176
163
|
const groups = await this.comfortCloudClient.getGroups();
|
|
177
|
-
this.
|
|
178
|
-
const devices =
|
|
179
|
-
const deviceInfos =
|
|
164
|
+
await this.setStateAsync("info.connection", true, true);
|
|
165
|
+
const devices = groups.flatMap((g) => g.devices);
|
|
166
|
+
const deviceInfos = devices.map((d) => {
|
|
180
167
|
return { guid: d.guid, name: d.name };
|
|
181
168
|
});
|
|
182
169
|
await Promise.all(deviceInfos.map(async (deviceInfo) => {
|
|
@@ -196,11 +183,12 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
196
183
|
}
|
|
197
184
|
}
|
|
198
185
|
async createDevices(groups) {
|
|
199
|
-
const devicesFromService =
|
|
200
|
-
const deviceInfos =
|
|
186
|
+
const devicesFromService = groups.flatMap((g) => g.devices);
|
|
187
|
+
const deviceInfos = devicesFromService.map((d) => {
|
|
201
188
|
return { guid: d.guid, name: d.name };
|
|
202
189
|
});
|
|
203
190
|
await Promise.all(deviceInfos.map(async (deviceInfo) => {
|
|
191
|
+
var _a;
|
|
204
192
|
this.log.debug(`Device info from group ${deviceInfo.guid}, ${deviceInfo.name}.`);
|
|
205
193
|
let device = null;
|
|
206
194
|
try {
|
|
@@ -210,207 +198,53 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
210
198
|
return;
|
|
211
199
|
}
|
|
212
200
|
if (device != null) {
|
|
213
|
-
this.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"guid",
|
|
218
|
-
{ role: "info.address", write: false, def: deviceInfo.guid, type: "string" },
|
|
219
|
-
void 0
|
|
220
|
-
);
|
|
221
|
-
this.readonlyStateNames.push("guid");
|
|
222
|
-
this.createState(
|
|
223
|
-
deviceInfo.name,
|
|
224
|
-
"",
|
|
225
|
-
"operate",
|
|
226
|
-
{
|
|
227
|
-
role: "switch.power",
|
|
228
|
-
states: { 0: import_panasonic_comfort_cloud_client.Power[0], 1: import_panasonic_comfort_cloud_client.Power[1] },
|
|
229
|
-
write: true,
|
|
230
|
-
def: device.operate,
|
|
231
|
-
type: "number"
|
|
232
|
-
},
|
|
233
|
-
void 0
|
|
234
|
-
);
|
|
235
|
-
this.createState(
|
|
236
|
-
deviceInfo.name,
|
|
237
|
-
"",
|
|
238
|
-
"temperatureSet",
|
|
239
|
-
{
|
|
240
|
-
role: "level.temperature",
|
|
241
|
-
write: true,
|
|
242
|
-
def: device.temperatureSet,
|
|
243
|
-
type: "number"
|
|
244
|
-
},
|
|
245
|
-
void 0
|
|
246
|
-
);
|
|
247
|
-
this.createState(
|
|
248
|
-
deviceInfo.name,
|
|
249
|
-
"",
|
|
250
|
-
"insideTemperature",
|
|
251
|
-
{
|
|
252
|
-
role: "level.temperature",
|
|
253
|
-
write: false,
|
|
254
|
-
def: device.insideTemperature,
|
|
255
|
-
type: "number"
|
|
256
|
-
},
|
|
257
|
-
void 0
|
|
258
|
-
);
|
|
259
|
-
this.readonlyStateNames.push("insideTemperature");
|
|
260
|
-
this.createState(
|
|
261
|
-
deviceInfo.name,
|
|
262
|
-
"",
|
|
263
|
-
"outTemperature",
|
|
264
|
-
{
|
|
265
|
-
role: "level.temperature",
|
|
266
|
-
write: false,
|
|
267
|
-
def: device.outTemperature,
|
|
268
|
-
type: "number"
|
|
269
|
-
},
|
|
270
|
-
void 0
|
|
271
|
-
);
|
|
272
|
-
this.readonlyStateNames.push("outTemperature");
|
|
273
|
-
this.createState(
|
|
274
|
-
deviceInfo.name,
|
|
275
|
-
"",
|
|
276
|
-
"airSwingLR",
|
|
277
|
-
{
|
|
278
|
-
role: "state",
|
|
279
|
-
states: {
|
|
280
|
-
0: import_panasonic_comfort_cloud_client.AirSwingLR[0],
|
|
281
|
-
1: import_panasonic_comfort_cloud_client.AirSwingLR[1],
|
|
282
|
-
2: import_panasonic_comfort_cloud_client.AirSwingLR[2],
|
|
283
|
-
3: import_panasonic_comfort_cloud_client.AirSwingLR[3],
|
|
284
|
-
4: import_panasonic_comfort_cloud_client.AirSwingLR[4]
|
|
285
|
-
},
|
|
286
|
-
write: true,
|
|
287
|
-
def: device.airSwingLR,
|
|
288
|
-
type: "number"
|
|
289
|
-
},
|
|
290
|
-
void 0
|
|
291
|
-
);
|
|
292
|
-
this.createState(
|
|
293
|
-
deviceInfo.name,
|
|
294
|
-
"",
|
|
295
|
-
"airSwingUD",
|
|
296
|
-
{
|
|
297
|
-
role: "state",
|
|
298
|
-
states: {
|
|
299
|
-
0: import_panasonic_comfort_cloud_client.AirSwingUD[0],
|
|
300
|
-
1: import_panasonic_comfort_cloud_client.AirSwingUD[1],
|
|
301
|
-
2: import_panasonic_comfort_cloud_client.AirSwingUD[2],
|
|
302
|
-
3: import_panasonic_comfort_cloud_client.AirSwingUD[3],
|
|
303
|
-
4: import_panasonic_comfort_cloud_client.AirSwingUD[4]
|
|
304
|
-
},
|
|
305
|
-
write: true,
|
|
306
|
-
def: device.airSwingUD,
|
|
307
|
-
type: "number"
|
|
308
|
-
},
|
|
309
|
-
void 0
|
|
310
|
-
);
|
|
311
|
-
this.createState(
|
|
312
|
-
deviceInfo.name,
|
|
313
|
-
"",
|
|
314
|
-
"fanAutoMode",
|
|
315
|
-
{
|
|
316
|
-
role: "state",
|
|
317
|
-
states: {
|
|
318
|
-
0: import_panasonic_comfort_cloud_client.FanAutoMode[0],
|
|
319
|
-
1: import_panasonic_comfort_cloud_client.FanAutoMode[1],
|
|
320
|
-
2: import_panasonic_comfort_cloud_client.FanAutoMode[2],
|
|
321
|
-
3: import_panasonic_comfort_cloud_client.FanAutoMode[3]
|
|
322
|
-
},
|
|
323
|
-
write: true,
|
|
324
|
-
def: device.fanAutoMode,
|
|
325
|
-
type: "number"
|
|
326
|
-
},
|
|
327
|
-
void 0
|
|
328
|
-
);
|
|
329
|
-
this.createState(
|
|
330
|
-
deviceInfo.name,
|
|
331
|
-
"",
|
|
332
|
-
"ecoMode",
|
|
333
|
-
{
|
|
334
|
-
role: "state",
|
|
335
|
-
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] },
|
|
336
|
-
write: true,
|
|
337
|
-
def: device.ecoMode,
|
|
338
|
-
type: "number"
|
|
339
|
-
},
|
|
340
|
-
void 0
|
|
341
|
-
);
|
|
342
|
-
this.createState(
|
|
343
|
-
deviceInfo.name,
|
|
344
|
-
"",
|
|
345
|
-
"operationMode",
|
|
346
|
-
{
|
|
347
|
-
role: "state",
|
|
348
|
-
states: {
|
|
349
|
-
0: import_panasonic_comfort_cloud_client.OperationMode[0],
|
|
350
|
-
1: import_panasonic_comfort_cloud_client.OperationMode[1],
|
|
351
|
-
2: import_panasonic_comfort_cloud_client.OperationMode[2],
|
|
352
|
-
3: import_panasonic_comfort_cloud_client.OperationMode[3],
|
|
353
|
-
4: import_panasonic_comfort_cloud_client.OperationMode[4]
|
|
354
|
-
},
|
|
355
|
-
write: true,
|
|
356
|
-
def: device.operationMode,
|
|
357
|
-
type: "number"
|
|
358
|
-
},
|
|
359
|
-
void 0
|
|
360
|
-
);
|
|
361
|
-
this.createState(
|
|
362
|
-
deviceInfo.name,
|
|
363
|
-
"",
|
|
364
|
-
"fanSpeed",
|
|
365
|
-
{
|
|
366
|
-
role: "state",
|
|
367
|
-
states: {
|
|
368
|
-
0: import_panasonic_comfort_cloud_client.FanSpeed[0],
|
|
369
|
-
1: import_panasonic_comfort_cloud_client.FanSpeed[1],
|
|
370
|
-
2: import_panasonic_comfort_cloud_client.FanSpeed[2],
|
|
371
|
-
3: import_panasonic_comfort_cloud_client.FanSpeed[3],
|
|
372
|
-
4: import_panasonic_comfort_cloud_client.FanSpeed[4],
|
|
373
|
-
5: import_panasonic_comfort_cloud_client.FanSpeed[5]
|
|
374
|
-
},
|
|
375
|
-
write: true,
|
|
376
|
-
def: device.fanSpeed,
|
|
377
|
-
type: "number"
|
|
378
|
-
},
|
|
379
|
-
void 0
|
|
380
|
-
);
|
|
381
|
-
this.createState(
|
|
382
|
-
deviceInfo.name,
|
|
383
|
-
"",
|
|
384
|
-
"actualNanoe",
|
|
385
|
-
{
|
|
386
|
-
role: "state",
|
|
387
|
-
states: {
|
|
388
|
-
0: import_panasonic_comfort_cloud_client.NanoeMode[0],
|
|
389
|
-
1: import_panasonic_comfort_cloud_client.NanoeMode[1],
|
|
390
|
-
2: import_panasonic_comfort_cloud_client.NanoeMode[2],
|
|
391
|
-
3: import_panasonic_comfort_cloud_client.NanoeMode[3],
|
|
392
|
-
4: import_panasonic_comfort_cloud_client.NanoeMode[4]
|
|
393
|
-
},
|
|
394
|
-
write: true,
|
|
395
|
-
def: device.actualNanoe,
|
|
396
|
-
type: "number"
|
|
201
|
+
await this.setObjectNotExistsAsync(deviceInfo.name, {
|
|
202
|
+
type: "device",
|
|
203
|
+
common: {
|
|
204
|
+
name: deviceInfo.name
|
|
397
205
|
},
|
|
398
|
-
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
206
|
+
native: {}
|
|
207
|
+
});
|
|
208
|
+
for (const stateDef of import_state_definitions.deviceStates) {
|
|
209
|
+
const common = {
|
|
210
|
+
name: stateDef.id,
|
|
211
|
+
role: stateDef.role,
|
|
212
|
+
write: stateDef.write,
|
|
213
|
+
type: stateDef.type,
|
|
214
|
+
read: stateDef.read !== void 0 ? stateDef.read : true,
|
|
215
|
+
def: stateDef.id === "guid" ? deviceInfo.guid : stateDef.def !== void 0 ? stateDef.def : device[stateDef.id]
|
|
216
|
+
};
|
|
217
|
+
if (stateDef.states) {
|
|
218
|
+
common.states = stateDef.states;
|
|
219
|
+
}
|
|
220
|
+
await this.setObjectNotExistsAsync(`${deviceInfo.name}.${stateDef.id}`, {
|
|
221
|
+
type: "state",
|
|
222
|
+
common,
|
|
223
|
+
native: {}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
407
226
|
this.log.info(`Device ${deviceInfo.name} created.`);
|
|
227
|
+
if ((_a = this.config) == null ? void 0 : _a.historyEnabled) {
|
|
228
|
+
await this.setObjectNotExistsAsync(`${deviceInfo.name}.history`, {
|
|
229
|
+
type: "channel",
|
|
230
|
+
common: { name: "History Data" },
|
|
231
|
+
native: {}
|
|
232
|
+
});
|
|
233
|
+
const historyStates = (0, import_state_definitions.getHistoryStates)();
|
|
234
|
+
for (const [id, def] of Object.entries(historyStates)) {
|
|
235
|
+
await this.setObjectNotExistsAsync(`${deviceInfo.name}.${id}`, {
|
|
236
|
+
type: "state",
|
|
237
|
+
common: def,
|
|
238
|
+
native: {}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
408
242
|
}
|
|
409
243
|
}));
|
|
410
244
|
this.log.debug("Device creation completed.");
|
|
411
245
|
}
|
|
412
246
|
async updateDevice(deviceName, stateName, state) {
|
|
413
|
-
if (
|
|
247
|
+
if (import_state_definitions.readonlyStateNames.includes(stateName)) {
|
|
414
248
|
return;
|
|
415
249
|
}
|
|
416
250
|
if (!state.ack) {
|
|
@@ -445,6 +279,8 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
445
279
|
try {
|
|
446
280
|
if (this.refreshTimeout)
|
|
447
281
|
clearTimeout(this.refreshTimeout);
|
|
282
|
+
if (this.refreshHistoryTimeout)
|
|
283
|
+
clearTimeout(this.refreshHistoryTimeout);
|
|
448
284
|
this.log.info("cleaned everything up...");
|
|
449
285
|
callback();
|
|
450
286
|
} catch (e) {
|
|
@@ -473,6 +309,15 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
473
309
|
await this.handleClientError(error);
|
|
474
310
|
}
|
|
475
311
|
await this.setStateAsync(id, false, true);
|
|
312
|
+
} else if (stateName == "refreshHistory" && state.val) {
|
|
313
|
+
try {
|
|
314
|
+
const groups = await this.comfortCloudClient.getGroups();
|
|
315
|
+
await this.refreshHistory(groups);
|
|
316
|
+
await this.setStateAsync(id, state, true);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
await this.handleClientError(error);
|
|
319
|
+
}
|
|
320
|
+
await this.setStateAsync(id, false, true);
|
|
476
321
|
}
|
|
477
322
|
} else if (!id.includes(".info.")) {
|
|
478
323
|
const elements = id.split(".");
|
|
@@ -489,11 +334,11 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
489
334
|
}
|
|
490
335
|
}
|
|
491
336
|
async getCurrentAppVersion() {
|
|
492
|
-
const response = await import_axios.default.get("https://
|
|
337
|
+
const response = await import_axios.default.get("https://itunes.apple.com/lookup?id=1348640525");
|
|
493
338
|
if (response.status !== 200)
|
|
494
339
|
return "";
|
|
495
|
-
const
|
|
496
|
-
return
|
|
340
|
+
const version = await response.data.results[0].version;
|
|
341
|
+
return version;
|
|
497
342
|
}
|
|
498
343
|
async handleDeviceError(deviceName, error) {
|
|
499
344
|
this.log.debug(`Try to handle device error for ${deviceName}.`);
|
|
@@ -516,15 +361,15 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
516
361
|
this.log.info(
|
|
517
362
|
`Token of comfort cloud client expired. Trying to login again. Code=${error.code}. Stack: ${error.stack}`
|
|
518
363
|
);
|
|
519
|
-
this.
|
|
364
|
+
await this.setStateAsync("info.connection", false, true);
|
|
520
365
|
await this.comfortCloudClient.login(
|
|
521
366
|
this.config.username,
|
|
522
367
|
this.config.password
|
|
523
368
|
);
|
|
524
|
-
this.
|
|
369
|
+
await this.setStateAsync("info.connection", true, true);
|
|
525
370
|
this.log.info("Login successful.");
|
|
526
371
|
} else if (error instanceof import_panasonic_comfort_cloud_client.ServiceError) {
|
|
527
|
-
this.
|
|
372
|
+
await this.setStateAsync("info.connection", false, true);
|
|
528
373
|
this.log.error(
|
|
529
374
|
`Service error: ${error.message}. Code=${error.code}. Stack: ${error.stack}`
|
|
530
375
|
);
|
|
@@ -547,6 +392,25 @@ class PanasonicComfortCloud extends utils.Adapter {
|
|
|
547
392
|
await this.handleClientError(error);
|
|
548
393
|
}
|
|
549
394
|
}
|
|
395
|
+
setupHistoryRefreshTimeout() {
|
|
396
|
+
this.log.debug("setupHistoryRefreshTimeout");
|
|
397
|
+
const refreshIntervalInMilliseconds = this.historyRefreshIntervalInMinutes * 60 * 1e3;
|
|
398
|
+
this.refreshHistoryTimeout = setTimeout(this.refreshHistoryTimeoutFunc.bind(this), refreshIntervalInMilliseconds);
|
|
399
|
+
}
|
|
400
|
+
async refreshHistoryTimeoutFunc() {
|
|
401
|
+
var _a;
|
|
402
|
+
this.log.debug(`refreshHistoryTimeoutFunc started.`);
|
|
403
|
+
try {
|
|
404
|
+
if ((_a = this.config) == null ? void 0 : _a.historyEnabled) {
|
|
405
|
+
const groups = await this.comfortCloudClient.getGroups();
|
|
406
|
+
await this.refreshHistory(groups);
|
|
407
|
+
}
|
|
408
|
+
this.setupHistoryRefreshTimeout();
|
|
409
|
+
} catch (error) {
|
|
410
|
+
this.log.warn(`Failed to refresh history: ${error}`);
|
|
411
|
+
this.setupHistoryRefreshTimeout();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
550
414
|
trimAll(text) {
|
|
551
415
|
const newText = text.trim().replace(/(\r\n|\n|\r)/gm, "");
|
|
552
416
|
return newText;
|