From 4c5db49c615c635671bd37381b6ff14125002c16 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Thu, 13 Jan 2022 19:20:33 +0100 Subject: [PATCH] mqtt integration --- espmusicmouse/host_driver/main.py | 3 +++ espmusicmouse/host_driver/mqtt.py | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/espmusicmouse/host_driver/main.py b/espmusicmouse/host_driver/main.py index 0deff1f..3a5c6ca 100755 --- a/espmusicmouse/host_driver/main.py +++ b/espmusicmouse/host_driver/main.py @@ -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 diff --git a/espmusicmouse/host_driver/mqtt.py b/espmusicmouse/host_driver/mqtt.py index e46a69b..ada5dae 100644 --- a/espmusicmouse/host_driver/mqtt.py +++ b/espmusicmouse/host_driver/mqtt.py @@ -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))