Skip to content

Commit

Permalink
(simatec) Fix request error
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Sep 28, 2024
1 parent 6b38dfd commit 8a9904c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ You must enter these in the configuration of the adapter.
<!-- ### **WORK IN PROGRESS** -->

## Changelog
### **WORK IN PROGRESS**
* (simatec) Fix request error
* (simatec) Dependencies updated

### 0.2.3 (2024-09-26)
* (simatec) Fix jsonConfig
* (simatec) Fix for Admin 7.1.5
Expand Down
13 changes: 13 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RemehaHomeAdapter extends utils.Adapter {
this.got = null;
this.account = '';
this.password = '';
this.timerSleep = 0;
this.pollInterval = 60;
this.accessToken = null;
this.refreshToken = null;
Expand Down Expand Up @@ -116,12 +117,19 @@ class RemehaHomeAdapter extends utils.Adapter {
try {
this.setState('info.connection', false, true);
this.clearInterval(this.interval);
this.clearTimeout(this.timerSleep);
callback();
} catch (e) {
callback();
}
}

async sleep(ms) {
return new Promise(async (resolve) => {
// @ts-ignore
this.timerSleep = this.setTimeout(async () => resolve(), ms);
});
}
async createDevices() {
const states = [
{ id: 'data.roomThermostat.roomTemperature', name: 'Room Temperature', read: true, write: false, type: 'number', role: 'value.temperature', unit: '°C' },
Expand Down Expand Up @@ -419,6 +427,8 @@ class RemehaHomeAdapter extends utils.Adapter {
await this.setState('data.roomThermostat.setZoneMode', { val: _zoneMode, ack: true })
}

await this.sleep(1000);

const appliance = await this.got.get(`https://api.bdrthermea.net/Mobile/api/appliances/${data?.appliances[0].applianceId}/technicaldetails`, {
headers: {
'Authorization': `Bearer ${this.accessToken}`,
Expand Down Expand Up @@ -454,6 +464,7 @@ class RemehaHomeAdapter extends utils.Adapter {
});
this.log.debug(`Get checkTokenValidity Status: ${response.statusCode === 200 ? 'OK' : 'failed'}`);
await this.setState('info.connection', response.statusCode === 200 ? true : false, true);
await this.sleep(500);

return response.statusCode;
} catch (error) {
Expand Down Expand Up @@ -490,6 +501,8 @@ class RemehaHomeAdapter extends utils.Adapter {
const valueZoneMode = responseJson.appliances[0].climateZones[0].zoneMode;
const valueProgNumber = responseJson.appliances[0].climateZones[0].activeHeatingClimateTimeProgramNumber;

await this.sleep(1000);

switch (type) {
case 'setPoint':
if (valueZoneMode !== 'Manual' || valueSetpoint !== postData?.roomTemperatureSetPoint) {
Expand Down
66 changes: 45 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node": ">= 18"
},
"dependencies": {
"@iobroker/adapter-core": "^3.1.6",
"@iobroker/adapter-core": "^3.2.1",
"url": "^0.11.4",
"got": "^13.0.0",
"tough-cookie": "^5.0.0"
Expand All @@ -38,7 +38,7 @@
"@iobroker/testing": "^5.0.0",
"chai": "^4.5.0",
"chai-as-promised": "^7.1.2",
"eslint": "^9.10.0",
"eslint": "^9.11.1",
"mocha": "^10.7.3",
"sinon": "^18.0.0",
"sinon-chai": "^3.7.0"
Expand Down

0 comments on commit 8a9904c

Please sign in to comment.