homebridge-philips-airplus-cloud 0.4.0 → 0.5.0

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,11 @@
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.0 — 2026-11-21
6
+
7
+ - New option **Filter alerts** (`filterAlerts`, default off): one contact sensor per filter, "Replace filter" and "Clean pre-filter", that opens when the filter drops to the alert threshold. The Home app never notifies about filter status, but it can notify when a contact sensor opens. A warning is also written to the Homebridge log.
8
+ - Fix: about once an hour, when the access token was renewed, the log showed "Not connected to the Philips cloud, command dropped" followed by "Connected to Philips cloud". During that reconnection the plugin still thought it was connected. HomeKit commands sent in that window are now queued and delivered as soon as the connection is back, status polls are skipped quietly, and the routine reconnection is logged at debug level only.
9
+
5
10
  ## 0.4.0 — 2026-10-25
6
11
 
7
12
  - Added the Philips Air+ icon to the README.
package/README.md CHANGED
@@ -5,11 +5,11 @@
5
5
  </table>
6
6
  <br />
7
7
 
8
- ![verified-by-homebridge](https://img.shields.io/badge/homebridge-verified-blueviolet?color=%23491F59&style=for-the-badge&logoColor=%23FFFFFF&logo=homebridge)
8
+ ![verified-by-homebridge](https://img.shields.io/badge/homebridge-verified-blueviolet?color=%23491F59&style=flat) [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-0070ba?logo=paypal&logoColor=white)](https://paypal.me/micheledipaola)
9
+
9
10
 
10
11
  # homebridge-philips-airplus-cloud
11
12
 
12
- [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-0070ba?logo=paypal&logoColor=white)](https://paypal.me/micheledipaola)
13
13
 
14
14
  Homebridge plugin for **Philips Air+** air purifiers (AC0650, AC0651, AC1715, PureProtect 3200i and others in the same family). It brings them into Apple Home through the Philips/Versuni **cloud**, with the same MQTT protocol used by the official Air+ app and Google Home. No local connection, IP address or port forwarding is needed.
15
15
 
@@ -91,6 +91,7 @@ The refresh token rotates on every use; the plugin keeps the current one in `<ho
91
91
  | `airQualitySensor` | `true` | Show the PM2.5 sensor |
92
92
  | `allergenSensor` | `true` | Show the allergen index as a second air quality sensor (models that report it) |
93
93
  | `filterSensors` | `true` | Show filter and pre-filter status |
94
+ | `filterAlerts` | `false` | Add a contact sensor per filter that opens when it needs replacing / cleaning, so the Home app can notify you (turn on notifications for the sensors in Home) |
94
95
  | `sleepSwitch` | `true` | Show the Sleep mode switch |
95
96
  | `sleepSwitchStyle` | `switch` | `purifier` shows the Sleep control as a second air purifier (purifier icon in Home) that only turns Sleep on/off |
96
97
  | `linkComponents` | `false` | Link Sleep, air quality and filters to the purifier. Off: each gets its own labelled tile in the purifier's combined view. On: Home shows them as controls inside the purifier, without labels |
@@ -73,6 +73,12 @@
73
73
  "type": "boolean",
74
74
  "default": true
75
75
  },
76
+ "filterAlerts": {
77
+ "title": "Filter alerts for Home notifications",
78
+ "type": "boolean",
79
+ "default": false,
80
+ "description": "Adds a contact sensor per filter ('Replace filter', 'Clean pre-filter') that opens when the filter needs attention, below the threshold set further down. In the Home app, turn on notifications for these sensors to be alerted."
81
+ },
76
82
  "sleepSwitch": {
77
83
  "title": "Show a Sleep mode switch",
78
84
  "type": "boolean",
@@ -182,6 +188,7 @@
182
188
  "airQualitySensor",
183
189
  "allergenSensor",
184
190
  "filterSensors",
191
+ "filterAlerts",
185
192
  "sleepSwitch",
186
193
  "sleepSwitchStyle",
187
194
  "linkComponents",
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.4.0",
4
+ "version": "0.5.0",
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/accessory.js CHANGED
@@ -292,12 +292,24 @@ class PurifierAccessory {
292
292
 
293
293
  // --- Filters
294
294
  this.filters = {};
295
+ this.filterAlerts = {};
295
296
  const filterDefs = [
296
- { kind: 'replace', subtype: 'filter', label: 'Filter' },
297
- { kind: 'clean', subtype: 'prefilter', label: 'Pre-filter' },
297
+ { kind: 'replace', subtype: 'filter', label: 'Filter', alertLabel: 'Replace filter' },
298
+ { kind: 'clean', subtype: 'prefilter', label: 'Pre-filter', alertLabel: 'Clean pre-filter' },
298
299
  ];
299
300
  for (const f of filterDefs) {
300
301
  const enabled = this._prop(`filter_${f.kind}_remaining`) && cfg.filterSensors !== false;
302
+ // filterAlerts: the Home app never notifies about filter status, but it
303
+ // can notify when a contact sensor opens. One sensor per filter, open
304
+ // while the filter needs replacing / cleaning.
305
+ const alertSubtype = `${f.subtype}-alert`;
306
+ if (enabled && cfg.filterAlerts === true) {
307
+ const a = this._service(Service.ContactSensor, f.alertLabel, alertSubtype);
308
+ a.getCharacteristic(Characteristic.ContactSensorState).onGet(() => this._filterChange(f.kind));
309
+ this.filterAlerts[f.kind] = a;
310
+ } else {
311
+ this._remove(Service.ContactSensor, alertSubtype);
312
+ }
301
313
  if (!enabled) {
302
314
  this._remove(Service.FilterMaintenance, f.subtype);
303
315
  continue;
@@ -482,7 +494,8 @@ class PurifierAccessory {
482
494
  // ------------------------------------------------------------ setters
483
495
 
484
496
  _ensureConnected() {
485
- if (!this.conn.connected) {
497
+ // During the hourly token renewal the command is queued, not refused.
498
+ if (!this.conn.available) {
486
499
  throw new this.api.hap.HapStatusError(this.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
487
500
  }
488
501
  }
@@ -715,6 +728,14 @@ class PurifierAccessory {
715
728
  if (life === null) continue;
716
729
  s.updateCharacteristic(Characteristic.FilterLifeLevel, life);
717
730
  s.updateCharacteristic(Characteristic.FilterChangeIndication, this._filterChange(kind));
731
+ const alert = this.filterAlerts && this.filterAlerts[kind];
732
+ if (alert) {
733
+ const open = this._filterChange(kind); // 1 = CONTACT_NOT_DETECTED ("open")
734
+ if (alert.getCharacteristic(Characteristic.ContactSensorState).value !== open && open === 1) {
735
+ this.log.warn(`${kind === 'replace' ? 'Filter needs replacing' : 'Pre-filter needs cleaning'} (${life}% left)`);
736
+ }
737
+ alert.updateCharacteristic(Characteristic.ContactSensorState, open);
738
+ }
718
739
  }
719
740
  }
720
741
  }
package/src/connection.js CHANGED
@@ -118,6 +118,9 @@ class DeviceConnection extends EventEmitter {
118
118
 
119
119
  async _connect() {
120
120
  if (this.stopped) return;
121
+ // From here until the new connection is up, nothing can be published:
122
+ // user commands are queued, polls are skipped.
123
+ this.connected = false;
121
124
  if (this.client) {
122
125
  this.client.removeAllListeners();
123
126
  this.client.on('error', () => {});
@@ -135,6 +138,7 @@ class DeviceConnection extends EventEmitter {
135
138
  accessToken = this.account.accessToken;
136
139
  clientId = buildClientId(await this.account.getUserId(), this.uuid);
137
140
  } catch (e) {
141
+ this.reconnecting = false;
138
142
  if (e instanceof AuthExpiredError) {
139
143
  this.log.error(`${e.message}. The device stays offline until you log in again.`);
140
144
  this.emit('authExpired');
@@ -173,7 +177,13 @@ class DeviceConnection extends EventEmitter {
173
177
  this.attempt = 0;
174
178
  this.lastMessageAt = Date.now();
175
179
  client.subscribe(C.TOPIC_STATUS(this.deviceId), { qos: 0 });
176
- this.log.info('Connected to Philips cloud');
180
+ // Routine reconnects (hourly token renewal) are logged at debug level.
181
+ if (!this.everConnected) this.log.info('Connected to Philips cloud');
182
+ else if (this.reconnecting) this.log.debug('Reconnected with the renewed access token');
183
+ else this.log.info('Reconnected to Philips cloud');
184
+ this.everConnected = true;
185
+ this.reconnecting = false;
186
+ this._flushQueue();
177
187
  this.emit('connected');
178
188
  });
179
189
 
@@ -203,6 +213,7 @@ class DeviceConnection extends EventEmitter {
203
213
  if (client !== this.client || this.stopped) return;
204
214
  const wasConnected = this.connected;
205
215
  this.connected = false;
216
+ this.reconnecting = false; // a failed routine reconnect is a real outage
206
217
  this.client = null;
207
218
  const wait = this._backoff(client.__rc);
208
219
  if (wasConnected) {
@@ -226,13 +237,39 @@ class DeviceConnection extends EventEmitter {
226
237
  }
227
238
  if (this.connected && this.tokenUsed !== this.account.accessToken) {
228
239
  this.log.debug('Access token changed, reconnecting with new credentials');
240
+ this.reconnecting = true;
229
241
  this._connect();
230
242
  }
231
243
  }
232
244
 
233
- _publish(topic, payload, qos = 0) {
245
+ /** True while connected, or while a routine reconnect is in progress. */
246
+ get available() {
247
+ return this.connected || !!this.reconnecting;
248
+ }
249
+
250
+ _flushQueue() {
251
+ const now = Date.now();
252
+ const queue = (this.queue || []).filter((q) => now - q.at < 60000);
253
+ this.queue = [];
254
+ if (queue.length) this.log.debug(`Sending ${queue.length} command(s) queued during reconnection`);
255
+ for (const q of queue) this.client.publish(q.topic, q.payload, { qos: q.qos });
256
+ }
257
+
258
+ /**
259
+ * @param {boolean} [queue] user commands: kept for up to 60 s while the
260
+ * connection is being re-established instead of being dropped. Status
261
+ * requests are not queued: they are repeated on every (re)connect anyway.
262
+ */
263
+ _publish(topic, payload, qos = 0, queue = false) {
234
264
  if (!this.client || !this.connected) {
235
- this.log.warn('Not connected to the Philips cloud, command dropped');
265
+ if (queue && !this.stopped) {
266
+ this.queue = (this.queue || []).slice(-19);
267
+ this.queue.push({ topic, payload, qos, at: Date.now() });
268
+ this.log.debug('Not connected right now, command queued until the connection is back');
269
+ return true;
270
+ }
271
+ if (this.reconnecting) this.log.debug('Reconnecting, status request skipped');
272
+ else this.log.warn('Not connected to the Philips cloud, command dropped');
236
273
  return false;
237
274
  }
238
275
  this.log.debug(`MQTT -> ${topic} ${payload}`);
@@ -245,8 +282,8 @@ class DeviceConnection extends EventEmitter {
245
282
  }
246
283
 
247
284
  setPort(port, properties, qos = 0) {
248
- const ok = this._publish(C.TOPIC_CONTROL(this.deviceId), buildCommand('setPort', port, properties), qos);
249
- if (ok) this.getPort(port === this.ports.filter_write ? this.ports.filter_read : this.ports.status);
285
+ const ok = this._publish(C.TOPIC_CONTROL(this.deviceId), buildCommand('setPort', port, properties), qos, true);
286
+ if (ok && this.connected) this.getPort(port === this.ports.filter_write ? this.ports.filter_read : this.ports.status);
250
287
  return ok;
251
288
  }
252
289
 
@@ -255,8 +292,8 @@ class DeviceConnection extends EventEmitter {
255
292
  }
256
293
 
257
294
  setPower(on) {
258
- const ok = this._publish(C.TOPIC_SHADOW_UPDATE(this.deviceId), JSON.stringify({ state: { desired: { powerOn: !!on } } }));
259
- if (ok) this.getPort(this.ports.status);
295
+ const ok = this._publish(C.TOPIC_SHADOW_UPDATE(this.deviceId), JSON.stringify({ state: { desired: { powerOn: !!on } } }), 0, true);
296
+ if (ok && this.connected) this.getPort(this.ports.status);
260
297
  return ok;
261
298
  }
262
299