Mercurial > code > home > repos > light-bridge
diff protocols.py @ 26:33b3eb24506e
wled (single bulb) support. more lights
author | drewp@bigasterisk.com |
---|---|
date | Sat, 03 Feb 2024 20:56:27 -0800 |
parents | 7d9a056e29fe |
children | fb2e91f230f4 |
line wrap: on
line diff
--- a/protocols.py Fri Feb 02 20:52:09 2024 -0800 +++ b/protocols.py Sat Feb 03 20:56:27 2024 -0800 @@ -51,7 +51,7 @@ def espColorMessage(dc: DeviceColor) -> dict: return { - "state":'ON', + "state": 'ON', "color": { "r": to8(dc.r), "g": to8(dc.g), @@ -116,6 +116,21 @@ # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} +class WledTransport(_WebTransport): + + async def send(self, dc: DeviceColor): + # see https://kno.wled.ge/interfaces/json-api/ + msg = { + 'seg': [{ + "cct": 128, # 0 warm; 255 cool + "col": [[to8(x) for x in [dc.r, dc.g, dc.b, dc.cw]], [], []] + }] + } + async with self._session.post(f'http://{self.hostname}/json/state', headers={'content-type': 'application/json'}, data=json.dumps(msg)) as resp: + await resp.text() + # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} + + class ShellyGen1WebTransport(_WebTransport): async def send(self, dc: DeviceColor):