Mercurial > code > home > repos > light-bridge
comparison protocols.py @ 23:7d9a056e29fe
esp rgbw output; cleanup
author | drewp@bigasterisk.com |
---|---|
date | Mon, 29 Jan 2024 23:41:27 -0800 |
parents | b8201490c731 |
children | 33b3eb24506e |
comparison
equal
deleted
inserted
replaced
22:178e020289c1 | 23:7d9a056e29fe |
---|---|
42 "transition": 0, | 42 "transition": 0, |
43 "brightness": to8(dc.brightness), | 43 "brightness": to8(dc.brightness), |
44 # temperature todo | 44 # temperature todo |
45 } | 45 } |
46 | 46 |
47 | |
47 def zbRelayMessage(dc: DeviceColor) -> dict: | 48 def zbRelayMessage(dc: DeviceColor) -> dict: |
48 return {'state': 'ON' if dc.brightness else 'OFF'} | 49 return {'state': 'ON' if dc.brightness else 'OFF'} |
49 | 50 |
51 | |
52 def espColorMessage(dc: DeviceColor) -> dict: | |
53 return { | |
54 "state":'ON', | |
55 "color": { | |
56 "r": to8(dc.r), | |
57 "g": to8(dc.g), | |
58 "b": to8(dc.b), | |
59 "w": to8(dc.w) | |
60 }, | |
61 } | |
62 | |
63 | |
50 def z2mSet(name): | 64 def z2mSet(name): |
51 return f'zigbee/{name}/set' | 65 return f'zigbee/{name}/set' |
66 | |
52 | 67 |
53 class ZigbeeTransport(Transport): | 68 class ZigbeeTransport(Transport): |
54 | 69 |
55 def __init__(self, mqtt: MqttIo, name: str, ieee: str, topic=z2mSet, msg=zbColorMessage): | 70 def __init__(self, mqtt: MqttIo, name: str, ieee: str, topic=z2mSet, msg=zbColorMessage): |
56 self.mqtt = mqtt | 71 self.mqtt = mqtt |
57 self.name = name | 72 self.name = name |
58 self.ieee = ieee | 73 self.ieee = ieee |
59 self.topic=topic | 74 self.topic = topic |
60 self.msg = msg | 75 self.msg = msg |
61 | 76 |
62 def linked(self): | 77 def linked(self): |
63 return {'url': f'https://bigasterisk.com/zigbee/console/#/device/{self.ieee}/info', 'label': self.name} | 78 return {'url': f'https://bigasterisk.com/zigbee/console/#/device/{self.ieee}/info', 'label': self.name} |
64 | 79 |
93 | 108 |
94 | 109 |
95 class TasmotaWebTransport(_WebTransport): | 110 class TasmotaWebTransport(_WebTransport): |
96 | 111 |
97 async def send(self, dc: DeviceColor): | 112 async def send(self, dc: DeviceColor): |
98 cmnd = 'Color ' + ','.join(str(int(x * 255)) for x in (dc.r, dc.g, dc.b, dc.cw, dc.ww)) | 113 cmnd = 'Color ' + ','.join(str(to8(x)) for x in (dc.r, dc.g, dc.b, dc.cw, dc.ww)) |
99 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: |
100 await resp.text() | 115 await resp.text() |
101 # {"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]} |
102 | 117 |
103 | 118 |
104 class ShellyGen1WebTransport(_WebTransport): | 119 class ShellyGen1WebTransport(_WebTransport): |
105 | 120 |
106 async def send(self, dc: DeviceColor): | 121 async def send(self, dc: DeviceColor): |
107 # also see https://shelly-api-docs.shelly.cloud/gen1/#shelly-rgbw2-color-status for metrics | 122 # also see https://shelly-api-docs.shelly.cloud/gen1/#shelly-rgbw2-color-status for metrics |
108 async with self._session.get(f'http://{self.hostname}/light/0', | 123 async with self._session.get(f'http://{self.hostname}/light/0', params={ |
109 params={ | 124 'red': to8(dc.r), |
110 'red': int(dc.r * 255), | 125 'green': to8(dc.g), |
111 'green': int(dc.g * 255), | 126 'blue': to8(dc.b), |
112 'blue': int(dc.b * 255), | 127 'white': to8(dc.w), |
113 'white': int(dc.w * 255), | 128 }) as resp: |
114 }) as resp: | |
115 await resp.text() | 129 await resp.text() |
116 # {..."mode":"color","red":255,"green":242,"blue":0,"white":255,"gain":59,"effect":0,"transition":0,"power":18.00,"overpower":false} | 130 # {..."mode":"color","red":255,"green":242,"blue":0,"white":255,"gain":59,"effect":0,"transition":0,"power":18.00,"overpower":false} |