2222 WLEDConnectionTimeoutError ,
2323 WLEDEmptyResponseError ,
2424 WLEDError ,
25+ WLEDUpgradeError ,
2526)
2627from .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