omni-notify-mcp 1.3.387 → 1.3.388
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/dist/gateway/cliSession.js +22 -5
- package/dist/gateway/nativeTerminal.js +16 -1
- package/package.json +1 -1
- package/dist/gateway/agentStream.js +0 -88
- package/dist/googlehome/foyer-client.js +0 -210
- package/dist/googlehome/foyer-codec.js +0 -318
- package/dist/googlehome/gpsoauth.js +0 -119
- package/dist/googlehome/index.js +0 -267
- package/dist/index.js +0 -41
- package/dist/shared/webhost/openedWorkspaces.js +0 -62
- package/scripts/shared/ownerGuard.cs +0 -665
- package/scripts/shared/ownerGuard.ps1 +0 -31
|
@@ -137,18 +137,35 @@ export class CliSession {
|
|
|
137
137
|
await this.ready();
|
|
138
138
|
if (this.ending || this.turn !== turn)
|
|
139
139
|
return;
|
|
140
|
-
if (this.restored
|
|
141
|
-
|
|
140
|
+
if (this.restored === 0 && this.terminal.hasUnsubmittedInput) {
|
|
141
|
+
this.settle(turn, () => turn.reject(new AgentTurnFailed("the native CLI already holds unsubmitted input; this request was not typed or submitted")));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
let revision = this.terminal.inputGeneration;
|
|
145
|
+
const changed = () => this.settle(turn, () => turn.reject(new AgentTurnFailed("native input changed while this request awaited acceptance; automatic Enter stopped without submitting the edited input")));
|
|
146
|
+
const write = (data) => {
|
|
147
|
+
const sent = this.terminal.inputIfUnchanged(data, revision);
|
|
148
|
+
if (sent === undefined) {
|
|
149
|
+
changed();
|
|
150
|
+
return Promise.resolve(false);
|
|
151
|
+
}
|
|
152
|
+
revision = sent.revision;
|
|
153
|
+
return sent.written.then(() => true);
|
|
154
|
+
};
|
|
155
|
+
if (this.restored > 0 && !await write("\x15".repeat(this.restored * CLEARS_PER_LINE + 1)))
|
|
156
|
+
return;
|
|
142
157
|
this.restored = 0;
|
|
143
|
-
await
|
|
158
|
+
if (!await write(`\x1b[200~${CLI_COMMAND_START.test(turn.prompt) ? ` ${turn.prompt}` : turn.prompt}\x1b[201~`))
|
|
159
|
+
return;
|
|
144
160
|
if (this.ending || this.turn !== turn)
|
|
145
161
|
return;
|
|
146
162
|
const press = () => {
|
|
147
163
|
if (!this.ending && this.turn === turn && !turn.taken && !this.terminal.info().ended)
|
|
148
|
-
void
|
|
164
|
+
void write("\r").catch((err) => this.settle(turn, () => turn.reject(new AgentTurnFailed(`Enter could not be pressed in the agent's CLI: ${err.message}`))));
|
|
149
165
|
};
|
|
150
166
|
press();
|
|
151
|
-
turn
|
|
167
|
+
if (this.turn === turn && !turn.taken)
|
|
168
|
+
turn.enter = setInterval(press, ENTER_EVERY_MS);
|
|
152
169
|
}
|
|
153
170
|
/** The driver's prompt is taken: Enter is no longer pressed, and the driver hears it started. */
|
|
154
171
|
takenNow(turn) {
|
|
@@ -63,6 +63,7 @@ export class NativeTerminal {
|
|
|
63
63
|
events = new EventEmitter();
|
|
64
64
|
/** What the keys have put in the CLI's input box since the last Enter, and whether a bracketed paste is open. */
|
|
65
65
|
typing = "";
|
|
66
|
+
inputRevision = 0;
|
|
66
67
|
pasting = false;
|
|
67
68
|
sequence = 0;
|
|
68
69
|
outputEnds = [];
|
|
@@ -264,10 +265,23 @@ export class NativeTerminal {
|
|
|
264
265
|
refuse(why) { this.failure ??= why; }
|
|
265
266
|
input(data, binary) {
|
|
266
267
|
this.live();
|
|
268
|
+
const reply = /^(?:\x1b\[\??\d+;\d+R|\x1b\[[?>][0-9;]*c|\x1b\[\??[0-9;]*\$y)+$/.test(data);
|
|
269
|
+
if (data.length > 0 && (binary || !reply))
|
|
270
|
+
this.inputRevision++;
|
|
267
271
|
if (!binary)
|
|
268
272
|
this.track(data);
|
|
269
273
|
return this.send({ kind: "input", data, binary });
|
|
270
274
|
}
|
|
275
|
+
get inputGeneration() { return this.inputRevision; }
|
|
276
|
+
get hasUnsubmittedInput() { return this.typing.length > 0 || this.pasting; }
|
|
277
|
+
/** A driver owns only the input it wrote: any intervening native input revokes its automatic Enter. */
|
|
278
|
+
inputIfUnchanged(data, expected) {
|
|
279
|
+
if (expected !== this.inputRevision)
|
|
280
|
+
return undefined;
|
|
281
|
+
const revision = this.inputRevision + 1;
|
|
282
|
+
const written = this.input(data, false);
|
|
283
|
+
return { revision, written };
|
|
284
|
+
}
|
|
271
285
|
/**
|
|
272
286
|
* Follows what the keys build in the CLI's input box: a bracketed paste is taken whole, its line breaks included; Enter
|
|
273
287
|
* outside a paste submits the line; Backspace and Ctrl+U edit it; any other escape sequence (an arrow, a function key)
|
|
@@ -286,7 +300,7 @@ export class NativeTerminal {
|
|
|
286
300
|
continue;
|
|
287
301
|
}
|
|
288
302
|
if (data[at] === "\x1b") {
|
|
289
|
-
at += /^\x1b(\[[0
|
|
303
|
+
at += /^\x1b(\[[0-?]*[ -/]*[@-~]|O.|.)?/.exec(data.slice(at))[0].length;
|
|
290
304
|
continue;
|
|
291
305
|
}
|
|
292
306
|
const key = data[at++];
|
|
@@ -310,6 +324,7 @@ export class NativeTerminal {
|
|
|
310
324
|
}
|
|
311
325
|
inputFiles(files) {
|
|
312
326
|
this.live();
|
|
327
|
+
this.inputRevision++;
|
|
313
328
|
const request = ++this.fileRequest;
|
|
314
329
|
return new Promise((resolve, reject) => {
|
|
315
330
|
const done = (message) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.388",
|
|
4
4
|
"description": "Reach your AI agents from anywhere — and let them reach you. One resident process on 127.0.0.1:7475 serves the whole tool surface to Claude Code, GitHub Copilot Chat and Codex: desktop, Telegram, Slack, ntfy, Discord, Teams and SMS are configured in one file, and agents notify you when long work finishes or a decision is needed, ask you a question and wait for your answer, and receive and reply to the messages you send them — with Do Not Disturb and idle detection deciding what actually gets through.",
|
|
5
5
|
"main": "dist/daemon.js",
|
|
6
6
|
"type": "module",
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The agent stream (#3402): the live feed of a conversation's agent — its thinking and its output as they arrive, told
|
|
3
|
-
* apart — that an MCP caller attaches to instead of waiting for the finished reply alone. The session driver appends a
|
|
4
|
-
* frame for every delta the CLI's own `stream_event` carries (`claudeProvider.ts` reads them; the CLI is started with
|
|
5
|
-
* `--include-partial-messages`), beside a frame for the tool the turn is on and one for each discrete conversation
|
|
6
|
-
* event, so a reader sees the whole turn in arrival order from one stream.
|
|
7
|
-
*
|
|
8
|
-
* The stream is served over the SAME authenticated gateway door as everything else (a Server-Sent Events route in
|
|
9
|
-
* `restDoor.ts`) and is owned by the person, exactly as a native terminal is (#3370): the owner is the door's own
|
|
10
|
-
* `personId()` and another person's key is refused with 404.
|
|
11
|
-
*
|
|
12
|
-
* A frame's `seq` is monotonic per conversation and a reader resumes with `after` = the last `seq` it read, so a
|
|
13
|
-
* dropped client that re-attaches misses nothing it had not already received; frames are held for the conversation's
|
|
14
|
-
* life and freed when it is deleted. The feed is live and in memory, not a durable transcript: a BN restart empties it
|
|
15
|
-
* and its `seq` starts again, so a re-attach with a `seq` from before a restart resumes within the new stream — the
|
|
16
|
-
* finished turn stays readable through the conversation's own log.
|
|
17
|
-
*
|
|
18
|
-
* NOTHING IS CAPPED HERE — no buffer size, no retained-history window and no idle bound is applied, because every such
|
|
19
|
-
* bound is a gate that is Meni's to rule on before it ships (the proposal sits on #3402's decision field).
|
|
20
|
-
*/
|
|
21
|
-
import { EventEmitter } from "events";
|
|
22
|
-
import { GatewayError, MAX_WAIT_SECONDS, readConversation } from "./conversations.js";
|
|
23
|
-
/**
|
|
24
|
-
* One conversation's live stream: the frames appended in order, the owner it belongs to, and the things waiting on a
|
|
25
|
-
* new frame. It is created by the session driver the moment the conversation's turn produces anything and bound to a
|
|
26
|
-
* person the first time the door serves it to one.
|
|
27
|
-
*/
|
|
28
|
-
class AgentStream {
|
|
29
|
-
/** The person this stream belongs to, fixed by the first sign-in that reads it (#3370); absent until then. */
|
|
30
|
-
owner;
|
|
31
|
-
seq = 0;
|
|
32
|
-
frames = [];
|
|
33
|
-
changed = new EventEmitter();
|
|
34
|
-
/** Appends one frame and wakes every reader; the new frame's own `seq` is returned so a caller can echo it back as `after`. */
|
|
35
|
-
append(kind, text, turn, rest = {}) {
|
|
36
|
-
const frame = { seq: ++this.seq, ts: new Date().toISOString(), kind, text, turn, ...rest };
|
|
37
|
-
this.frames.push(frame);
|
|
38
|
-
this.changed.emit("change");
|
|
39
|
-
return frame;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The frames past `after`, or — a reader with no position — the whole stream so far; `after` is the last `seq` the
|
|
43
|
-
* reader had, so what it returns is exactly what the reader has not seen. `holdMs` bounds the wait for a new frame:
|
|
44
|
-
* the SSE route holds `MAX_WAIT_SECONDS` (the same cap every blocking BN call obeys) and writes each frame the moment
|
|
45
|
-
* it is produced instead of polling, while the MCP read a tool-only caller polls with is given 0 and answers at once.
|
|
46
|
-
*/
|
|
47
|
-
async read(after, signal, holdMs = MAX_WAIT_SECONDS * 1000) {
|
|
48
|
-
for (;;) {
|
|
49
|
-
const frames = after === undefined ? this.frames.slice() : this.frames.filter((frame) => frame.seq > after);
|
|
50
|
-
if (frames.length > 0 || signal.aborted || holdMs === 0)
|
|
51
|
-
return { frames, seq: this.seq };
|
|
52
|
-
await new Promise((resolve) => {
|
|
53
|
-
const done = () => { clearTimeout(timer); this.changed.off("change", done); signal.removeEventListener("abort", done); resolve(); };
|
|
54
|
-
const timer = setTimeout(done, holdMs);
|
|
55
|
-
this.changed.once("change", done);
|
|
56
|
-
signal.addEventListener("abort", done, { once: true });
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const streams = new Map();
|
|
62
|
-
/** This conversation's stream, made if it is not there yet: the session driver appends to it from the first frame of a turn. */
|
|
63
|
-
export function agentStream(id) {
|
|
64
|
-
const existing = streams.get(id);
|
|
65
|
-
if (existing !== undefined)
|
|
66
|
-
return existing;
|
|
67
|
-
const stream = new AgentStream();
|
|
68
|
-
streams.set(id, stream);
|
|
69
|
-
return stream;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* The stream of `id` as `owner`'s, for the door: the conversation must exist, and the stream belongs to the first person
|
|
73
|
-
* who reads it — another person's key is refused with 404, never handed someone else's stream. Every later reader of the
|
|
74
|
-
* same person is served the same stream, so a re-attach resumes it.
|
|
75
|
-
*/
|
|
76
|
-
export function agentStreamFor(owner, id) {
|
|
77
|
-
readConversation(id);
|
|
78
|
-
const stream = agentStream(id);
|
|
79
|
-
if (stream.owner === undefined)
|
|
80
|
-
stream.owner = owner;
|
|
81
|
-
else if (stream.owner !== owner)
|
|
82
|
-
throw new GatewayError(404, "No agent stream for this person.");
|
|
83
|
-
return stream;
|
|
84
|
-
}
|
|
85
|
-
/** The conversation is gone: its stream and every frame it held are dropped. */
|
|
86
|
-
export function dropAgentStream(id) {
|
|
87
|
-
streams.delete(id);
|
|
88
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
// The foyer-pa RPC client: builds positional `application/json+protobuf` arrays (via foyer-codec),
|
|
2
|
-
// POSTs them to Google's Home Graph foyer endpoint, mints the bearer from the master token
|
|
3
|
-
// (gpsoauth), and retries once on 401/403 while advancing scope negotiation.
|
|
4
|
-
// Ported from coredevices/pebble-plugins `googlehome/src/foyer-client.ts` (which names the Kotlin
|
|
5
|
-
// `FoyerRpcClient`/`FoyerAuthImpl` as its origin).
|
|
6
|
-
import * as codec from './foyer-codec.js';
|
|
7
|
-
import { FoyerAuthError } from './gpsoauth.js';
|
|
8
|
-
const BASE = 'https://googlehomefoyer-pa.clients6.google.com/$rpc/google.internal.home.foyer.v1.';
|
|
9
|
-
const HOME_CONTROL_SERVICE = 'HomeControlService';
|
|
10
|
-
const STRUCTURES_SERVICE = 'StructuresService';
|
|
11
|
-
const AUTOMATION_SERVICE = 'AutomationService';
|
|
12
|
-
const CONTENT_TYPE = 'application/json+protobuf';
|
|
13
|
-
// The (app, client_sig, scope) triple that yields a bearer foyer-pa accepts.
|
|
14
|
-
const APP = 'com.google.android.apps.chromecast.app';
|
|
15
|
-
const CLIENT_SIG = '24bb24c05e47e0aefa68a58a766179d9b613a600';
|
|
16
|
-
const SCOPE_CANDIDATES = [
|
|
17
|
-
'oauth2:https://www.googleapis.com/auth/homegraph',
|
|
18
|
-
'oauth2:https://www.google.com/accounts/OAuthLogin',
|
|
19
|
-
];
|
|
20
|
-
/** A refusal the calling agent should read: no structure, a routine that cannot be started, … */
|
|
21
|
-
export class GoogleHomeError extends Error {
|
|
22
|
-
}
|
|
23
|
-
export class FoyerHttpError extends GoogleHomeError {
|
|
24
|
-
status;
|
|
25
|
-
constructor(status, message) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.status = status;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** Strips a leading XSSI guard line (`)]}'`) some clients6 endpoints prepend. */
|
|
31
|
-
export function stripXssiPrefix(body) {
|
|
32
|
-
const trimmed = body.replace(/^\s+/, '');
|
|
33
|
-
if (trimmed.startsWith(")]}'")) {
|
|
34
|
-
return trimmed.substring(4).replace(/^[\r\n]+/, '');
|
|
35
|
-
}
|
|
36
|
-
return body;
|
|
37
|
-
}
|
|
38
|
-
/** Mints + caches short-lived foyer bearers from the master token, with scope negotiation. */
|
|
39
|
-
export class FoyerAuth {
|
|
40
|
-
masterToken;
|
|
41
|
-
androidId;
|
|
42
|
-
oauth;
|
|
43
|
-
scopes;
|
|
44
|
-
app;
|
|
45
|
-
clientSig;
|
|
46
|
-
fallbackTtlSeconds;
|
|
47
|
-
expirySkewSeconds;
|
|
48
|
-
nowEpochSeconds;
|
|
49
|
-
cachedToken = null;
|
|
50
|
-
expiresAtEpoch = 0;
|
|
51
|
-
scopeIndex = 0;
|
|
52
|
-
constructor(masterToken, androidId, oauth, scopes = SCOPE_CANDIDATES, app = APP, clientSig = CLIENT_SIG, fallbackTtlSeconds = 55 * 60, expirySkewSeconds = 60, nowEpochSeconds = () => Math.floor(Date.now() / 1000)) {
|
|
53
|
-
this.masterToken = masterToken;
|
|
54
|
-
this.androidId = androidId;
|
|
55
|
-
this.oauth = oauth;
|
|
56
|
-
this.scopes = scopes;
|
|
57
|
-
this.app = app;
|
|
58
|
-
this.clientSig = clientSig;
|
|
59
|
-
this.fallbackTtlSeconds = fallbackTtlSeconds;
|
|
60
|
-
this.expirySkewSeconds = expirySkewSeconds;
|
|
61
|
-
this.nowEpochSeconds = nowEpochSeconds;
|
|
62
|
-
}
|
|
63
|
-
async bearer() {
|
|
64
|
-
const now = this.nowEpochSeconds();
|
|
65
|
-
if (this.cachedToken != null && now < this.expiresAtEpoch)
|
|
66
|
-
return this.cachedToken;
|
|
67
|
-
return this.mint(now);
|
|
68
|
-
}
|
|
69
|
-
invalidate() {
|
|
70
|
-
this.cachedToken = null;
|
|
71
|
-
this.expiresAtEpoch = 0;
|
|
72
|
-
this.scopeIndex = this.scopes.length === 0 ? 0 : (this.scopeIndex + 1) % this.scopes.length;
|
|
73
|
-
}
|
|
74
|
-
async mint(now) {
|
|
75
|
-
if (this.scopes.length === 0)
|
|
76
|
-
throw new FoyerAuthError('no foyer scope candidates configured; cannot mint a bearer');
|
|
77
|
-
let lastError = null;
|
|
78
|
-
for (let offset = 0; offset < this.scopes.length; offset++) {
|
|
79
|
-
const i = (this.scopeIndex + offset) % this.scopes.length;
|
|
80
|
-
try {
|
|
81
|
-
const token = await this.oauth.getAuthToken(this.masterToken, this.androidId, this.scopes[i], this.app, this.clientSig);
|
|
82
|
-
this.scopeIndex = i;
|
|
83
|
-
this.cachedToken = token.auth;
|
|
84
|
-
this.expiresAtEpoch = this.deadlineFor(token.expiryEpochSeconds, now);
|
|
85
|
-
return token.auth;
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
lastError = e instanceof Error ? e : new FoyerAuthError(String(e));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
throw lastError instanceof Error ? lastError : new FoyerAuthError('no foyer scope candidates could be minted');
|
|
92
|
-
}
|
|
93
|
-
deadlineFor(expiryEpochSeconds, now) {
|
|
94
|
-
const cap = now + this.fallbackTtlSeconds;
|
|
95
|
-
const base = expiryEpochSeconds != null && expiryEpochSeconds > now ? Math.min(expiryEpochSeconds, cap) : cap;
|
|
96
|
-
return base - this.expirySkewSeconds;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export class FoyerClient {
|
|
100
|
-
auth;
|
|
101
|
-
constructor(auth) {
|
|
102
|
-
this.auth = auth;
|
|
103
|
-
}
|
|
104
|
-
// Reads ---------------------------------------------------------------------------------------
|
|
105
|
-
async fetchHomeGraph() {
|
|
106
|
-
const resp = await this.rpc(STRUCTURES_SERVICE, 'GetHomeGraph', []);
|
|
107
|
-
return codec.parseGetHomeGraph(resp);
|
|
108
|
-
}
|
|
109
|
-
async getHomeGraph() {
|
|
110
|
-
const g = await this.fetchHomeGraph();
|
|
111
|
-
return { homes: g.homes, devices: g.devices };
|
|
112
|
-
}
|
|
113
|
-
async listRooms() {
|
|
114
|
-
return (await this.fetchHomeGraph()).rooms;
|
|
115
|
-
}
|
|
116
|
-
async getTraits(deviceIds) {
|
|
117
|
-
if (deviceIds.length === 0)
|
|
118
|
-
return [];
|
|
119
|
-
const resp = await this.rpc(HOME_CONTROL_SERVICE, 'GetTraits', codec.buildGetTraitsRequest(deviceIds));
|
|
120
|
-
return codec.parseGetTraits(resp);
|
|
121
|
-
}
|
|
122
|
-
// Control (existing devices only; no add/delete) ----------------------------------------------
|
|
123
|
-
async setOnOff(deviceId, agentId, partnerDeviceId, on) {
|
|
124
|
-
return this.update(deviceId, codec.buildOnOff(deviceId, agentId, partnerDeviceId, on), on);
|
|
125
|
-
}
|
|
126
|
-
async setBrightness(deviceId, agentId, partnerDeviceId, pct) {
|
|
127
|
-
return this.update(deviceId, codec.buildBrightness(deviceId, agentId, partnerDeviceId, clamp(pct, 0, 100)));
|
|
128
|
-
}
|
|
129
|
-
async setColorTemperature(deviceId, agentId, partnerDeviceId, kelvin) {
|
|
130
|
-
return this.update(deviceId, codec.buildColorTemperature(deviceId, agentId, partnerDeviceId, kelvin));
|
|
131
|
-
}
|
|
132
|
-
async setVolume(deviceId, agentId, partnerDeviceId, pct) {
|
|
133
|
-
return this.update(deviceId, codec.buildVolume(deviceId, agentId, partnerDeviceId, clamp(pct, 0, 100)));
|
|
134
|
-
}
|
|
135
|
-
async setMuted(deviceId, agentId, partnerDeviceId, muted) {
|
|
136
|
-
return this.update(deviceId, codec.buildMuted(deviceId, agentId, partnerDeviceId, muted));
|
|
137
|
-
}
|
|
138
|
-
async listAutomations() {
|
|
139
|
-
const structureId = (await this.fetchHomeGraph()).homes[0]?.id;
|
|
140
|
-
if (structureId == null)
|
|
141
|
-
throw new GoogleHomeError('no home/structure found; cannot list routines');
|
|
142
|
-
const resp = await this.rpc(AUTOMATION_SERVICE, 'ListAutomations', codec.buildListAutomationsRequest(structureId));
|
|
143
|
-
return codec.parseListAutomations(resp);
|
|
144
|
-
}
|
|
145
|
-
async runAutomation(automation) {
|
|
146
|
-
if (!automation.manuallyRunnable) {
|
|
147
|
-
throw new GoogleHomeError(`routine '${automation.name}' is condition/schedule-triggered and can't be started on demand`);
|
|
148
|
-
}
|
|
149
|
-
const structureId = (await this.fetchHomeGraph()).homes[0]?.id;
|
|
150
|
-
if (structureId == null)
|
|
151
|
-
throw new GoogleHomeError('no home/structure found; cannot run a routine');
|
|
152
|
-
const resp = await this.rpc(AUTOMATION_SERVICE, 'ExecuteAutomation', codec.buildExecuteAutomationRequest(structureId, automation.id));
|
|
153
|
-
return Array.isArray(resp) && resp.length > 0 && String(resp[0]) === '1';
|
|
154
|
-
}
|
|
155
|
-
// Internals -----------------------------------------------------------------------------------
|
|
156
|
-
async update(deviceId, body, fallbackOnOff) {
|
|
157
|
-
const resp = await this.rpc(HOME_CONTROL_SERVICE, 'UpdateTraits', body);
|
|
158
|
-
const echoed = codec.parseGetTraits(resp).find((s) => s.id === deviceId);
|
|
159
|
-
if (echoed)
|
|
160
|
-
return echoed;
|
|
161
|
-
const readback = (await this.getTraits([deviceId])).find((s) => s.id === deviceId);
|
|
162
|
-
if (readback)
|
|
163
|
-
return readback;
|
|
164
|
-
return {
|
|
165
|
-
id: deviceId,
|
|
166
|
-
online: true,
|
|
167
|
-
onOff: fallbackOnOff ?? null,
|
|
168
|
-
brightnessPct: null,
|
|
169
|
-
colorTemperatureK: null,
|
|
170
|
-
volumePct: null,
|
|
171
|
-
muted: null,
|
|
172
|
-
locked: null,
|
|
173
|
-
jammed: null,
|
|
174
|
-
thermostatMode: null,
|
|
175
|
-
setpointC: null,
|
|
176
|
-
setpointF: null,
|
|
177
|
-
ambientC: null,
|
|
178
|
-
temperatureUnit: null,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
/** POSTs body to `<BASE><service>/<method>`; on 401/403 invalidates + retries once. */
|
|
182
|
-
async rpc(service, method, body) {
|
|
183
|
-
const url = `${BASE}${service}/${method}`;
|
|
184
|
-
const bodyJson = JSON.stringify(body);
|
|
185
|
-
let response = await this.post(url, bodyJson, await this.auth.bearer());
|
|
186
|
-
if (response.status === 401 || response.status === 403) {
|
|
187
|
-
this.auth.invalidate();
|
|
188
|
-
response = await this.post(url, bodyJson, await this.auth.bearer());
|
|
189
|
-
}
|
|
190
|
-
if (response.status < 200 || response.status > 299) {
|
|
191
|
-
throw new FoyerHttpError(response.status, `google home ${service}/${method} -> HTTP ${response.status}: ${response.body.substring(0, 300)}`);
|
|
192
|
-
}
|
|
193
|
-
return JSON.parse(stripXssiPrefix(response.body));
|
|
194
|
-
}
|
|
195
|
-
async post(url, bodyJson, bearer) {
|
|
196
|
-
const resp = await fetch(url, {
|
|
197
|
-
method: 'POST',
|
|
198
|
-
headers: {
|
|
199
|
-
Authorization: `Bearer ${bearer}`,
|
|
200
|
-
'X-User-Agent': 'grpc-web-javascript/0.1',
|
|
201
|
-
'Content-Type': CONTENT_TYPE,
|
|
202
|
-
},
|
|
203
|
-
body: bodyJson,
|
|
204
|
-
});
|
|
205
|
-
return { status: resp.status, body: await resp.text() };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function clamp(n, lo, hi) {
|
|
209
|
-
return Math.max(lo, Math.min(hi, n));
|
|
210
|
-
}
|