homebridge-polestar-c3 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.3 — 18 November 2026
4
+ Verified by Homebridge 🎉. Suggestions from the review:
5
+ - Fix: the client advertised gzip support it does not have; a compressed reply would have thrown outside any error handler and could crash Homebridge. It now only asks for uncompressed replies, and an unexpected compressed frame is reported as a normal error.
6
+ - Client messages (GOAWAY, retries, failed pings) go through the Homebridge log with the plugin name; routine reconnects are now debug-level, so the hourly `HTTP/2 GOAWAY received` line no longer shows in the normal log.
7
+ - Licence identifier updated to `GPL-3.0-only`.
8
+ - "Verified by Homebridge" badge in the README.
9
+
10
+ ## 0.2.2 — 17 November 2026
11
+ - Fix: about once an hour a refresh failed with "Refresh failed: no status could be read". The Polestar backend closes the connection roughly every hour (HTTP/2 GOAWAY) and requests in flight were cancelled without a retry. Each status read now retries once on a fresh connection.
12
+ - "Refresh failed" now includes the underlying reason.
13
+ - Fix: a refresh error was not reported when one of the services is unsupported by the vehicle.
14
+
3
15
  ## 0.2.1 — 16 November 2026
4
16
  - Everything in English: log messages, accessory names, settings screen and documentation.
5
17
  - Existing accessories keep the names they already have in the Home app; only newly added accessories get English names.
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # homebridge-polestar-c3
2
2
 
