From 5b045a2c2a8eac40bb3ccf89caddf705eb287b12 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 06:41:50 +0000 Subject: [PATCH 1/7] chore(deps): update dependency ruff to v0.8.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 78fcd6f..5ed717c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ colorlog==6.9.0 homeassistant>=2023.9.3 pip>=24.1,<25 -ruff==0.8.0 +ruff==0.8.1 pre-commit black From faad626e8139253e5240645dc4b053aebaaeceaf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:28:15 +0000 Subject: [PATCH 2/7] chore(deps): update dependency ruff to v0.8.2 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5ed717c..48f6722 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ colorlog==6.9.0 homeassistant>=2023.9.3 pip>=24.1,<25 -ruff==0.8.1 +ruff==0.8.2 pre-commit black From 057ae080f433b3e39b7d339b2cd5ad6a03d82fb1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:29:39 +0000 Subject: [PATCH 3/7] chore(deps): update dependency ruff to v0.8.3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 48f6722..e486a09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ colorlog==6.9.0 homeassistant>=2023.9.3 pip>=24.1,<25 -ruff==0.8.2 +ruff==0.8.3 pre-commit black From bbd7025a4f09784d741d0d94cf5604bf911df3d2 Mon Sep 17 00:00:00 2001 From: Marco Franke Date: Mon, 16 Dec 2024 07:47:11 +0000 Subject: [PATCH 4/7] feat: added multicolor images for multicolor filaments closed #150 --- custom_components/spoolman/const.py | 1 + custom_components/spoolman/sensor.py | 61 +++++++++++++++++++++------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/custom_components/spoolman/const.py b/custom_components/spoolman/const.py index 71de15b..1c5fbcc 100644 --- a/custom_components/spoolman/const.py +++ b/custom_components/spoolman/const.py @@ -13,6 +13,7 @@ PUBLIC_IMAGE_PATH = "www/spoolman_images" LOCAL_IMAGE_PATH = "/local/spoolman_images" +DEFAULT_SPOOL_COLOR_HEX = "FFFFFF" EVENT_THRESHOLD_EXCEEDED = "spoolman_spool_threshold_exceeded" diff --git a/custom_components/spoolman/sensor.py b/custom_components/spoolman/sensor.py index 79db74d..42b6747 100644 --- a/custom_components/spoolman/sensor.py +++ b/custom_components/spoolman/sensor.py @@ -11,10 +11,11 @@ from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity -from PIL import Image +from PIL import Image, ImageDraw from .const import ( CONF_URL, + DEFAULT_SPOOL_COLOR_HEX, DOMAIN, EVENT_THRESHOLD_EXCEEDED, LOCAL_IMAGE_PATH, @@ -63,27 +64,59 @@ async def async_setup_entry( def _generate_entity_picture(spool_data, image_dir): - """Generate an entity picture with the specified color and save it to the www directory.""" - filament = spool_data["filament"] - - if filament.get("color_hex") is None: + """Generate an entity picture with the specified color(s) and save it to the www directory.""" + filament = spool_data.get("filament", {}) + + # Retrieve color(s) + multi_color_hexes = filament.get("multi_color_hexes", "").split(",") + color_hex = filament.get("color_hex", DEFAULT_SPOOL_COLOR_HEX) + multi_color_direction = filament.get("multi_color_direction", "coaxial") + + # Determine colors: prioritize multi_color_hexes if available + if multi_color_hexes and any(c.strip() for c in multi_color_hexes): + colors = [c.strip() for c in multi_color_hexes if len(c.strip()) == 6] + elif color_hex: + colors = [color_hex] + else: _LOGGER.warning( - "SpoolManCoordinator: Spool with ID '%s' has no color_hex set. Can't create entity picture.", - spool_data["id"], + "SpoolManCoordinator: Spool with ID '%s' has no valid color information.", + spool_data.get("id", "unknown"), ) return None - color_hex = filament.get("color_hex", "FFFFFF") - image = Image.new("RGB", (100, 100), f"#{color_hex}") - image_name = f"spool_{spool_data['id']}.png" - - # Check if the directory exists, and create it if it doesn't + # Create image + image_size = (100, 100) + image = Image.new("RGB", image_size, int(DEFAULT_SPOOL_COLOR_HEX, 16)) # Use integer for default white color + draw = ImageDraw.Draw(image) + + # Draw colors + if len(colors) > 1: + if multi_color_direction == "coaxial": + step = image_size[0] // len(colors) + for i, color in enumerate(colors): + draw.rectangle([ + (i * step, 0), + ((i + 1) * step - 1, image_size[1]) + ], fill=f"#{color}") + else: + # Alternate style: radial (circular gradient) + for i, color in enumerate(colors): + radius = image_size[0] // (2 * len(colors)) * (i + 1) + draw.ellipse([ + (image_size[0] // 2 - radius, image_size[1] // 2 - radius), + (image_size[0] // 2 + radius, image_size[1] // 2 + radius) + ], fill=f"#{color}") + else: + # Single color fallback + draw.rectangle([(0, 0), image_size], fill=f"#{colors[0]}") + + # Save the image + image_name = f"spool_{spool_data.get('id', 'unknown')}.png" os.makedirs(image_dir, exist_ok=True) - image_path = os.path.join(image_dir, image_name) image.save(image_path) - # Get the URL for the saved image + # Return the URL for the saved image return f"{LOCAL_IMAGE_PATH}/{image_name}" From 9811903502e3ba1db84f5c1a3e0fe8c015d3a547 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 16 Dec 2024 07:48:32 +0000 Subject: [PATCH 5/7] =?UTF-8?q?chore(release):=20=F0=9F=93=A2=200.7.0-dev.?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [0.7.0-dev.1](https://github.com/Disane87/spoolman-homeassistant/compare/v0.6.0...v0.7.0-dev.1) (2024-12-16) ### 🚀 Features * added multicolor images for multicolor filaments ([bbd7025](https://github.com/Disane87/spoolman-homeassistant/commit/bbd7025a4f09784d741d0d94cf5604bf911df3d2)), closes [#150](https://github.com/Disane87/spoolman-homeassistant/issues/150) --- CHANGELOG.md | 6 ++++++ hacs.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8793133..f69f561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.7.0-dev.1](https://github.com/Disane87/spoolman-homeassistant/compare/v0.6.0...v0.7.0-dev.1) (2024-12-16) + +### 🚀 Features + +* added multicolor images for multicolor filaments ([bbd7025](https://github.com/Disane87/spoolman-homeassistant/commit/bbd7025a4f09784d741d0d94cf5604bf911df3d2)), closes [#150](https://github.com/Disane87/spoolman-homeassistant/issues/150) + ## [0.6.0](https://github.com/Disane87/spoolman-homeassistant/compare/v0.5.0...v0.6.0) (2024-12-16) ### 🚀 Features diff --git a/hacs.json b/hacs.json index 7c67ab7..19476ea 100644 --- a/hacs.json +++ b/hacs.json @@ -2,6 +2,6 @@ "name": "Spoolman", "homeassistant": "2023.9.0", "render_readme": true, - "filename": "spoolman-homeassistant_0.6.0.zip", + "filename": "spoolman-homeassistant_0.7.0-dev.1.zip", "zip_release": true } From d2f28098d6ebb169a7c9a0fb1e55685cc7d305a7 Mon Sep 17 00:00:00 2001 From: Marco Franke Date: Mon, 16 Dec 2024 07:57:07 +0000 Subject: [PATCH 6/7] feat: added longitudinal color closed #150 --- custom_components/spoolman/sensor.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/custom_components/spoolman/sensor.py b/custom_components/spoolman/sensor.py index 42b6747..86ae55d 100644 --- a/custom_components/spoolman/sensor.py +++ b/custom_components/spoolman/sensor.py @@ -98,13 +98,12 @@ def _generate_entity_picture(spool_data, image_dir): (i * step, 0), ((i + 1) * step - 1, image_size[1]) ], fill=f"#{color}") - else: - # Alternate style: radial (circular gradient) + elif multi_color_direction == "longitudinal": + step = image_size[1] // len(colors) for i, color in enumerate(colors): - radius = image_size[0] // (2 * len(colors)) * (i + 1) - draw.ellipse([ - (image_size[0] // 2 - radius, image_size[1] // 2 - radius), - (image_size[0] // 2 + radius, image_size[1] // 2 + radius) + draw.rectangle([ + (0, i * step), + (image_size[0], (i + 1) * step - 1) ], fill=f"#{color}") else: # Single color fallback From ab5adfb25c35dc6cb75102d6a9725c033c22945b Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 16 Dec 2024 07:58:18 +0000 Subject: [PATCH 7/7] =?UTF-8?q?chore(release):=20=F0=9F=93=A2=200.7.0-dev.?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [0.7.0-dev.2](https://github.com/Disane87/spoolman-homeassistant/compare/v0.7.0-dev.1...v0.7.0-dev.2) (2024-12-16) ### 🚀 Features * added longitudinal color ([d2f2809](https://github.com/Disane87/spoolman-homeassistant/commit/d2f28098d6ebb169a7c9a0fb1e55685cc7d305a7)), closes [#150](https://github.com/Disane87/spoolman-homeassistant/issues/150) --- CHANGELOG.md | 6 ++++++ hacs.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f69f561..925ade8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.7.0-dev.2](https://github.com/Disane87/spoolman-homeassistant/compare/v0.7.0-dev.1...v0.7.0-dev.2) (2024-12-16) + +### 🚀 Features + +* added longitudinal color ([d2f2809](https://github.com/Disane87/spoolman-homeassistant/commit/d2f28098d6ebb169a7c9a0fb1e55685cc7d305a7)), closes [#150](https://github.com/Disane87/spoolman-homeassistant/issues/150) + ## [0.7.0-dev.1](https://github.com/Disane87/spoolman-homeassistant/compare/v0.6.0...v0.7.0-dev.1) (2024-12-16) ### 🚀 Features diff --git a/hacs.json b/hacs.json index 19476ea..508c672 100644 --- a/hacs.json +++ b/hacs.json @@ -2,6 +2,6 @@ "name": "Spoolman", "homeassistant": "2023.9.0", "render_readme": true, - "filename": "spoolman-homeassistant_0.7.0-dev.1.zip", + "filename": "spoolman-homeassistant_0.7.0-dev.2.zip", "zip_release": true }