Skip to content

Commit

Permalink
add gatewayindex
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed May 3, 2024
1 parent b4232ec commit b6a4f81
Show file tree
Hide file tree
Showing 6 changed files with 944 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .releaseconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["iobroker", "license", "manual-review"]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 TA2k <[email protected]>
Copyright (c) 2023-2030 TA2k <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ setState("viessmannapi.0.xxxxxxx.0.features.ventilation.schedule.commands.setSch

MIT License

Copyright (c) 2023 TA2k <[email protected]>
Copyright (c) 2023-2030 TA2k <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 25 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Viessmannapi extends utils.Adapter {
this.idArray = [];
this.session = {};
this.rangeMapSupport = {};
this.gateWayIndexOject = {};
}

/**
Expand Down Expand Up @@ -205,6 +206,8 @@ class Viessmannapi extends utils.Adapter {
});
for (const installation of this.installationArray) {
const installationId = installation.id.toString();

let currentGatewayIndex = this.config.gatewayIndex;
if (installation.gateways.length > 1) {
this.log.info(
'Found ' + installation.gateways.length + ' gateways for installation for installation ' + installation.id,
Expand All @@ -214,29 +217,30 @@ class Viessmannapi extends utils.Adapter {
installation.gateways = installation.gateways.filter((gateway) => {
return gateway.aggregatedStatus !== 'Offline';
});
//check if gatewayIndex is valid
if (currentGatewayIndex > installation.gateways.length) {
this.log.warn(
'Gateway Index ' +
currentGatewayIndex +
' is not valid. Please check the number of gateways for installation ' +
installation.id +
' index is set to 1',
);
currentGatewayIndex = 1;
}
this.log.warn(
'Found ' +
installation.gateways.length +
' online gateways select ' +
this.config.gatewayIndex +
currentGatewayIndex +
' gateway. for installation ' +
installation.id,
);
}
//check if gatewayIndex is valid
if (this.config.gatewayIndex > installation.gateways.length) {
this.log.warn(
'Gateway Index ' +
this.config.gatewayIndex +
' is not valid. Please check the number of gateways for installation ' +
installation.id +
' index is set to 1',
);
this.config.gatewayIndex = 1;
}
const gateway = installation.gateways[this.config.gatewayIndex - 1];
this.gateWayIndexOject[installationId] = currentGatewayIndex;
const gateway = installation.gateways[currentGatewayIndex - 1];
if (!gateway || gateway == null) {
this.log.warn('No gateway found for installation ' + installation.id + 'and index ' + this.config.gatewayIndex);
this.log.warn('No gateway found for installation ' + installation.id + 'and index ' + currentGatewayIndex);
this.log.info(JSON.stringify(installation.gateways));
return;
}
Expand Down Expand Up @@ -278,12 +282,13 @@ class Viessmannapi extends utils.Adapter {
};

for (const installation of this.installationArray) {
if (!installation['gateways'][this.config.gatewayIndex - 1]) {
const currentGatewayIndex = this.gateWayIndexOject[installation.id.toString()];
if (!installation['gateways'][currentGatewayIndex - 1]) {
this.log.warn('No gateway found for installation ' + installation.id);
return;
}

for (const device of installation['gateways'][this.config.gatewayIndex - 1]['devices']) {
for (const device of installation['gateways'][currentGatewayIndex - 1]['devices']) {
if (this.config.devicelist) {
const deviceArray = this.config.devicelist.replace(/\s/g, '').split(',');
if (!deviceArray.includes(device.id.toString())) {
Expand Down Expand Up @@ -379,12 +384,12 @@ class Viessmannapi extends utils.Adapter {
};
for (const installation of this.installationArray) {
const installationId = installation.id.toString();

if (!installation['gateways'][this.config.gatewayIndex - 1]) {
this.log.warn('No gateway found for installation ' + installation.id + 'and index ' + this.config.gatewayIndex);
const currentGatewayIndex = this.gateWayIndexOject[installationId];
if (!installation['gateways'][currentGatewayIndex - 1]) {
this.log.warn('No gateway found for installation ' + installation.id + 'and index ' + currentGatewayIndex);
return;
}
const gatewaySerial = installation['gateways'][this.config.gatewayIndex - 1].serial.toString();
const gatewaySerial = installation['gateways'][currentGatewayIndex - 1].serial.toString();
await this.requestClient({
method: 'get',
url: 'https://api.viessmann.com/iot/v2/events-history/installations/' + installationId + '/events',
Expand Down
Loading

0 comments on commit b6a4f81

Please sign in to comment.