@khalido/home 0.2.0 → 0.2.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/dist/connector.d.ts +2 -0
  3. package/dist/connector.js +3 -0
  4. package/dist/connectors/amber/client.d.ts +1 -1
  5. package/dist/connectors/amber/client.js +1 -1
  6. package/dist/connectors/amber/index.js +2 -2
  7. package/dist/connectors/enphase/client.d.ts +1 -1
  8. package/dist/connectors/enphase/client.js +1 -1
  9. package/dist/connectors/enphase/index.js +2 -1
  10. package/dist/connectors/hue/events.d.ts +0 -2
  11. package/dist/connectors/hue/events.js +1 -2
  12. package/dist/connectors/hue/index.js +2 -2
  13. package/dist/connectors/printers/client.d.ts +41 -6
  14. package/dist/connectors/printers/client.js +81 -8
  15. package/dist/connectors/printers/codec.d.ts +17 -3
  16. package/dist/connectors/printers/codec.js +32 -8
  17. package/dist/connectors/printers/index.d.ts +2 -0
  18. package/dist/connectors/printers/index.js +4 -0
  19. package/dist/connectors/printers/raster.d.ts +30 -0
  20. package/dist/connectors/printers/raster.js +175 -0
  21. package/dist/connectors/printers/state.d.ts +2 -0
  22. package/dist/connectors/spotify/changes.d.ts +1 -1
  23. package/dist/connectors/spotify/changes.js +1 -1
  24. package/dist/connectors/spotify/index.js +12 -1
  25. package/dist/connectors/up/client.d.ts +1 -1
  26. package/dist/connectors/up/client.js +1 -1
  27. package/dist/connectors/up/index.js +2 -2
  28. package/dist/connectors/weather/google.js +2 -2
  29. package/docs/cli.md +2 -0
  30. package/docs/decisions.md +7 -0
  31. package/docs/ideas.md +2 -0
  32. package/package.json +1 -1
  33. package/skills/draw-home/README.md +2 -0
  34. package/skills/use-home/SKILL.md +1 -1
  35. package/src/cli/enphase.ts +31 -5
  36. package/src/cli/main.ts +8 -3
  37. package/src/cli/printers.ts +254 -3
  38. package/src/connector.ts +5 -0
  39. package/src/connectors/amber/README.md +1 -1
  40. package/src/connectors/amber/client.ts +1 -1
  41. package/src/connectors/amber/index.ts +2 -2
  42. package/src/connectors/enphase/README.md +3 -1
  43. package/src/connectors/enphase/client.ts +1 -1
  44. package/src/connectors/enphase/index.ts +2 -1
  45. package/src/connectors/hue/events.ts +1 -4
  46. package/src/connectors/hue/index.ts +2 -2
  47. package/src/connectors/printers/README.md +9 -4
  48. package/src/connectors/printers/client.ts +186 -12
  49. package/src/connectors/printers/codec.ts +44 -10
  50. package/src/connectors/printers/index.ts +17 -0
  51. package/src/connectors/printers/raster.ts +215 -0
  52. package/src/connectors/printers/state.ts +2 -0
  53. package/src/connectors/spotify/README.md +3 -1
  54. package/src/connectors/spotify/changes.ts +1 -1
  55. package/src/connectors/spotify/index.ts +12 -1
  56. package/src/connectors/up/README.md +1 -1
  57. package/src/connectors/up/client.ts +1 -1
  58. package/src/connectors/up/index.ts +2 -2
  59. package/src/connectors/weather/google.ts +6 -2
@@ -29,8 +29,14 @@ export const TAG = {
29
29
  mimeMediaType: 0x49,
30
30
  } as const;
31
31
 
32
- /** The operation ids this package sends. Identify-Printer (0x003C) and Print-Job (0x0002) are the writes that come later. */
33
- export const OPERATION = { getPrinterAttributes: 0x000b } as const;
32
+ /** The operation ids this package sends (RFC 8011; Identify-Printer from PWG 5100.13). */
33
+ export const OPERATION = {
34
+ printJob: 0x0002,
35
+ validateJob: 0x0004,
36
+ cancelJob: 0x0008,
37
+ getPrinterAttributes: 0x000b,
38
+ identifyPrinter: 0x003c,
39
+ } as const;
34
40
 
