diff --git a/internal_filesystem/builtin/apps/com.micropythonos.about/assets/about.py b/internal_filesystem/builtin/apps/com.micropythonos.about/assets/about.py index 2ba6ae4a..c9a1ad3b 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.about/assets/about.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.about/assets/about.py @@ -1,6 +1,5 @@ -from mpos import Activity, DisplayMetrics +from mpos import Activity, DisplayMetrics, BuildInfo, DeviceInfo -import mpos.info import sys class About(Activity): @@ -46,8 +45,8 @@ class About(Activity): # Basic OS info self._add_label(screen, f"{lv.SYMBOL.HOME} System Information", is_header=True) - self._add_label(screen, f"MicroPythonOS version: {mpos.info.CURRENT_OS_VERSION}") - self._add_label(screen, f"Hardware ID: {mpos.info.get_hardware_id()}") + self._add_label(screen, f"MicroPythonOS version: {BuildInfo.version.release}") + self._add_label(screen, f"Hardware ID: {DeviceInfo.hardware_id}") self._add_label(screen, f"sys.version: {sys.version}") self._add_label(screen, f"sys.implementation: {sys.implementation}") self._add_label(screen, f"sys.byteorder: {sys.byteorder}") @@ -83,6 +82,7 @@ class About(Activity): # These are always written to sys.stdout #self._add_label(screen, f"micropython.mem_info(): {micropython.mem_info()}") #self._add_label(screen, f"micropython.qstr_info(): {micropython.qstr_info()}") + import mpos self._add_label(screen, f"mpos.__path__: {mpos.__path__}") # this will show .frozen if the /lib folder is frozen (prod build) # ESP32 hardware info diff --git a/internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py b/internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py index 25f04688..6ac9d652 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py @@ -2,8 +2,7 @@ import lvgl as lv import ujson import time -from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, DisplayMetrics -import mpos.info +from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, DisplayMetrics, DeviceInfo, BuildInfo class OSUpdate(Activity): @@ -47,7 +46,7 @@ class OSUpdate(Activity): self.current_version_label = lv.label(self.main_screen) self.current_version_label.align(lv.ALIGN.TOP_LEFT,0,0) - self.current_version_label.set_text(f"Installed OS version: {mpos.info.CURRENT_OS_VERSION}") + self.current_version_label.set_text(f"Installed OS version: {BuildInfo.version.release}") self.force_update = lv.checkbox(self.main_screen) self.force_update.set_text("Force Update") self.force_update.add_event_cb(lambda *args: self.force_update_clicked(), lv.EVENT.VALUE_CHANGED, None) @@ -182,7 +181,7 @@ class OSUpdate(Activity): return f"An error occurred:\n{str(error)}\n\nPlease try again." async def show_update_info(self): - hwid = mpos.info.get_hardware_id() + hwid = DeviceInfo.hardware_id try: # Use UpdateChecker to fetch update info @@ -217,7 +216,7 @@ class OSUpdate(Activity): self.download_update_url = download_url # Use UpdateChecker to determine if update is available - is_newer = self.update_checker.is_update_available(version, mpos.info.CURRENT_OS_VERSION) + is_newer = self.update_checker.is_update_available(version, BuildInfo.version.release) if is_newer: label = "New" diff --git a/internal_filesystem/lib/mpos/__init__.py b/internal_filesystem/lib/mpos/__init__.py index 5b1282e5..858f6c35 100644 --- a/internal_filesystem/lib/mpos/__init__.py +++ b/internal_filesystem/lib/mpos/__init__.py @@ -14,6 +14,8 @@ from .task_manager import TaskManager from .camera_manager import CameraManager from .sensor_manager import SensorManager from .time_zone import TimeZone +from .device_info import DeviceInfo +from .build_info import BuildInfo # Common activities from .app.activities.chooser import ChooserActivity @@ -65,6 +67,8 @@ __all__ = [ "SharedPreferences", "ConnectivityManager", "DownloadManager", "WifiService", "AudioFlinger", "Intent", "ActivityNavigator", "PackageManager", "TaskManager", "CameraManager", + # Device and build info + "DeviceInfo", "BuildInfo", # Common activities "ChooserActivity", "ViewActivity", "ShareActivity", "SettingActivity", "SettingsActivity", "CameraActivity", diff --git a/internal_filesystem/lib/mpos/apps.py b/internal_filesystem/lib/mpos/apps.py index f48b69a0..10ae498a 100644 --- a/internal_filesystem/lib/mpos/apps.py +++ b/internal_filesystem/lib/mpos/apps.py @@ -3,7 +3,6 @@ import lvgl as lv import _thread import traceback -import mpos.info import mpos.ui # Run the script in the current thread: diff --git a/internal_filesystem/lib/mpos/build_info.py b/internal_filesystem/lib/mpos/build_info.py new file mode 100644 index 00000000..259ea478 --- /dev/null +++ b/internal_filesystem/lib/mpos/build_info.py @@ -0,0 +1,13 @@ +""" +BuildInfo - OS version and build information +""" + + +class BuildInfo: + """OS version and build information.""" + + class version: + """Version information.""" + + release = "0.7.0" # Human-readable version: "0.7.0" + sdk_int = 0 # API level: 0 diff --git a/internal_filesystem/lib/mpos/device_info.py b/internal_filesystem/lib/mpos/device_info.py new file mode 100644 index 00000000..b4f4296c --- /dev/null +++ b/internal_filesystem/lib/mpos/device_info.py @@ -0,0 +1,29 @@ +""" +DeviceInfo - Device hardware information +""" + + +class DeviceInfo: + """Device hardware information.""" + + hardware_id = "missing-hardware-info" + + @classmethod + def set_hardware_id(cls, device_id): + """ + Set the device/hardware identifier (called during boot). + + Args: + device_id: The hardware identifier string + """ + cls.hardware_id = device_id + + @classmethod + def get_hardware_id(cls): + """ + Get the hardware identifier. + + Returns: + str: The hardware identifier + """ + return cls.hardware_id diff --git a/internal_filesystem/lib/mpos/info.py b/internal_filesystem/lib/mpos/info.py deleted file mode 100644 index 96af7d0d..00000000 --- a/internal_filesystem/lib/mpos/info.py +++ /dev/null @@ -1,11 +0,0 @@ -CURRENT_OS_VERSION = "0.7.0" - -# Unique string that defines the hardware, used by OSUpdate and the About app -_hardware_id = "missing-hardware-info" - -def set_hardware_id(value): - global _hardware_id - _hardware_id = value - -def get_hardware_id(): - return _hardware_id diff --git a/internal_filesystem/lib/mpos/main.py b/internal_filesystem/lib/mpos/main.py index ad2332cc..ef4700ea 100644 --- a/internal_filesystem/lib/mpos/main.py +++ b/internal_filesystem/lib/mpos/main.py @@ -6,7 +6,7 @@ import mpos.apps import mpos.ui import mpos.ui.topmenu -from mpos import AppearanceManager, DisplayMetrics, PackageManager, SharedPreferences, TaskManager +from mpos import AppearanceManager, DisplayMetrics, PackageManager, SharedPreferences, TaskManager, DeviceInfo # White text on black logo works (for dark mode) and can be inverted (for light mode) logo_white = "M:builtin/res/mipmap-mdpi/MicroPythonOS-logo-white-long-w296.png" # from the MPOS-logo repo @@ -65,8 +65,7 @@ def detect_board(): board = detect_board() print(f"Initializing {board} hardware") -import mpos.info -mpos.info.set_hardware_id(board) +DeviceInfo.set_hardware_id(board) __import__(f"mpos.board.{board}") # Allow LVGL M:/path/to/file or M:relative/path/to/file to work for image set_src etc diff --git a/tests/test_graphical_about_app.py b/tests/test_graphical_about_app.py index 96cb1498..cfe7a921 100644 --- a/tests/test_graphical_about_app.py +++ b/tests/test_graphical_about_app.py @@ -18,7 +18,6 @@ Usage: import unittest import lvgl as lv import mpos.apps -import mpos.info import mpos.ui import os from mpos import ( @@ -26,7 +25,9 @@ from mpos import ( capture_screenshot, find_label_with_text, verify_text_present, - print_screen_labels + print_screen_labels, + DeviceInfo, + BuildInfo ) @@ -51,7 +52,7 @@ class TestGraphicalAboutApp(unittest.TestCase): pass # Directory already exists # Store hardware ID for verification - self.hardware_id = mpos.info.get_hardware_id() + self.hardware_id = DeviceInfo.hardware_id print(f"Testing with hardware ID: {self.hardware_id}") def tearDown(self): @@ -161,7 +162,7 @@ class TestGraphicalAboutApp(unittest.TestCase): ) # Verify the actual version string is present - os_version = mpos.info.CURRENT_OS_VERSION + os_version = BuildInfo.version.release self.assertTrue( verify_text_present(screen, os_version), f"OS version '{os_version}' not found on screen" diff --git a/tests/test_graphical_osupdate.py b/tests/test_graphical_osupdate.py index 036397cb..83dbfeb6 100644 --- a/tests/test_graphical_osupdate.py +++ b/tests/test_graphical_osupdate.py @@ -11,7 +11,9 @@ from mpos import ( capture_screenshot, find_label_with_text, verify_text_present, - print_screen_labels + print_screen_labels, + DeviceInfo, + BuildInfo ) @@ -148,7 +150,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase): # Check that it contains the current version label_text = version_label.get_text() - current_version = mpos.info.CURRENT_OS_VERSION + current_version = BuildInfo.version.release self.assertIn(current_version, label_text, f"Current version {current_version} not in label text: {label_text}") @@ -186,7 +188,7 @@ class TestOSUpdateGraphicalStatusMessages(unittest.TestCase): def setUp(self): """Set up test fixtures.""" - self.hardware_id = mpos.info.get_hardware_id() + self.hardware_id = DeviceInfo.hardware_id self.screenshot_dir = "tests/screenshots" try: @@ -243,7 +245,7 @@ class TestOSUpdateGraphicalScreenshots(unittest.TestCase): def setUp(self): """Set up test fixtures.""" - self.hardware_id = mpos.info.get_hardware_id() + self.hardware_id = DeviceInfo.hardware_id self.screenshot_dir = "tests/screenshots" try: