mqtt integration
This commit is contained in:
parent
1458793d74
commit
4c5db49c61
|
@ -17,6 +17,7 @@ from ruamel.yaml import YAML
|
|||
import warnings
|
||||
from pprint import pprint
|
||||
from typing import Optional
|
||||
from mqtt import start_mqtt
|
||||
|
||||
yaml = YAML(typ='safe')
|
||||
|
||||
|
@ -252,6 +253,8 @@ def main(config_path):
|
|||
baudrate=115200)
|
||||
transport, protocol = loop.run_until_complete(coro)
|
||||
controller = Controller(protocol, hass, cfg)
|
||||
mqtt_cfg = cfg["general"]["mqtt"]
|
||||
loop.create_task(start_mqtt(protocol, mqtt_cfg["server"], mqtt_cfg["user"],mqtt_cfg["password"] ))
|
||||
loop.create_task(hass.connect())
|
||||
return controller, loop
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from led_cmds import ColorRGBW, EffectStaticConfig, EffectCircularConfig, EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig
|
||||
from led_cmds import ColorRGBW, EffectStaticConfig, EffectCircularConfig, EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig, EffectSwipeAndChange
|
||||
import asyncio
|
||||
import asyncio_mqtt
|
||||
import json
|
||||
|
||||
BRIGHTNESS_SCALE = 0.4 # power supply is a bit weak -> scale brightness down globally
|
||||
BRIGHTNESS_SCALE = 1 # power supply is a bit weak -> scale brightness down globally
|
||||
|
||||
|
||||
class ShelveLightMqtt:
|
||||
|
@ -62,18 +62,20 @@ class ShelveLightMqtt:
|
|||
elif self._effect == "circular":
|
||||
eff = EffectCircularConfig()
|
||||
eff.color = self._color
|
||||
elif self._effect == "wipe-up":
|
||||
eff = EffectAlexaSwipeConfig()
|
||||
eff.secondary_color = self._color
|
||||
eff.primary_color = self._last_color
|
||||
eff.bell_curve_width_in_leds = 5
|
||||
eff.swipe_speed = 180
|
||||
elif self._effect == "two-color":
|
||||
elif self._effect == "wipeup":
|
||||
eff = EffectSwipeAndChange()
|
||||
eff.swipe.secondary_color = self._color
|
||||
eff.swipe.primary_color = self._last_color
|
||||
eff.swipe.bell_curve_width_in_leds = 5
|
||||
eff.swipe.swipe_speed = 180
|
||||
eff.change.color1 = self._color
|
||||
eff.change.color2 = self._last_color
|
||||
elif self._effect == "twocolor":
|
||||
eff = EffectRandomTwoColorInterpolationConfig()
|
||||
eff.color1 = self._color
|
||||
eff.color2 = self._last_color
|
||||
eff.start_with_existing = True
|
||||
elif self._effect == "two-color-random":
|
||||
elif self._effect == "twocolorrandom":
|
||||
eff = EffectRandomTwoColorInterpolationConfig()
|
||||
eff.color1 = self._color
|
||||
eff.color2 = self._last_color
|
||||
|
@ -128,7 +130,7 @@ class ShelveLightMqtt:
|
|||
'rgb_state_topic': f'{base_name}/lights_{id}/rgb_state',
|
||||
'effect_command_topic': f'{base_name}/lights_{id}/effect',
|
||||
'effect_state_topic': f'{base_name}/lights_{id}/effect_state',
|
||||
'effect_list': ['static', 'circular', 'wipe-up', 'two-color', 'two-color-random'],
|
||||
'effect_list': ['static', 'circular', 'wipeup', 'twocolor', 'twocolorrandom'],
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,5 +150,5 @@ if __name__ == "__main__":
|
|||
def shelve_led_effect(self, effect):
|
||||
print("EFF ", repr(effect))
|
||||
|
||||
password = "pw"
|
||||
password = "KNLEFLZF94yA6Zhj141"
|
||||
asyncio.run(start_mqtt(DummyProtocol(), "homeassistant", "musicmouse", password))
|
||||
|
|
Loading…
Reference in New Issue