From 6ec15c971d676e4bfedb0a7849fbe6d0d7bc45fc Mon Sep 17 00:00:00 2001 From: simatec Date: Mon, 9 Sep 2024 22:38:20 +0200 Subject: [PATCH] (simatec) First Beta --- README.md | 6 ++++-- main.js | 23 +++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b88cd17..2de7fa9 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This adapter uses the service `Sentry.io` to automatically report exceptions and --- -## remeha-home adapter for ioBroker +## Remeha Home adapter for ioBroker --- @@ -41,8 +41,10 @@ You must enter these in the configuration of the adapter. ## Changelog ### **WORK IN PROGRESS** -* (simatec) initial release +* (simatec) First Beta +### 0.0.1 (2024-09-09) +* (simatec) First Commit --- ## License diff --git a/main.js b/main.js index 4f53713..b8467cd 100644 --- a/main.js +++ b/main.js @@ -130,10 +130,14 @@ class RemehaHomeAdapter extends utils.Adapter { async poll() { try { - if (this.accessToken === null || await this.checkTokenValidity(this.accessToken) !== 200) { + if (this.accessToken === null) { await this.resolveExternalData(); + } else if (this.accessToken !== null && await this.checkTokenValidity(this.accessToken) !== 200) { + await this.refreshAccessToken(); + } + if (await this.checkTokenValidity(this.accessToken) === 200) { + await this.updateDevices(); } - await this.updateDevices(); } catch (error) { this.log.error(`Polling error: ${error.message}`); } @@ -309,7 +313,7 @@ class RemehaHomeAdapter extends utils.Adapter { followRedirect: true, responseType: 'json' }); - this.log.debug('Access Token Stattus:' + response.statusCode); + this.log.debug('Access Token Status:' + response.statusCode); this.accessToken = response.body.access_token; this.refreshToken = response.body.refresh_token; return this.accessToken; @@ -343,11 +347,7 @@ class RemehaHomeAdapter extends utils.Adapter { async updateDevices() { try { - if (this.accessToken === null) { - await this.fetchAccessToken(); - } else if (await this.checkTokenValidity(this.accessToken) !== 200) { - await this.refreshAccessToken(); - } + this.update = true; const response = await this.got.get('https://api.bdrthermea.net/Mobile/api/homes/dashboard', { headers: { @@ -357,7 +357,7 @@ class RemehaHomeAdapter extends utils.Adapter { } }); this.log.debug('Status Update: ' + response.statusCode); - this.update = true; + const data = JSON.parse(response.body); await this.setState('data.roomThermostat.roomTemperature', { val: data.appliances[0].climateZones[0].roomTemperature, ack: true }); @@ -398,8 +398,6 @@ class RemehaHomeAdapter extends utils.Adapter { } catch (error) { this.log.error(`Error updating devices: ${error}`); } - - } async checkTokenValidity(token) { @@ -447,9 +445,6 @@ class RemehaHomeAdapter extends utils.Adapter { const valueZoneMode = responseJson.appliances[0].climateZones[0].zoneMode; const valueProgNumber = responseJson.appliances[0].climateZones[0].activeHeatingClimateTimeProgramNumber; - this.log.debug('Zone Mode:' + zoneMode); - this.log.debug('Setpoint Value:' + valueSetpoint); - switch (type) { case 'setPoint': if (valueZoneMode !== 'Manual' || valueSetpoint !== postData?.roomTemperatureSetPoint) {