changeset 22:178e020289c1

'full' button; other clean up
author drewp@bigasterisk.com
date Mon, 29 Jan 2024 13:01:23 -0800
parents b8201490c731
children 7d9a056e29fe
files light.py src/main.ts
diffstat 2 files changed, 8 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/light.py	Mon Jan 29 12:27:08 2024 -0800
+++ b/light.py	Mon Jan 29 13:01:23 2024 -0800
@@ -102,6 +102,8 @@
     _d: dict[str, Light] = {}
 
     def __init__(self, mqtt: MqttIo):
+        # todo: combine mqtt, aiohttp session, and pigpiod client into some
+        # Transports object
         self.mqtt = mqtt
 
         self.add(makeZbBar(mqtt, 'do-bar', '0xa4c13844948d2da4'))
--- a/src/main.ts	Mon Jan 29 12:27:08 2024 -0800
+++ b/src/main.ts	Mon Jan 29 13:01:23 2024 -0800
@@ -86,7 +86,7 @@
       </table>
       <p>Updated ${this.reportTime.toLocaleString("sv")}</p>
       <p>
-        <a href="metrics">metrics</a> |
+        <a href="metrics">metrics</a> | <a href="https://bigasterisk.com/code/light-bridge/files/tip/">code</a> |
         <a href="api/graph">graph</a>
       </p>
       <bigast-loginbar></bigast-loginbar>
@@ -112,8 +112,9 @@
         <td class="col-group-1"><code>${this.renderLinked(d.address)}</code></td>
         <td class="col-group-2">
           <code>${d.requestingColor}</code>
-          <input type="color" @input=${this.onRequestingColor.bind(this, d.name)} .value="${d.requestingColor}" />
-          <button @click=${this.onZero.bind(this, d.name)}>off</button>
+          <input type="color" @input=${this.onRequestingColor.bind(this, d.name, null)} .value="${d.requestingColor}" />
+          <button @click=${this.onRequestingColor.bind(this, d.name, "#000000")}>off</button>
+          <button @click=${this.onRequestingColor.bind(this, d.name, "#ffffff")}>full</button>
         </td>
         <td class="col-group-2 opt"><code>${JSON.stringify(d.requestingDeviceColor)}</code></td>
         <td class="col-group-3">${d.emittingColor} <span class="color" style="background: ${d.emittingColor}"></span></td>
@@ -131,19 +132,9 @@
     return addr;
   }
 
-  async onRequestingColor(lightName: string, ev: InputEvent) {
+  async onRequestingColor(lightName: string, preset: string | null, ev: InputEvent) {
     const currentRequest = this.lightByName.get(lightName)!.requestingColor;
-    const value = (ev.target as HTMLInputElement).value;
-    this.onCol(value, currentRequest, lightName);
-  }
-  
-  async onZero(lightName: string, ev: InputEvent) {
-    const currentRequest = this.lightByName.get(lightName)!.requestingColor;
-    const value = "#000000";
-    this.onCol(value, currentRequest, lightName);
-  }
-
-  private onCol(value: string, currentRequest: string, lightName: string) {
+    const value = preset || (ev.target as HTMLInputElement).value;
     console.log("LbPage ~ onRequestingColor ~ value === currentRequest:", value, currentRequest);
     if (value === currentRequest) {
       return;