Skip to content

Commit dfd7714

Browse files
authored
WLED Upgrade improvements (#468)
1 parent 2f85409 commit dfd7714

4 files changed

Lines changed: 42 additions & 7 deletions

File tree

examples/upgrade.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ async def main():
1010
"""Show example on upgrade your WLED device."""
1111
async with WLED("10.10.11.54") as led:
1212
device = await led.update()
13-
print(device.info)
13+
print(f"Latest stable version: {device.info.version_latest_stable}")
14+
print(f"Latest beta version: {device.info.version_latest_beta}")
15+
print(f"Current version: {device.info.version}")
1416

17+
print("Upgrading WLED....")
1518
await led.upgrade(version="0.13.0-b4")
1619

20+
print("Waiting for WLED to come back....")
21+
await asyncio.sleep(5)
22+
23+
device = await led.update(full_update=True)
24+
print(f"Current version: {device.info.version}")
25+
1726

1827
if __name__ == "__main__":
1928
asyncio.run(main())

src/wled/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
WLEDConnectionError,
2222
WLEDConnectionTimeoutError,
2323
WLEDError,
24+
WLEDUpgradeError,
2425
)
2526

2627
__all__ = [
@@ -42,4 +43,5 @@
4243
"WLEDConnectionError",
4344
"WLEDConnectionTimeoutError",
4445
"WLEDError",
46+
"WLEDUpgradeError",
4547
]

src/wled/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ class WLEDConnectionTimeoutError(WLEDConnectionError):
1919

2020
class WLEDConnectionClosed(WLEDConnectionError):
2121
"""WLED WebSocket connection has been closed."""
22+
23+
24+
class WLEDUpgradeError(WLEDError):
25+
"""WLED upgrade exception."""

src/wled/wled.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
WLEDConnectionTimeoutError,
2323
WLEDEmptyResponseError,
2424
WLEDError,
25+
WLEDUpgradeError,
2526
)
2627
from .models import Device, Live, Playlist, Preset
2728

@@ -590,21 +591,40 @@ async def upgrade(self, *, version: str) -> None:
590591
version: The version to upgrade to.
591592
592593
Raises:
593-
WLEDError: If the upgrade fails.
594+
WLEDUpgradeError: If the upgrade has failed.
594595
WLEDConnectionTimeoutError: When a connection timeout occurs.
595596
WLEDConnectionError: When a connection error occurs.
596597
"""
597598
if self._device is None:
598599
await self.update()
599600

600601
if self.session is None or self._device is None:
601-
return
602+
raise WLEDUpgradeError("Unexpected upgrade error; No session or device")
602603

603604
if self._device.info.architecture not in {"esp8266", "esp32"}:
604-
raise WLEDError("Upgrade is only supported on ESP8266 and ESP32")
605+
raise WLEDUpgradeError("Upgrade is only supported on ESP8266 and ESP32")
606+
607+
if not self._device.info.version:
608+
raise WLEDUpgradeError("Current version is unknown, cannot perform upgrade")
609+
610+
if self._device.info.version == version:
611+
raise WLEDUpgradeError("Device already running the requested version")
612+
613+
# Determine if this is an Ethernet board
614+
ethernet = ""
615+
if (
616+
self._device.info.architecture == "esp32"
617+
and self._device.info.wifi is not None
618+
and not self._device.info.wifi.bssid
619+
and self._device.info.version
620+
and self._device.info.version >= "0.10.0"
621+
):
622+
ethernet = "_Ethernet"
605623

606624
url = URL.build(scheme="http", host=self.host, port=80, path="/update")
607-
update_file = f"WLED_{version}_{self._device.info.architecture.upper()}.bin"
625+
update_file = (
626+
f"WLED_{version}_{self._device.info.architecture.upper()}{ethernet}.bin"
627+
)
608628
download_url = f"https://github.com/Aircoookie/WLED/releases/download/v{version}/{update_file}"
609629

610630
try:
@@ -621,10 +641,10 @@ async def upgrade(self, *, version: str) -> None:
621641
) from exception
622642
except aiohttp.ClientResponseError as exception:
623643
if exception.status == 404:
624-
raise WLEDError(
644+
raise WLEDUpgradeError(
625645
f"Requested WLED version '{version}' does not exists"
626646
) from exception
627-
raise WLEDError(
647+
raise WLEDUpgradeError(
628648
f"Could not download requested WLED version '{version}' from {download_url}"
629649
) from exception
630650
except (aiohttp.ClientError, socket.gaierror) as exception:

0 commit comments

Comments
 (0)