Skip to content

Commit

Permalink
(simatec) First Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Sep 9, 2024
1 parent 683278d commit 6ec15c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


---
Expand All @@ -41,8 +41,10 @@ You must enter these in the configuration of the adapter.
<!-- ### **WORK IN PROGRESS** -->
## Changelog
### **WORK IN PROGRESS**
* (simatec) initial release
* (simatec) First Beta

### 0.0.1 (2024-09-09)
* (simatec) First Commit
---

## License
Expand Down
23 changes: 9 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand All @@ -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 });
Expand Down Expand Up @@ -398,8 +398,6 @@ class RemehaHomeAdapter extends utils.Adapter {
} catch (error) {
this.log.error(`Error updating devices: ${error}`);
}


}

async checkTokenValidity(token) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6ec15c9

Please sign in to comment.