Mercurial > code > home > repos > light-bridge
comparison protocols.py @ 28:fb2e91f230f4
new wled mode and more lights
author | drewp@bigasterisk.com |
---|---|
date | Mon, 02 Sep 2024 20:00:53 -0700 |
parents | 33b3eb24506e |
children |
comparison
equal
deleted
inserted
replaced
27:32cfefe3155b | 28:fb2e91f230f4 |
---|---|
1 import json | |
1 import logging | 2 import logging |
2 import json | 3 from enum import Enum |
4 | |
3 import aiohttp | 5 import aiohttp |
6 | |
4 from color_convert import DeviceColor | 7 from color_convert import DeviceColor |
5 from mqtt_io import MqttIo | 8 from mqtt_io import MqttIo |
6 | 9 |
7 log = logging.getLogger('prot') | 10 log = logging.getLogger('prot') |
8 | 11 |
114 async with self._session.get(f'http://{self.hostname}/cm', params={'cmnd': cmnd}) as resp: | 117 async with self._session.get(f'http://{self.hostname}/cm', params={'cmnd': cmnd}) as resp: |
115 await resp.text() | 118 await resp.text() |
116 # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} | 119 # {"POWER":"ON","Dimmer":21,"Color":"3636363600","HSBColor":"0,0,21","White":21,"CT":153,"Channel":[21,21,21,21,0]} |
117 | 120 |
118 | 121 |
122 class WledControl(Enum): | |
123 wholeStringColor = 'wholeStringColor' | |
124 brightness = 'brightness' | |
125 | |
126 | |
119 class WledTransport(_WebTransport): | 127 class WledTransport(_WebTransport): |
120 | 128 |
129 def __init__(self, hostname: str, control: WledControl): | |
130 super().__init__(hostname) | |
131 self.control = control | |
132 | |
121 async def send(self, dc: DeviceColor): | 133 async def send(self, dc: DeviceColor): |
122 # see https://kno.wled.ge/interfaces/json-api/ | 134 if self.control == WledControl.wholeStringColor: |
123 msg = { | 135 # see https://kno.wled.ge/interfaces/json-api/ |
124 'seg': [{ | 136 msg = { |
125 "cct": 128, # 0 warm; 255 cool | 137 'seg': [{ |
126 "col": [[to8(x) for x in [dc.r, dc.g, dc.b, dc.cw]], [], []] | 138 "cct": 128, # 0 warm; 255 cool |
127 }] | 139 "col": [[to8(x) for x in [dc.r, dc.g, dc.b, dc.cw]], [], []] |
128 } | 140 }] |
141 } | |
142 elif self.control == WledControl.brightness: | |
143 msg = {"bri": to8(dc.brightness)} | |
144 else: | |
145 raise NotImplementedError | |
129 async with self._session.post(f'http://{self.hostname}/json/state', headers={'content-type': 'application/json'}, data=json.dumps(msg)) as resp: | 146 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() | 147 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 | 148 |
133 | 149 |
134 class ShellyGen1WebTransport(_WebTransport): | 150 class ShellyGen1WebTransport(_WebTransport): |
135 | 151 |
136 async def send(self, dc: DeviceColor): | 152 async def send(self, dc: DeviceColor): |