homebridge-sensus 1.0.2 → 1.0.4

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessory.d.ts","sourceRoot":"","sources":["../src/accessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAgD,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAc,MAAM,aAAa,CAAC;AAQ7D,qBAAa,yBAAyB;IAYlC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAb5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAGxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiB;IACpD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAE9C,OAAO,CAAC,QAAQ,CAA2B;gBAGxB,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,kBAAkB;IA6DhD;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAwB5B,wDAAwD;IACxD,OAAO,CAAC,qBAAqB;IAY7B,2EAA2E;YAC7D,IAAI;CAoCnB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessory.js","sourceRoot":"","sources":["../src/accessory.ts"],"names":[],"mappings":";;;AAIA,+DAA+D;AAC/D,MAAM,0BAA0B,GAAG,sCAAsC,CAAC,CAAC,cAAc;AACzF,MAAM,oBAAoB,GAAG,sCAAsC,CAAC,CAAO,mBAAmB;AAE9F,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAEzC,MAAa,yBAAyB;IAW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CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EACzC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAC9C,CAAC;QAEF,kCAAkC;QAClC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAE9C,gBAAgB;QAChB,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CACpB,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,IAAI;YAClC,SAAS,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,SAAS,KAAK;YACjD,YAAY,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,SAAS,KAAK;YAClD,WAAW,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,SAAS,KAAK;YACrD,QAAQ,SAAS,EAAE;YACnB,CAAC,QAAQ,CAAC,CAAC,CAAC,oBAAoB,QAAQ,CAAC,KAAK,WAAW,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CACjF,CAAC;IACJ,CAAC;CACF;AAzJD,8DAyJC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;yBAIvB,KAAK,GAAG,KAAG,IAAI;AAAzB,kBAEE"}
package/dist/index.js CHANGED
@@ -2,6 +2,6 @@
2
2
  const platform_1 = require("./platform");
3
3
  const settings_1 = require("./settings");
4
4
  module.exports = (api) => {
5
- api.registerPlatform(settings_1.PLATFORM_NAME, platform_1.SensusAnalyticsPlatform);
5
+ api.registerPlatform(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, platform_1.SensusAnalyticsPlatform);
6
6
  };
7
7
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,yCAAqD;AACrD,yCAAwD;AAExD,iBAAS,CAAC,GAAQ,EAAQ,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,sBAAW,EAAE,wBAAa,EAAE,kCAAuB,CAAC,CAAC;AAC5E,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,iBAAiB,EACjB,cAAc,EACd,OAAO,EACR,MAAM,YAAY,CAAC;AAMpB,qBAAa,uBAAwB,YAAW,qBAAqB;aAQjD,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAT1B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxC,SAAgB,cAAc,EAAE,OAAO,cAAc,CAAC;IAGtD,SAAgB,iBAAiB,EAAE,iBAAiB,EAAE,CAAM;gBAG1C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IAY1B,qEAAqE;IACrE,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAKtD,OAAO,CAAC,eAAe;CAoCxB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;AAUA,yCAAwD;AACxD,2CAAwD;AACxD,2CAAiD;AAEjD,MAAa,uBAAuB;IAOlC,YACkB,GAAW,EACX,MAAsB,EACtB,GAAQ;QAFR,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAgB;QACtB,QAAG,GAAH,GAAG,CAAK;QAN1B,wCA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B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAKD,qBAAa,kBAAkB;IAM3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG;IAVtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAS;gBAGN,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM;IAexB,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAyBzB,SAAS,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;YAoC/B,cAAc;YA8Bd,eAAe;CAmD9B"}
package/dist/sensusApi.js CHANGED
@@ -4,6 +4,8 @@ exports.SensusAnalyticsApi = void 0;
4
4
  const axios_1 = require("axios");
5
5
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
6
6
  const tough_cookie_1 = require("tough-cookie");
