11import lvgl as lv
2- import requests
32import ujson
43import time
54
@@ -184,15 +183,19 @@ def _get_user_friendly_error(self, error):
184183
185184 # Show update info with a delay, to ensure ordering of multiple lv.async_call()
186185 def schedule_show_update_info (self ):
187- timer = lv .timer_create (self .show_update_info , 150 , None )
188- timer .set_repeat_count (1 )
186+ # Create async task for show_update_info with a delay
187+ async def delayed_show_update_info ():
188+ await TaskManager .sleep_ms (150 )
189+ await self .show_update_info ()
189190
190- def show_update_info (self , timer = None ):
191+ TaskManager .create_task (delayed_show_update_info ())
192+
193+ async def show_update_info (self ):
191194 hwid = mpos .info .get_hardware_id ()
192195
193196 try :
194197 # Use UpdateChecker to fetch update info
195- update_info = self .update_checker .fetch_update_info (hwid )
198+ update_info = await self .update_checker .fetch_update_info (hwid )
196199 if self .has_foreground ():
197200 self .handle_update_info (
198201 update_info ["version" ],
@@ -696,14 +699,14 @@ def set_boot_partition_and_restart(self):
696699class UpdateChecker :
697700 """Handles checking for OS updates from remote server."""
698701
699- def __init__ (self , requests_module = None , json_module = None ):
702+ def __init__ (self , download_manager = None , json_module = None ):
700703 """Initialize with optional dependency injection for testing.
701704
702705 Args:
703- requests_module: HTTP requests module (defaults to requests )
706+ download_manager: DownloadManager module (defaults to mpos.DownloadManager )
704707 json_module: JSON parsing module (defaults to ujson)
705708 """
706- self .requests = requests_module if requests_module else requests
709+ self .download_manager = download_manager if download_manager else DownloadManager
707710 self .json = json_module if json_module else ujson
708711
709712 def get_update_url (self , hardware_id ):
@@ -722,7 +725,7 @@ def get_update_url(self, hardware_id):
722725 infofile = f"osupdate_{ hardware_id } .json"
723726 return f"https://updates.micropythonos.com/{ infofile } "
724727
725- def fetch_update_info (self , hardware_id ):
728+ async def fetch_update_info (self , hardware_id ):
726729 """Fetch and parse update information from server.
727730
728731 Args:
@@ -734,27 +737,20 @@ def fetch_update_info(self, hardware_id):
734737
735738 Raises:
736739 ValueError: If JSON is malformed or missing required fields
737- ConnectionError : If network request fails
740+ RuntimeError : If network request fails
738741 """
739742 url = self .get_update_url (hardware_id )
740743 print (f"OSUpdate: fetching { url } " )
741744
742745 try :
743- response = self .requests .get (url )
744-
745- if response .status_code != 200 :
746- # Use RuntimeError instead of ConnectionError (not available in MicroPython)
747- raise RuntimeError (
748- f"HTTP { response .status_code } while checking { url } "
749- )
746+ # Use DownloadManager to fetch the JSON data
747+ response_data = await self .download_manager .download_url (url )
750748
751749 # Parse JSON
752750 try :
753- update_data = self .json .loads (response . text )
751+ update_data = self .json .loads (response_data )
754752 except Exception as e :
755753 raise ValueError (f"Invalid JSON in update file: { e } " )
756- finally :
757- response .close ()
758754
759755 # Validate required fields
760756 required_fields = ['version' , 'download_url' , 'changelog' ]
0 commit comments