# HG changeset patch # User drewp@bigasterisk.com # Date 1706501000 28800 # Node ID 1c865af058e789f4d3637b6614257a8c528026b6 # Parent 7cc004eafb82389a38e8271e6e0cc1754a8a428d start make* funcs and add links to light addresses diff -r 7cc004eafb82 -r 1c865af058e7 light.py --- a/light.py Sun Jan 28 20:02:34 2024 -0800 +++ b/light.py Sun Jan 28 20:03:20 2024 -0800 @@ -1,6 +1,6 @@ import asyncio import logging -from dataclasses import dataclass, field +from dataclasses import dataclass from typing import Callable from color import Color @@ -22,10 +22,26 @@ return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0]) +class Address: + + def linked(self): + return {'label': str(self)} + + +class ZigbeeAddress(Address): + + def __init__(self, name: str, ieee: str): + self.name = name + self.ieee = ieee + + def linked(self): + return {'url': f'https://bigasterisk.com/zigbee/console/#/device/{self.ieee}/info', 'label': 'do-bar'} + + @dataclass class Light: name: str - address: str + address: Address requestingColor: Color = Color.fromHex('#000000') requestingDeviceColor: DeviceColor = DeviceColor() @@ -42,7 +58,7 @@ def to_dict(self): d = { 'name': self.name, - 'address': self.address, + 'address': self.address.linked(), 'requestingColor': self.requestingColor.hex(), 'requestingDeviceColor': self.requestingDeviceColor.summary(), 'emittingColor': self.emittingColor.hex(), @@ -66,12 +82,15 @@ self.notifyChanged() +def makeZbBar(name: str, ieee: str) -> Light: + return Light(name=name, address=ZigbeeAddress(name, ieee)) + + class Lights: _d: dict[str, Light] = {} def __init__(self): - self.add(Light('do-desk', 'topic1')) - self.add(Light('do-desk2', 'topic2')) + self.add(makeZbBar('do-bar', '0xa4c13844948d2da4')) def add(self, d: Light): d.notifyChanged = self.notifyChanged diff -r 7cc004eafb82 -r 1c865af058e7 src/main.ts --- a/src/main.ts Sun Jan 28 20:02:34 2024 -0800 +++ b/src/main.ts Sun Jan 28 20:03:20 2024 -0800 @@ -1,9 +1,9 @@ -import { LitElement, css, html } from "lit"; +import { LitElement, TemplateResult, css, html } from "lit"; import { customElement, state } from "lit/decorators.js"; interface Light { name: string; - address: string; + address: { url?: string; label: string }; requestingColor: string; requestingDeviceColor: object; emittingColor: string; @@ -57,6 +57,7 @@ super.connectedCallback(); const es = new EventSource("api/table"); es.onmessage = (ev) => { + console.log("got table update"); const body = JSON.parse(ev.data); this.lights = body.lights.map((wrappedLight: any) => wrappedLight.light as Light); this.rebuildLightByName(); @@ -75,22 +76,6 @@

Light-bridge

- ${this.lights.map( - (d: Light) => html` - - - - - - - - - - ` - )} ${this.renderLightHeaders()} ${this.lights.map(this.renderLightRow.bind(this))}
${d.name}${d.address} - ${d.requestingColor} - - ${JSON.stringify(d.requestingDeviceColor)}${d.emittingColor} ${d.online ? "✔" : ""}${d.latencyMs} ms

Updated ${this.reportTime.toLocaleString("sv")}

@@ -113,6 +98,32 @@ latency `; } + + renderLightRow(d: Light) { + return html` + + ${d.name} + ${this.renderLinked(d.address)} + + ${d.requestingColor} + + + ${JSON.stringify(d.requestingDeviceColor)} + ${d.emittingColor} + ${d.online ? "✔" : ""} + ${d.latencyMs} ms + + `; + } + + private renderLinked(link: { url?: string; label: string }): TemplateResult { + var addr = html`${link.label}`; + if (link.url) { + addr = html`${addr}`; + } + return addr; + } + async onRequestingColor(lightName: string, ev: InputEvent) { const currentRequest = this.lightByName.get(lightName)!.requestingColor; const value = (ev.target as HTMLInputElement).value;