homebridge-withings-environment-data 0.2.0 → 0.3.2

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/README.md CHANGED
@@ -54,14 +54,17 @@ Fields:
54
54
  matching the scale's own upload cadence).
55
55
  - **CO2 Detected Threshold (ppm)**: ppm above which the CarbonDioxideSensor
56
56
  reports "abnormal" (default 1000).
57
+ - **ntfy Topic (optional)**: if set, sends a push notification via
58
+ [ntfy.sh](https://ntfy.sh) to this topic the first time a poll fails
59
+ (not repeated on every subsequent failure in the same streak — only once
60
+ a poll succeeds again does the next failure trigger a fresh
61
+ notification). Leave blank to disable.
57
62
 
58
63
  ## How authentication works
59
64
 
60
- Logging in with email and password on every poll turned out to be a bad
61
- idea in practice: Withings appears to throttle repeated automated logins
62
- quite aggressively. Instead, the plugin reuses a long-lived (~1 week)
63
- `session_key` that Withings' own web app relies on to stay logged in
64
- without re-entering credentials each time.
65
+ The plugin reuses a long-lived (~1 week) `session_key`, the same
66
+ mechanism Withings' own web app relies on to stay logged in without
67
+ re-entering credentials each time.
65
68
 
66
69
  That session is cached in a small file in Homebridge's own storage
67
70
  directory, `withings-environment-data-session.json`, and reused across
@@ -55,6 +55,11 @@
55
55
  "default": 2,
56
56
  "minimum": 0,
57
57
  "description": "Consecutive failed polls to tolerate (keeping the last known readings) before the Home app shows \"No Response\". 0 means show it immediately on any failure."
58
+ },
59
+ "ntfyTopic": {
60
+ "title": "ntfy Topic (optional)",
61
+ "type": "string",
62
+ "description": "If set, sends a push notification via ntfy.sh to this topic the first time a poll fails (not repeated on every subsequent failure in the same streak). Leave blank to disable."
58
63
  }
59
64
  }
60
65
  }
package/index.js CHANGED
@@ -93,6 +93,9 @@ class WithingsEnvironmentDataPlatform {
93
93
  this.hasEverSucceeded = false;
94
94
  this.missedCycles = 0;
95
95
  this.lastReading = { co2: null, temperature: null };
96
+ // Only send one ntfy notification per failure streak, not on every
97
+ // missed poll — reset once a poll succeeds again.
98
+ this.hasNotifiedFailure = false;
96
99
 
97
100
  // The long-lived (~1 week) session_key that lets us skip email/password/2FA
98
101
  // entirely on most polls — see lib/login.js's resumeSession(). Persisted to
@@ -235,6 +238,7 @@ class WithingsEnvironmentDataPlatform {
235
238
  this.applyReading(co2, temperature);
236
239
  this.setFault(false);
237
240
  this.missedCycles = 0;
241
+ this.hasNotifiedFailure = false;
238
242
  } catch (err) {
239
243
  // Deliberately do not touch the value characteristics here — the Home app
240
244
  // should keep showing the last known good reading, not go blank, on a
@@ -245,6 +249,26 @@ class WithingsEnvironmentDataPlatform {
245
249
  this.missedCycles += 1;
246
250
  this.log.error(`Withings poll failed (missed cycle ${this.missedCycles}): ${err.message}`);
247
251
  this.setFault(true);
252
+
253
+ if (!this.hasNotifiedFailure) {
254
+ this.hasNotifiedFailure = true;
255
+ await this.sendNtfyNotification(err.message);
256
+ }
257
+ }
258
+ }
259
+
260
+ async sendNtfyNotification(errorMessage) {
261
+ const topic = this.config.ntfyTopic;
262
+ if (!topic) return;
263
+
264
+ try {
265
+ await fetch(`https://ntfy.sh/${encodeURIComponent(topic)}`, {
266
+ method: 'POST',
267
+ headers: { Title: 'Homebridge: Getting Withings Environment Data Failed!' },
268
+ body: errorMessage,
269
+ });
270
+ } catch (err) {
271
+ this.log.warn(`Failed to send ntfy notification: ${err.message}`);
248
272
  }
249
273
  }
250
274
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-withings-environment-data",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
4
  "description": "Homebridge plugin exposing ambient CO2/air-quality and room temperature readings from a Withings WS-50 scale as HomeKit sensors",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -9,7 +9,14 @@
9
9
  "config.schema.json"
10
10
  ],
11
11
  "keywords": [
12
- "homebridge-plugin"
12
+ "homebridge-plugin",
13
+ "withings",
14
+ "ws-50",
15
+ "environment-data",
16
+ "temperature",
17
+ "co2",
18
+ "air-quality",
19
+ "homekit"
13
20
  ],
14
21
  "engines": {
15
22
  "homebridge": ">=1.6.0",