Mercurial > code > home > repos > light-bridge
changeset 1:42a494b8ee1a
show report time
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 15:43:54 -0800 |
parents | 5a77696c6dab |
children | c6fd04e07db0 |
files | light_bridge.py src/main.ts |
diffstat | 2 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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())
--- 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 @@ ` )} </table> + <p>Updated ${this.reportTime.toLocaleString("sv")}</p> <p> <a href="metrics">metrics</a> | <a href="api/graph">graph</a>