Mercurial > code > home > repos > light-bridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
25:cee43f550577 | 26:33b3eb24506e |
---|---|
49 return {'state': 'ON' if dc.brightness else 'OFF'} | 49 return {'state': 'ON' if dc.brightness else 'OFF'} |
50 | 50 |
51 | 51 |
52 def espColorMessage(dc: DeviceColor) -> dict: | 52 def espColorMessage(dc: DeviceColor) -> dict: |
53 return { | 53 return { |
54 "state":'ON', | 54 "state": 'ON', |
55 "color": { | 55 "color": { |
56 "r": to8(dc.r), | 56 "r": to8(dc.r), |
57 "g": to8(dc.g), | 57 "g": to8(dc.g), |
58 "b": to8(dc.b), | 58 "b": to8(dc.b), |
59 "w": to8(dc.w) | 59 "w": to8(dc.w) |
114 async with self._session.get(f'http://{self.hostname}/cm', params={'cmnd': cmnd}) as resp: | 114 async with self._session.get(f'http://{self.hostname}/cm', params={'cmnd': cmnd}) as resp: |
115 await resp.text() | 115 await resp.text() |
116 # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} | 116 # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} |
117 | 117 |
118 | 118 |
119 class WledTransport(_WebTransport): | |
120 | |
121 async def send(self, dc: DeviceColor): | |
122 # see https://kno.wled.ge/interfaces/json-api/ | |
123 msg = { | |
124 'seg': [{ | |
125 "cct": 128, # 0 warm; 255 cool | |
126 "col": [[to8(x) for x in [dc.r, dc.g, dc.b, dc.cw]], [], []] | |
127 }] | |
128 } | |
129 async with self._session.post(f'http://{self.hostname}/json/state', headers={'content-type': 'application/json'}, data=json.dumps(msg)) as resp: | |
130 await resp.text() | |
131 # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} | |
132 | |
133 | |
119 class ShellyGen1WebTransport(_WebTransport): | 134 class ShellyGen1WebTransport(_WebTransport): |
120 | 135 |
121 async def send(self, dc: DeviceColor): | 136 async def send(self, dc: DeviceColor): |
122 # also see https://shelly-api-docs.shelly.cloud/gen1/#shelly-rgbw2-color-status for metrics | 137 # also see https://shelly-api-docs.shelly.cloud/gen1/#shelly-rgbw2-color-status for metrics |
123 async with self._session.get(f'http://{self.hostname}/light/0', params={ | 138 async with self._session.get(f'http://{self.hostname}/light/0', params={ |