From bc17e9b389818fefef87d99956dd7a50cc2812cb Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Tue, 11 Jan 2022 16:36:39 -0800 Subject: [PATCH] fixes for working on mac air --- meshtastic/__init__.py | 5 ++++- meshtastic/ble_interface.py | 12 ++++++++++-- meshtastic/tests/test_ble_interface.py | 4 +++- meshtastic/tests/test_mesh_interface.py | 1 + pytest.ini | 3 +++ requirements.txt | 1 - setup.py | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 0bcf102..98bc9dc 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -72,7 +72,6 @@ from typing import * import serial import timeago import google.protobuf.json_format -import pygatt from pubsub import pub from dotmap import DotMap from tabulate import tabulate @@ -83,6 +82,10 @@ from meshtastic import (mesh_pb2, portnums_pb2, apponly_pb2, admin_pb2, environmental_measurement_pb2, remote_hardware_pb2, channel_pb2, radioconfig_pb2, util) +if platform.system() == 'Linux': + # pylint: disable=E0401 + import pygatt + # Note: To follow PEP224, comments should be after the module variable. LOCAL_ADDR = "^local" diff --git a/meshtastic/ble_interface.py b/meshtastic/ble_interface.py index 0f45174..0bafefc 100644 --- a/meshtastic/ble_interface.py +++ b/meshtastic/ble_interface.py @@ -1,10 +1,16 @@ """Bluetooth interface """ import logging -import pygatt - +import platform from meshtastic.mesh_interface import MeshInterface +from meshtastic.util import our_exit + +if platform.system() == 'Linux': + # pylint: disable=E0401 + import pygatt + + # Our standard BLE characteristics TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7" @@ -16,6 +22,8 @@ class BLEInterface(MeshInterface): """A not quite ready - FIXME - BLE interface to devices""" def __init__(self, address, noProto=False, debugOut=None): + if platform.system() != 'Linux': + our_exit("Linux is the only platform with experimental BLE support.", 1) self.address = address if not noProto: self.adapter = pygatt.GATTToolBackend() # BGAPIBackend() diff --git a/meshtastic/tests/test_ble_interface.py b/meshtastic/tests/test_ble_interface.py index 9840aca..f0cd962 100644 --- a/meshtastic/tests/test_ble_interface.py +++ b/meshtastic/tests/test_ble_interface.py @@ -1,12 +1,14 @@ """Meshtastic unit tests for ble_interface.py""" +from unittest.mock import patch import pytest from ..ble_interface import BLEInterface @pytest.mark.unit -def test_BLEInterface(): +@patch('platform.system', return_value='Linux') +def test_BLEInterface(mock_platform): """Test that we can instantiate a BLEInterface""" iface = BLEInterface('foo', debugOut=True, noProto=True) iface.close() diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index 7208138..b0b9d76 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -418,6 +418,7 @@ def test_sendPacket_with_destination_as_LOCAL_ADDR_with_myInfo(caplog, reset_glo iface = MeshInterface(noProto=True) myInfo = MagicMock() iface.myInfo = myInfo + iface.myInfo.my_node_num = 1 with caplog.at_level(logging.DEBUG): meshPacket = mesh_pb2.MeshPacket() iface._sendPacket(meshPacket, destinationId=LOCAL_ADDR) diff --git a/pytest.ini b/pytest.ini index 50b0844..ba73ac0 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,6 +2,9 @@ addopts = -m "not int and not smoke1 and not smoke2 and not smokewifi and not examples and not smokevirt" +filterwarnings = + ignore::DeprecationWarning + markers = unit: marks tests as unit tests unitslow: marks slow unit tests diff --git a/requirements.txt b/requirements.txt index f14fecc..2b0e347 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ protobuf dotmap pexpect pyqrcode -pygatt tabulate timeago webencodings diff --git a/setup.py b/setup.py index 6c28280..d9d1c3c 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( include_package_data=True, install_requires=["pyserial>=3.4", "protobuf>=3.13.0", "pypubsub>=4.0.3", "dotmap>=1.3.14", "pexpect>=4.6.0", "pyqrcode>=1.2.1", - "pygatt>=4.0.5", "tabulate>=0.8.9", "timeago>=1.0.15", "pyyaml"], + "tabulate>=0.8.9", "timeago>=1.0.15", "pyyaml"], extras_require={ 'tunnel': ["pytap2>=2.0.0"] },