Skip to content

Commit

Permalink
fix: catch any random BLE errors on LIVE_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Jan 25, 2024
1 parent 5bd15d5 commit b8d0a76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion backend/pinecil_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ async def monitor(self, stop_event):
await self.broadcast(msg)
except DeviceDisconnectedException:
logging.info("Pinecil disconnected")
self.broadcast(
await self.broadcast(
json.dumps({"status": "ERROR", "message": "Device disconnected"})
)
except Exception as e:
logging.warning("Error while getting live data - ignored")
9 changes: 5 additions & 4 deletions backend/test_pinecil_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def select_pinecil(index):

@pytest.fixture
def mock_broadcast():
return MagicMock()
return AsyncMock()


@pytest.mark.asyncio
Expand All @@ -97,11 +97,12 @@ async def test_monitor_no_pinecil_found(
@pytest.mark.asyncio
async def test_monitor_success(mock_pinecil_finder, mock_broadcast):
stop_event = asyncio.Event()
monitor = PinecilMonitor(mock_pinecil_finder, mock_broadcast)
mock_broadcast_sets_event = AsyncMock(side_effect=lambda msg: stop_event.set())

monitor = PinecilMonitor(mock_pinecil_finder, mock_broadcast_sets_event)
asyncio.create_task(monitor.monitor(stop_event))
await asyncio.sleep(0.2)
stop_event.set()
mock_broadcast.assert_called_with(
mock_broadcast_sets_event.assert_called_with(
'{"command": "LIVE_DATA", "payload": {"temp": 100, "voltage": 230}, "status": "OK"}'
)

Expand Down

0 comments on commit b8d0a76

Please sign in to comment.