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
7 changes: 6 additions & 1 deletion examples/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"""Asynchronous Python client for WLED."""

import asyncio
import sys

from wled import WLED, WLEDReleases


async def main() -> None:
if len(sys.argv) < 2:
print("Usage: python upgrade.py <ip_address>")
sys.exit(1)

Comment on lines +11 to +14
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

"""Show example on upgrade your WLED device."""
async with WLEDReleases() as releases:
latest = await releases.releases()
Expand All @@ -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

device = await led.update()
print(f"Current version: {device.info.version}")

Expand Down
9 changes: 9 additions & 0 deletions src/wled/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ class Info(BaseModel): # pylint: disable=too-many-instance-attributes
brand: str = "WLED"
"""The producer/vendor of the light. Always WLED for standard installations."""

release: str | None = None
"""The release name of the WLED device firmware.

Examples:
- ESP32_Ethernet
- ESP8266_160
- ESP8266_compat
"""

build: str = field(default="Unknown", metadata=field_options(alias="vid"))
"""Build ID (YYMMDDB, B = daily build index)."""

Expand Down
5 changes: 4 additions & 1 deletion src/wled/wled.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ async def upgrade(self, *, version: str | AwesomeVersion) -> None:
url = URL.build(scheme="http", host=self.host, port=80, path="/update")
architecture = self._device.info.architecture.upper()
update_file = f"WLED_{version}_{architecture}{ethernet}.bin{gzip}"
if self._device.info.release is not None:
update_file = f"{self._device.info.brand}_{version}_{self._device.info.release}.bin{gzip}"

download_url = (
"https://github.com/Aircoookie/WLED/releases/download"
f"/v{version}/{update_file}"
Expand All @@ -659,7 +662,7 @@ async def upgrade(self, *, version: str | AwesomeVersion) -> None:
raise WLEDConnectionTimeoutError(msg) from exception
except aiohttp.ClientResponseError as exception:
if exception.status == 404:
msg = f"Requested WLED version '{version}' does not exists"
msg = f"Requested file {update_file} does not exists"
raise WLEDUpgradeError(msg) from exception
msg = (
f"Could not download requested WLED version '{version}'"
Expand Down