# HG changeset patch # User drewp@bigasterisk.com # Date 1706485434 28800 # Node ID 42a494b8ee1aed25262ac786f4a34e9c4816ab88 # Parent 5a77696c6dabfcf5745b8865992c9da871e43f5e show report time diff -r 5a77696c6dab -r 42a494b8ee1a light_bridge.py --- a/light_bridge.py Sun Jan 28 15:32:18 2024 -0800 +++ b/light_bridge.py Sun Jan 28 15:43:54 2024 -0800 @@ -6,6 +6,7 @@ from functools import partial import json import logging +import time import background_loop from patchablegraph import PatchableGraph @@ -81,8 +82,8 @@ async def g(): async for ping in lights.changes(): - yield json.dumps(lights.to_js()) await asyncio.sleep(1) + yield json.dumps({'now': time.time()} | lights.to_js()) return EventSourceResponse(g()) diff -r 5a77696c6dab -r 42a494b8ee1a src/main.ts --- a/src/main.ts Sun Jan 28 15:32:18 2024 -0800 +++ b/src/main.ts Sun Jan 28 15:43:54 2024 -0800 @@ -29,12 +29,15 @@ `, ]; @state() lights: object[] = []; + @state() reportTime: Date; connectedCallback(): void { super.connectedCallback(); const es = new EventSource("api/table"); es.onmessage = (ev) => { - this.lights = JSON.parse(ev.data).lights; + const body = JSON.parse(ev.data); + this.lights = body.lights; + this.reportTime = new Date(body.now * 1000); }; } render() { @@ -68,6 +71,7 @@ ` )} +
Updated ${this.reportTime.toLocaleString("sv")}