homebridge-philips-air-purifier-complete 3.2.4 → 3.2.5

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
@@ -6,6 +6,22 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6
6
 
7
7
  ---
8
8
 
9
+ ## [3.2.5] — 15/06/2026
10
+
11
+ ### Fixed
12
+
13
+ - Air+ Cloud login: extract the authorisation code directly from the URL the user pastes —
14
+ whether it is the `com.philips.air://loginredirect?code=…` deep link or the `accounts.home.id`
15
+ consent/proxy page — by parsing the query string, then the URL fragment, then a regex fallback.
16
+ The v3.2.4 approach refetched the proxy page server-side, which could never succeed because the
17
+ authorisation code is bound to the user's authenticated browser session; that refetch is now only
18
+ a last resort. This is the fix for testers who reported the proxy page error after approving access.
19
+ - Air+ Cloud login: reworded the on-screen steps so the `accounts.home.id` URL is presented as an
20
+ equally valid thing to paste, not a fallback, since many desktop browsers never leave the
21
+ `com.philips.air://` URL in the address bar.
22
+
23
+ ---
24
+
9
25
  ## [3.2.4] — 15/06/2026
10
26
 
11
27
  ### Fixed
@@ -265,9 +265,8 @@
265
265
  <ol style="color: var(--muted); font-size: 13px; padding-left: 20px; margin: 0 0 14px; line-height: 1.7;">
