diff light.py @ 13:1c865af058e7

start make* funcs and add links to light addresses
author drewp@bigasterisk.com
date Sun, 28 Jan 2024 20:03:20 -0800
parents 7cc004eafb82
children e3dbd04dab96
line wrap: on
line diff
--- 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