commit
MAOW
diff --git a/src/docs.ts b/src/docs.ts
index fee37d1..0270527 100644
--- a/src/docs.ts
+++ b/src/docs.ts
@@ -384,11 +384,11 @@ var GROUPS = [
{
id: "devices", name: "Devices", blurb: "Latest known device state (battery, charging, low power mode, wifi).",
endpoints: [
- { m: "GET", path: "/devices", auth: "public", desc: "All devices → { device, level, charging, lowPowerMode, wifi, updated_at }." },
+ { m: "GET", path: "/devices", auth: "public", desc: "All devices → { device, level, charging, lowPowerMode, wifi, watch, airpods, updated_at }." },
{ m: "GET", path: "/devices/:device", auth: "public", desc: "One device, or 404." },
- { m: "POST", path: "/devices?device=iphone&level=25&charging=1&lpm=0&wifi=Home", auth: "key",
+ { m: "POST", path: "/devices?device=iphone&level=25&charging=1&lpm=0&wifi=Home&watch=1&airpods=0", auth: "key",
desc: "Report device state. Only 'device' is required; supplied fields are updated, the rest untouched. Send the X-Battery-Key header.",
- params: [["device", "1–64 chars (required)."], ["level", "Optional. Integer 0–100."], ["charging", "Optional. 1 (true) or 0 (false)."], ["lpm", "Optional. 1 (true) or 0 (false) → lowPowerMode."], ["wifi", "Optional. Any string (network name), ≤128 chars."]] },
+ params: [["device", "1–64 chars (required)."], ["level", "Optional. Integer 0–100."], ["charging", "Optional. 1 (true) or 0 (false)."], ["lpm", "Optional. 1 (true) or 0 (false) → lowPowerMode."], ["wifi", "Optional. Any string (network name), ≤128 chars."], ["watch", "Optional. 1 (connected) or 0 (not connected)."], ["airpods", "Optional. 1 (connected) or 0 (not connected)."]] },
{ m: "DELETE", path: "/devices?device=iphone", auth: "key",
desc: "Delete a device's state. Returns 404 if the device doesn't exist. Send the X-Battery-Key header.",
params: [["device", "1–64 chars (required)."]] }
diff --git a/src/system/routes/devices.ts b/src/system/routes/devices.ts
index 8419ee8..5734aaf 100644
--- a/src/system/routes/devices.ts
+++ b/src/system/routes/devices.ts
@@ -17,6 +17,8 @@
* charging — 1 (true) or 0 (false)
* lpm — 1 (true) or 0 (false), stored as `lowPowerMode`
* wifi — any string (the network name), 0–128 chars
+ * watch — 1 (connected) or 0 (not connected)
+ * airpods — 1 (connected) or 0 (not connected)
*/
import { Hono } from "hono";
@@ -42,7 +44,7 @@ deviceRoutes.post("/", verifyBatteryAccess, async (c) => {
return c.json({ detail: "Query param 'device' must be a string between 1 and 64 characters" }, 422);
}
- const patch: { level?: number; charging?: boolean; lowPowerMode?: boolean; wifi?: string } = {};
+ const patch: { level?: number; charging?: boolean; lowPowerMode?: boolean; wifi?: string; watch?: boolean; airpods?: boolean } = {};
const levelRaw = c.req.query("level");
if (levelRaw !== undefined) {
@@ -73,6 +75,18 @@ deviceRoutes.post("/", verifyBatteryAccess, async (c) => {
patch.wifi = wifi;
}
+ const watch = parseFlag(c.req.query("watch"));
+ if (watch === null) {
+ return c.json({ detail: "Query param 'watch' must be 1 (true) or 0 (false)" }, 422);
+ }
+ if (watch !== undefined) patch.watch = watch;
+
+ const airpods = parseFlag(c.req.query("airpods"));
+ if (airpods === null) {
+ return c.json({ detail: "Query param 'airpods' must be 1 (true) or 0 (false)" }, 422);
+ }
+ if (airpods !== undefined) patch.airpods = airpods;
+
const record = await setDeviceLevel(device, patch);
broadcastDeviceUpdate(record);
return c.json({ success: true, ...record });
diff --git a/src/system/services/devices.ts b/src/system/services/devices.ts
index 668f11a..fa79573 100644
--- a/src/system/services/devices.ts
+++ b/src/system/services/devices.ts
@@ -13,11 +13,13 @@ interface DeviceRecord {
charging?: boolean;
lowPowerMode?: boolean;
wifi?: string;
+ watch?: boolean;
+ airpods?: boolean;
updated_at: string;
}
/** Fields a caller may set. All optional — only provided fields are updated. */
-type DevicePatch = Pick<DeviceRecord, "level" | "charging" | "lowPowerMode" | "wifi">;
+type DevicePatch = Pick<DeviceRecord, "level" | "charging" | "lowPowerMode" | "wifi" | "watch" | "airpods">;
type DevicesMap = Record<string, DeviceRecord>;
@@ -50,6 +52,8 @@ export async function setDeviceLevel(
...(patch.charging !== undefined ? { charging: patch.charging } : {}),
...(patch.lowPowerMode !== undefined ? { lowPowerMode: patch.lowPowerMode } : {}),
...(patch.wifi !== undefined ? { wifi: patch.wifi } : {}),
+ ...(patch.watch !== undefined ? { watch: patch.watch } : {}),
+ ...(patch.airpods !== undefined ? { airpods: patch.airpods } : {}),
updated_at: new Date().toISOString(),
};