mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
timing and test fixes
This commit is contained in:
@@ -4,7 +4,7 @@ import asyncio
|
|||||||
from meshcore import MeshCore
|
from meshcore import MeshCore
|
||||||
from meshcore import BLEConnection
|
from meshcore import BLEConnection
|
||||||
|
|
||||||
ADDRESS = "Meshcore-lora-py-tester" # node ble adress or name
|
ADDRESS = "T1000_S" # node ble adress or name
|
||||||
|
|
||||||
async def main () :
|
async def main () :
|
||||||
con = BLEConnection(ADDRESS)
|
con = BLEConnection(ADDRESS)
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ class BLEConnection:
|
|||||||
if self.client:
|
if self.client:
|
||||||
logger.debug("Using pre-configured BleakClient.")
|
logger.debug("Using pre-configured BleakClient.")
|
||||||
# If a client is already provided, ensure its disconnect callback is set
|
# If a client is already provided, ensure its disconnect callback is set
|
||||||
self.client._disconnected_callback = self.handle_disconnect
|
assert isinstance(self.client, BleakClient)
|
||||||
|
self.client.set_disconnected_callback(self.handle_disconnect)
|
||||||
self.address = self.client.address
|
self.address = self.client.address
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ class EventDispatcher:
|
|||||||
for key, value in subscription.attribute_filters.items()):
|
for key, value in subscription.attribute_filters.items()):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Fire and forget - don't await!
|
# Fire the call back asychronously
|
||||||
asyncio.create_task(self._execute_callback(subscription.callback, event.clone()))
|
asyncio.create_task(self._execute_callback(subscription.callback, event.clone()))
|
||||||
|
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class SerialConnection:
|
|||||||
logger.debug('port opened')
|
logger.debug('port opened')
|
||||||
if isinstance(transport, serial_asyncio.SerialTransport) and transport.serial:
|
if isinstance(transport, serial_asyncio.SerialTransport) and transport.serial:
|
||||||
transport.serial.rts = False # You can manipulate Serial object via transport
|
transport.serial.rts = False # You can manipulate Serial object via transport
|
||||||
# Signal that connection is established
|
|
||||||
self.cx._connected_event.set()
|
self.cx._connected_event.set()
|
||||||
|
|
||||||
def data_received(self, data):
|
def data_received(self, data):
|
||||||
@@ -39,7 +38,6 @@ class SerialConnection:
|
|||||||
|
|
||||||
def connection_lost(self, exc):
|
def connection_lost(self, exc):
|
||||||
logger.debug('Serial port closed')
|
logger.debug('Serial port closed')
|
||||||
# Clear the connected event
|
|
||||||
self.cx._connected_event.clear()
|
self.cx._connected_event.clear()
|
||||||
if self.cx._disconnect_callback:
|
if self.cx._disconnect_callback:
|
||||||
asyncio.create_task(self.cx._disconnect_callback("serial_disconnect"))
|
asyncio.create_task(self.cx._disconnect_callback("serial_disconnect"))
|
||||||
@@ -54,7 +52,6 @@ class SerialConnection:
|
|||||||
"""
|
"""
|
||||||
Connects to the device
|
Connects to the device
|
||||||
"""
|
"""
|
||||||
# Clear any previous connection state
|
|
||||||
self._connected_event.clear()
|
self._connected_event.clear()
|
||||||
|
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
@@ -62,7 +59,6 @@ class SerialConnection:
|
|||||||
loop, lambda: self.MCSerialClientProtocol(self),
|
loop, lambda: self.MCSerialClientProtocol(self),
|
||||||
self.port, baudrate=self.baudrate)
|
self.port, baudrate=self.baudrate)
|
||||||
|
|
||||||
# Wait for the actual connection to be established
|
|
||||||
await self._connected_event.wait()
|
await self._connected_event.wait()
|
||||||
logger.info("Serial Connection started")
|
logger.info("Serial Connection started")
|
||||||
return self.port
|
return self.port
|
||||||
@@ -108,7 +104,6 @@ class SerialConnection:
|
|||||||
if self.transport:
|
if self.transport:
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
self.transport = None
|
self.transport = None
|
||||||
# Clear the connected event
|
|
||||||
self._connected_event.clear()
|
self._connected_event.clear()
|
||||||
logger.debug("Serial Connection closed")
|
logger.debug("Serial Connection closed")
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class TestBLEConnection(unittest.TestCase):
|
|||||||
asyncio.run(ble_conn.send(data_to_send))
|
asyncio.run(ble_conn.send(data_to_send))
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
|
assert(isinstance(ble_conn.rx_char, MagicMock))
|
||||||
ble_conn.rx_char.write_gatt_char.assert_called_once_with(ble_conn.rx_char, data_to_send, response=True)
|
ble_conn.rx_char.write_gatt_char.assert_called_once_with(ble_conn.rx_char, data_to_send, response=True)
|
||||||
|
|
||||||
def _get_mock_bleak_client(self):
|
def _get_mock_bleak_client(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user