Skip to content

Commit

Permalink
fix role detection and role parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Oct 16, 2023
1 parent 4e392d5 commit 2bc643b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 66 deletions.
14 changes: 7 additions & 7 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: false,
printWidth: 120,
useTabs: false,
tabWidth: 4,
endOfLine: "lf",
semi: true,
trailingComma: 'all',
singleQuote: false,
printWidth: 120,
useTabs: false,
tabWidth: 4,
endOfLine: 'lf',
};
122 changes: 66 additions & 56 deletions lib/extractKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,27 @@ async function extractKeys(adapter, path, element, preferedArrayName, forceIndex

if (Array.isArray(element[key])) {
extractArray(adapter, element, key, path, write, preferedArrayName, forceIndex);
} else if (element[key] !== null && typeof element[key] === "object" && (path + "." + key).indexOf(".entries.value") === -1) {
} else if (
element[key] !== null &&
typeof element[key] === "object" &&
(path + "." + key).indexOf(".entries.value") === -1
) {
extractKeys(adapter, path + "." + key, element[key], preferedArrayName, forceIndex, write);
} else {
let type = typeof element[key];
key = key.replace(/\./g, "_").replace(/;/g, "_");
if ((path + "." + key).indexOf(".entries.value") !== -1) {

const entries = await adapter.getObjectAsync(path + "." + key);
if (entries) {
if (!entries.common.type) {
adapter.log.debug(path)
await adapter.delObjectAsync(path + "." + key,{recursive:true});
adapter.log.debug(path);
await adapter.delObjectAsync(path + "." + key, { recursive: true });
}
}
element[key] = JSON.stringify(element[key]);
type = "json";
}
if (!alreadyCreatedOBjects[path + "." + key]) {

await adapter
.setObjectNotExistsAsync(path + "." + key, {
type: "state",
Expand Down Expand Up @@ -120,57 +123,57 @@ async function extractKeys(adapter, path, element, preferedArrayName, forceIndex
};

if (element.params && Object.keys(element.params).length > 0) {
if(Object.keys(element.params).length > 1) {
common.param = [];
common.type = "object";
for(let param of Object.keys(element.params)) {
let curparam = {
param: param,
type: "mixed"
};
if (Object.keys(element.params).length > 1) {
common.param = [];
common.type = "object";
for (let param of Object.keys(element.params)) {
let curparam = {
param: param,
type: "mixed",
};

if (element.params[param] && element.params[param].type === "number") {
curparam.type = "number";
}
if (element.params[param] && element.params[param].constraints) {
const constrains = element.params[param].constraints;
if (constrains.min) {
curparam.min = constrains.min;
}
if (constrains.max) {
curparam.max = constrains.max;
}
if (constrains.enum) {
curparam.states = {};
for (const cenum of constrains.enum) {
curparam.states[cenum] = cenum;
}
}
}
common.param.push(curparam);
}
} else {
param = Object.keys(element.params)[0];
common.param = param;
if (element.params[param] && element.params[param].type === "number") {
common.type = "number";
}
if (element.params[param] && element.params[param].constraints) {
const constrains = element.params[param].constraints;
if (constrains.min) {
common.min = constrains.min;
}
if (constrains.max) {
common.max = constrains.max;
}
if (constrains.enum) {
common.states = {};
for (const cenum of constrains.enum) {
common.states[cenum] = cenum;
}
}
}
}
if (element.params[param] && element.params[param].type === "number") {
curparam.type = "number";
}
if (element.params[param] && element.params[param].constraints) {
const constrains = element.params[param].constraints;
if (constrains.min) {
curparam.min = constrains.min;
}
if (constrains.max) {
curparam.max = constrains.max;
}
if (constrains.enum) {
curparam.states = {};
for (const cenum of constrains.enum) {
curparam.states[cenum] = cenum;
}
}
}
common.param.push(curparam);
}
} else {
param = Object.keys(element.params)[0];
common.param = param;
if (element.params[param] && element.params[param].type === "number") {
common.type = "number";
}
if (element.params[param] && element.params[param].constraints) {
const constrains = element.params[param].constraints;
if (constrains.min) {
common.min = constrains.min;
}
if (constrains.max) {
common.max = constrains.max;
}
if (constrains.enum) {
common.states = {};
for (const cenum of constrains.enum) {
common.states[cenum] = cenum;
}
}
}
}
}
await adapter.setObjectNotExistsAsync(setStatePath, {
type: "state",
Expand Down Expand Up @@ -199,7 +202,14 @@ function extractArray(adapter, element, key, path, write, preferedArrayName, for
}
let arrayPath = key + index;
if (typeof arrayElement === "string") {
extractKeys(adapter, path + "." + key + "." + arrayElement, arrayElement, preferedArrayName, forceIndex, write);
extractKeys(
adapter,
path + "." + key + "." + arrayElement,
arrayElement,
preferedArrayName,
forceIndex,
write,
);
return;
}
if (typeof arrayElement[Object.keys(arrayElement)[0]] === "string") {
Expand Down
8 changes: 5 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,12 @@ class Viessmannapi extends utils.Adapter {
url = url.replace("$gatewaySerial", device.gatewaySerial);
if (
!ignoreFilter &&
(device.roles.includes("type:gateway") || device.roles.includes("type:virtual"))
device.roles.some((role) => {
return role.includes("type:gateway") || role.includes("type:virtual");
})
) {
this.log.debug("ignore " + device.type);
return;
this.log.debug("ignore " + device.device.deviceType);

This comment has been minimized.

Copy link
@BuZZy1337

BuZZy1337 Oct 16, 2023

Causes crash. Correct format:

this.log.debug("ignore " + device.deviceType);
continue;
}
await this.requestClient({
method: "get",
Expand Down

1 comment on commit 2bc643b

@BuZZy1337
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Row 308 causes Crash.
It hast to be

this.log.debug("ignore " + device.deviceType);

Please sign in to comment.