From 621a03e47942fed007a5238a906ade7f3a614677 Mon Sep 17 00:00:00 2001 From: Aaron Shaw Date: Tue, 27 Jun 2023 22:17:13 +0100 Subject: [PATCH] bobcat: add is_bobcat check --- hm_pyhelper/hardware_definitions.py | 4 ++++ hm_pyhelper/sbc.py | 8 +++++++ .../tests/test_hardware_definitions.py | 23 +++++++++++++++++-- pyproject.toml | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/hm_pyhelper/hardware_definitions.py b/hm_pyhelper/hardware_definitions.py index 55c02f6..feea425 100644 --- a/hm_pyhelper/hardware_definitions.py +++ b/hm_pyhelper/hardware_definitions.py @@ -3,6 +3,10 @@ UnknownVariantAttributeException +def is_bobcat_px30() -> bool: + return sbc.is_sbc_type(sbc.DeviceVendorID.BOBCAT_PX30) + + def is_rockpi() -> bool: return sbc.is_sbc_type(sbc.DeviceVendorID.ROCK_PI) diff --git a/hm_pyhelper/sbc.py b/hm_pyhelper/sbc.py index abd832c..4aff392 100644 --- a/hm_pyhelper/sbc.py +++ b/hm_pyhelper/sbc.py @@ -19,6 +19,7 @@ class DeviceVendorID(Enum): INVALID = auto() ROCK_PI = auto() RASPBERRY_PI = auto() + BOBCAT_PX30 = auto() # Pulled from @@ -36,7 +37,10 @@ class DeviceVendorID(Enum): BALENA_ENV_ROCKPI_MODELS = ['rockpi-4b-rk3399'] +BALENA_ENV_BOBCATPX30_MODELS = ['isg-503'] + BALENA_MODELS = { + DeviceVendorID.BOBCAT_PX30: BALENA_ENV_BOBCATPX30_MODELS, DeviceVendorID.ROCK_PI: BALENA_ENV_ROCKPI_MODELS, DeviceVendorID.RASPBERRY_PI: BALENA_ENV_RASPBERRY_PI_MODELS } @@ -170,6 +174,10 @@ def sbc_info() -> SBCInfo: sbc_info = SBCInfo(vendor_id=DeviceVendorID.ROCK_PI, vendor_name='Radxa Rock Pi', model_name=dev_model) + elif dev_model.lower().find('px30') >= 0: + sbc_info = SBCInfo(vendor_id=DeviceVendorID.BOBCAT_PX30, + vendor_name='Bobcat', + model_name=dev_model) return sbc_info diff --git a/hm_pyhelper/tests/test_hardware_definitions.py b/hm_pyhelper/tests/test_hardware_definitions.py index b8182ba..b2044c8 100644 --- a/hm_pyhelper/tests/test_hardware_definitions.py +++ b/hm_pyhelper/tests/test_hardware_definitions.py @@ -7,9 +7,9 @@ UnknownVariantAttributeException from hm_pyhelper.hardware_definitions import is_rockpi, variant_definitions, \ - get_variant_attribute, is_raspberry_pi + get_variant_attribute, is_raspberry_pi, is_bobcat_px30 from hm_pyhelper.sbc import BALENA_ENV_RASPBERRY_PI_MODELS, \ - BALENA_ENV_ROCKPI_MODELS + BALENA_ENV_ROCKPI_MODELS, BALENA_ENV_BOBCATPX30_MODELS BUILTINS_OPEN_LITERAL = "builtins.open" @@ -140,3 +140,22 @@ def test_is_rock_pi(self): # which will not exist on test environment. with self.assertRaises(FileNotFoundError): self.assertFalse(is_rockpi()) + + mock_known_bobcat_px30_dts_models = ["Bobcat PX30"] + + def test_is_bobcat_px30(self): + for model in self.mock_known_bobcat_px30_dts_models: + with patch(BUILTINS_OPEN_LITERAL, new_callable=mock_open, read_data=model): + self.assertTrue(is_bobcat_px30()) + with patch(BUILTINS_OPEN_LITERAL, new_callable=mock_open, + read_data="raspberry something"): + self.assertFalse(is_bobcat_px30()) + + # test balena env based detection + for model in BALENA_ENV_BOBCATPX30_MODELS: + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': model}): + self.assertTrue(is_bobcat_px30()) + # in absence of the env, it should look for /proc/device-tree/model + # which will not exist on test environment. + with self.assertRaises(FileNotFoundError): + self.assertFalse(is_bobcat_px30()) diff --git a/pyproject.toml b/pyproject.toml index 2b2a861..a14313e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "hm_pyhelper" -version = "0.14.19" +version = "0.14.20" description = "Helium Python Helper" authors = ["Nebra Ltd "] readme = "README.md"