Skip to content

Commit 5b701c3

Browse files
committed
fixed issue with relogin upon token expiry
1 parent c5a32cd commit 5b701c3

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

README.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ This channel contains values polled from SENEC App-API.
303303
Placeholder for the next version (at the beginning of the line):
304304
### **WORK IN PROGRESS**
305305
-->
306+
### **WORK IN PROGRESS**
307+
- Fixing issues with polling from senec api when token expires
308+
- Old entries in changelog moved to old.
309+
306310
### 2.4.0 (2026-02-28)
307311
- Senec changed login procedure (again). Adapter now also works with 2-stage login where senec asks for username/email first and password second.
308312
- Dependency updates
@@ -352,39 +356,6 @@ This channel contains values polled from SENEC App-API.
352356
* Updated to use new SENEC API via mein-senec.de - Thanks to @maett81
353357
* Some code and dependency housekeeping
354358

355-
### 1.6.17
356-
* License update
357-
358-
### 1.6.16
359-
* Moved Dashboard to ApiV2. This invalidates existing datapoints under /Dashboard/ and introduces "Dashboard/currently" and "Dashboard/today" due to changes in the API.
360-
361-
### 1.6.15
362-
* Maintenance update (dependencies, ...)
363-
364-
### 1.6.14
365-
* Bugfix (values were way off)
366-
367-
### 1.6.13 (NoBl)
368-
* Removed Support for node 16
369-
* Added more translations
370-
* Code cleanup
371-
372-
### 1.6.12 (NoBl)
373-
* Updated license
374-
375-
### 1.6.11 (NoBl)
376-
* Moving from Senec App API 3.12.0 to 4.3.3 (thanks to oakdesign@github for providing the new API!)
377-
* This WILL invalidate all current API datapoints in the Statistik branch. Easiest solution to this: Delete the Statistik branch.
378-
* Remember to force a rebuild of historic data in adapter settings!
379-
380-
### 1.6.10 (NoBl)
381-
* Bugfix for AllTimeHistory (should work again)
382-
383-
### 1.6.9 (NoBl)
384-
* Added switch in config to enable active control of appliance (you will need activate this, if you want to control the appliance via the adapter)
385-
* Improved handling of forced loading (please report if we need more appliance-states covered by this)
386-
* Minor improvements and bugfixes
387-
388359
### [Former Updates](CHANGELOG_old.md)
389360

390361
## License

main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const axios = require("axios");
66
const tough = require("tough-cookie");
77
const CookieJar = tough.CookieJar;
88
const { wrapper } = require("axios-cookiejar-support");
9-
const jar = new CookieJar();
9+
let jar = new CookieJar();
1010
const api_client = wrapper(axios.create({ withCredentials: true, timeout: 10000 }));
1111
api_client.defaults.headers.post["Content-Type"] = "application/json";
1212
const https = require("https");
@@ -245,6 +245,7 @@ class Senec extends utils.Adapter {
245245
if (this.timerAPI) {
246246
clearTimeout(this.timerAPI);
247247
}
248+
this.doState(ID_TOKEN_STATE, null, "Access Token", "", false);
248249
this.log.info("cleaned everything up...");
249250
this.setState("info.connection", false, true);
250251
callback();
@@ -474,6 +475,7 @@ class Senec extends utils.Adapter {
474475

475476
async senecLogin() {
476477
this.log.info("🔄 Start Senec API Login Flow...");
478+
jar = new CookieJar();
477479
try {
478480
const codeVerifier = generateCodeVerifier();
479481
const codeChallenge = generateCodeChallenge(codeVerifier);
@@ -574,7 +576,7 @@ class Senec extends utils.Adapter {
574576

575577
const accessToken = tokenRes.data.access_token;
576578
this.log.info("✅ API Login erfolgreich.");
577-
this.doState(ID_TOKEN_STATE, accessToken, "Access Token", "", false);
579+
await this.doState(ID_TOKEN_STATE, accessToken, "Access Token", "", false);
578580
return accessToken;
579581
} catch (e) {
580582
this.log.error(`❌ Login Error: ${e.message}`);
@@ -658,6 +660,7 @@ class Senec extends utils.Adapter {
658660
}
659661
// this.log.info("⚠️ Token outdated. Re-Login...");
660662
this.log.info("ℹ️ Token outdated. Re-Login...");
663+
jar = new CookieJar();
661664
const newToken = await this.senecLogin();
662665
if (newToken) {
663666
setTimeout(() => this.pollSenecApi(true, retry), 2000);

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// "noUnusedLocals": true,
2222
// "noUnusedParameters": true,
2323
"useUnknownInCatchVariables": false,
24+
"paths": {
25+
"axios": ["./node_modules/axios/index.d.ts"]
26+
}
2427
},
2528
"include": [
2629
"**/*.js",

0 commit comments

Comments
 (0)