diff --git a/common/esim/__init__.py b/common/esim/__init__.py new file mode 100644 index 000000000..5f83412c0 --- /dev/null +++ b/common/esim/__init__.py @@ -0,0 +1,3 @@ +from openpilot.common.esim.base import LPABase, LPAError, LPAProfileNotFoundError, Profile + +__all__ = ["LPABase", "LPAError", "LPAProfileNotFoundError", "Profile"] diff --git a/common/esim/base.py b/common/esim/base.py new file mode 100644 index 000000000..b783a630b --- /dev/null +++ b/common/esim/base.py @@ -0,0 +1,55 @@ +from abc import ABC, abstractmethod +from dataclasses import dataclass + + +class LPAError(RuntimeError): + pass + + +class LPAProfileNotFoundError(LPAError): + pass + + +@dataclass +class Profile: + iccid: str + nickname: str + enabled: bool + provider: str + + @property + def is_comma(self) -> bool: + return self.provider == 'Webbing' and self.iccid.startswith('8985235') + + +class LPABase(ABC): + @abstractmethod + def list_profiles(self) -> list[Profile]: + pass + + @abstractmethod + def get_active_profile(self) -> Profile | None: + pass + + @abstractmethod + def delete_profile(self, iccid: str) -> None: + pass + + @abstractmethod + def download_profile(self, qr: str, nickname: str | None = None) -> None: + pass + + @abstractmethod + def nickname_profile(self, iccid: str, nickname: str) -> None: + pass + + @abstractmethod + def switch_profile(self, iccid: str) -> None: + pass + + def process_notifications(self) -> None: + pass + + @abstractmethod + def is_euicc(self) -> bool: + pass diff --git a/system/hardware/esim.py b/common/esim/esim.py similarity index 97% rename from system/hardware/esim.py rename to common/esim/esim.py index 18d84de98..788e944c4 100755 --- a/system/hardware/esim.py +++ b/common/esim/esim.py @@ -2,7 +2,7 @@ import argparse from openpilot.system.hardware import HARDWARE -from openpilot.system.hardware.base import LPABase, Profile +from openpilot.common.esim.base import LPABase, Profile def sorted_profiles(lpa: LPABase) -> list[Profile]: diff --git a/system/hardware/tici/gsma_ci_bundle.pem b/common/esim/gsma_ci_bundle.pem similarity index 100% rename from system/hardware/tici/gsma_ci_bundle.pem rename to common/esim/gsma_ci_bundle.pem diff --git a/system/hardware/tici/lpa.py b/common/esim/lpa.py similarity index 99% rename from system/hardware/tici/lpa.py rename to common/esim/lpa.py index 618d11e5d..400982332 100644 --- a/system/hardware/tici/lpa.py +++ b/common/esim/lpa.py @@ -19,7 +19,7 @@ from typing import Any from pathlib import Path from openpilot.common.time_helpers import system_time_valid -from openpilot.system.hardware.base import LPABase, LPAError, LPAProfileNotFoundError, Profile +from openpilot.common.esim.base import LPABase, LPAError, LPAProfileNotFoundError, Profile GSMA_CI_BUNDLE = str(Path(__file__).parent / "gsma_ci_bundle.pem") diff --git a/system/hardware/base.py b/system/hardware/base.py index 5bcf886ae..dccb16893 100644 --- a/system/hardware/base.py +++ b/system/hardware/base.py @@ -3,27 +3,11 @@ from abc import abstractmethod, ABC from dataclasses import dataclass, fields from cereal import log +from openpilot.common.esim.base import LPABase NetworkType = log.DeviceState.NetworkType NetworkStrength = log.DeviceState.NetworkStrength -class LPAError(RuntimeError): - pass - -class LPAProfileNotFoundError(LPAError): - pass - -@dataclass -class Profile: - iccid: str - nickname: str - enabled: bool - provider: str - - @property - def is_comma(self) -> bool: - return self.provider == 'Webbing' and self.iccid.startswith('8985235') - @dataclass class ThermalZone: # a zone from /sys/class/thermal/thermal_zone* @@ -70,38 +54,6 @@ class ThermalConfig: ret[f.name + "TempC"] = v.read() return ret -class LPABase(ABC): - @abstractmethod - def list_profiles(self) -> list[Profile]: - pass - - @abstractmethod - def get_active_profile(self) -> Profile | None: - pass - - @abstractmethod - def delete_profile(self, iccid: str) -> None: - pass - - @abstractmethod - def download_profile(self, qr: str, nickname: str | None = None) -> None: - pass - - @abstractmethod - def nickname_profile(self, iccid: str, nickname: str) -> None: - pass - - @abstractmethod - def switch_profile(self, iccid: str) -> None: - pass - - def process_notifications(self) -> None: - pass - - @abstractmethod - def is_euicc(self) -> bool: - pass - class HardwareBase(ABC): @staticmethod def get_cmdline() -> dict[str, str]: diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index 10b6d7646..252474e12 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -10,9 +10,10 @@ from pathlib import Path from cereal import log from openpilot.common.utils import sudo_read, sudo_write from openpilot.common.gpio import gpio_set, gpio_init, get_irqs_for_action -from openpilot.system.hardware.base import HardwareBase, LPABase, ThermalConfig, ThermalZone +from openpilot.common.esim.base import LPABase +from openpilot.system.hardware.base import HardwareBase, ThermalConfig, ThermalZone from openpilot.system.hardware.tici import iwlist -from openpilot.system.hardware.tici.lpa import TiciLPA +from openpilot.common.esim.lpa import TiciLPA from openpilot.system.hardware.tici.pins import GPIO from openpilot.system.hardware.tici.amplifier import Amplifier diff --git a/tools/op.sh b/tools/op.sh index 1188d21ac..ecef240b5 100755 --- a/tools/op.sh +++ b/tools/op.sh @@ -298,7 +298,7 @@ function op_check() { function op_esim() { op_before_cmd - op_run_command system/hardware/esim.py "$@" + op_run_command common/esim/esim.py "$@" } function op_build() {