Skip to content

Commit

Permalink
split out task creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Dec 2, 2023
1 parent 8bb0aa4 commit d582406
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pyacaia_async/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
self._queue: asyncio.Queue = asyncio.Queue()
self._heartbeat_task: asyncio.Task | None = None
self._process_queue_task: asyncio.Task | None = None
self._tasks_initialized = False

self._msg_types["auth"] = encode_id(is_pyxis_style=is_new_style_scale)

Expand Down Expand Up @@ -232,16 +233,22 @@ async def connect(

except BleakDeviceNotFoundError as ex:
raise AcaiaDeviceNotFound("Device not found") from ex

self._setup_tasks()

if not self._heartbeat_task:
self._heartbeat_task = asyncio.create_task(
def _setup_tasks(self) -> None:
"""Setup background tasks""":
if self._tasks_initialized:
return

self._heartbeat_task = asyncio.create_task(
self._send_heartbeats(
interval=HEARTBEAT_INTERVAL if not self._is_new_style_scale else 1,
new_style_heartbeat=self._is_new_style_scale,
)
)
if not self._process_queue_task:
self._process_queue_task = asyncio.create_task(self._process_queue())
self._process_queue_task = asyncio.create_task(self._process_queue())
self._tasks_initialized = True

async def auth(self) -> None:
"""Send auth message to scale, if subscribed to notifications returns Settings object"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyacaia_async",
version="0.0.11b7",
version="0.0.11b8",
description="An async implementation of PyAcaia",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit d582406

Please sign in to comment.