From ac87955be76840855dede264e1441063aa0f71f8 Mon Sep 17 00:00:00 2001 From: numanair Date: Sat, 12 Nov 2022 22:44:33 -0800 Subject: [PATCH 1/8] Fix WLED preset-selection in upcoming release Fix for upcoming WLED 0.14 release. https://discord.com/channels/473448917040758787/779395228624617512/1041238039319543908 --- moonraker/components/wled.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index b3d6baa1e..e4439fe23 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -143,7 +143,7 @@ async def wled_on(self: Strip, preset: int) -> None: self.brightness = -1 self.intensity = -1 self.speed = -1 - await self._send_wled_command({"on": True, "ps": preset}) + await self._send_wled_command({"ps": preset}) async def wled_off(self: Strip) -> None: logging.debug(f"WLED: {self.name} off") From cd85b5826dd402b9781f82c57048c90e7854c8e5 Mon Sep 17 00:00:00 2001 From: numanair Date: Sat, 12 Nov 2022 22:50:55 -0800 Subject: [PATCH 2/8] Add optional WLED Strip/Segment Parameter Add 0-indexed "id" parameter to wled_control for applying settings to different segments. --- moonraker/components/wled.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index e4439fe23..57fb4b14f 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -154,10 +154,10 @@ async def wled_off(self: Strip) -> None: await self._send_wled_command({"on": False}) async def wled_control(self: Strip, brightness: int, intensity: int, - speed: int) -> None: + speed: int, id: int) -> None: logging.debug( f"WLED: {self.name} control {self.onoff} BRIGHTNESS={brightness} " - f"INTENSITY={intensity} SPEED={speed} CURRENTPRESET={self.preset}") + f"INTENSITY={intensity} SPEED={speed} ID={id} CURRENTPRESET={self.preset}") if self.onoff == OnOff.off: logging.info("wled control only permitted when strip is on") @@ -178,11 +178,17 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("BRIGHTNESS should be between 1 and 255") else: shouldSend = True + self.id = id self.brightness = brightness - control["bri"] = self.brightness # Brightness in seg {} - only if a preset is on if self.preset != -1: - control["seg"]["bri"] = self.brightness + if self.id != -1: + # Set specific segment (id) brightness + control["seg"]["id"] = self.id + control["seg"]["bri"] = self.brightness + else: + # No segment id specified, so set master brightness + control["bri"] = self.brightness # Intensity - only if a preset is on if intensity > -1 and self.preset != -1: @@ -190,8 +196,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("INTENSITY should be between 0 and 255") else: shouldSend = True + self.id = id self.intensity = intensity control["seg"]["ix"] = self.intensity + if self.id != -1: + control["seg"]["id"] = self.id # Speed - only if a preset is on if speed > -1 and self.preset != -1: @@ -199,8 +208,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("SPEED should be between 0 and 255") else: shouldSend = True + self.id = id self.speed = speed control["seg"]["sx"] = self.speed + if self.id != -1: + control["seg"]["id"] = self.id # Control brightness, intensity, and speed for segment # This will allow full control for effects such as "Percent" @@ -448,7 +460,7 @@ async def wled_on(self: WLED, strip: str, preset: int) -> None: # state: True, False, "on", "off" # preset: wled preset (int) to use (ignored if state False or "Off") async def set_wled_state(self: WLED, strip: str, state: str = None, - preset: int = -1, brightness: int = -1, + preset: int = -1, id: int = -1, brightness: int = -1, intensity: int = -1, speed: int = -1) -> None: status = None @@ -479,7 +491,7 @@ async def set_wled_state(self: WLED, strip: str, state: str = None, # Control if brightness != -1 or intensity != -1 or speed != -1: - await self.strips[strip].wled_control(brightness, intensity, speed) + await self.strips[strip].wled_control(brightness, intensity, speed, id) # Individual pixel control, for compatibility with SET_LED async def set_wled(self: WLED, From f644cba7894a03f2731f537ee9211f4218c42478 Mon Sep 17 00:00:00 2001 From: numanair Date: Sat, 12 Nov 2022 22:44:33 -0800 Subject: [PATCH 3/8] WLED: Fix WLED preset-selection in upcoming release Fix for upcoming WLED 0.14 release when setting presets. https://discord.com/channels/473448917040758787/779395228624617512/1041238039319543908 Signed-off-by: Cole Morris --- moonraker/components/wled.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index b3d6baa1e..e4439fe23 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -143,7 +143,7 @@ async def wled_on(self: Strip, preset: int) -> None: self.brightness = -1 self.intensity = -1 self.speed = -1 - await self._send_wled_command({"on": True, "ps": preset}) + await self._send_wled_command({"ps": preset}) async def wled_off(self: Strip) -> None: logging.debug(f"WLED: {self.name} off") From f69680aa57cd783381c4e6704989b6220dbb6460 Mon Sep 17 00:00:00 2001 From: numanair Date: Sat, 12 Nov 2022 22:50:55 -0800 Subject: [PATCH 4/8] WLED: Add optional WLED Strip/Segment Parameter Add 0-indexed "id" parameter to wled_control for applying settings to different segments. Signed-off-by: Cole Morris --- moonraker/components/wled.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index e4439fe23..57fb4b14f 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -154,10 +154,10 @@ async def wled_off(self: Strip) -> None: await self._send_wled_command({"on": False}) async def wled_control(self: Strip, brightness: int, intensity: int, - speed: int) -> None: + speed: int, id: int) -> None: logging.debug( f"WLED: {self.name} control {self.onoff} BRIGHTNESS={brightness} " - f"INTENSITY={intensity} SPEED={speed} CURRENTPRESET={self.preset}") + f"INTENSITY={intensity} SPEED={speed} ID={id} CURRENTPRESET={self.preset}") if self.onoff == OnOff.off: logging.info("wled control only permitted when strip is on") @@ -178,11 +178,17 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("BRIGHTNESS should be between 1 and 255") else: shouldSend = True + self.id = id self.brightness = brightness - control["bri"] = self.brightness # Brightness in seg {} - only if a preset is on if self.preset != -1: - control["seg"]["bri"] = self.brightness + if self.id != -1: + # Set specific segment (id) brightness + control["seg"]["id"] = self.id + control["seg"]["bri"] = self.brightness + else: + # No segment id specified, so set master brightness + control["bri"] = self.brightness # Intensity - only if a preset is on if intensity > -1 and self.preset != -1: @@ -190,8 +196,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("INTENSITY should be between 0 and 255") else: shouldSend = True + self.id = id self.intensity = intensity control["seg"]["ix"] = self.intensity + if self.id != -1: + control["seg"]["id"] = self.id # Speed - only if a preset is on if speed > -1 and self.preset != -1: @@ -199,8 +208,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("SPEED should be between 0 and 255") else: shouldSend = True + self.id = id self.speed = speed control["seg"]["sx"] = self.speed + if self.id != -1: + control["seg"]["id"] = self.id # Control brightness, intensity, and speed for segment # This will allow full control for effects such as "Percent" @@ -448,7 +460,7 @@ async def wled_on(self: WLED, strip: str, preset: int) -> None: # state: True, False, "on", "off" # preset: wled preset (int) to use (ignored if state False or "Off") async def set_wled_state(self: WLED, strip: str, state: str = None, - preset: int = -1, brightness: int = -1, + preset: int = -1, id: int = -1, brightness: int = -1, intensity: int = -1, speed: int = -1) -> None: status = None @@ -479,7 +491,7 @@ async def set_wled_state(self: WLED, strip: str, state: str = None, # Control if brightness != -1 or intensity != -1 or speed != -1: - await self.strips[strip].wled_control(brightness, intensity, speed) + await self.strips[strip].wled_control(brightness, intensity, speed, id) # Individual pixel control, for compatibility with SET_LED async def set_wled(self: WLED, From c176b823324b6137409e6841f5f334ebaf8375e4 Mon Sep 17 00:00:00 2001 From: numanair Date: Sat, 19 Nov 2022 21:18:28 -0800 Subject: [PATCH 5/8] docs: Add WLED ID parameter to example Added optional ID parameter to the example macro Signed-off-by: Cole Morris --- docs/configuration.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index ae259fdb1..946e8a335 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1627,12 +1627,15 @@ gcode: {% set brightness = params.BRIGHTNESS|default(-1)|int %} {% set intensity = params.INTENSITY|default(-1)|int %} {% set speed = params.SPEED|default(-1)|int %} + {% set id = params.ID|default(-1)|int %} + # Optionally specify a WLED segment with the ID parameter, which starts at 0. {action_call_remote_method("set_wled_state", strip=strip, brightness=brightness, intensity=intensity, - speed=speed)} + speed=speed, + id=id)} [gcode_macro WLED_OFF] description: Turn WLED strip off From 83c546ff59aa20dff17250ad777137aa473e0258 Mon Sep 17 00:00:00 2001 From: numanair Date: Sun, 20 Nov 2022 20:25:35 -0800 Subject: [PATCH 6/8] WLED: corrections to line length corrected 3 long lines Signed-off-by: Cole Morris --- moonraker/components/wled.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index 57fb4b14f..ee01484d7 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -157,7 +157,8 @@ async def wled_control(self: Strip, brightness: int, intensity: int, speed: int, id: int) -> None: logging.debug( f"WLED: {self.name} control {self.onoff} BRIGHTNESS={brightness} " - f"INTENSITY={intensity} SPEED={speed} ID={id} CURRENTPRESET={self.preset}") + f"INTENSITY={intensity} SPEED={speed} " + f"ID={id}CURRENTPRESET={self.preset}") if self.onoff == OnOff.off: logging.info("wled control only permitted when strip is on") @@ -460,8 +461,9 @@ async def wled_on(self: WLED, strip: str, preset: int) -> None: # state: True, False, "on", "off" # preset: wled preset (int) to use (ignored if state False or "Off") async def set_wled_state(self: WLED, strip: str, state: str = None, - preset: int = -1, id: int = -1, brightness: int = -1, - intensity: int = -1, speed: int = -1) -> None: + preset: int = -1, id: int = -1, + brightness: int = -1, intensity: int = -1, + speed: int = -1) -> None: status = None if isinstance(state, bool): @@ -491,7 +493,8 @@ async def set_wled_state(self: WLED, strip: str, state: str = None, # Control if brightness != -1 or intensity != -1 or speed != -1: - await self.strips[strip].wled_control(brightness, intensity, speed, id) + await self.strips[strip].wled_control( + brightness, intensity, speed, id) # Individual pixel control, for compatibility with SET_LED async def set_wled(self: WLED, From 302ec1a1b9bdab6b032effa6b7886d64a34edfbe Mon Sep 17 00:00:00 2001 From: numanair Date: Mon, 21 Nov 2022 02:35:35 -0800 Subject: [PATCH 7/8] wled: add argument "id" to request Signed-off-by: Cole Morris --- moonraker/components/wled.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index ee01484d7..6acdf3d58 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -530,6 +530,7 @@ async def _handle_single_wled_request(self: WLED, brightness: int = web_request.get_int('brightness', -1) intensity: int = web_request.get_int('intensity', -1) speed: int = web_request.get_int('speed', -1) + id: int = web_request.get_int('id', -1) req_action = web_request.get_action() if strip_name not in self.strips: @@ -543,7 +544,8 @@ async def _handle_single_wled_request(self: WLED, raise self.server.error( f"Invalid requested action '{action}'") result = await self._process_request(strip, action, preset, - brightness, intensity, speed) + brightness, intensity, + speed, id) return {strip_name: result} async def _handle_batch_wled_request(self: WLED, @@ -559,7 +561,7 @@ async def _handle_batch_wled_request(self: WLED, for name, strip in requested_strips.items(): if strip is not None: result[name] = await self._process_request(strip, req, -1, - -1, -1, -1) + -1, -1, -1, -1) else: result[name] = {"error": "strip_not_found"} return result @@ -570,7 +572,8 @@ async def _process_request(self: WLED, preset: int, brightness: int, intensity: int, - speed: int + speed: int, + id: int ) -> Dict[str, Any]: strip_onoff = strip.onoff @@ -588,7 +591,7 @@ async def _process_request(self: WLED, await strip.wled_on(preset) if brightness != -1 or intensity != -1 or speed != -1: - await strip.wled_control(brightness, intensity, speed) + await strip.wled_control(brightness, intensity, speed, id) else: strip_onoff = OnOff.off await strip.wled_off() From 110dc5409b7e336d34c7893a81a60e929328d87b Mon Sep 17 00:00:00 2001 From: Cole Morris Date: Tue, 14 Mar 2023 18:18:04 -0700 Subject: [PATCH 8/8] WLED: rename id parameter to segment --- moonraker/components/wled.py | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/moonraker/components/wled.py b/moonraker/components/wled.py index 4ca2d6287..8f5ca19f5 100644 --- a/moonraker/components/wled.py +++ b/moonraker/components/wled.py @@ -152,11 +152,11 @@ async def wled_off(self: Strip) -> None: await self._send_wled_command({"on": False}) async def wled_control(self: Strip, brightness: int, intensity: int, - speed: int, id: int) -> None: + speed: int, segment: int) -> None: logging.debug( f"WLED: {self.name} control {self.onoff} BRIGHTNESS={brightness} " f"INTENSITY={intensity} SPEED={speed} " - f"ID={id}CURRENTPRESET={self.preset}") + f"SEGMENT={segment}CURRENTPRESET={self.preset}") if self.onoff == OnOff.off: logging.info("wled control only permitted when strip is on") @@ -177,16 +177,16 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("BRIGHTNESS should be between 1 and 255") else: shouldSend = True - self.id = id + self.segment = segment self.brightness = brightness # Brightness in seg {} - only if a preset is on if self.preset != -1: - if self.id != -1: - # Set specific segment (id) brightness - control["seg"]["id"] = self.id + if self.segment != -1: + # Set specific segment (segment) brightness + control["seg"]["segment"] = self.segment control["seg"]["bri"] = self.brightness else: - # No segment id specified, so set master brightness + # No segment segment specified, so set master brightness control["bri"] = self.brightness # Intensity - only if a preset is on @@ -195,11 +195,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("INTENSITY should be between 0 and 255") else: shouldSend = True - self.id = id + self.segment = segment self.intensity = intensity control["seg"]["ix"] = self.intensity - if self.id != -1: - control["seg"]["id"] = self.id + if self.segment != -1: + control["seg"]["segment"] = self.segment # Speed - only if a preset is on if speed > -1 and self.preset != -1: @@ -207,11 +207,11 @@ async def wled_control(self: Strip, brightness: int, intensity: int, logging.info("SPEED should be between 0 and 255") else: shouldSend = True - self.id = id + self.segment = segment self.speed = speed control["seg"]["sx"] = self.speed - if self.id != -1: - control["seg"]["id"] = self.id + if self.segment != -1: + control["seg"]["segment"] = self.segment # Control brightness, intensity, and speed for segment # This will allow full control for effects such as "Percent" @@ -463,7 +463,7 @@ async def set_wled_state( strip: str, state: Optional[str] = None, preset: int = -1, - id: int = -1, + segment: int = -1, brightness: int = -1, intensity: int = -1, speed: int = -1 @@ -498,7 +498,7 @@ async def set_wled_state( # Control if brightness != -1 or intensity != -1 or speed != -1: await self.strips[strip].wled_control( - brightness, intensity, speed, id) + brightness, intensity, speed, segment) # Individual pixel control, for compatibility with SET_LED async def set_wled(self: WLED, @@ -534,7 +534,7 @@ async def _handle_single_wled_request(self: WLED, brightness: int = web_request.get_int('brightness', -1) intensity: int = web_request.get_int('intensity', -1) speed: int = web_request.get_int('speed', -1) - id: int = web_request.get_int('id', -1) + segment: int = web_request.get_int('segment', -1) req_action = web_request.get_action() if strip_name not in self.strips: @@ -549,7 +549,7 @@ async def _handle_single_wled_request(self: WLED, f"Invalid requested action '{action}'") result = await self._process_request(strip, action, preset, brightness, intensity, - speed, id) + speed, segment) return {strip_name: result} async def _handle_batch_wled_request(self: WLED, @@ -577,7 +577,7 @@ async def _process_request(self: WLED, brightness: int, intensity: int, speed: int, - id: int + segment: int ) -> Dict[str, Any]: strip_onoff = strip.onoff @@ -595,7 +595,7 @@ async def _process_request(self: WLED, await strip.wled_on(preset) if brightness != -1 or intensity != -1 or speed != -1: - await strip.wled_control(brightness, intensity, speed, id) + await strip.wled_control(brightness, intensity, speed, segment) else: strip_onoff = OnOff.off await strip.wled_off()