homebridge-philips-airplus-cloud 0.5.1 → 0.5.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
@@ -2,6 +2,15 @@
2
2
 
3
3
  The Home Assistant integration in `custom_components/` is unchanged from upstream and keeps its own history.
4
4
 
5
+ ## 0.5.3 — 2026-11-21
6
+
7
+ - Fix: logging in from the settings panel failed with "Request a new code first" when the page was reloaded between "Send code" and "Log in" — typically on a phone, after switching to the mail app to read the code, because Homebridge UI then restarts the panel. The pending request is now kept by the page: after a reload the panel reopens on the code field and the code can still be verified.
8
+ - Fix: the login no longer fails if the Philips API refuses to return the account's user id; it is only used to name the cloud connection and has a fallback.
9
+
10
+ ## 0.5.2 — 2026-11-21
11
+
12
+ - README: new "Filter notifications" section — how to turn on notifications for the filter alert sensors in the Home app, why a sensor that is already open does not notify, and how to name the sensors so "opened / closed" reads clearly. No code changes.
13
+
5
14
  ## 0.5.1 — 2026-11-21
6
15
 
7
16
  - Fix: login and device discovery failed with HTTP 403 ("User is not authorized to access this resource…"). The Philips/Versuni API now rejects requests with the User-Agent the plugin used, `okhttp/4.12.0 (Android 14; Pixel 7)`, before even checking the login. The plugin now sends `okhttp/4.12.0`, as the upstream Home Assistant integration does since 1.1.7. The same API is used on every reconnect, so existing installations should update too.
