Mercurial > code > home > repos > light-bridge
comparison light.py @ 21:b8201490c731
more light types
author | drewp@bigasterisk.com |
---|---|
date | Mon, 29 Jan 2024 12:27:08 -0800 |
parents | 24a574108365 |
children | 178e020289c1 |
comparison
equal
deleted
inserted
replaced
20:24a574108365 | 21:b8201490c731 |
---|---|
2 import logging | 2 import logging |
3 from dataclasses import dataclass | 3 from dataclasses import dataclass |
4 from typing import Callable | 4 from typing import Callable |
5 | 5 |
6 from color import Color | 6 from color import Color |
7 from color_convert import DeviceColor, oneWhiteConv, relayConv, twoWhitesConv, zbConv | 7 from color_convert import DeviceColor, brightnessConv, ikeaWhiteConv, oneWhiteConv, relayConv, twoWhitesConv, zbConv |
8 from mqtt_io import MqttIo | 8 from mqtt_io import MqttIo |
9 from protocols import ShellyGen1WebTransport, SonoffRelayTransport, TasmotaWebTransport, Transport, ZigbeeTransport | 9 from protocols import ShellyGen1WebTransport, SonoffRelayTransport, TasmotaWebTransport, Transport, ZigbeeTransport, zbBrightnessMessage, zbRelayMessage, zbWhiteSpectrumMessage |
10 | 10 |
11 log = logging.getLogger('lite') | 11 log = logging.getLogger('lite') |
12 | 12 |
13 | 13 |
14 @dataclass | 14 @dataclass |
78 | 78 |
79 def makeSonoffRelay(mqtt: MqttIo, name: str, topic: str) -> Light: | 79 def makeSonoffRelay(mqtt: MqttIo, name: str, topic: str) -> Light: |
80 return Light(name=name, convertColor=relayConv, transport=SonoffRelayTransport(mqtt, topic)) | 80 return Light(name=name, convertColor=relayConv, transport=SonoffRelayTransport(mqtt, topic)) |
81 | 81 |
82 | 82 |
83 def makeZbIkeaWhiteTemp(mqtt: MqttIo, name: str, ieee: str) -> Light: | |
84 return Light(name=name, convertColor=ikeaWhiteConv, transport=ZigbeeTransport(mqtt, name, ieee, msg=zbWhiteSpectrumMessage)) | |
85 | |
86 | |
87 def makeZbBrightness(mqtt: MqttIo, name: str, ieee: str) -> Light: | |
88 return Light(name=name, convertColor=brightnessConv, transport=ZigbeeTransport(mqtt, name, ieee, msg=zbBrightnessMessage)) | |
89 | |
90 | |
91 def makeZbRelay(mqtt: MqttIo, name: str, ieee: str) -> Light: | |
92 return Light(name=name, convertColor=relayConv, transport=ZigbeeTransport(mqtt, name, ieee, msg=zbRelayMessage)) | |
93 | |
94 | |
95 def makeEspBrightness(mqtt: MqttIo, name: str, topicPrefix: str) -> Light: | |
96 return Light(name=name, | |
97 convertColor=brightnessConv, | |
98 transport=ZigbeeTransport(mqtt, name, '', topic=lambda *arg: topicPrefix + '/command', msg=zbBrightnessMessage)) | |
99 | |
100 | |
83 class Lights: | 101 class Lights: |
84 _d: dict[str, Light] = {} | 102 _d: dict[str, Light] = {} |
85 | 103 |
86 def __init__(self, mqtt: MqttIo): | 104 def __init__(self, mqtt: MqttIo): |
87 self.mqtt = mqtt | 105 self.mqtt = mqtt |
88 | 106 |
89 self.add(makeZbBar(mqtt, 'do-bar', '0xa4c13844948d2da4')) | 107 self.add(makeZbBar(mqtt, 'do-bar', '0xa4c13844948d2da4')) |
90 self.add(makeTasmota('do-lamp', 'tasmota-9E2AB7-2743')) | 108 self.add(makeTasmota('do-lamp', 'tasmota-9E2AB7-2743')) |
109 self.add(makeTasmota('li-high-shelf', 'light-li-ceil')) | |
110 self.add(makeTasmota('tr-door', 'light-tr-door')) | |
91 self.add(makeShellyRGW2('ki-ceiling', 'shellyrgbw2-e868e7f34c35')) | 111 self.add(makeShellyRGW2('ki-ceiling', 'shellyrgbw2-e868e7f34c35')) |
92 self.add(makeShellyRGW2('ki-counter', 'shellyrgbw2-e868e7f34cb2')) | 112 self.add(makeShellyRGW2('ki-counter', 'shellyrgbw2-e868e7f34cb2')) |
93 # br-floor online=online | metric=1 (graph) lqi=93 bright=12 | |
94 # br-wall online=online | metric=1 (graph) lqi=30 bright=0 | |
95 | 113 |
96 # en online=online | metric=1 (graph) lqi=36 bright=216 | 114 self.add(makeZbIkeaWhiteTemp(mqtt, 'br-floor', '0x000b57fffedabd20')) |
97 # ft-ceil online=online | metric=1 (graph) lqi=96 bright=252 | 115 self.add(makeZbIkeaWhiteTemp(mqtt, 'br-wall', '0x14b457fffe2dab6e')) |
98 # go-high online=online | metric=1 (graph) lqi=93 bright=253 | 116 self.add(makeZbIkeaWhiteTemp(mqtt, 'en', '0x000b57fffe988959')) |
99 # li-toys online=online | metric=1 (graph) lqi=96 bright=28 | 117 self.add(makeZbIkeaWhiteTemp(mqtt, 'py', '0x000b57fffeaf42cd')) |
100 # py online=online | metric=1 (graph) lqi=93 bright=216 | 118 self.add(makeZbIkeaWhiteTemp(mqtt, 'rr-lamp', '0x000b57fffe32e5a5')) |
101 # rr-lamp online=offline | metric=0 (graph) lqi=... bright=... | |
102 # sh-top online=online | metric=1 (graph) lqi=93 bright=254 | |
103 # ws-hanging online=online | metric=1 (graph) lqi=39 bright=... | |
104 # light-li-high-shelf uptimesec=2232334 wifi=-65 dim=100 color=0000002FD0 | |
105 # light-sh uptimesec=... wifi=... dim=... color=... | |
106 # light-tr-wall uptimesec=5082251 wifi=-38 dim=34 color=5700000000 | |
107 | 119 |
108 # wled-ft-hanging offline #FFA000 bright=128 | 120 self.add(makeZbBrightness(mqtt, 'go-high', '0x847127fffebb3efa')) |
109 # string-tr online #8CFF82 bright=128 | 121 |
110 # light-tr-ball online #808A03 bright=12 | 122 self.add(makeZbRelay(mqtt, 'ws-hanging', '0xd0cf5efffe720b46')) |
111 # string-hr online #C9FFDC bright=131 | |
112 | 123 |
113 self.add(makeSonoffRelay(mqtt, 'li-lamp0', 'sonoff_0')) | 124 self.add(makeSonoffRelay(mqtt, 'li-lamp0', 'sonoff_0')) |
114 self.add(makeSonoffRelay(mqtt, 'li-lamp1', 'sonoff_1')) | 125 self.add(makeSonoffRelay(mqtt, 'li-lamp1', 'sonoff_1')) |
115 self.add(makeSonoffRelay(mqtt, 'li-lamp2', 'sonoff_2')) | 126 self.add(makeSonoffRelay(mqtt, 'li-lamp2', 'sonoff_2')) |
116 self.add(makeSonoffRelay(mqtt, 'li-lamp3', 'sonoff_3')) | 127 self.add(makeSonoffRelay(mqtt, 'li-lamp3', 'sonoff_3')) |
117 self.add(makeSonoffRelay(mqtt, 'li-lamp4', 'sonoff_4')) | 128 self.add(makeSonoffRelay(mqtt, 'li-lamp4', 'sonoff_4')) |
129 | |
130 self.add(makeEspBrightness(mqtt, 'ws-high0', 'workshop/light/high0')) | |
131 self.add(makeEspBrightness(mqtt, 'ws-high1', 'workshop/light/high1')) | |
132 self.add(makeEspBrightness(mqtt, 'ws-high2', 'workshop/light/high2')) | |
133 self.add(makeEspBrightness(mqtt, 'ws-high3', 'workshop/light/high3')) | |
134 self.add(makeEspBrightness(mqtt, 'ws-kid', 'workshop/light/kid')) | |
135 self.add(makeEspBrightness(mqtt, 'ws-sewing', 'workshop/light/sewing')) | |
136 | |
137 # ft-ceil | |
138 # li-toys | |
139 # sh-top | |
140 # light-sh | |
141 # ga-hanging | |
142 | |
143 # wled: | |
144 # string-tr | |
145 # string-hr | |
146 # light-tr-ball | |
147 # wled-ft-hanging | |
118 | 148 |
119 def add(self, d: Light): | 149 def add(self, d: Light): |
120 d.notifyChanged = self.notifyChanged | 150 d.notifyChanged = self.notifyChanged |
121 self._d[d.name] = d | 151 self._d[d.name] = d |
122 | 152 |