Mercurial > code > home > repos > light-bridge
diff light.py @ 15:61d4ccecfed8
rough refactor
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 21:18:01 -0800 |
parents | e3dbd04dab96 |
children | 1d15dc4d673f |
line wrap: on
line diff
--- a/light.py Sun Jan 28 20:49:42 2024 -0800 +++ b/light.py Sun Jan 28 21:18:01 2024 -0800 @@ -10,52 +10,6 @@ log = logging.getLogger('light') -@dataclass(frozen=True) -class DeviceColor: - """neutral representation of the adjusted color that we send to a device""" - r: float = 0 - g: float = 0 - b: float = 0 - w: float = 0 - x: float = 0 - y: float = 0 - - def summary(self) -> dict: - return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0]) - - -class Transport: - - def linked(self): - return {'label': str(self)} - - async def send(self, dc: DeviceColor): - raise TypeError - - -def zigbeeHexMessage(color: DeviceColor, bw=False) -> dict: - bright = max(color.r, color.g, color.b) - msg: dict = {"transition": 0, "brightness": int(255 * bright)} - if not bw: - c = "#%02x%02x%02x" % (int(color.r * 255), int(color.g * 255), int(color.b * 255)) - msg["color"] = {"hex": c} - return msg - - -class ZigbeeTransport(Transport): - - def __init__(self, mqtt: MqttIo, name: str, ieee: str): - self.mqtt = mqtt - self.name = name - self.ieee = ieee - - def linked(self): - return {'url': f'https://bigasterisk.com/zigbee/console/#/device/{self.ieee}/info', 'label': 'do-bar'} - - async def send(self, dc: DeviceColor): - await self.mqtt.publish(f'zigbee/{self.name}/set', json.dumps(zigbeeHexMessage(dc, bw=False))) - - @dataclass class Light: name: str