From 4d79156452db4dd757a04b510a5773f718501612 Mon Sep 17 00:00:00 2001 From: M0rroww Date: Tue, 18 Oct 2022 22:42:52 +0200 Subject: [PATCH 1/2] Add color selection for clock and weather --- README.md | 1 + custom_components/timebox_mini/__init__.py | 9 +++++++++ custom_components/timebox_mini/services.yaml | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index e867d64..ae40e40 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The Divoom Timebox Mini is a Bluetooth speaker with a 11x11 RGB LED matrix. This component allow to run the following actions on your Timebox Mini from a HomeAssistant service: - Set the clock automatically from your system clock - Display the clock +- Set the LED color of clock and weather - Set the audio volume level - Set the LED brightness level - Display the weather information (you have to use Divoom phone app to send weather info to your timebox) diff --git a/custom_components/timebox_mini/__init__.py b/custom_components/timebox_mini/__init__.py index 5ea68a4..cdd59d6 100755 --- a/custom_components/timebox_mini/__init__.py +++ b/custom_components/timebox_mini/__init__.py @@ -21,6 +21,7 @@ DOMAIN = "timebox_mini" ATTR_MAC = "mac_addr" ATTR_ACTION = "action" +ATTR_COLOR = "color" ATTR_IMAGE = "image" ATTR_ANIM = "animation" ATTR_VOLUME = "volume" @@ -286,12 +287,20 @@ def handle_action(call): attributes={'animation': anim}) elif action == "weather": + # Get color from attribute + clr = call.data.get(ATTR_COLOR, "white") + # Convert color in rgb + c = color_convert(Color(clr).get_rgb()) _LOGGER.debug('Action : weather') dev.send(set_temp_color(c[0], c[1], c[2], 0xff)) hass.states.set(entity_id=DOMAIN + "." + slugify(mac) + "_current_view", new_state=action) elif action == "clock": + # Get color from attribute + clr = call.data.get(ATTR_COLOR, "white") + # Convert color in rgb + c = color_convert(Color(clr).get_rgb()) _LOGGER.debug('Action : clock') dev.send(set_time_color(c[0], c[1], c[2], 0xff)) hass.states.set(entity_id=DOMAIN + "." + slugify(mac) + "_current_view", diff --git a/custom_components/timebox_mini/services.yaml b/custom_components/timebox_mini/services.yaml index 27bef94..219fc63 100644 --- a/custom_components/timebox_mini/services.yaml +++ b/custom_components/timebox_mini/services.yaml @@ -28,6 +28,24 @@ action: - "set_volume" - "set_time" - "set_brightness" + + color: + name: Color + description: The color to use for the action + required: true + example: "red" + default: "white" + # Selector (https://www.home-assistant.io/docs/blueprint/selectors/) to control the input UI for this field + selector: + select: + options: + - "white" + - "red" + - "green" + - "blue" + - "yellow" + - "cyan" + - "magenta" image: name: Image name From 375276ba3eaf4a03c20d9f1a14cc92eb919a895c Mon Sep 17 00:00:00 2001 From: M0rroww Date: Tue, 18 Oct 2022 22:49:27 +0200 Subject: [PATCH 2/2] Remove initial color generation --- custom_components/timebox_mini/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/custom_components/timebox_mini/__init__.py b/custom_components/timebox_mini/__init__.py index cdd59d6..9a7883e 100755 --- a/custom_components/timebox_mini/__init__.py +++ b/custom_components/timebox_mini/__init__.py @@ -254,8 +254,6 @@ def handle_action(call): _LOGGER.error('Error connecting to %s : %s' % (mac, e)) return - c = color_convert(Color("white").get_rgb()) - if action == "image": image = call.data.get(ATTR_IMAGE, "home_assistant_black") _LOGGER.debug('Action : image %s' % (dir_path + "/matrices/" + image + ".png"))