homebridge-brother-printer 0.3.0 → 0.3.1
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 +16 -0
- package/README.md +8 -3
- package/lib/accessory.js +45 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.1 - 2026-11-07
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Inkjets: the battery is now named Ink instead of Toner, unless you renamed it in Home.
|
|
7
|
+
- Printers that report no levels no longer get a battery added and removed again on every
|
|
8
|
+
restart.
|
|
9
|
+
- Settings that aren't numbers (for example in a hand-edited `config.json`) fall back to
|
|
10
|
+
their defaults. Before, a non-numeric low toner threshold meant the low alert never fired.
|
|
11
|
+
- Numeric settings are kept within the ranges the settings screen allows.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- README: notes that renaming a printer creates a new accessory, and how long going
|
|
15
|
+
offline takes before the printer has answered.
|
|
16
|
+
- Tests for the battery, settings, No Response and the Problem sensor; tests and lint run
|
|
17
|
+
on GitHub Actions for every push and pull request.
|
|
18
|
+
|
|
3
19
|
## 0.3.0 - 2026-11-07
|
|
4
20
|
|
|
5
21
|
### Added
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Each printer gets these sensors:
|
|
|
21
21
|
native low-battery alert at or below your threshold. On color printers it shows the
|
|
22
22
|
lowest color, so the alert fires when any color runs low.
|
|
23
23
|
- **Toner Low** (optional contact sensor): Opens when the toner or ink is low, so Home
|
|
24
|
-
notifies
|
|
24
|
+
notifies it by name instead of "battery is low".
|
|
25
25
|
- **Toner / ink tiles** (optional humidity sensors): the level as a number on its own tile,
|
|
26
26
|
one per color on color printers.
|
|
27
27
|
|
|
@@ -76,7 +76,7 @@ Set it up in the plugin's settings screen, or in `config.json`:
|
|
|
76
76
|
|
|
77
77
|
| Option | Default | Description |
|
|
78
78
|
|---|---|---|
|
|
79
|
-
| `name` | `Printer` | Accessory name. Must be unique per printer. |
|
|
79
|
+
| `name` | `Printer` | Accessory name. Must be unique per printer. Changing it later creates a new accessory: its room, automations and notification settings in Home start over. |
|
|
80
80
|
| `host` | | Printer IP address or hostname. Printers without one are ignored. |
|
|
81
81
|
| `community` | `public` | SNMP community string. |
|
|
82
82
|
| `port` | `161` | SNMP port. |
|
|
@@ -99,7 +99,8 @@ words them its own way:
|
|
|
99
99
|
- The printing sensor reads **Detected** / **Not Detected**.
|
|
100
100
|
- Low toner or ink is announced as **"battery is low"**. For a clearer message, turn on
|
|
101
101
|
`lowTonerSensor`: its contact sensor opens at the same point and Home notifies it by
|
|
102
|
-
name
|
|
102
|
+
name, as it does for any contact sensor that opens. Turn on its notifications in the
|
|
103
|
+
Home app.
|
|
103
104
|
- Home shows only one battery per accessory. With `showDrum` on, it may show the drum
|
|
104
105
|
instead of the toner, which is why the drum is off by default. It's still read, and the
|
|
105
106
|
plugin logs a warning when it nears end of life. Apps like Eve show both.
|
|
@@ -125,6 +126,10 @@ defaults that's about 3.5 minutes; `pollInterval: 30` with `offlineAfter: 1` bri
|
|
|
125
126
|
about 40 s. With `offlineAfter: 1`, a single lost packet can make it flash No Response for
|
|
126
127
|
one poll.
|
|
127
128
|
|
|
129
|
+
If the printer hasn't answered since Homebridge started and `snmpVersion` is `auto`, each
|
|
130
|
+
poll tries v2c and then v1, so the timeout counts twice (about 20 s per poll). Once it has
|
|
131
|
+
answered, the version that worked is used.
|
|
132
|
+
|
|
128
133
|
Brother lasers normally still answer SNMP in Sleep and Deep Sleep.
|
|
129
134
|
|
|
130
135
|
## Checking what your printer reports
|
package/lib/accessory.js
CHANGED
|
@@ -26,6 +26,11 @@ function pagesCharacteristic(hap) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const clamp = (v) => Math.max(0, Math.min(100, Math.round(v)));
|
|
29
|
+
/** A whole number setting; anything that isn't a number gets the default */
|
|
30
|
+
const setting = (v, def, min, max) => {
|
|
31
|
+
const n = typeof v === 'string' && v.trim() === '' ? NaN : Number(v ?? def);
|
|
32
|
+
return Number.isFinite(n) ? Math.max(min, Math.min(max, Math.round(n))) : def;
|
|
33
|
+
};
|
|
29
34
|
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
30
35
|
const TILE_SUBTYPE = { black: 'tonerTile', cyan: 'tile-cyan', magenta: 'tile-magenta', yellow: 'tile-yellow' };
|
|
31
36
|
const FAULT_NAMES = {
|
|
@@ -49,21 +54,21 @@ class PrinterAccessory {
|
|
|
49
54
|
|
|
50
55
|
this.options = {
|
|
51
56
|
host: config.host,
|
|
52
|
-
port:
|
|
57
|
+
port: setting(config.port, 161, 1, 65535),
|
|
53
58
|
community: config.community || 'public',
|
|
54
59
|
timeout: 5000,
|
|
55
60
|
retries: 1,
|
|
56
61
|
version: ['1', '2c'].includes(String(config.snmpVersion)) ? String(config.snmpVersion) : 'auto',
|
|
57
62
|
state: {},
|
|
58
63
|
};
|
|
59
|
-
this.interval =
|
|
60
|
-
this.lowToner =
|
|
61
|
-
this.lowDrum =
|
|
64
|
+
this.interval = setting(config.pollInterval, 60, 10, 3600) * 1000;
|
|
65
|
+
this.lowToner = setting(config.lowTonerThreshold, 10, 0, 100);
|
|
66
|
+
this.lowDrum = setting(config.lowDrumThreshold, 10, 0, 100);
|
|
62
67
|
this.showDrum = config.showDrum === true;
|
|
63
68
|
this.tonerTile = config.tonerTile === true;
|
|
64
69
|
this.faultSensor = config.faultSensor !== false;
|
|
65
70
|
this.lowTonerSensor = config.lowTonerSensor === true;
|
|
66
|
-
this.offlineAfter =
|
|
71
|
+
this.offlineAfter = setting(config.offlineAfter, 3, 1, 20);
|
|
67
72
|
this.debug = config.debug === true;
|
|
68
73
|
|
|
69
74
|
this.failures = 0;
|
|
@@ -105,9 +110,15 @@ class PrinterAccessory {
|
|
|
105
110
|
if (!this.occupancy.testCharacteristic(Pages)) { this.occupancy.addCharacteristic(Pages); }
|
|
106
111
|
this.pages = this.occupancy.getCharacteristic(Pages);
|
|
107
112
|
|
|
108
|
-
// Toner and drum as batteries so Home raises native "low" alerts
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
// Toner and drum as batteries so Home raises native "low" alerts. A printer
|
|
114
|
+
// that reported no levels last time gets none until it reports some.
|
|
115
|
+
if (acc.context.noLevels) {
|
|
116
|
+
this.removeSubtype(Service.Battery, 'toner');
|
|
117
|
+
this.toner = null;
|
|
118
|
+
} else {
|
|
119
|
+
this.toner = this.battery('toner', `${this.name} ${acc.context.kind || 'Toner'}`);
|
|
120
|
+
this.occupancy.addLinkedService(this.toner);
|
|
121
|
+
}
|
|
111
122
|
|
|
112
123
|
if (this.showDrum) {
|
|
113
124
|
this.drum = this.battery('drum', `${this.name} Drum`);
|
|
@@ -369,6 +380,7 @@ class PrinterAccessory {
|
|
|
369
380
|
|
|
370
381
|
if (!d.supplies.length) {
|
|
371
382
|
// Some models (e.g. ink tank printers) report no levels at all
|
|
383
|
+
this.remember({ noLevels: true });
|
|
372
384
|
if (this.toner) {
|
|
373
385
|
this.log.info(`[${this.name}] This printer doesn't report ${kind.toLowerCase()} levels; `
|
|
374
386
|
+ 'leaving out the battery.');
|
|
@@ -385,6 +397,8 @@ class PrinterAccessory {
|
|
|
385
397
|
this.guard(this.toner.getCharacteristic(C.BatteryLevel));
|
|
386
398
|
this.guard(this.toner.getCharacteristic(C.StatusLowBattery));
|
|
387
399
|
}
|
|
400
|
+
this.renameBattery(kind);
|
|
401
|
+
this.remember({ noLevels: false, kind });
|
|
388
402
|
|
|
389
403
|
const flagged = d.errors.includes('lowToner') || d.errors.includes('noToner');
|
|
390
404
|
const isLow = (s) => s.level <= this.lowToner || (s.fine !== null && s.fine <= this.lowToner);
|
|
@@ -448,6 +462,29 @@ class PrinterAccessory {
|
|
|
448
462
|
this.last.warned[key] = condition;
|
|
449
463
|
}
|
|
450
464
|
|
|
465
|
+
/**
|
|
466
|
+
* The battery is made before the first poll says toner or ink, so on an
|
|
467
|
+
* inkjet it starts as "Toner". Rename it, unless the user renamed it in Home.
|
|
468
|
+
*/
|
|
469
|
+
renameBattery(kind) {
|
|
470
|
+
const C = this.hap.Characteristic;
|
|
471
|
+
const was = this.accessory.context.kind || 'Toner';
|
|
472
|
+
if (was === kind) { return; }
|
|
473
|
+
const name = `${this.name} ${kind}`;
|
|
474
|
+
this.toner.setCharacteristic(C.Name, name);
|
|
475
|
+
const current = this.toner.getCharacteristic(C.ConfiguredName).value;
|
|
476
|
+
if (!current || current === `${this.name} ${was}`) { this.toner.setCharacteristic(C.ConfiguredName, name); }
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Store values in the accessory cache, saving only when something changed */
|
|
480
|
+
remember(values) {
|
|
481
|
+
const ctx = this.accessory.context;
|
|
482
|
+
const changed = Object.entries(values).filter(([k, v]) => ctx[k] !== v);
|
|
483
|
+
if (!changed.length) { return; }
|
|
484
|
+
for (const [k, v] of changed) { ctx[k] = v; }
|
|
485
|
+
this.api.updatePlatformAccessories([this.accessory]);
|
|
486
|
+
}
|
|
487
|
+
|
|
451
488
|
setBattery(svc, level, threshold) {
|
|
452
489
|
const C = this.hap.Characteristic;
|
|
453
490
|
svc.updateCharacteristic(C.BatteryLevel, level);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-brother-printer",
|
|
3
3
|
"displayName": "Brother Printer",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "Brother laser and inkjet printers in HomeKit: printing state, problem alerts and toner or ink levels, read locally over SNMP.",
|
|
6
6
|
"author": "Manuel Zamfir",
|
|
7
7
|
"license": "MIT",
|