package/README.md CHANGED
@@ -102,6 +102,27 @@ The refresh token rotates on every use; the plugin keeps the current one in `<ho
102
102
  | `filterChangeThreshold` | `10` | Filter life (%) at or below which HomeKit shows "replace filter" |
103
103
  | `pollInterval` | `120` | Seconds between safety-net status polls |
104
104
 
105
+ ## Filter notifications
106
+
107
+ The Home app shows "Replace filter" inside the purifier but never sends a notification for it. With **Filter alerts** turned on, the plugin adds a contact sensor per filter that Home *can* notify about:
108
+
109
+ | Sensor | Opens when | Closes when |
110
+ |---|---|---|
111
+ | **Replace filter** | the filter drops to the alert threshold (10% by default) | the filter is replaced and its counter reset |
112
+ | **Clean pre-filter** | the pre-filter is due for cleaning | the pre-filter is cleaned and its counter reset |
113
+
114
+ To get notified:
115
+
116
+ 1. In the plugin settings → **Options**, turn on **Filter alerts for Home notifications**, save and restart Homebridge.
117
+ 2. In the Home app, open the purifier, then each of the two sensors → settings → turn on **Status notifications**. They are off by default.
118
+ 3. Also check that notifications are allowed for the Home app in the iPhone's Settings → Notifications → Home.
119
+
120
+ Good to know:
121
+
122
+ - Home notifies when a sensor **changes** state. A sensor that is already open when you turn the option on (a filter already due) does not notify until it closes and opens again.
123
+ - The wording "opened / closed" comes from the Home app and cannot be changed by the plugin. Give the sensors names that make the sentence clear, for example **Pre-filter to clean** ("Pre-filter to clean opened" = clean it, "… closed" = done). Names you set in Home are kept across restarts and updates.
124
+ - To be warned earlier, raise **Filter change alert below (%)** in the options.
125
+
105
126
  ## Running alongside Home Assistant or the app
106
127
 
107
128
  Each client uses its own MQTT client id (`…_hb` for Homebridge, `…_ha` for Home Assistant), so the Air+ app, Home Assistant and Homebridge can all stay connected at the same time.
@@ -70,11 +70,37 @@
70
70
  homebridge.fixScrollHeight();
71
71
  }
72
72
 
73
+ // The pending code request (email + vToken) is kept in the page's storage,
74
+ // so the login can be finished even if the settings page is reloaded or
75
+ // the panel's server restarts while you read the email (common on phones).
76
+ const PENDING_KEY = 'philips-airplus-pending-login';
77
+ const PENDING_MAX_AGE = 15 * 60 * 1000;
78
+ let pending = null;
79
+ function savePending(p) {
80
+ pending = p;
81
+ try {
82
+ if (p) localStorage.setItem(PENDING_KEY, JSON.stringify(p));
83
+ else localStorage.removeItem(PENDING_KEY);
84
+ } catch {
85
+ // storage unavailable: keep it in memory only
86
+ }
87
+ }
88
+ function loadPending() {
89
+ try {
90
+ const p = JSON.parse(localStorage.getItem(PENDING_KEY) || 'null');
91
+ if (p && p.email && p.vToken && Date.now() - p.at < PENDING_MAX_AGE) return p;
92
+ } catch {
93
+ // ignore unreadable storage
94
+ }
95
+ return null;
96
+ }
97
+
73
98
  $('send-btn').addEventListener('click', async () => {
74
99
  const email = $('email').value.trim();
75
100
  homebridge.showSpinner();
76
101
  try {
77
- await homebridge.request('/send-code', { email });
102
+ const r = await homebridge.request('/send-code', { email });
103
+ savePending(r && r.vToken ? { email: r.email || email, vToken: r.vToken, at: Date.now() } : null);
78
104
  $('email-echo').textContent = email;
79
105
  showStep('code');
80
106
  $('code').focus();
@@ -89,9 +115,13 @@
89
115
  $('verify-btn').addEventListener('click', async () => {
90
116
  homebridge.showSpinner();
91
117
  try {
92
- const r = await homebridge.request('/verify-code', { code: $('code').value });
118
+ const body = { code: $('code').value };
119
+ if (pending) Object.assign(body, { email: pending.email, vToken: pending.vToken });
120
+ const r = await homebridge.request('/verify-code', body);
121
+ const loginEmail = (pending && pending.email) || $('email').value.trim();
122
+ savePending(null);
93
123
  Object.assign(configs[0], {
94
- email: $('email').value.trim(),
124
+ email: loginEmail,
95
125
  refreshToken: r.refreshToken,
96
126
  clientId: r.clientId,
97
127
  userId: r.userId,
@@ -109,7 +139,10 @@
109
139
  }
110
140
  });
111
141
 
112
- $('back-btn').addEventListener('click', () => showStep('email'));
142
+ $('back-btn').addEventListener('click', () => {
143
+ savePending(null);
144
+ showStep('email');
145
+ });
113
146
  $('email').addEventListener('keydown', (e) => e.key === 'Enter' && $('send-btn').click());
114
147
  $('code').addEventListener('keydown', (e) => e.key === 'Enter' && $('verify-btn').click());
115
148
 
@@ -119,6 +152,13 @@
119
152
  });
120
153
 
121
154
  showStatus();
155
+ pending = loadPending();
156
+ if (pending) {
157
+ // Back from the mail app: go straight to the code field.
158
+ $('email').value = pending.email;
159
+ $('email-echo').textContent = pending.email;
160
+ showStep('code');
161
+ }
122
162
  homebridge.showSchemaForm();
123
163
  })();
124
164
  </script>
@@ -21,10 +21,18 @@ const { LoginSession } = require('../src/cloud');
21
21
  } catch (e) {
22
22
  throw new RequestError(e.message, {});
23
23
  }
24
- return { sent: true };
24
+ // The page keeps email + vToken, so the code can still be verified if
25
+ // this server process is restarted in between (Homebridge UI restarts
26
+ // it when the settings page reloads, e.g. after switching to the mail
27
+ // app on a phone to read the code).
28
+ return { sent: true, email: this.session.email, vToken: this.session.vToken };
25
29
  });
26
30
 
27
- this.onRequest('/verify-code', async ({ code } = {}) => {
31
+ this.onRequest('/verify-code', async ({ code, email, vToken } = {}) => {
32
+ if (vToken && email && (!this.session || this.session.vToken !== vToken)) {
33
+ this.session = new LoginSession({ log: (m) => console.log(`[philips-airplus-ui] ${m}`) });
34
+ this.session.resume(email, vToken);
35
+ }
28
36
  if (!this.session) throw new RequestError('Request a new code first', {});
29
37
  try {
30
38
  await this.session.verifyCode(code);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-philips-airplus-cloud",
3
3
  "displayName": "Philips Air+",
4
- "version": "0.5.1",
4
+ "version": "0.5.3",
5
5
  "description": "Homebridge plugin for Philips Air+ / PureProtect air purifiers via the Philips (Versuni) cloud — the same MQTT protocol used by the Air+ app and Google Home.",
6
6
  "main": "src/index.js",
7
7
  "license": "MIT",
package/src/account.js CHANGED
@@ -111,7 +111,13 @@ class Account {
111
111
  async getUserId() {
112
112
  if (!this.userId) {
113
113
  await this.ensureToken();
114
- this.userId = await cloud.fetchUserId(this.accessToken, this.fetch);
114
+ try {
115
+ this.userId = await cloud.fetchUserId(this.accessToken, this.fetch);
116
+ } catch (e) {
117
+ // Only used to build a nicer MQTT client id; there is a fallback.
118
+ this.log.debug(`Could not read the user id: ${e.message}`);
119
+ return null;
120
+ }
115
121
  this._save();
116
122
  }
117
123
  return this.userId;
package/src/cloud.js CHANGED
@@ -107,6 +107,12 @@ class LoginSession {
107
107
  return true;
108
108
  }
109
109
 
110
+ /** Continue a login started by sendCode() in another process. */
111
+ resume(email, vToken) {
112
+ this.email = String(email).trim();
113
+ this.vToken = vToken;
114
+ }
115
+
110
116
  async verifyCode(code) {
111
117
  if (!this.vToken) throw new CloudError('Request a code first');
112
118
  const data = await this._postForm(C.GIGYA_OTP_LOGIN_ENDPOINT, {
@@ -225,7 +231,14 @@ class LoginSession {
225
231
  }
226
232
  }
227
233
 
228
- const userId = await fetchUserId(tokens.accessToken, this.fetch);
234
+ // The user id only makes the MQTT client id nicer; a failure here must
235
+ // not fail the whole login (the client id has a fallback without it).
236
+ let userId = null;
237
+ try {
238
+ userId = await fetchUserId(tokens.accessToken, this.fetch);
239
+ } catch (e) {
240
+ this.log(`Could not read the user id (${e.message}); continuing without it`);
241
+ }
229
242
  return {
230
243
  ...tokens,
231
244
  userId,