Skip to content

Device release aware update #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

netmindz
Copy link

@netmindz netmindz commented Feb 3, 2025

Proposed Changes

Where the WLED device is new enough to return the release name as part of the device info, use this value to build the bin file name.
When this release info is not present, fallback to the original behaviour to download the "vanilla" build for your architecture

This is so that is the device is for example running the ESP8266_160 or ESP8266_compat release they stay on that release rather than switching to the default ESP8266 build

Summary by CodeRabbit

  • New Features
    • The upgrade process now lets users specify the device’s IP address via a command-line argument for enhanced flexibility.
    • Device details now include a release identifier to support more specific version selection during upgrades.
    • The upgrade mechanism has been refined to incorporate release-specific information when available.
  • Bug Fixes
    • Improved error messaging for version requests that do not exist, providing more specific feedback based on the device's release information.

Copy link

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request introduces three main changes. The upgrade example no longer hardcodes the WLED IP address; instead, it accepts a command-line argument by importing the sys module. Additionally, a new optional release attribute is added to the Info class in the models to capture device release information. Furthermore, the upgrade method in the WLED class is modified to conditionally format the update file based on whether the device’s release information is present.

Changes

File(s) Change Summary
examples/upgrade.py Modified to accept a command-line IP address; added usage message for missing IP.
src/wled/models.py Added a new optional attribute `release: str
src/wled/wled.py Updated the upgrade method to conditionally format the update_file based on the device's release information.

Possibly related PRs

  • Rewrite wled library #1334: The changes in the main PR, which enhance the examples/upgrade.py script to allow dynamic IP address input, are related to the modifications in the retrieved PR that also involve updates to the examples/upgrade.py script, specifically in how it handles WLED device upgrades.

Suggested labels

breaking-change, performance, refactor

Poem

I'm a hopping rabbit in lines of code,
Leaping over changes in my humble abode.
The IP now dances from command-line grace,
And device releases add a new trace.
With carrots of logic and a playful hop,
We celebrate progress that just won’t stop!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 436f1ee and 4c8e50b.

📒 Files selected for processing (1)
  • src/wled/models.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/wled/models.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netmindz netmindz changed the title Device aware update Device release aware update Feb 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/wled/wled.py (1)

638-642: Improve code style by removing unnecessary parentheses.

The parentheses around the if condition are not needed in Python.

-        if(self._device.info.release is not None):
+        if self._device.info.release is not None:
             update_file = f"{self._device.info.brand}_{version}_{self._device.info.release}.bin{gzip}"
         else:
             update_file = f"WLED_{version}_{architecture}{ethernet}.bin{gzip}"
src/wled/models.py (1)

428-430: Fix typo and enhance docstring.

The docstring has a typo and could benefit from more comprehensive examples.

     release: str | None = None
-    """The releae name, e.g ESP32_Ethernet, ESP8266_160"""
+    """The release name of the WLED device.
+
+    Examples:
+        - ESP32_Ethernet
+        - ESP8266_160
+        - ESP8266_compat
+    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 161789c and ebb015f.

📒 Files selected for processing (3)
  • examples/upgrade.py (2 hunks)
  • src/wled/models.py (1 hunks)
  • src/wled/wled.py (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/upgrade.py (1)

10-15: Improve function docstring.

The docstring should be moved to the correct position and enhanced to better describe the function's purpose and usage.

Apply this diff to improve the docstring:

-async def main() -> None:
-    if len(sys.argv) < 2:
-        print("Usage: python upgrade.py <ip_address>")
-        sys.exit(1)
-
-    """Show example on upgrade your WLED device."""
+async def main() -> None:
+    """Demonstrate WLED device upgrade functionality.
+
+    This example script connects to a WLED device using the provided IP address,
+    checks for the latest stable release, and performs an upgrade while maintaining
+    device-specific release compatibility.
+
+    Usage:
+        python upgrade.py <ip_address>
+    """
+    if len(sys.argv) < 2:
+        print("Usage: python upgrade.py <ip_address>")
+        sys.exit(1)
🧰 Tools
🪛 Ruff (0.8.2)

10-10: Missing docstring in public function

(D103)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebb015f and 913ebc8.

📒 Files selected for processing (3)
  • examples/upgrade.py (2 hunks)
  • src/wled/models.py (1 hunks)
  • src/wled/wled.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/wled/models.py
  • src/wled/wled.py
🧰 Additional context used
🪛 Ruff (0.8.2)
examples/upgrade.py

10-10: Missing docstring in public function

(D103)

🔇 Additional comments (3)
examples/upgrade.py (3)

5-5: LGTM!

The sys module import is correctly placed and necessary for command-line argument handling.


11-14: LGTM!

The error handling for command-line arguments has been implemented as suggested, with a clear usage message and proper exit code.


25-25: LGTM!

The WLED client instantiation now correctly uses the IP address from command-line arguments, making the script more flexible.

@frenck frenck added the new-feature New features or options. label Feb 20, 2025
Comment on lines +11 to +14
if len(sys.argv) < 2:
print("Usage: python upgrade.py <ip_address>")
sys.exit(1)

Copy link
Owner

@frenck frenck Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

If we wanted to do proper arg handling in the example, we'd do it differently. Let's remove it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive my inexperience with python, if there is a better way please suggest rather than rejecting an improvement

@@ -17,7 +22,7 @@ async def main() -> None:
print("No stable version found")
return

async with WLED("10.10.11.54") as led:
async with WLED(sys.argv[1]) as led:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this is just an example

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to run the example to test the behaviour against many different devices in you don't have to edit the file by hand reach each find

Comment on lines 429 to 436
"""The releae name, e.g ESP32_Ethernet, ESP8266_160"""
"""The release name of the WLED device.

Examples:
- ESP32_Ethernet
- ESP8266_160
- ESP8266_compat
"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two comment sections?

I'm not understanding the comment contents, why is this relevant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well spotted. The alternative format suggestion by CodeRabbit hasn't applied properly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

src/wled/wled.py Outdated
Comment on lines 638 to 642
if self._device.info.release is not None:
update_file = f"{self._device.info.brand}_{version}_{self._device.info.release}.bin{gzip}"
else:
update_file = f"WLED_{version}_{architecture}{ethernet}.bin{gzip}"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be rewritten without the else:.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@frenck frenck marked this pull request as draft February 20, 2025 23:39
@netmindz netmindz marked this pull request as ready for review February 21, 2025 09:50
@netmindz
Copy link
Author

netmindz commented Mar 6, 2025

Happy with the changes now?

@netmindz netmindz requested a review from frenck March 14, 2025 07:44
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Apr 13, 2025
@netmindz
Copy link
Author

Are you happy with the changes I made @frenck ?

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New features or options.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants