Skip to content

Commit 78a3a91

Browse files
committed
fix Skoda MQTT: refresh token on 'Not authorized' instead of blind reconnect
Like HA's _on_pre_connect_callback pattern: when broker rejects with "Not authorized", stop the client and trigger an immediate token refresh rather than reconnecting 10x with the same expired access token. Also register FCM token with Skoda only once (not on every token refresh).
1 parent f4ca267 commit 78a3a91

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,10 @@ class VwWeconnect extends utils.Adapter {
29162916
return;
29172917
}
29182918
this.fcmToken = fcmToken;
2919-
await this.registerFcmTokenWithSkoda(fcmToken);
2919+
if (!this.fcmTokenRegistered) {
2920+
await this.registerFcmTokenWithSkoda(fcmToken);
2921+
this.fcmTokenRegistered = true;
2922+
}
29202923
} catch (error) {
29212924
this.log.error("MQTT: FCM registration failed: " + error.message);
29222925
return;
@@ -2977,6 +2980,11 @@ class VwWeconnect extends utils.Adapter {
29772980
});
29782981
this.mqttClient.on("error", (error) => {
29792982
this.log.error("MQTT Error: " + error);
2983+
if (error && error.message && error.message.includes("Not authorized")) {
2984+
this.log.info("MQTT: Not authorized - triggering token refresh");
2985+
this.mqttClient.end();
2986+
this.refreshSkodaEToken().catch(() => {});
2987+
}
29802988
});
29812989
this.mqttClient.on("close", () => {
29822990
this.log.info("MQTT Connection closed");

0 commit comments

Comments
 (0)