35
41
  const STRING_TAGS: ReadonlySet<number> = new Set([
36
42
  TAG.textWithoutLanguage,
@@ -138,19 +144,30 @@ export function encodeMessage(m: IppMessage): Uint8Array<ArrayBuffer> {
138
144
  });
139
145
  }
140
146
  out.push(TAG.end);
141
- return Uint8Array.from([...out, ...(m.data ?? [])]);
147
+ const bytes = new Uint8Array(out.length + (m.data?.length ?? 0));
148
+ bytes.set(out);
149
+ if (m.data) bytes.set(m.data, out.length);
150
+ return bytes;
142
151
  }
143
152
 
144
- /** The Get-Printer-Attributes request: IPP 2.0, utf-8, English, the printer's `ipp://` URI, and the attributes wanted. */
145
- export function getPrinterAttributesRequest(
153
+ /**
154
+ * A request to one printer: IPP 2.0, utf-8, English, the printer's `ipp://` URI, then `attributes` in the operation
155
+ * group, `job` (when given) in a job group, and `data` (a document) after the end tag.
156
+ */
157
+ export function operationRequest(
158
+ code: number,
146
159
  printerUri: string,
147
- requested: string[],
148
- requestId = 1,
160
+ options: {
161
+ attributes?: IppAttribute[];
162
+ job?: IppAttribute[];
163
+ data?: Uint8Array;
164
+ requestId?: number;
165
+ } = {},
149
166
  ): Uint8Array<ArrayBuffer> {
150
167
  return encodeMessage({
151
168
  version: [2, 0],
152
- code: OPERATION.getPrinterAttributes,
153
- requestId,
169
+ code,
170
+ requestId: options.requestId ?? 1,
154
171
  groups: [
155
172
  {
156
173
  tag: TAG.operation,
@@ -162,13 +179,30 @@ export function getPrinterAttributesRequest(
162
179
  values: ["en"],
163
180
  },
164
181
  { name: "printer-uri", tag: TAG.uri, values: [printerUri] },
165
- { name: "requested-attributes", tag: TAG.keyword, values: requested },
182
+ ...(options.attributes ?? []),
166
183
  ],
167
184
  },
185
+ ...(options.job?.length
186
+ ? [{ tag: TAG.job, attributes: options.job }]
187
+ : []),
168
188
  ],
189
+ data: options.data,
169
190
  });
170
191
  }
171
192
 
193
+ /** The Get-Printer-Attributes request: the attributes wanted. */
194
+ export const getPrinterAttributesRequest = (
195
+ printerUri: string,
196
+ requested: string[],
197
+ requestId = 1,
198
+ ) =>
199
+ operationRequest(OPERATION.getPrinterAttributes, printerUri, {
200
+ requestId,
201
+ attributes: [
202
+ { name: "requested-attributes", tag: TAG.keyword, values: requested },
203
+ ],
204
+ });
205
+
172
206
  const fail = (why: string): never => {
173
207
  throw new Error(`ipp: ${why}`);
174
208
  };
@@ -39,6 +39,21 @@ export {
39
39
  type PrinterStatus,
40
40
  printerText,
41
41
  } from "./state.ts";
42
+ export {
43
+ cancelJob,
44
+ identifyPrinter,
45
+ type PrintedJob,
46
+ type PrinterAddress,
47
+ type PrintJob,
48
+ printJob,
49
+ validateJob,
50
+ } from "./client.ts";
51
+ export {
52
+ type GreyPage,
53
+ mediaPixels,
54
+ pwgRaster,
55
+ type RasterMedia,
56
+ } from "./raster.ts";
42
57
 
43
58
  /** One printer in a home config. Everything the printer reports about itself (model, markers, state) comes live; `host` and `port` are only where it last answered. */
