homebridge-polestar-c3 0.2.2 → 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,12 @@
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
+
3
10
  ## 0.2.2 — 17 November 2026
4
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.
5
12
  - "Refresh failed" now includes the underlying reason.
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
 
@@ -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.2",
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",