Skip to content

Commit

Permalink
Move NetworkType out of modem_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Jun 9, 2024
1 parent 4827f4f commit cefce4c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
8 changes: 3 additions & 5 deletions python/yaroc/clients/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..utils.async_serial import AsyncATCom
from ..utils.retries import BackoffBatchedRetries
from ..utils.sim7020 import SIM7020Interface
from ..utils.sys_info import NetworkType
from .client import Client

BROKER_URL = "broker.emqx.io"
Expand Down Expand Up @@ -111,10 +112,7 @@ async def send_status(self, status: Status, mac_addr: str) -> bool:
cellid = await self.mm.get_cellid(modems[0])
if cellid is not None:
status.mini_call_home.cellid = cellid
if (
network_state.type == utils.modem_manager.NetworkType.Unknown
and random.randint(0, 4) == 2
):
if network_state.type == NetworkType.Unknown and random.randint(0, 4) == 2:
await self.mm.signal_setup(modems[0], 20)
except Exception as e:
logging.error(f"Error while getting signal strength: {e}")
Expand Down Expand Up @@ -217,7 +215,7 @@ async def send_status(self, status: Status, mac_addr: str) -> bool:
mch.signal_dbm = rssi_dbm
mch.signal_snr = snr
mch.cellid = cellid
mch.network_type = utils.modem_manager.NetworkType.NbIot.value
mch.network_type = NetworkType.NbIot.value

return await self._send(self.topics.status, status.SerializeToString(), "MiniCallHome")

Expand Down
3 changes: 1 addition & 2 deletions python/yaroc/clients/roc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from ..pb.status_pb2 import EventType, Status
from ..rs import SiPunchLog
from ..utils.modem_manager import NetworkType
from ..utils.sys_info import FREQ_MULTIPLIER
from ..utils.sys_info import FREQ_MULTIPLIER, NetworkType
from .client import Client

ROC_SEND_PUNCH = "https://roc.olresultat.se/ver7.1/sendpunches_v2.php"
Expand Down
14 changes: 2 additions & 12 deletions python/yaroc/utils/modem_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dbus_next.aio import MessageBus
from dbus_next.constants import BusType

from .sys_info import NetworkType

MODEM_MANAGER = "org.freedesktop.ModemManager1"


Expand All @@ -22,18 +24,6 @@ def __str__(self):
return str(self.name.lower())


class NetworkType(Enum):
Unknown = 0
NbIot = 1
Gsm = 2
Umts = 3
Lte = 4
Nr5g = 5

def __str__(self):
return self.name.removeprefix("NetworkType.").upper()


@dataclass
class NetworkState:
type: NetworkType = NetworkType.Unknown
Expand Down
13 changes: 13 additions & 0 deletions python/yaroc/utils/sys_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import subprocess
from datetime import datetime, timedelta, timezone
from enum import Enum
from math import floor

import psutil
Expand All @@ -14,6 +15,18 @@
FREQ_MULTIPLIER: int = 20


class NetworkType(Enum):
Unknown = 0
NbIot = 1
Gsm = 2
Umts = 3
Lte = 4
Nr5g = 5

def __str__(self):
return self.name.removeprefix("NetworkType.").upper()


def eth_mac_addr() -> str | None:
for name, addresses in psutil.net_if_addrs().items():
if name.startswith("e"):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_modem_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from yaroc.utils.modem_manager import NetworkState, NetworkType
from yaroc.utils.modem_manager import NetworkState
from yaroc.utils.sys_info import NetworkType


class TestNetworkState(unittest.TestCase):
Expand Down

0 comments on commit cefce4c

Please sign in to comment.