44
59
  export const configSchema = z.looseObject({
@@ -184,6 +199,8 @@ export function printers(
184
199
  name: t.name,
185
200
  model: good.model ?? t.foundModel,
186
201
  host: t.host,
202
+ port: t.port,
203
+ rp: t.rp,
187
204
  room: t.room,
188
205
  ...(offline ? { state: "offline" as const } : {}),
189
206
  ipps: t.ipps,
@@ -0,0 +1,215 @@
1
+ // PWG Raster (PWG 5102.4), 8-bit grey only: what an AirPrint printer that lists `image/pwg-raster` takes when it lists no
2
+ // PDF. A file is "RaS2", then per page a 1796-byte big-endian header and the page's pixels, compressed line by line:
3
+ // a line-repeat byte (the line appears n + 1 times), then runs: 0 to 127 is one pixel repeated n + 1 times, 129 to 255 is
4
+ // 257 − n pixels as they are. Checked against a page macOS's own filters made for a Brother (test/fixtures/printers).
5
+
6
+ /** One page: `pixels` is `width × height` bytes, row by row from the top, 0 black to 255 white. */
7
+ export type GreyPage = {
8
+ width: number;
9
+ height: number;
10
+ pixels: Uint8Array;
11
+ };
12
+
13
+ /** What every page is printed as: the printer's resolution and the PWG media name and size it lists. */
14
+ export type RasterMedia = {
15
+ /** PWG self-describing name, as the printer lists it in `media-supported`: `iso_a4_210x297mm`. */
16
+ name: string;
17
+ /** dots per inch, one of the printer's `pwg-raster-document-resolution-supported`. */
18
+ dpi: number;
19
+ };
20
+
21
+ const HEADER = 1796;
22
+ const SGRAY = 18; // cupsColorSpace for sgray (PWG 5102.4 table 9)
23
+ const WHITE = 0xffffff; // AlternatePrimary: the white point, as PWG 5102.4 recommends
24
+
25
+ /** A PWG media name's size in inches: `iso_a4_210x297mm` is 8.27 × 11.69. */
26
+ function mediaInches(name: string): { width: number; height: number } {
27
+ const m = /_(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)(mm|in)$/.exec(name);
28
+ if (!m) throw new RangeError(`not a PWG media size: ${name}`);
29
+ const per = m[3] === "mm" ? 1 / 25.4 : 1;
30
+ return { width: Number(m[1]) * per, height: Number(m[2]) * per };
31
+ }
32
+
33
+ /** The pixels a page of this media is at its resolution, rounded down as macOS's filters do: A4 at 600 dpi is 4960 × 7015. */
34
+ export function mediaPixels(media: RasterMedia): {
35
+ width: number;
36
+ height: number;
37
+ } {
38
+ const i = mediaInches(media.name);
39
+ return {
40
+ width: Math.floor(i.width * media.dpi),
41
+ height: Math.floor(i.height * media.dpi),
42
+ };
43
+ }
44
+
45
+ function header(page: GreyPage, media: RasterMedia, total: number) {
46
+ const h = new Uint8Array(HEADER);
47
+ const v = new DataView(h.buffer);
48
+ const u32 = (offset: number, n: number) => v.setUint32(offset, n);
49
+ const str = (offset: number, s: string) =>
50
+ h.set(new TextEncoder().encode(s).subarray(0, 63), offset);
51
+ const pt = mediaPixels({ name: media.name, dpi: 72 }); // PageSize is in points
52
+ str(0, "PwgRaster"); // MediaClass
53
+ u32(276, media.dpi); // HWResolution
54
+ u32(280, media.dpi);
55
+ u32(340, 1); // NumCopies: copies are the job's, not the page's
56
+ u32(352, pt.width); // PageSize, points
57
+ u32(356, pt.height);
58
+ u32(372, page.width); // Width, Height in pixels
59
+ u32(376, page.height);
60
+ u32(384, 8); // BitsPerColor
61
+ u32(388, 8); // BitsPerPixel
62
+ u32(392, page.width); // BytesPerLine
63
+ u32(400, SGRAY); // ColorSpace; ColorOrder (396) 0 is chunky
64
+ u32(420, 1); // NumColors
65
+ u32(452, total); // TotalPageCount
66
+ u32(456, 1); // CrossFeedTransform
67
+ u32(460, 1); // FeedTransform
68
+ u32(480, WHITE); // AlternatePrimary
69
+ str(1732, media.name); // PageSizeName
70
+ return h;
71
+ }
72
+
73
+ /** One line's runs, appended to `out`. */
74
+ function packLine(line: Uint8Array, out: number[]) {
75
+ let i = 0;
76
+ while (i < line.length) {
77
+ let run = 1;
78
+ while (run < 128 && i + run < line.length && line[i + run] === line[i])
79
+ run++;
80
+ if (run > 1 || i + 1 === line.length) {
81
+ out.push(run - 1, line[i]!);
82
+ i += run;
83
+ continue;
84
+ }
85
+ // Literal: up to 128 pixels, stopping before two equal pixels that would pack better as a repeat.
86
+ let n = 1;
87
+ while (
88
+ n < 128 &&
89
+ i + n < line.length &&
90
+ !(i + n + 1 < line.length && line[i + n] === line[i + n + 1])
91
+ )
92
+ n++;
93
+ if (n === 1) {
94
+ out.push(0, line[i]!); // a lone pixel is a repeat of one: 257 − 256 can't be written
95
+ i += 1;
96
+ continue;
97
+ }
98
+ out.push(257 - n);
99
+ for (let k = 0; k < n; k++) out.push(line[i + k]!);
100
+ i += n;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Pages as one PWG Raster document, `image/pwg-raster`. Every page must be `width × height` bytes. Pages may come one at
106
+ * a time (a generator), so only the packed document and the current page are held; then `total` is the page count.
107
+ */
108
+ export function pwgRaster(
109
+ pages: Iterable<GreyPage>,
110
+ media: RasterMedia,
111
+ total = Array.isArray(pages) ? pages.length : 0,
112
+ ): Uint8Array<ArrayBuffer> {
113
+ const chunks: Uint8Array[] = [new TextEncoder().encode("RaS2")];
114
+ for (const page of pages) {
115
+ if (page.pixels.length !== page.width * page.height)
116
+ throw new RangeError(
117
+ `a ${page.width} × ${page.height} page needs ${page.width * page.height} bytes, got ${page.pixels.length}`,
118
+ );
119
+ chunks.push(header(page, media, total));
120
+ let y = 0;
121
+ while (y < page.height) {
122
+ const line = page.pixels.subarray(y * page.width, (y + 1) * page.width);
123
+ let repeat = 0;
124
+ while (
125
+ repeat < 255 &&
126
+ y + repeat + 1 < page.height &&
127
+ equal(
128
+ line,
129
+ page.pixels.subarray(
130
+ (y + repeat + 1) * page.width,
131
+ (y + repeat + 2) * page.width,
132
+ ),
133
+ )
134
+ )
135
+ repeat++;
136
+ const out = [repeat]; // one line at a time: a page as a number[] would be hundreds of MB
137
+ packLine(line, out);
138
+ chunks.push(Uint8Array.from(out));
139
+ y += repeat + 1;
140
+ }
141
+ }
142
+ const size = chunks.reduce((n, c) => n + c.length, 0);
143
+ const file = new Uint8Array(size);
144
+ let at = 0;
145
+ for (const c of chunks) (file.set(c, at), (at += c.length));
146
+ return file;
147
+ }
148
+
149
+ function equal(a: Uint8Array, b: Uint8Array) {
150
+ if (a.length !== b.length) return false;
151
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
152
+ return true;
153
+ }
154
+
155
+ /** A PWG Raster document back as pages and their headers' key fields; for tests and for checking a file before it prints. */
156
+ export function readPwgRaster(file: Uint8Array): (GreyPage & {
157
+ dpi: number;
158
+ pageSizeName: string;
159
+ colorSpace: number;
160
+ bitsPerPixel: number;
161
+ })[] {
162
+ const text = new TextDecoder();
163
+ if (text.decode(file.subarray(0, 4)) !== "RaS2")
164
+ throw new Error("pwg raster: no RaS2 sync word");
165
+ const pages = [];
166
+ let at = 4;
167
+ while (at < file.length) {
168
+ const v = new DataView(file.buffer, file.byteOffset + at, HEADER);
169
+ const width = v.getUint32(372);
170
+ const height = v.getUint32(376);
171
+ const bitsPerPixel = v.getUint32(388);
172
+ const bytes = bitsPerPixel / 8;
173
+ const name = file.subarray(at + 1732, at + 1796);
174
+ const pageSizeName = text.decode(name.subarray(0, name.indexOf(0)));
175
+ const page = {
176
+ width,
177
+ height,
178
+ dpi: v.getUint32(276),
179
+ pageSizeName,
180
+ colorSpace: v.getUint32(400),
181
+ bitsPerPixel,
182
+ pixels: new Uint8Array(width * height * bytes),
183
+ };
184
+ at += HEADER;
185
+ const lineBytes = width * bytes;
186
+ let y = 0;
187
+ while (y < height) {
188
+ const repeat = file[at++]! + 1;
189
+ const line = new Uint8Array(lineBytes);
190
+ let x = 0;
191
+ while (x < lineBytes) {
192
+ const c = file[at++]!;
193
+ if (c === 128) {
194
+ line.fill(255, x); // the rest of the line is white
195
+ break;
196
+ }
197
+ if (c < 128) {
198
+ const px = file.subarray(at, at + bytes);
199
+ for (let k = 0; k <= c; k++) line.set(px, x + k * bytes);
200
+ at += bytes;
201
+ x += (c + 1) * bytes;
202
+ } else {
203
+ const n = (257 - c) * bytes;
204
+ line.set(file.subarray(at, at + n), x);
205
+ at += n;
206
+ x += n;
207
+ }
208
+ }
209
+ for (let k = 0; k < repeat && y < height; k++, y++)
210
+ page.pixels.set(line, y * lineBytes);
211
+ }
212
+ pages.push(page);
213
+ }
214
+ return pages;
215
+ }
@@ -21,6 +21,8 @@ export type Printer = {
21
21
  name: string;
22
22
  model?: string;
23
23
  host?: string;
24
+ port?: number; // where it last answered, with `rp`: what a write needs to reach it
25
+ rp?: string; // the IPP path from discovery's TXT; absent is `ipp/print`
24
26
  room?: string;
25
27
  state?: PrinterStatus; // absent when the printer sent a code outside 3 to 5; `stateCode` has it
26
28
  stateCode?: number;
@@ -58,6 +58,8 @@ Not built: `deactivate`, `available_actions`. An ad (`entity_type: "ad"`) shows
58
58
 
59
59
  ## Unverified
60
60
 
61
+ What Soloist does that this connector works around, and the upstream issues to watch: [khalido/home.ts#1](https://github.com/khalido/home.ts/issues/1).
62
+
61
63
  Writes through this connector, and what a live read hasn't shown. In particular:
62
64
 
63
65
  - **Stalls:** whether the reported position freezes in one (if not, only an overrun is caught), whether `get_state` re-anchors the position, and whether a seek or a pause and play restarts it.
@@ -70,7 +72,7 @@ Writes through this connector, and what a live read hasn't shown. In particular:
70
72
 
71
73
  **2026-11-11, Raspberry Pi 5, Bun 1.4.4, on 0.1.3** (chota-bot's session; `maxVolume: 40` watching, writes from the CLI in another process). Two gaps in the cap, not fixed:
72
74
 
73
- - From inactive and paused at 60, `play`: lowered to 40 within 2 ms of going active, `playing` at 40, then 60 again 90 ms after `playing`, and it played at 60. The cap takes its first confirmed lowering as done, so nothing lowered it again, and `anomaly` still said "lowered it". Soloist puts its own level back after `playing`.
75
+ - From inactive and paused at 60, `play`: lowered to 40 within 2 ms of going active, `playing` at 40, then 60 again 90 ms after `playing`, and it played at 60. The cap takes its first confirmed lowering as done, so nothing lowered it again, and `anomaly` still said "lowered it". After 0.2.0 the note adds "it is back at 60"; the level is left alone, since it is the one the speaker was playing at. Soloist puts its own level back after `playing`.
74
76
  - The connector started while the speaker was already active and paused at 60: `play` resumed at 60, nothing lowered it, no anomaly. This is the documented "not on resuming from pause while active".
75
77
  - A volume set by hand (35) held through pause and play, so the put-back belongs to activation, not to pause.
76
78
 
@@ -138,7 +138,7 @@ export function spotifyChanges(
138
138
  /**
139
139
  * The speaker in a few words: `Kitchen speaker: playing "Song" by Band · 35%`, `…: waiting for someone to pick it`, or,
140
140
  * for music on another Spotify device, `…: silent · "Song" by Band is playing on another Spotify device` (no volume: it isn't this speaker's playing level).
141
- * `on` names where, when the caller knows (`spotifyElsewhere`): `… is playing on Front room speaker`.
141
+ * `on` names where, when the caller knows (`spotifyElsewhere`): `… is playing on Den speaker`.
142
142
  */
143
143
  export function spotifyText(s: SpotifyState, on: string[] = []): string {
144
144
  const who = s.deviceName ?? "Soloist";
@@ -390,6 +390,17 @@ export function spotify(
390
390
  * one raised before it is reported can't be told from the start's own jump, so it is lowered too.
391
391
  */
392
392
  const applyCap = () => {
393
+ // Lowered, then above the cap again in the same window: Soloist putting its own level back (seen live) or a person.
394
+ // The note says where it is now, not only that it was lowered.
395
+ if (capped && capNote && cap !== undefined && state.volume !== undefined) {
396
+ const base = capNote.replace(/; it is back at \d+$/, "");
397
+ const note =
398
+ state.volume > cap + VOLUME_SLACK
399
+ ? `${base}; it is back at ${state.volume}`
400
+ : base;
401
+ if (note !== capNote) ((capNote = note), publish());
402
+ return;
403
+ }
393
404
  if (
394
405
  cap === undefined ||
395
406
  capped ||
@@ -410,7 +421,7 @@ export function spotify(
410
421
  if (confirmed) {
411
422
  capped = true;
412
423
  if (state.status === "idle") return;
413
- capNote = `started at volume ${from}, above maxVolume ${cap}; lowered it (Soloist issue #23)`;
424
+ capNote = `started at volume ${from}, above maxVolume ${cap}; lowered it to ${cap} (Soloist issue #23)`;
414
425
  note = undefined;
415
426
  return publish();
416
427
  }
@@ -7,7 +7,7 @@ Reads the household's spending from Up Bank's API: two months of transactions, s
7
7
  - **`client.ts`**: `upClient({ token, fetch })`. Reads: `ping`, `accounts(filter)`, `transactions(query)` following cursors to `limit` (default 1000) and `pageCap` (20) and returning `{ transactions, truncated }` so a cut-off list never looks complete, `transaction(id)`, `categories`, `tags`, `webhooks`, `webhook(id)`, `webhookLogs(id)`. Writes: `setCategory(id, categoryId | null)`, `addTags(id, labels)`, `removeTags(id, labels)`, each re-reading and returning the transaction as Up now holds it; `createWebhook`, `deleteWebhook`, `pingWebhook`. A transaction is flattened to cents (Up's `valueInBaseUnits`) and ids.
8
8
  - **`spend.ts`**, pure, one owner per number. `notSpend(t)` is the rule and says why: held, money in, `transferAccount` set (a movement between your own accounts), or a description Up gives its own movements ("Cover from", "Forward to", "Round Up", "Quick save transfer"). "Transfer to …" is not on the list: paying someone else is spend. `isSpend`, `spendByCategory` (parents and children, excluded movements counted and summed so a total can be checked), `spendByMerchant`, `uncategorised` (spend with no category; money in is categorisable too but left out), `recurring` (a heuristic: three or more months within 20% of the median), `unusual` (over twice the median of three or more earlier purchases at that merchant), `dollars` for display.
9
9
  - **`webhook.ts`**: `verifyWebhook(rawBody, signature, secret)`, the SHA-256 HMAC of the raw body in hex, Web Crypto, compared in constant time; `parseWebhookEvent(body)` gives the event type and the transaction id. A consumer's handler verifies, then calls `home.refresh("up")`.
10
- - **The integration** (`up({ token, account?, timeZone?, fetch })`, with `client` on it for a consumer's writes): every 15 minutes it reads the categories, the accounts the filter names, and 63 days of transactions, then cuts this month and last in the home's time zone. The snapshot holds each month's spend by category and top five merchants, the ids still to categorise, and the latest 20 purchases trimmed to id, time, description, amount, category, status and tags (movements between your own accounts are left out: their descriptions name the accounts). Never kept: raw text, message, note, who spent (`performingCustomer`), account ids, balances. A 401 is `unavailable`; a read that hit its page cap is an `anomaly`, as is an amount missing or not in AUD. It never writes.
10
+ - **The integration** (`up({ token, account?, timeZone?, fetch })`, with `client` on it for a consumer's writes): every 15 minutes it reads the categories, the accounts the filter names, and 63 days of transactions, then cuts this month and last in the home's time zone. The snapshot holds each month's spend by category and top five merchants, the ids still to categorise, and the latest 20 purchases trimmed to id, time, description, amount, category, status and tags (movements between your own accounts are left out: their descriptions name the accounts). Never kept: raw text, message, note, who spent (`performingCustomer`), account ids, balances. A 401 or 403 is `unavailable`; a read that hit its page cap is an `anomaly`, as is an amount missing or not in AUD. It never writes.
11
11
  - **Config**: `{ connector: "up", key: "UP_TOKEN", account: { ownershipType: "JOINT", accountType: "TRANSACTIONAL" } }`. Accounts are chosen by type and ownership, never by id. Without `account`, every account is read; transfers between them are excluded by `transferAccount`.
12
12
  - **CLI**: `home up` (this month, last month, to categorise, top five categories), `home up transactions [--since] [--until] [--category] [--tag] [--status] [--limit] [--json|--csv]`, `categories`, `uncategorised`, `spend [--by category|merchant|recurring]`, and the writes `categorise <id> <category|none>`, `tag <id> <label> [--remove]`, `webhooks [get|logs|ping|create|delete]`. `UP_ACCOUNT` ("JOINT TRANSACTIONAL") is the filter's env form.
13
13
  - **Household filter** (`household: { categories, tags }` in the config, `UP_HOUSEHOLD="home tag:home"` in env): the totals, top merchants and recent rows count only purchases in a listed category or its parent, or with a listed tag, so a family dashboard shows groceries and utilities, not personal spending. Tag anything else `home` in the Up app to bring it in. "To categorise" still looks at every purchase, since a category is how one joins. A listed category Up does not have is an `anomaly`, not a silent zero. `inHousehold` is the one owner of the rule; `home up spend` applies it too. `webhooks create` writes the secret Up returns once to `~/.config/home/up-webhook-<id>.secret` (0600); it is never printed.
@@ -6,7 +6,7 @@ import { ConnectorError, fetchTimeout, getJson } from "../../connector.ts";
6
6
 
7
7
  const BASE = "https://api.up.com.au/api/v1";
8
8
 
9
- /** A failed Up call. `status` 401 means the token is wrong or revoked; 429 the rate limit (unpublished: read `X-RateLimit-Remaining`). */
9
+ /** A failed Up call. `status` 401 or 403 (`isRejectedKey`) means the token is wrong or revoked; 429 the rate limit (unpublished: read `X-RateLimit-Remaining`). */
10
10
  export class UpError extends ConnectorError {}
11
11
 
12
12
  const Money = z.looseObject({
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { asOf, type Clock, realClock } from "../../clock.ts";
3
- import { errorText } from "../../connector.ts";
3
+ import { errorText, isRejectedKey } from "../../connector.ts";
4
4
  import { envName, type Integration } from "../../home.ts";
5
5
  import type { Manifest } from "../../manifest.ts";
6
6
  import { poller } from "../../poll.ts";
@@ -288,7 +288,7 @@ export function up(config: UpConfig): Integration<UpSnapshot, "up"> & {
288
288
  });
289
289
  } catch (error) {
290
290
  if (signal.aborted) return; // stopped mid-read: not a failure
291
- if (error instanceof UpError && error.status === 401)
291
+ if (isRejectedKey(error))
292
292
  return update({
293
293
  status: "unavailable",
294
294
  reason: "auth",
@@ -1,5 +1,9 @@
1
1
  import { z } from "zod";
2
- import { ConnectorError, fetchTimeout } from "../../connector.ts";
2
+ import {
3
+ ConnectorError,
4
+ fetchTimeout,
5
+ isRejectedKey,
6
+ } from "../../connector.ts";
3
7
  import { RAIN_INTENSITIES } from "./rain.ts";
4
8
  import { sunDisagrees } from "./sun.ts";
5
9
  import {
@@ -434,7 +438,7 @@ export function google(options: GoogleOptions): WeatherSource {
434
438
  ? error
435
439
  : ({} as { status?: number; why?: string });
436
440
  const said = `HTTP ${status}${why ? ` ${why}` : ""}`;
437
- if (status === 401 || status === 403 || why?.startsWith("API_KEY_"))
441
+ if (isRejectedKey(error) || why?.startsWith("API_KEY_"))
438
442
  return {
439
443
  stop: `google: the key was rejected (${said})`,
440
444
  stopReason: "auth",