iobroker.parcel 0.0.32 → 0.1.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/io-package.json +4 -1
- package/main.js +51 -40
- package/package.json +5 -5
- package/lib/json2iob.js +0 -290
package/io-package.json
CHANGED
package/main.js
CHANGED
|
@@ -21,7 +21,7 @@ const utils = require("@iobroker/adapter-core");
|
|
|
21
21
|
const axios = require("axios");
|
|
22
22
|
const qs = require("qs");
|
|
23
23
|
const crypto = require("crypto");
|
|
24
|
-
const Json2iob = require("
|
|
24
|
+
const Json2iob = require("json2iob");
|
|
25
25
|
const getPwd = require("./lib/rsaKey");
|
|
26
26
|
const tough = require("tough-cookie");
|
|
27
27
|
const { HttpsCookieAgent } = require("http-cookie-agent/http");
|
|
@@ -1089,12 +1089,12 @@ class Parcel extends utils.Adapter {
|
|
|
1089
1089
|
async loginHermes() {
|
|
1090
1090
|
await this.requestClient({
|
|
1091
1091
|
method: "post",
|
|
1092
|
-
url: "https://mobile-app-api.a0930.prd.hc.de/api/
|
|
1092
|
+
url: "https://mobile-app-api.a0930.prd.hc.de/api/v12/users/login",
|
|
1093
1093
|
headers: {
|
|
1094
1094
|
accept: "application/json",
|
|
1095
1095
|
"api-key": "acefe97f-89fc-4f4e-9543-fc6b90f68928",
|
|
1096
1096
|
"content-type": "application/json; charset=utf-8",
|
|
1097
|
-
"user-agent": "Hermes - ios -
|
|
1097
|
+
"user-agent": "Hermes - ios - 12.1.1 (2689)",
|
|
1098
1098
|
"accept-language": "de-de",
|
|
1099
1099
|
},
|
|
1100
1100
|
data: { username: this.config.hermesusername, password: this.config.hermespassword },
|
|
@@ -1514,11 +1514,11 @@ class Parcel extends utils.Adapter {
|
|
|
1514
1514
|
hermes: [
|
|
1515
1515
|
{
|
|
1516
1516
|
path: "hermes",
|
|
1517
|
-
url: "https://mobile-app-api.a0930.prd.hc.de/api/
|
|
1517
|
+
url: "https://mobile-app-api.a0930.prd.hc.de/api/v12/shipments",
|
|
1518
1518
|
header: {
|
|
1519
1519
|
accept: "application/json",
|
|
1520
1520
|
"api-key": "acefe97f-89fc-4f4e-9543-fc6b90f68928",
|
|
1521
|
-
"user-agent": "Hermes - ios -
|
|
1521
|
+
"user-agent": "Hermes - ios - 12.1.1 (2689)",
|
|
1522
1522
|
"accept-language": "de-de",
|
|
1523
1523
|
authorization: "Bearer " + this.hermesAuthToken,
|
|
1524
1524
|
},
|
|
@@ -1594,7 +1594,7 @@ class Parcel extends utils.Adapter {
|
|
|
1594
1594
|
res.data = JSON.parse(res.data);
|
|
1595
1595
|
}
|
|
1596
1596
|
for (const parcel of res.data) {
|
|
1597
|
-
parcel.id = parcel.shipmentId;
|
|
1597
|
+
parcel.id = parcel.shipmentId || parcel.externalId;
|
|
1598
1598
|
}
|
|
1599
1599
|
data = { sendungen: res.data };
|
|
1600
1600
|
}
|
|
@@ -1770,28 +1770,33 @@ class Parcel extends utils.Adapter {
|
|
|
1770
1770
|
this.mergedJson = this.mergedJson.concat(sendungsArray);
|
|
1771
1771
|
}
|
|
1772
1772
|
if (id === "hermes" && data.sendungen) {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1773
|
+
try {
|
|
1774
|
+
const sendungsArray = data.sendungen.map((sendung) => {
|
|
1775
|
+
let name = sendung.description;
|
|
1776
|
+
if (sendung.sender && sendung.sender.lastname) {
|
|
1777
|
+
name = name + " " + sendung.sender.lastname;
|
|
1778
|
+
}
|
|
1779
|
+
const sendungsObject = {
|
|
1780
|
+
id: sendung.id,
|
|
1781
|
+
name: name,
|
|
1782
|
+
status: sendung.status.text.longText || "",
|
|
1783
|
+
source: "Hermes",
|
|
1784
|
+
};
|
|
1784
1785
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1786
|
+
sendungsObject.delivery_status = this.deliveryStatusCheck(sendung, id, sendungsObject);
|
|
1787
|
+
if (sendungsObject.delivery_status === this.delivery_status.OUT_FOR_DELIVERY) {
|
|
1788
|
+
sendungsObject.inDelivery = true;
|
|
1789
|
+
this.inDelivery.push(sendungsObject);
|
|
1790
|
+
}
|
|
1791
|
+
this.mergedJsonObject[sendung.id] = sendungsObject;
|
|
1791
1792
|
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1793
|
+
return sendungsObject;
|
|
1794
|
+
});
|
|
1795
|
+
this.mergedJson = this.mergedJson.concat(sendungsArray);
|
|
1796
|
+
} catch (error) {
|
|
1797
|
+
this.log.info("Hermes response incomplete cannot parse result");
|
|
1798
|
+
this.log.info(error);
|
|
1799
|
+
}
|
|
1795
1800
|
}
|
|
1796
1801
|
|
|
1797
1802
|
if (id === "dpd" && data && data.sendungen) {
|
|
@@ -1982,18 +1987,21 @@ class Parcel extends utils.Adapter {
|
|
|
1982
1987
|
return dhl_status[sendung.sendungsdetails.sendungsverlauf.fortschritt];
|
|
1983
1988
|
}
|
|
1984
1989
|
}
|
|
1985
|
-
if (id === "hermes" && sendung.
|
|
1990
|
+
if (id === "hermes" && sendung.status) {
|
|
1986
1991
|
const hermes_status = {
|
|
1987
|
-
|
|
1992
|
+
AM_PKS_ABGEGEBEN: this.delivery_status.REGISTERED,
|
|
1988
1993
|
1: this.delivery_status.REGISTERED,
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1994
|
+
PAKETSHOP_AN_FAHRER_UEBERGEBEN: this.delivery_status.IN_PREPARATION,
|
|
1995
|
+
UNTERWEGS: this.delivery_status.IN_TRANSIT,
|
|
1996
|
+
ZUSTELLTOUR: this.delivery_status.OUT_FOR_DELIVERY,
|
|
1997
|
+
ZUGESTELLT: this.delivery_status.DELIVERED,
|
|
1993
1998
|
};
|
|
1994
|
-
if (hermes_status[sendung.
|
|
1995
|
-
return hermes_status[sendung.
|
|
1999
|
+
if (hermes_status[sendung.status.parcelStatus] !== undefined) {
|
|
2000
|
+
return hermes_status[sendung.status.parcelStatus];
|
|
1996
2001
|
}
|
|
2002
|
+
// if (hermes_status[sendung.status.parcelStatus] !== undefined) {
|
|
2003
|
+
// return hermes_status[sendung.status.parcelStatus];
|
|
2004
|
+
// }
|
|
1997
2005
|
}
|
|
1998
2006
|
if (id === "dpd" && sendung.statusId) {
|
|
1999
2007
|
const dpd_status = {
|
|
@@ -2214,12 +2222,15 @@ class Parcel extends utils.Adapter {
|
|
|
2214
2222
|
method: "get",
|
|
2215
2223
|
url: "https://www.amazon.de/gp/css/order-history?ref_=nav_orders_first&disableCsd=missing-library",
|
|
2216
2224
|
headers: {
|
|
2217
|
-
|
|
2218
|
-
|
|
2225
|
+
authority: "www.amazon.de",
|
|
2226
|
+
accept:
|
|
2227
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
2219
2228
|
"accept-language": "de-de",
|
|
2229
|
+
"cache-control": "max-age=0",
|
|
2230
|
+
"user-agent":
|
|
2231
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
|
|
2232
|
+
"viewport-width": "1272",
|
|
2220
2233
|
},
|
|
2221
|
-
jar: this.cookieJar,
|
|
2222
|
-
withCredentials: true,
|
|
2223
2234
|
})
|
|
2224
2235
|
.then(async (res) => {
|
|
2225
2236
|
// this.log.debug(JSON.stringify(res.data));
|
|
@@ -2331,12 +2342,12 @@ class Parcel extends utils.Adapter {
|
|
|
2331
2342
|
if (id === "hermes") {
|
|
2332
2343
|
await this.requestClient({
|
|
2333
2344
|
method: "post",
|
|
2334
|
-
url: "https://mobile-app-api.a0930.prd.hc.de/api/
|
|
2345
|
+
url: "https://mobile-app-api.a0930.prd.hc.de/api/v12/users/refreshtoken",
|
|
2335
2346
|
headers: {
|
|
2336
2347
|
"Content-Type": "application/json; charset=utf-8",
|
|
2337
2348
|
Accept: "application/json",
|
|
2338
2349
|
"api-key": "acefe97f-89fc-4f4e-9543-fc6b90f68928",
|
|
2339
|
-
"User-Agent": "Hermes - ios -
|
|
2350
|
+
"User-Agent": "Hermes - ios - 12.1.1 (2689)",
|
|
2340
2351
|
"Accept-Language": "de-de",
|
|
2341
2352
|
},
|
|
2342
2353
|
data: `{"refreshToken":"${this.sessions["hermes"].refreshToken}"}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.parcel",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Parcel tracking",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TA2k",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"axios": "^1.4.0",
|
|
30
30
|
"http-cookie-agent": "^5.0.4",
|
|
31
31
|
"jsdom": "^21.1.2",
|
|
32
|
-
"
|
|
32
|
+
"json2iob": "^2.4.5",
|
|
33
33
|
"qs": "^6.11.2",
|
|
34
34
|
"tough-cookie": "^4.1.3",
|
|
35
35
|
"uuid": "^9.0.0"
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"@types/chai": "^4.3.5",
|
|
40
40
|
"@types/chai-as-promised": "^7.1.5",
|
|
41
41
|
"@types/mocha": "^10.0.1",
|
|
42
|
-
"@types/node": "^20.4.
|
|
42
|
+
"@types/node": "^20.4.10",
|
|
43
43
|
"@types/proxyquire": "^1.3.28",
|
|
44
|
-
"@types/sinon": "^10.0.
|
|
44
|
+
"@types/sinon": "^10.0.16",
|
|
45
45
|
"@types/sinon-chai": "^3.2.9",
|
|
46
46
|
"chai": "^4.3.7",
|
|
47
47
|
"chai-as-promised": "^7.1.1",
|
|
48
|
-
"eslint": "^8.
|
|
48
|
+
"eslint": "^8.47.0",
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"proxyquire": "^2.1.3",
|
|
51
51
|
"sinon": "^15.2.0",
|
package/lib/json2iob.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
//v1.4
|
|
2
|
-
/*
|
|
3
|
-
options:
|
|
4
|
-
write //set common write variable to true
|
|
5
|
-
forceIndex //instead of trying to find names for array entries, use the index as the name
|
|
6
|
-
channelName //set name of the root channel
|
|
7
|
-
preferedArrayName //set key to use this as an array entry name
|
|
8
|
-
autoCast (true false) // make JSON.parse to parse numbers correctly
|
|
9
|
-
descriptions: Object of names for state keys
|
|
10
|
-
*/
|
|
11
|
-
const JSONbig = require("json-bigint")({ storeAsString: true });
|
|
12
|
-
module.exports = class Json2iob {
|
|
13
|
-
constructor(adapter) {
|
|
14
|
-
this.adapter = adapter;
|
|
15
|
-
this.alreadyCreatedObjects = {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async parse(path, element, options) {
|
|
19
|
-
try {
|
|
20
|
-
if (element === null || element === undefined) {
|
|
21
|
-
this.adapter.log.debug("Cannot extract empty: " + path);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const objectKeys = Object.keys(element);
|
|
26
|
-
|
|
27
|
-
if (!options || !options.write) {
|
|
28
|
-
if (!options) {
|
|
29
|
-
options = { write: false };
|
|
30
|
-
} else {
|
|
31
|
-
options["write"] = false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof element === "string" || typeof element === "number") {
|
|
36
|
-
let name = element;
|
|
37
|
-
if (typeof element === "number") {
|
|
38
|
-
name = element.toString();
|
|
39
|
-
}
|
|
40
|
-
if (!this.alreadyCreatedObjects[path]) {
|
|
41
|
-
await this.adapter
|
|
42
|
-
.setObjectNotExistsAsync(path, {
|
|
43
|
-
type: "state",
|
|
44
|
-
common: {
|
|
45
|
-
name: name,
|
|
46
|
-
role: this.getRole(element, options.write),
|
|
47
|
-
type: element !== null ? typeof element : "mixed",
|
|
48
|
-
write: options.write,
|
|
49
|
-
read: true,
|
|
50
|
-
},
|
|
51
|
-
native: {},
|
|
52
|
-
})
|
|
53
|
-
.then(() => {
|
|
54
|
-
// this.alreadyCreatedObjects[path] = true;
|
|
55
|
-
})
|
|
56
|
-
.catch((error) => {
|
|
57
|
-
this.adapter.log.error(error);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.adapter.setState(path, element, true);
|
|
62
|
-
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (!this.alreadyCreatedObjects[path]) {
|
|
66
|
-
await this.adapter
|
|
67
|
-
.setObjectNotExistsAsync(path, {
|
|
68
|
-
type: "channel",
|
|
69
|
-
common: {
|
|
70
|
-
name: options.channelName || "",
|
|
71
|
-
type: "mixed",
|
|
72
|
-
write: false,
|
|
73
|
-
read: true,
|
|
74
|
-
},
|
|
75
|
-
native: {},
|
|
76
|
-
})
|
|
77
|
-
.then(() => {
|
|
78
|
-
// this.alreadyCreatedObjects[path] = true;
|
|
79
|
-
options.channelName = undefined;
|
|
80
|
-
})
|
|
81
|
-
.catch((error) => {
|
|
82
|
-
this.adapter.log.error(error);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if (Array.isArray(element)) {
|
|
86
|
-
this.extractArray(element, "", path, options);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
objectKeys.forEach(async (key) => {
|
|
90
|
-
if (this.isJsonString(element[key]) && options.autoCast) {
|
|
91
|
-
element[key] = JSONbig.parse(element[key]);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (Array.isArray(element[key])) {
|
|
95
|
-
this.extractArray(element, key, path, options);
|
|
96
|
-
} else if (element[key] !== null && typeof element[key] === "object") {
|
|
97
|
-
this.parse(path + "." + key, element[key], options);
|
|
98
|
-
} else {
|
|
99
|
-
if (!this.alreadyCreatedObjects[path + "." + key]) {
|
|
100
|
-
let objectName = key;
|
|
101
|
-
if (options.descriptions && options.descriptions[key]) {
|
|
102
|
-
objectName = options.descriptions[key];
|
|
103
|
-
}
|
|
104
|
-
const type = element[key] !== null ? typeof element[key] : "mixed";
|
|
105
|
-
const common = {
|
|
106
|
-
name: objectName,
|
|
107
|
-
role: this.getRole(element[key], options.write),
|
|
108
|
-
type: type,
|
|
109
|
-
write: options.write,
|
|
110
|
-
read: true,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
await this.adapter
|
|
114
|
-
.setObjectNotExistsAsync(path + "." + key, {
|
|
115
|
-
type: "state",
|
|
116
|
-
common: common,
|
|
117
|
-
native: {},
|
|
118
|
-
})
|
|
119
|
-
.then(() => {
|
|
120
|
-
// this.alreadyCreatedObjects[path + "." + key] = true;
|
|
121
|
-
})
|
|
122
|
-
.catch((error) => {
|
|
123
|
-
this.adapter.log.error(error);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
this.adapter.setState(path + "." + key, element[key], true);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
} catch (error) {
|
|
130
|
-
this.adapter.log.error("Error extract keys: " + path + " " + JSON.stringify(element));
|
|
131
|
-
this.adapter.log.error(error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
extractArray(element, key, path, options) {
|
|
135
|
-
try {
|
|
136
|
-
if (key) {
|
|
137
|
-
element = element[key];
|
|
138
|
-
}
|
|
139
|
-
element.forEach(async (arrayElement, index) => {
|
|
140
|
-
index = index + 1;
|
|
141
|
-
if (index < 10) {
|
|
142
|
-
index = "0" + index;
|
|
143
|
-
}
|
|
144
|
-
let arrayPath = key + index;
|
|
145
|
-
if (typeof arrayElement === "string") {
|
|
146
|
-
this.parse(path + "." + key + "." + arrayElement, arrayElement, options);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (typeof arrayElement[Object.keys(arrayElement)[0]] === "string") {
|
|
150
|
-
arrayPath = arrayElement[Object.keys(arrayElement)[0]];
|
|
151
|
-
}
|
|
152
|
-
Object.keys(arrayElement).forEach((keyName) => {
|
|
153
|
-
if (keyName.endsWith("Id") && arrayElement[keyName] !== null) {
|
|
154
|
-
if (arrayElement[keyName] && arrayElement[keyName].replace) {
|
|
155
|
-
arrayPath = arrayElement[keyName].replace(/\./g, "");
|
|
156
|
-
} else {
|
|
157
|
-
arrayPath = arrayElement[keyName];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
Object.keys(arrayElement).forEach((keyName) => {
|
|
162
|
-
if (keyName.endsWith("Name")) {
|
|
163
|
-
if (arrayElement[keyName] && arrayElement[keyName].replace) {
|
|
164
|
-
arrayPath = arrayElement[keyName].replace(/\./g, "");
|
|
165
|
-
} else {
|
|
166
|
-
arrayPath = arrayElement[keyName];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
if (arrayElement.id) {
|
|
172
|
-
if (arrayElement.id.replace) {
|
|
173
|
-
arrayPath = arrayElement.id.replace(/\./g, "");
|
|
174
|
-
} else {
|
|
175
|
-
arrayPath = arrayElement.id;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (arrayElement.name) {
|
|
179
|
-
arrayPath = arrayElement.name.replace(/\./g, "");
|
|
180
|
-
}
|
|
181
|
-
if (arrayElement.label) {
|
|
182
|
-
arrayPath = arrayElement.label.replace(/\./g, "");
|
|
183
|
-
}
|
|
184
|
-
if (arrayElement.labelText) {
|
|
185
|
-
arrayPath = arrayElement.labelText.replace(/\./g, "");
|
|
186
|
-
}
|
|
187
|
-
if (arrayElement.start_date_time) {
|
|
188
|
-
arrayPath = arrayElement.start_date_time.replace(/\./g, "");
|
|
189
|
-
}
|
|
190
|
-
if (options.preferedArrayName && options.preferedArrayName.indexOf("+") !== -1) {
|
|
191
|
-
const preferedArrayNameArray = options.preferedArrayName.split("+");
|
|
192
|
-
if (arrayElement[preferedArrayNameArray[0]]) {
|
|
193
|
-
const element0 = arrayElement[preferedArrayNameArray[0]].replace(/\./g, "").replace(/\ /g, "");
|
|
194
|
-
let element1 = "";
|
|
195
|
-
if (preferedArrayNameArray[1].indexOf("/") !== -1) {
|
|
196
|
-
const subArray = preferedArrayNameArray[1].split("/");
|
|
197
|
-
const subElement = arrayElement[subArray[0]];
|
|
198
|
-
if (subElement && subElement[subArray[1]] !== undefined) {
|
|
199
|
-
element1 = subElement[subArray[1]];
|
|
200
|
-
} else if (arrayElement[subArray[1]] !== undefined) {
|
|
201
|
-
element1 = arrayElement[subArray[1]];
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
element1 = arrayElement[preferedArrayNameArray[1]].replace(/\./g, "").replace(/\ /g, "");
|
|
205
|
-
}
|
|
206
|
-
arrayPath = element0 + "-" + element1;
|
|
207
|
-
}
|
|
208
|
-
} else if (options.preferedArrayName && options.preferedArrayName.indexOf("/") !== -1) {
|
|
209
|
-
const preferedArrayNameArray = options.preferedArrayName.split("/");
|
|
210
|
-
const subElement = arrayElement[preferedArrayNameArray[0]];
|
|
211
|
-
if (subElement) {
|
|
212
|
-
arrayPath = subElement[preferedArrayNameArray[1]].replace(/\./g, "").replace(/\ /g, "");
|
|
213
|
-
}
|
|
214
|
-
} else if (options.preferedArrayName && arrayElement[options.preferedArrayName]) {
|
|
215
|
-
arrayPath = arrayElement[options.preferedArrayName].replace(/\./g, "");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (options.forceIndex) {
|
|
219
|
-
arrayPath = key + index;
|
|
220
|
-
}
|
|
221
|
-
//special case array with 2 string objects
|
|
222
|
-
if (
|
|
223
|
-
!options.forceIndex &&
|
|
224
|
-
Object.keys(arrayElement).length === 2 &&
|
|
225
|
-
typeof Object.keys(arrayElement)[0] === "string" &&
|
|
226
|
-
typeof Object.keys(arrayElement)[1] === "string" &&
|
|
227
|
-
typeof arrayElement[Object.keys(arrayElement)[0]] !== "object" &&
|
|
228
|
-
typeof arrayElement[Object.keys(arrayElement)[1]] !== "object" &&
|
|
229
|
-
arrayElement[Object.keys(arrayElement)[0]] !== "null"
|
|
230
|
-
) {
|
|
231
|
-
let subKey = arrayElement[Object.keys(arrayElement)[0]];
|
|
232
|
-
const subValue = arrayElement[Object.keys(arrayElement)[1]];
|
|
233
|
-
const subName = Object.keys(arrayElement)[0] + " " + Object.keys(arrayElement)[1];
|
|
234
|
-
if (key) {
|
|
235
|
-
subKey = key + "." + subKey;
|
|
236
|
-
}
|
|
237
|
-
if (!this.alreadyCreatedObjects[path + "." + subKey]) {
|
|
238
|
-
await this.adapter
|
|
239
|
-
.setObjectNotExistsAsync(path + "." + subKey, {
|
|
240
|
-
type: "state",
|
|
241
|
-
common: {
|
|
242
|
-
name: subName,
|
|
243
|
-
role: this.getRole(subValue, options.write),
|
|
244
|
-
type: subValue !== null ? typeof subValue : "mixed",
|
|
245
|
-
write: options.write,
|
|
246
|
-
read: true,
|
|
247
|
-
},
|
|
248
|
-
native: {},
|
|
249
|
-
})
|
|
250
|
-
.then(() => {
|
|
251
|
-
// this.alreadyCreatedObjects[path + "." + subKey] = true;
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
this.adapter.setState(path + "." + subKey, subValue, true);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
this.parse(path + "." + arrayPath, arrayElement, options);
|
|
258
|
-
});
|
|
259
|
-
} catch (error) {
|
|
260
|
-
this.adapter.log.error("Cannot extract array " + path);
|
|
261
|
-
this.adapter.log.error(error);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
isJsonString(str) {
|
|
265
|
-
try {
|
|
266
|
-
JSON.parse(str);
|
|
267
|
-
} catch (e) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
getRole(element, write) {
|
|
273
|
-
if (typeof element === "boolean" && !write) {
|
|
274
|
-
return "indicator";
|
|
275
|
-
}
|
|
276
|
-
if (typeof element === "boolean" && write) {
|
|
277
|
-
return "switch";
|
|
278
|
-
}
|
|
279
|
-
if (typeof element === "number" && !write) {
|
|
280
|
-
return "value";
|
|
281
|
-
}
|
|
282
|
-
if (typeof element === "number" && write) {
|
|
283
|
-
return "level";
|
|
284
|
-
}
|
|
285
|
-
if (typeof element === "string") {
|
|
286
|
-
return "text";
|
|
287
|
-
}
|
|
288
|
-
return "state";
|
|
289
|
-
}
|
|
290
|
-
};
|