Skip to content

Commit

Permalink
Use asyncio sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
abmantis authored and newAM committed Aug 24, 2023
1 parent 21f1525 commit d09fdb4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions idasen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import asyncio
import logging
import sys
import time


_UUID_HEIGHT: str = "99fa0021-338a-1024-8a49-009c0215f78a"
Expand Down Expand Up @@ -116,7 +115,7 @@ async def _connect(self):
self._logger.warning(
f"Failed to connect, retrying ({i}/{self.RETRY_COUNT})..."
)
time.sleep(0.3 * i)
await asyncio.sleep(0.3 * i)

async def monitor(self, callback: Callable[[float], Awaitable[None]]):
output_service_uuid = "99fa0020-338a-1024-8a49-009c0215f78a"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_idasen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import bleak
import idasen
import pytest
import time


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -154,8 +153,8 @@ async def test_fail_to_connect(caplog, monkeypatch):
async def raise_exception(*_):
raise Exception

# patch `time.sleep()` to prevent making the tests unnecessarily long.
monkeypatch.setattr(time, "sleep", lambda *_: None)
# patch `asyncio.sleep()` to prevent making the tests unnecessarily long.
monkeypatch.setattr(asyncio, "sleep", mock.AsyncMock())

caplog.set_level("WARNING")

Expand Down

0 comments on commit d09fdb4

Please sign in to comment.