Skip to content

Commit

Permalink
Added possible fix for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
robertraaijmakers committed Feb 22, 2025
1 parent e6950d6 commit bb2a89c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
},
"1.0.3": {
"en": "New version, better error handling, supporting more capabilities and updating settings with flow cards."
},
"1.0.4": {
"en": "Added possible fix for an issue that the login got stuck and the app crashes after a while."
}
}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.alfen",
"version": "1.0.3",
"version": "1.0.4",
"compatibility": ">=12.0.0",
"sdk": 3,
"platforms": [
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "com.alfen",
"version": "1.0.3",
"version": "1.0.4",
"compatibility": ">=12.0.0",
"sdk": 3,
"platforms": [
Expand Down
10 changes: 8 additions & 2 deletions drivers/chargepoint/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = class MyDevice extends Homey.Device {
apiUrl: string = 'api';
alfenApi!: AlfenApi;

currentInterval: NodeJS.Timeout | null = null;

/**
* onInit is called when the device is initialized.
*/
Expand Down Expand Up @@ -43,8 +45,12 @@ module.exports = class MyDevice extends Homey.Device {
// Register flow card listeners
this.#registerFlowCardListeners();

// Set interval and refresh device data
this.homey.setInterval(this.refreshDevice.bind(this), this.refreshRate * 1000);
// Set (and clear) interval and refresh device data
if (this.currentInterval) clearInterval(this.currentInterval);
this.currentInterval = this.homey.setInterval(() => {
this.refreshDevice();
}, this.refreshRate * 1000);

await this.refreshDevice();
}

Expand Down
6 changes: 5 additions & 1 deletion lib/AlfenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class AlfenApi {
this.#log(`Starting login process: ${this.#retrieving}`);

// Try handling multiple requests at the same time
if (this.#retrieving > 10) {
this.#retrieving = 1;
await this.apiLogout();
}

if (this.#agent == null) this.#retrieving = 0;
this.#retrieving += 1;
if (this.#agent != null) return; // Already running another process and already loggedin
Expand Down Expand Up @@ -124,7 +129,6 @@ export class AlfenApi {
} catch (error) {
this.#agent = null;
this.#log('Logout failed:', error);
//throw new Error(`Logout failed: ${error}`);
}
}

Expand Down

0 comments on commit bb2a89c

Please sign in to comment.