7
+ // 1 CCF (hundred cubic feet) = 748.052 gallons
8
+ const CCF_TO_GALLONS = 748.052;
7
9
  class SensusAnalyticsApi {
8
10
  constructor(baseUrl, username, password, accountNumber, meterNumber, log) {
9
11
  this.baseUrl = baseUrl;
@@ -89,16 +91,18 @@ class SensusAnalyticsApi {
89
91
  this.log.warn('Sensus Analytics: unexpected daily data structure');
90
92
  return null;
91
93
  }
94
+ const rawUnit = (device.usageUnit || 'CCF').toUpperCase();
95
+ const toGallons = rawUnit === 'CCF' ? CCF_TO_GALLONS : 1;
92
96
  return {
93
- dailyUsage: parseFloat(device.dailyUsage) || 0,
94
- usageUnit: device.usageUnit || 'CCF',
97
+ dailyUsage: Math.round(((parseFloat(device.dailyUsage) || 0) * toGallons) * 100) / 100,
98
+ usageUnit: 'GAL',
95
99
  meterAddress: device.meterAddress1 || '',
96
100
  lastRead: device.lastRead || '',
97
101
  meterId: String(device.meterId || ''),
98
102
  meterLat: parseFloat(device.meterLat) || 0,
99
103
  meterLong: parseFloat(device.meterLong) || 0,
100
- odometer: parseFloat(device.latestReadUsage) || 0,
101
- billingUsage: parseFloat(device.billingUsage) || 0,
104
+ odometer: Math.round(((parseFloat(device.latestReadUsage) || 0) * toGallons) * 100) / 100,
105
+ billingUsage: Math.round(((parseFloat(device.billingUsage) || 0) * toGallons) * 100) / 100,
102
106
  };
103
107
  }
104
108
  async fetchHourlyData() {
@@ -127,14 +131,15 @@ class SensusAnalyticsApi {
127
131
  return [];
128
132
  }
129
133
  // First element is units row: [usageUnit, rainUnit, tempUnit, altUnit]
130
- const [usageUnit, rainUnit, tempUnit] = usageArray[0];
134
+ const [rawUsageUnit, rainUnit, tempUnit] = usageArray[0];
131
135
  const rows = usageArray.slice(1);
136
+ const toGallons = (rawUsageUnit ?? 'CCF').toUpperCase() === 'CCF' ? CCF_TO_GALLONS : 1;
132
137
  return rows.map((row) => ({
133
138
  timestamp: row[0],
134
- usage: row[1] ?? 0,
139
+ usage: Math.round(((row[1] ?? 0) * toGallons) * 100) / 100,
135
140
  rain: row[2] ?? 0,
136
141
  temp: row[3] ?? 0,
137
- usageUnit: usageUnit ?? 'CCF',
142
+ usageUnit: 'GAL',
138
143
  rainUnit: rainUnit ?? 'INCHES',
139
144
  tempUnit: tempUnit ?? 'FAHRENHEIT',
140
145
  }));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sensusApi.js","sourceRoot":"","sources":["../src/sensusApi.ts"],"names":[],"mappings":";;;AAAA,iCAA6C;AAC7C,qEAAkD;AAClD,+CAAyC;AA8BzC,+CAA+C;AAC/C,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,MAAa,kBAAkB;IAK7B,YACmB,OAAe,EACf,QAAgB,EAChB,QAAgB,EAChB,aAAqB,EACrB,WAAmB,EACnB,GAAW;QALX,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,kBAAa,GAAb,aAAa,CAAQ;QACrB,gBAAW,GAAX,WAAW,CAAQ;QACnB,QAAG,GAAH,GAAG,CAAQ;QARtB,aAAQ,GAAG,KAAK,CAAC;QAUvB,IAAI,CAAC,GAAG,GAAG,IAAI,wBAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAA,iCAAO,EACnB,eAAK,CAAC,MAAM,CAAC;YACX,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YACnC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,eAAe,EAAE,IAAI;YACrB,sDAAsD;YACtD,YAAY,EAAE,CAAC;YACf,OAAO,EAAE,KAAK;SACf,CAAC,CACH,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACxD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACpB,0BAA0B,EAC1B,IAAI,eAAe,CAAC;gBAClB,UAAU,EAAE,IAAI,CAAC,QAAQ;g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AS,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;YACtE,IAAI,EAAG,GAAG,CAAC,CAAC,CAAY,IAAI,CAAC;YAC7B,IAAI,EAAG,GAAG,CAAC,CAAC,CAAY,IAAI,CAAC;YAC7B,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,QAAQ,IAAI,QAAQ;YAC9B,QAAQ,EAAE,QAAQ,IAAI,YAAY;SACnC,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAxKD,gDAwKC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAC/C,eAAO,MAAM,WAAW,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,iBAAiB,CAAC;AAClC,QAAA,WAAW,GAAG,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,26 @@
1
1
  {
2
2
  "name": "homebridge-sensus",
3
- "version": "1.0.2",
3
+ "displayName": "Homebridge Sensus",
4
+ "version": "1.0.4",
4
5
  "description": "Homebridge plugin for Sensus Analytics water meters",
5
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/jmarrmd/homebridge-sensus.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/jmarrmd/homebridge-sensus/issues"
13
+ },
14
+ "homepage": "https://github.com/jmarrmd/homebridge-sensus#readme",
6
15
  "main": "dist/index.js",
16
+ "files": [
17
+ "dist/",
18
+ "config.schema.json"
19
+ ],
7
20
  "scripts": {
8
- "build": "tsc",
9
- "watch": "tsc --watch",
10
- "prepare": "npm run build",
11
- "prepublishOnly": "npm run build"
21
+ "build": "true",
22
+ "compile": "tsc",
23
+ "watch": "tsc --watch"
12
24
  },
13
25
  "keywords": [
14
26
  "homebridge-plugin",
package/src/accessory.ts DELETED
@@ -1,164 +0,0 @@
1
- import { PlatformAccessory, CharacteristicValue, Service, Characteristic } from 'homebridge';
2
- import { SensusAnalyticsPlatform } from './platform';
3
- import { SensusAnalyticsApi, SensusData } from './sensusApi';
4
-
5
- // Eve for HomeKit custom characteristic UUIDs for water meters
6
- const EVE_UUID_WATER_CONSUMPTION = 'E863F10D-079E-48FF-8F27-9C2605A29F52'; // daily usage
7
- const EVE_UUID_TOTAL_WATER = 'E863F10C-079E-48FF-8F27-9C2605A29F52'; // odometer / total
8
-
9
- const DEFAULT_POLL_INTERVAL_MINUTES = 30;
10
-
11
- export class SensusWaterMeterAccessory {
12
- private readonly leakService: Service;
13
- private readonly leakThreshold: number;
14
- private readonly pollIntervalMs: number;
15
-
16
- // Direct references to Eve custom characteristics to avoid UUID lookups on update
17
- private readonly eveConsumptionChar: Characteristic;
18
- private readonly eveTotalChar: Characteristic;
19
-
20
- private lastData: SensusData | null = null;
21
-
22
- constructor(
23
- private readonly platform: SensusAnalyticsPlatform,
24
- private readonly accessory: PlatformAccessory,
25
- private readonly apiClient: SensusAnalyticsApi,
26
- ) {
27
- const { hap } = platform.api;
28
- const { Service: Svc, Characteristic: Char } = platform;
29
-
30
- this.leakThreshold = (platform.config.leakThreshold as number | undefined) ?? 150;
31
- this.pollIntervalMs =
32
- ((platform.config.pollInterval as number | undefined) ?? DEFAULT_POLL_INTERVAL_MINUTES) *
33
- 60 *
34
- 1000;
35
-
36
- // ── Accessory Information ─────────────────────────────────────────────
37
- this.accessory
38
- .getService(Svc.AccessoryInformation)!
39
- .setCharacteristic(Char.Manufacturer, 'Sensus')
40
- .setCharacteristic(Char.Model, 'Smart Water Meter')
41
- .setCharacteristic(
42
- Char.SerialNumber,
43
- (accessory.context.meterNumber as string | undefined) ?? 'Unknown',
44
- );
45
-
46
- // ── Leak Sensor (primary HomeKit service) ─────────────────────────────
47
- // Visible in Apple Home app as a leak sensor tile with alert notifications
48
- this.leakService =
49
- this.accessory.getService(Svc.LeakSensor) ?? this.accessory.addService(Svc.LeakSensor);
50
-
51
- this.leakService.setCharacteristic(Char.Name, accessory.displayName);
52
-
53
- this.leakService
54
- .getCharacteristic(Char.LeakDetected)
55
- .onGet(this.handleLeakDetectedGet.bind(this));
56
-
57
- this.leakService
58
- .getCharacteristic(Char.StatusActive)
59
- .onGet(() => true);
60
-
61
- // ── Eve Custom Characteristics ────────────────────────────────────────
62
- // These are shown in the Eve for HomeKit app as consumption graphs.
63
- // They are attached to the LeakSensor service so they share one accessory tile.
64
-
65
- this.eveConsumptionChar = this.addEveCharacteristic(
66
- 'Water Consumption',
67
- EVE_UUID_WATER_CONSUMPTION,
68
- hap.Formats.FLOAT,
69
- [hap.Perms.NOTIFY, hap.Perms.PAIRED_READ],
70
- 0, 1_000_000, 0.001,
71
- );
72
-
73
- this.eveTotalChar = this.addEveCharacteristic(
74
- 'Total Water Consumption',
75
- EVE_UUID_TOTAL_WATER,
76
- hap.Formats.FLOAT,
77
- [hap.Perms.NOTIFY, hap.Perms.PAIRED_READ],
78
- 0, 1_000_000_000, 0.001,
79
- );
80
-
81
- // ── Start polling ─────────────────────────────────────────────────────
82
- this.poll();
83
- setInterval(() => this.poll(), this.pollIntervalMs);
84
- }
85
-
86
- /**
87
- * Creates and registers a custom Characteristic on the LeakSensor service.
88
- * If the characteristic already exists (restored from cache), it is returned as-is.
89
- */
90
- private addEveCharacteristic(
91
- displayName: string,
92
- uuid: string,
93
- format: string,
94
- perms: string[],
95
- minValue: number,
96
- maxValue: number,
97
- minStep: number,
98
- ): Characteristic {
99
- const { hap } = this.platform.api;
100
-
101
- const existing = this.leakService.characteristics.find((c) => c.UUID === uuid);
102
- if (existing) {
103
- return existing;
104
- }
105
-
106
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
- const props: any = { format, unit: 'gal', minValue, maxValue, minStep, perms };
108
- const char = new hap.Characteristic(displayName, uuid, props);
109
- char.setValue(0);
110
- this.leakService.addCharacteristic(char);
111
- return char;
112
- }
113
-
114
- /** Called by HomeKit to read the current leak state. */
115
- private handleLeakDetectedGet(): CharacteristicValue {
116
- const { LEAK_DETECTED, LEAK_NOT_DETECTED } = this.platform.Characteristic.LeakDetected;
117
-
118
- if (!this.lastData) {
119
- return LEAK_NOT_DETECTED;
120
- }
121
-
122
- return this.lastData.daily.dailyUsage > this.leakThreshold
123
- ? LEAK_DETECTED
124
- : LEAK_NOT_DETECTED;
125
- }
126
-
127
- /** Fetch latest data from Sensus Analytics and push updates to HomeKit. */
128
- private async poll(): Promise<void> {
129
- this.platform.log.debug('Sensus Analytics: polling for new data...');
130
-
131
- const data = await this.apiClient.fetchData();
132
- if (!data) {
133
- this.platform.log.warn('Sensus Analytics: no data returned, will retry next interval');
134
- return;
135
- }
136
-
137
- this.lastData = data;
138
- const { daily, hourly } = data;
139
- const { LEAK_DETECTED, LEAK_NOT_DETECTED } = this.platform.Characteristic.LeakDetected;
140
-
141
- const isLeaking = daily.dailyUsage > this.leakThreshold;
142
-
143
- // Push updates to HomeKit
144
- this.leakService.updateCharacteristic(
145
- this.platform.Characteristic.LeakDetected,
146
- isLeaking ? LEAK_DETECTED : LEAK_NOT_DETECTED,
147
- );
148
-
149
- // Eve consumption characteristics
150
- this.eveConsumptionChar.updateValue(daily.dailyUsage);
151
- this.eveTotalChar.updateValue(daily.odometer);
152
-
153
- // Log a summary
154
- const lastHour = hourly.at(-1);
155
- this.platform.log.info(
156
- `[${this.accessory.displayName}] ` +
157
- `daily=${daily.dailyUsage} ${daily.usageUnit} | ` +
158
- `odometer=${daily.odometer} ${daily.usageUnit} | ` +
159
- `billing=${daily.billingUsage} ${daily.usageUnit} | ` +
160
- `leak=${isLeaking}` +
161
- (lastHour ? ` | lastHourUsage=${lastHour.usage} | temp=${lastHour.temp}°F` : ''),
162
- );
163
- }
164
- }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- import { API } from 'homebridge';
2
- import { SensusAnalyticsPlatform } from './platform';
3
- import { PLATFORM_NAME } from './settings';
4
-
5
- export = (api: API): void => {
6
- api.registerPlatform(PLATFORM_NAME, SensusAnalyticsPlatform);
7
- };
package/src/platform.ts DELETED
@@ -1,79 +0,0 @@
1
- import {
2
- API,
3
- Characteristic,
4
- DynamicPlatformPlugin,
5
- Logger,
6
- PlatformAccessory,
7
- PlatformConfig,
8
- Service,
9
- } from 'homebridge';
10
-
11
- import { PLATFORM_NAME, PLUGIN_NAME } from './settings';
12
- import { SensusWaterMeterAccessory } from './accessory';
13
- import { SensusAnalyticsApi } from './sensusApi';
14
-
15
- export class SensusAnalyticsPlatform implements DynamicPlatformPlugin {
16
- public readonly Service: typeof Service;
17
- public readonly Characteristic: typeof Characteristic;
18
-
19
- // Restored cached accessories from disk
20
- public readonly cachedAccessories: PlatformAccessory[] = [];
21
-
22
- constructor(
23
- public readonly log: Logger,
24
- public readonly config: PlatformConfig,
25
- public readonly api: API,
26
- ) {
27
- this.Service = this.api.hap.Service;
28
- this.Characteristic = this.api.hap.Characteristic;
29
-
30
- this.log.debug('Sensus Analytics platform initialising');
31
-
32
- this.api.on('didFinishLaunching', () => {
33
- this.discoverDevices();
34
- });
35
- }
36
-
37
- /** Called by Homebridge to restore cached accessories on startup. */
38
- configureAccessory(accessory: PlatformAccessory): void {
39
- this.log.info('Restoring cached accessory:', accessory.displayName);
40
- this.cachedAccessories.push(accessory);
41
- }
42
-
43
- private discoverDevices(): void {
44
- const { baseUrl, username, password, accountNumber, meterNumber } = this.config;
45
-
46
- if (!baseUrl || !username || !password || !accountNumber || !meterNumber) {
47
- this.log.error(
48
- 'Sensus Analytics: missing required config fields ' +
49
- '(baseUrl, username, password, accountNumber, meterNumber)',
50
- );
51
- return;
52
- }
53
-
54
- const apiClient = new SensusAnalyticsApi(
55
- baseUrl,
56
- username,
57
- password,
58
- accountNumber,
59
- meterNumber,
60
- this.log,
61
- );
62
-
63
- const displayName = (this.config.name as string | undefined) || 'Sensus Water Meter';
64
- const uuid = this.api.hap.uuid.generate(`sensus-${meterNumber}`);
65
-
66
- const existing = this.cachedAccessories.find((a) => a.UUID === uuid);
67
-
68
- if (existing) {
69
- this.log.info('Restoring water meter accessory:', existing.displayName);
70
- new SensusWaterMeterAccessory(this, existing, apiClient);
71
- } else {
72
- this.log.info('Adding new water meter accessory:', displayName);
73
- const accessory = new this.api.platformAccessory(displayName, uuid);
74
- accessory.context.meterNumber = meterNumber;
75
- new SensusWaterMeterAccessory(this, accessory, apiClient);
76
- this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
77
- }
78
- }
79
- }
package/src/sensusApi.ts DELETED
@@ -1,197 +0,0 @@
1
- import axios, { AxiosInstance } from 'axios';
2
- import { wrapper } from 'axios-cookiejar-support';
3
- import { CookieJar } from 'tough-cookie';
4
- import { Logger } from 'homebridge';
5
-
6
- export interface DailyData {
7
- dailyUsage: number;
8
- usageUnit: string;
9
- meterAddress: string;
10
- lastRead: string;
11
- meterId: string;
12
- meterLat: number;
13
- meterLong: number;
14
- odometer: number;
15
- billingUsage: number;
16
- }
17
-
18
- export interface HourlyEntry {
19
- timestamp: number;
20
- usage: number;
21
- rain: number;
22
- temp: number;
23
- usageUnit: string;
24
- rainUnit: string;
25
- tempUnit: string;
26
- }
27
-
28
- export interface SensusData {
29
- daily: DailyData;
30
- hourly: HourlyEntry[];
31
- }
32
-
33
- export class SensusAnalyticsApi {
34
- private readonly client: AxiosInstance;
35
- private readonly jar: CookieJar;
36
- private loggedIn = false;
37
-
38
- constructor(
39
- private readonly baseUrl: string,
40
- private readonly username: string,
41
- private readonly password: string,
42
- private readonly accountNumber: string,
43
- private readonly meterNumber: string,
44
- private readonly log: Logger,
45
- ) {
46
- this.jar = new CookieJar();
47
- this.client = wrapper(
48
- axios.create({
49
- baseURL: baseUrl.replace(/\/$/, ''),
50
- jar: this.jar,
51
- withCredentials: true,
52
- // Follow redirects but treat 302 as success for login
53
- maxRedirects: 5,
54
- timeout: 15000,
55
- }),
56
- );
57
- }
58
-
59
- async login(): Promise<boolean> {
60
- try {
61
- this.log.debug('Sensus Analytics: attempting login...');
62
- await this.client.post(
63
- '/j_spring_security_check',
64
- new URLSearchParams({
65
- j_username: this.username,
66
- j_password: this.password,
67
- }).toString(),
68
- {
69
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
70
- // A 302 redirect means login was processed; axios follows it automatically
71
- validateStatus: (s) => s < 400,
72
- },
73
- );
74
- this.loggedIn = true;
75
- this.log.debug('Sensus Analytics: login successful');
76
- return true;
77
- } catch (err) {
78
- this.loggedIn = false;
79
- this.log.error('Sensus Analytics: login failed:', (err as Error).message);
80
- return false;
81
- }
82
- }
83
-
84
- async fetchData(): Promise<SensusData | null> {
85
- if (!this.loggedIn) {
86
- const ok = await this.login();
87
- if (!ok) {
88
- return null;
89
- }
90
- }
91
-
92
- try {
93
- const [daily, hourly] = await Promise.all([
94
- this.fetchDailyData(),
95
- this.fetchHourlyData(),
96
- ]);
97
-
98
- if (!daily) {
99
- // Session may have expired — clear and retry once
100
- this.loggedIn = false;
101
- const ok = await this.login();
102
- if (!ok) {
103
- return null;
104
- }
105
- const retried = await this.fetchDailyData();
106
- if (!retried) {
107
- return null;
108
- }
109
- return { daily: retried, hourly: hourly ?? [] };
110
- }
111
-
112
- return { daily, hourly: hourly ?? [] };
113
- } catch (err) {
114
- this.loggedIn = false;
115
- this.log.error('Sensus Analytics: error fetching data:', (err as Error).message);
116
- return null;
117
- }
118
- }
119
-
120
- private async fetchDailyData(): Promise<DailyData | null> {
121
- const response = await this.client.post('/water/widget/byPage', {
122
- group: 'meters',
123
- accountNumber: this.accountNumber,
124
- deviceId: this.meterNumber,
125
- });
126
-
127
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
- const device = (response.data as any)?.widgetList?.[0]?.data?.devices?.[0];
129
- if (!device) {
130
- this.log.warn('Sensus Analytics: unexpected daily data structure');
131
- return null;
132
- }
133
-
134
- return {
135
- dailyUsage: parseFloat(device.dailyUsage) || 0,
136
- usageUnit: device.usageUnit || 'CCF',
137
- meterAddress: device.meterAddress1 || '',
138
- lastRead: device.lastRead || '',
139
- meterId: String(device.meterId || ''),
140
- meterLat: parseFloat(device.meterLat) || 0,
141
- meterLong: parseFloat(device.meterLong) || 0,
142
- odometer: parseFloat(device.latestReadUsage) || 0,
143
- billingUsage: parseFloat(device.billingUsage) || 0,
144
- };
145
- }
146
-
147
- private async fetchHourlyData(): Promise<HourlyEntry[] | null> {
148
- // Fetch the previous day's data (Sensus updates at midnight)
149
- const yesterday = new Date();
150
- yesterday.setDate(yesterday.getDate() - 1);
151
- const startOfDay = new Date(
152
- yesterday.getFullYear(),
153
- yesterday.getMonth(),
154
- yesterday.getDate(),
155
- );
156
- const endOfDay = new Date(startOfDay.getTime() + 86_400_000 - 1);
157
-
158
- const response = await this.client.get(
159
- `/water/usage/${this.accountNumber}/${this.meterNumber}`,
160
- {
161
- params: {
162
- start: startOfDay.getTime(),
163
- end: endOfDay.getTime(),
164
- zoom: 'day',
165
- page: 'null',
166
- weather: '1',
167
- },
168
- },
169
- );
170
-
171
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
172
- const data = response.data as any;
173
- if (!data?.operationSuccess) {
174
- this.log.warn('Sensus Analytics: hourly data fetch unsuccessful');
175
- return null;
176
- }
177
-
178
- const usageArray: unknown[][] = data?.data?.usage;
179
- if (!Array.isArray(usageArray) || usageArray.length < 2) {
180
- return [];
181
- }
182
-
183
- // First element is units row: [usageUnit, rainUnit, tempUnit, altUnit]
184
- const [usageUnit, rainUnit, tempUnit] = usageArray[0] as string[];
185
- const rows = usageArray.slice(1);
186
-
187
- return rows.map((row) => ({
188
- timestamp: row[0] as number,
189
- usage: (row[1] as number) ?? 0,
190
- rain: (row[2] as number) ?? 0,
191
- temp: (row[3] as number) ?? 0,
192
- usageUnit: usageUnit ?? 'CCF',
193
- rainUnit: rainUnit ?? 'INCHES',
194
- tempUnit: tempUnit ?? 'FAHRENHEIT',
195
- }));
196
- }
197
- }
package/src/settings.ts DELETED
@@ -1,2 +0,0 @@
1
- export const PLATFORM_NAME = 'SensusAnalytics';
2
- export const PLUGIN_NAME = 'homebridge-sensus';
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": ["ES2020"],
6
- "strict": true,
7
- "noImplicitAny": true,
8
- "strictNullChecks": true,
9
- "moduleResolution": "node",
10
- "experimentalDecorators": true,
11
- "skipLibCheck": true,
12
- "outDir": "dist",
13
- "declaration": true,
14
- "declarationMap": true,
15
- "sourceMap": true
16
- },
17
- "include": ["src"]
18
- }