iobroker.panasonic-comfort-cloud 2.2.1 → 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/LICENSE +1 -1
- package/README.md +11 -1
- package/admin/i18n/de/translations.json +3 -3
- package/admin/i18n/en/translations.json +1 -1
- package/admin/i18n/es/translations.json +4 -4
- package/admin/i18n/fr/translations.json +4 -4
- package/admin/i18n/it/translations.json +3 -3
- package/admin/i18n/nl/translations.json +1 -1
- package/admin/i18n/pl/translations.json +3 -3
- package/admin/i18n/pt/translations.json +2 -2
- package/admin/i18n/ru/translations.json +3 -3
- package/admin/i18n/uk/translations.json +1 -1
- package/admin/i18n/zh-cn/translations.json +2 -2
- package/admin/jsonConfig.json +43 -0
- package/build/main.js +410 -500
- package/build/main.js.map +1 -7
- package/io-package.json +190 -216
- package/package.json +22 -20
- package/admin/index_m.html +0 -130
package/build/main.js
CHANGED
|
@@ -1,520 +1,430 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.log.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
-
|
|
496
|
-
|
|
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
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|