Skip to content

Commit

Permalink
bobcat: add is_bobcat check
Browse files Browse the repository at this point in the history
  • Loading branch information
shawaj committed Jun 28, 2023
1 parent 99c6a63 commit 621a03e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions hm_pyhelper/hardware_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions hm_pyhelper/sbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DeviceVendorID(Enum):
INVALID = auto()
ROCK_PI = auto()
RASPBERRY_PI = auto()
BOBCAT_PX30 = auto()


# Pulled from
Expand All @@ -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
}
Expand Down Expand Up @@ -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


Expand Down
23 changes: 21 additions & 2 deletions hm_pyhelper/tests/test_hardware_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 621a03e

Please sign in to comment.