3
+ [![verified-by-homebridge](https://img.shields.io/badge/homebridge-verified-blueviolet?color=%23491F59&style=flat)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
3
4
  [![Tests](https://github.com/jeroendbr-web/homebridge-polestar-c3/actions/workflows/test.yml/badge.svg)](https://github.com/jeroendbr-web/homebridge-polestar-c3/actions/workflows/test.yml)
4
5
  [![Release](https://img.shields.io/github/v/release/jeroendbr-web/homebridge-polestar-c3?label=release)](https://github.com/jeroendbr-web/homebridge-polestar-c3/releases)
5
6
  [![Homebridge](https://img.shields.io/badge/homebridge-1.8%20%7C%202.x-491F59?logo=homebridge)](https://homebridge.io)
@@ -85,7 +86,12 @@ npm install
85
86
  npm test
86
87
  ```
87
88
 
88
- The Polestar client in `lib/polestar-c3/` is an unmodified copy of `clone_modules/polestar-c3/` from [kaohlive/Polestar](https://github.com/kaohlive/Polestar). To update it, copy those files over.
89
+ The Polestar client in `lib/polestar-c3/` is a copy of `clone_modules/polestar-c3/` from [kaohlive/Polestar](https://github.com/kaohlive/Polestar) (v3.5.0), with two small local changes, each marked with a `homebridge-polestar-c3:` comment:
90
+
91
+ - `grpc.js` only asks for uncompressed replies, and a compressed frame is rejected as an error instead of throwing in an event handler.
92
+ - `client.js` accepts an optional `logger` so its messages go through the Homebridge log.
93
+
94
+ When updating the client from upstream, re-apply these changes.
89
95
 
90
96
  ## Credits
91
97
 
@@ -94,4 +100,4 @@ The Polestar client in `lib/polestar-c3/` is an unmodified copy of `clone_module
94
100
 
95
101
  ## License
96
102
 
97
- GPL-3.0, see [LICENSE](LICENSE).
103
+ GPL-3.0-only, see [LICENSE](LICENSE).
package/lib/platform.js CHANGED
@@ -126,6 +126,7 @@ class PolestarPlatform {
126
126
  tokens: this.loadSession(),
127
127
  onTokens: (tokens) => this.saveSession(tokens),
128
128
  onEvent: (type, detail) => this.logAuthEvent(type, detail),
129
+ logger: { debug: (m) => this.log.debug(m), warn: (m) => this.log.warn(m) },
129
130
  });
130
131
  await this.client.login();
131
132
 
@@ -452,19 +453,36 @@ class PolestarPlatform {
452
453
  // Polling
453
454
  // ---------------------------------------------------------------
454
455
 
456
+ /**
457
+ * Read one status service. Returns the response, null when the vehicle does
458
+ * not support it, or undefined on error.
459
+ *
460
+ * The backend closes the HTTP/2 connection roughly every hour (GOAWAY). The
461
+ * bundled client then destroys the session, which cancels requests that are
462
+ * in flight with an error it does not treat as transient. One retry on a
463
+ * fresh connection covers that.
464
+ */
455
465
  async readSafe(key, fn) {
456
466
  if (this.unsupported.has(key)) return null;
457
- try {
458
- return await fn();
459
- } catch (err) {
460
- if (isUnimplemented(err)) {
461
- this.unsupported.add(key);
462
- this.log.info(`Reading '${key}' is not supported by this vehicle; skipping.`);
463
- return null;
467
+ for (let attempt = 0; attempt < 2; attempt++) {
468
+ try {
469
+ return await fn();
470
+ } catch (err) {
471
+ if (isUnimplemented(err)) {
472
+ this.unsupported.add(key);
473
+ this.log.info(`Reading '${key}' is not supported by this vehicle; skipping.`);
474
+ return null;
475
+ }
476
+ this.lastReadError = friendlyError(err);
477
+ if (attempt === 0) {
478
+ this.log.debug(`Reading '${key}' failed (${this.lastReadError}); retrying.`);
479
+ await new Promise((resolve) => setTimeout(resolve, 2000));
480
+ } else {
481
+ this.log.debug(`Reading '${key}' failed again: ${this.lastReadError}`);
482
+ }
464
483
  }
465
- this.log.debug(`Reading '${key}' failed: ${friendlyError(err)}`);
466
- return undefined; // error, not "unsupported"
467
484
  }
485
+ return undefined; // error, not "unsupported"
468
486
  }
469
487
 
470
488
  async refresh() {
@@ -511,8 +529,9 @@ class PolestarPlatform {
511
529
  }
512
530
 
513
531
  const anyOk = [battery, exterior, climate].some((r) => r && typeof r === 'object');
514
- if (!anyOk && [battery, exterior, climate].every((r) => r === undefined)) {
515
- throw new Error('no status could be read');
532
+ // null = not supported (ignored), undefined = read error
533
+ if (!anyOk && [battery, exterior, climate].some((r) => r === undefined)) {
534
+ throw new Error(`no status could be read (${this.lastReadError || 'unknown error'})`);
516
535
  }
517
536
  if (anyOk) s.lastOk = Date.now();
518
537
 
@@ -71,6 +71,13 @@ class PolestarC3 {
71
71
  this._endpoint = null;
72
72
  this._session = null;
73
73
  this._vin = null;
74
+ // homebridge-polestar-c3: optional logger ({ debug, warn }) instead of console
75
+ this._logger = authOptions.logger || null;
76
+ }
77
+
78
+ _log(level, msg) {
79
+ if (this._logger && typeof this._logger[level] === 'function') this._logger[level](msg);
80
+ else console.warn(msg);
74
81
  }
75
82
 
76
83
  async login() {
@@ -94,7 +101,7 @@ class PolestarC3 {
94
101
  session.on('error', () => { /* swallow to allow reconnect */ });
95
102
  session.on('close', () => { if (this._session === session) this._session = null; });
96
103
  session.on('goaway', () => {
97
- console.warn('[polestar-c3] HTTP/2 GOAWAY received, resetting session');
104
+ this._log('debug', '[polestar-c3] HTTP/2 GOAWAY received, resetting session');
98
105
  if (this._session === session) this._session = null;
99
106
  try { session.destroy(); } catch (_) {}
100
107
  });
@@ -105,7 +112,7 @@ class PolestarC3 {
105
112
  try {
106
113
  session.ping((err) => {
107
114
  if (err) {
108
- console.warn('[polestar-c3] ping failed, destroying session:', err.message);
115
+ this._log('warn', `[polestar-c3] ping failed, destroying session: ${err.message}`);
109
116
  if (this._session === session) this._session = null;
110
117
  try { session.destroy(); } catch (_) {}
111
118
  }
@@ -133,7 +140,7 @@ class PolestarC3 {
133
140
  const msg = err.message || '';
134
141
  const transient = /\bstatus=(13|14)\b|GOAWAY|goaway|ECONNRESET|EPIPE|ETIMEDOUT|NGHTTP2_/i.test(msg);
135
142
  if (attempt < retries && transient) {
136
- console.warn(`[polestar-c3] transient error on ${method}, retrying (${msg})`);
143
+ this._log('debug', `[polestar-c3] transient error on ${method}, retrying (${msg})`);
137
144
  this._session = null;
138
145
  continue;
139
146
  }
@@ -56,7 +56,8 @@ function unaryUnary(session, method, requestBytes, metadata = {}, { timeoutMs =
56
56
  ':path': method,
57
57
  'content-type': 'application/grpc',
58
58
  te: 'trailers',
59
- 'grpc-accept-encoding': 'identity,gzip',
59
+ // homebridge-polestar-c3: only ask for uncompressed replies (parseFrames cannot inflate)
60
+ 'grpc-accept-encoding': 'identity',
60
61
  'grpc-encoding': 'identity',
61
62
  'user-agent': USER_AGENT,
62
63
  ...metadata,
@@ -115,7 +116,13 @@ function unaryUnary(session, method, requestBytes, metadata = {}, { timeoutMs =
115
116
  finish(reject, new Error(`gRPC ${method} returned empty body; ${dump}`));
116
117
  return;
117
118
  }
118
- const frames = parseFrames(body);
119
+ let frames;
120
+ try {
121
+ frames = parseFrames(body);
122
+ } catch (err) {
123
+ finish(reject, new Error(`gRPC ${method} ${err.message}`));
124
+ return;
125
+ }
119
126
  if (frames.length === 0) {
120
127
  finish(reject, new Error(`gRPC ${method} body (${body.length}B) not parseable as gRPC frames; hex=${body.toString('hex').slice(0, 80)}…`));
121
128
  return;
@@ -135,7 +142,8 @@ function serverStreamFirst(session, method, requestBytes, metadata = {}, { timeo
135
142
  ':path': method,
136
143
  'content-type': 'application/grpc',
137
144
  te: 'trailers',
138
- 'grpc-accept-encoding': 'identity,gzip',
145
+ // homebridge-polestar-c3: only ask for uncompressed replies (parseFrames cannot inflate)
146
+ 'grpc-accept-encoding': 'identity',
139
147
  'grpc-encoding': 'identity',
140
148
  'user-agent': USER_AGENT,
141
149
  ...metadata,
@@ -179,6 +187,10 @@ function serverStreamFirst(session, method, requestBytes, metadata = {}, { timeo
179
187
  buffered = Buffer.concat([buffered, chunk]);
180
188
  // Try to parse the first complete frame.
181
189
  if (buffered.length < 5) return;
190
+ if (buffered[0] !== 0) {
191
+ finish(reject, new Error(`gRPC ${method} compressed gRPC frames not supported`));
192
+ return;
193
+ }
182
194
  const len = buffered.readUInt32BE(1);
183
195
  if (buffered.length < 5 + len) return;
184
196
  const frame = buffered.slice(5, 5 + len);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "homebridge-polestar-c3",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Unofficial Homebridge plugin for Polestar 2/3/4 via the C3 cloud backend: lock, climate, charging, battery and doors in HomeKit.",
5
- "license": "GPL-3.0",
5
+ "license": "GPL-3.0-only",
6
6
  "main": "index.js",
7
7
  "engines": {
8
8
  "node": "^22.12.0 || ^24.0.0 || ^26.0.0",