mqtt integration

This commit is contained in:
Martin Bauer 2022-01-13 19:20:33 +01:00
parent 1458793d74
commit 4c5db49c61
2 changed files with 17 additions and 12 deletions

View File

@ -17,6 +17,7 @@ from ruamel.yaml import YAML
import warnings import warnings
from pprint import pprint from pprint import pprint
from typing import Optional from typing import Optional
from mqtt import start_mqtt
yaml = YAML(typ='safe') yaml = YAML(typ='safe')
@ -252,6 +253,8 @@ def main(config_path):
baudrate=115200) baudrate=115200)
transport, protocol = loop.run_until_complete(coro) transport, protocol = loop.run_until_complete(coro)
controller = Controller(protocol, hass, cfg) 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()) loop.create_task(hass.connect())
return controller, loop return controller, loop

View File

@ -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
import asyncio_mqtt import asyncio_mqtt
import json 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: class ShelveLightMqtt:
@ -62,18 +62,20 @@ class ShelveLightMqtt:
elif self._effect == "circular": elif self._effect == "circular":
eff = EffectCircularConfig() eff = EffectCircularConfig()
eff.color = self._color eff.color = self._color
elif self._effect == "wipe-up": elif self._effect == "wipeup":
eff = EffectAlexaSwipeConfig() eff = EffectSwipeAndChange()
eff.secondary_color = self._color eff.swipe.secondary_color = self._color
eff.primary_color = self._last_color eff.swipe.primary_color = self._last_color
eff.bell_curve_width_in_leds = 5 eff.swipe.bell_curve_width_in_leds = 5
eff.swipe_speed = 180 eff.swipe.swipe_speed = 180
elif self._effect == "two-color": eff.change.color1 = self._color
eff.change.color2 = self._last_color
elif self._effect == "twocolor":
eff = EffectRandomTwoColorInterpolationConfig() eff = EffectRandomTwoColorInterpolationConfig()
eff.color1 = self._color eff.color1 = self._color
eff.color2 = self._last_color eff.color2 = self._last_color
eff.start_with_existing = True eff.start_with_existing = True
elif self._effect == "two-color-random": elif self._effect == "twocolorrandom":
eff = EffectRandomTwoColorInterpolationConfig() eff = EffectRandomTwoColorInterpolationConfig()
eff.color1 = self._color eff.color1 = self._color
eff.color2 = self._last_color eff.color2 = self._last_color
@ -128,7 +130,7 @@ class ShelveLightMqtt:
'rgb_state_topic': f'{base_name}/lights_{id}/rgb_state', 'rgb_state_topic': f'{base_name}/lights_{id}/rgb_state',
'effect_command_topic': f'{base_name}/lights_{id}/effect', 'effect_command_topic': f'{base_name}/lights_{id}/effect',
'effect_state_topic': f'{base_name}/lights_{id}/effect_state', '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): def shelve_led_effect(self, effect):
print("EFF ", repr(effect)) print("EFF ", repr(effect))
password = "pw" password = "KNLEFLZF94yA6Zhj141"
asyncio.run(start_mqtt(DummyProtocol(), "homeassistant", "musicmouse", password)) asyncio.run(start_mqtt(DummyProtocol(), "homeassistant", "musicmouse", password))