266
266
  <li><a id="auth-link" href="#" target="_blank" rel="noopener">Open the Philips login page</a> (a new tab will open automatically — click the link if it didn't).</li>
267
267
  <li>Log in to your Philips account and approve access when prompted.</li>
268
- <li>Your browser will try to open the Philips Air app. If it can't, it will show an error or a Philips page — this is expected.</li>
269
- <li>Check your browser's <strong style="color: var(--text);">address bar</strong> at that moment. It should show a URL starting with <code style="background:#1a1a1a; padding: 1px 4px; border-radius: 3px; font-size: 12px;">com.philips.air://loginredirect?code=…</code> — copy and paste that here.</li>
270
- <li>If your address bar shows a Philips website (like <em>accounts.home.id</em>), paste that URL here instead — we'll try to extract the code automatically.</li>
268
+ <li>After approving, your browser will try to open the Philips Air app and will land on either an error page or a Philips page (<em>accounts.home.id</em>) — this is expected.</li>
269
+ <li>Copy the <strong style="color: var(--text);">full URL from your browser's address bar</strong> and paste it below. It works whether it starts with <code style="background:#1a1a1a; padding: 1px 4px; border-radius: 3px; font-size: 12px;">com.philips.air://loginredirect?code=…</code> or is an <em>accounts.home.id</em> address — as long as it contains <code style="background:#1a1a1a; padding: 1px 4px; border-radius: 3px; font-size: 12px;">code=…</code>.</li>
271
270
  </ol>
272
271
  <div class="field">
273
272
  <label for="redirect-url">Redirect URL (from your browser's address bar)</label>
@@ -59,11 +59,16 @@ class AirPlusSetupServer extends HomebridgePluginUiServer {
59
59
  throw new Error('Redirect URL is required');
60
60
  }
61
61
 
62
- let code = null;
63
-
64
- if (redirectUrl.includes('accounts.home.id/authui/client/proxy')) {
65
- // User pasted the Philips consent proxy page URL instead of the final deep-link redirect.
66
- // Fetch the proxy page and try to extract com.philips.air://loginredirect?code=... from the HTML.
62
+ // The authorisation code lives in the URL the user copied — whether that is the
63
+ // com.philips.air:// deep link or the accounts.home.id consent/proxy page that
64
+ // many desktop browsers land on instead. Parse it directly (query → fragment →
65
+ // regex), mirroring scripts/airplus_setup.py.
66
+ let code = this._extractCode(redirectUrl);
67
+
68
+ // Last resort: the user pasted a Philips consent page that did not carry the
69
+ // code in its own URL. Fetch it and scan for an embedded deep link. This only
70
+ // works if the page is reachable unauthenticated, so treat failure as benign.
71
+ if (!code && redirectUrl.includes('accounts.home.id')) {
67
72
  try {
68
73
  const proxyUrl = new URL(redirectUrl);
69
74
  const html = await this._httpsGetRaw({
@@ -74,28 +79,17 @@ class AirPlusSetupServer extends HomebridgePluginUiServer {
74
79
  const m = html.match(/com\.philips\.air:\/\/loginredirect[^\s"'\\]*code=([^&\s"'\\]+)/);
75
80
  if (m) code = decodeURIComponent(m[1]);
76
81
  } catch (_) { /* fall through to descriptive error */ }
82
+ }
77
83
 
78
- if (!code) {
79
- throw new Error(
80
- 'This is the Philips login confirmation page, not the final redirect URL. ' +
81
- 'After approving access your browser will try to open the Philips Air app — ' +
82
- 'look at your address bar at that moment; it will show a URL starting with ' +
83
- '"com.philips.air://loginredirect?code=…". Copy that URL and paste it here.'
84
- );
85
- }
86
- } else {
87
- // Normal path: user pasted the com.philips.air:// deep-link URL (or similar)
88
- const parseable = redirectUrl.replace(/^com\.philips\.air:\/\//, 'https://x/');
89
- let parsed;
90
- try { parsed = new URL(parseable); } catch (_) { parsed = null; }
91
- code = parsed && parsed.searchParams.get('code');
92
- if (!code) {
93
- throw new Error(
94
- 'No authorisation code found in redirect URL. ' +
95
- 'Paste the full URL from your browser’s address bar after approving access — ' +
96
- 'it should start with “com.philips.air://loginredirect?code=…”.'
97
- );
98
- }
84
+ if (!code) {
85
+ throw new Error(
86
+ 'No authorisation code found in that URL. After approving access, copy the ' +
87
+ 'full URL from your browser’s address bar and paste it here — it will start ' +
88
+ 'with either "com.philips.air://loginredirect?code=…" or an "accounts.home.id" ' +
89
+ 'address containing "code=…". If you only see a Philips confirmation page with ' +
90
+ 'no "code=" in its address, log in again and copy the URL the moment the page ' +
91
+ 'finishes loading.'
92
+ );
99
93
  }
100
94
 
101
95
  const tokenBody = new URLSearchParams({
@@ -183,6 +177,30 @@ class AirPlusSetupServer extends HomebridgePluginUiServer {
183
177
  return { success: true, uuid, name: name || 'Philips Air Purifier', tokenFile: tokenPath };
184
178
  }
185
179
 
180
+ _extractCode(redirectUrl) {
181
+ const trimmed = String(redirectUrl || '').trim();
182
+ if (!trimmed) return null;
183
+
184
+ // Normalise the custom scheme so the URL parser accepts it.
185
+ const normalised = trimmed.replace(/^com\.philips\.air:\/\//i, 'https://airplus.local/');
186
+ let parsed = null;
187
+ try { parsed = new URL(normalised); } catch (_) { parsed = null; }
188
+
189
+ if (parsed) {
190
+ const fromQuery = parsed.searchParams.get('code');
191
+ if (fromQuery) return fromQuery;
192
+ // OIDC may return the response in the URL fragment (#code=…&state=…).
193
+ if (parsed.hash && parsed.hash.length > 1) {
194
+ const fromFragment = new URLSearchParams(parsed.hash.slice(1)).get('code');
195
+ if (fromFragment) return fromFragment;
196
+ }
197
+ }
198
+
199
+ // Fallback for unusual encodings the URL parser may not split cleanly.
200
+ const m = trimmed.match(/[?&#]code=([^&\s"'\\]+)/);
201
+ return m ? decodeURIComponent(m[1]) : null;
202
+ }
203
+
186
204
  _httpsRequest(options, postBody) {
187
205
  return new Promise((resolve, reject) => {
188
206
  const req = https.request(options, (res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-philips-air-purifier-complete",
3
- "version": "3.2.4",
3
+ "version": "3.2.5",
4
4
  "customUi": true,
5
5
  "description": "Homebridge plugin for Philips Air Purifier with bundled CoAP control library and Python 3.12+/Node.js 24 support",
6
6
  "main": "index.js",