Skip to content

Commit

Permalink
Added option to turn of local polling
Browse files Browse the repository at this point in the history
  • Loading branch information
NoBl committed Oct 9, 2023
1 parent 4a45a30 commit 4a9ebd6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
34 changes: 34 additions & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@
"zh-cn": "一般环境"
},
"items": {
"lala_use": {
"type": "checkbox",
"sm": 12,
"md": 6,
"lg": 6,
"label": {
"en": "Connect via lala.cgi?",
"de": "Verbinden über lala.cgi?",
"ru": "Подключитесь через lala.cgi?",
"pt": "Ligar via lala.cgi?",
"nl": "Connecteren via lala.cgi?",
"fr": "Connectez-vous via lala.cgi?",
"it": "Collegare via lala.cgi?",
"es": "¿Conectar vía lala.cgi?",
"pl": "Połączenie przez lala.cgi?",
"uk": "Підключення через lala.cgi?",
"zh-cn": "陪审团?"
},
"help": {
"en": "Connect to SENEC appliance via local network. This requires access to local monitoring.",
"de": "Verbindung zum SENEC Gerät wird über lokales Netzwerk hergestellt. Dies erfordert den Zugang zur lokalen Überwachung.",
"ru": "Подключитесь к SENEC Appliance через местную сеть. Это требует доступа к местному мониторингу.",
"pt": "Conecte-se ao aparelho SENEC via rede local. Isso requer acesso ao monitoramento local.",
"nl": "Verbinding met SENEC appliance via het lokale netwerk. Dit vereist toegang tot de lokale monitoring.",
"fr": "Connectez-vous à l'appareil SENEC via le réseau local. Cela nécessite l'accès à la surveillance locale.",
"it": "Collegare l'apparecchio SENEC tramite rete locale. Ciò richiede l'accesso al monitoraggio locale.",
"es": "Conéctese a SENEC appliance vía red local. Esto requiere acceso a la vigilancia local.",
"pl": "Złącza się do SENEC poprzez lokalną sieć. Potrzebuje to dostęp do monitorowania miejscowego.",
"uk": "Підключення до додатку SENEC через локальну мережу. Це вимагає доступу до локального моніторингу.",
"zh-cn": "通过当地网络,与SENEC的观察站一致。 这需要获得地方监测。."
},
"default": true,
"newLine": true
},
"senecip": {
"type": "text",
"sm": 12,
Expand Down
1 change: 1 addition & 0 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
]
},
"native": {
"lala_use": true,
"senecip": "0.0.0.0",
"interval": 10,
"intervalLow": 60,
Expand Down
36 changes: 28 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const apiSystemsUrl = apiUrl + "/anlagen";
const apiKnownSystems = []

let apiConnected = false;
let lalaConnected = false;
let apiLoginToken = "";
let retry = 0; // retry-counter
let retryLowPrio = 0; // retry-counter
Expand Down Expand Up @@ -62,14 +63,32 @@ class Senec extends utils.Adapter {
this.setState('info.connection', false, true);
try {
await this.checkConfig();
await this.initPollSettings();
await this.checkConnection();
await this.initSenecAppApi();
if (apiConnected) await this.getApiSystems();
await this.pollSenec(true, 0); // highPrio
await this.pollSenec(false, 0); // lowPrio
if (apiConnected) await this.pollSenecAppApi(0); // App API
this.setState('info.connection', true, true);
if (this.config.lala_use) {
this.log.info("Usage of lala.cgi configured.");
await this.initPollSettings();
await this.checkConnection();
if (lalaConnected) {
await this.pollSenec(true, 0); // highPrio
await this.pollSenec(false, 0); // lowPrio
}
} else {
this.log.warn("Usage of lala.cgi not configured. Only polling SENEC App API if configured.");
}
if (this.config.api_use) {
this.log.info("Usage of SENEC App API configured.");
await this.initSenecAppApi();
if (apiConnected) {
await this.getApiSystems();
await this.pollSenecAppApi(0); // App API
}
} else {
this.log.warn("Usage of SENEC App API not configured. Only polling appliance via local network if configured.");
}
if (lalaConnected || apiConnected) {
this.setState('info.connection', true, true);
} else {
this.log.error("Neither local connection nor API connection configured. Please check config!");
}
} catch (error) {
this.log.error(error);
this.setState('info.connection', false, true);
Expand Down Expand Up @@ -227,6 +246,7 @@ class Senec extends utils.Adapter {
this.log.info('connecting to Senec: ' + url);
const body = await this.doGet(url, form, this, this.config.pollingTimeout, true);
this.log.info('connected to Senec: ' + url);
lalaConnected = true;
} catch (error) {
throw new Error("Error connecting to Senec (IP: " + connectVia + this.config.senecip + "). Exiting! (" + error + "). Try to toggle https-mode in settings and check FQDN of SENEC appliance.");
}
Expand Down

0 comments on commit 4a9ebd6

Please sign in to comment.