adapt device connection component to use @task decorator

This commit is contained in:
Mose Müller 2024-08-06 11:18:27 +02:00
parent 09fae01985
commit be3011c565

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import pydase.data_service import pydase.data_service
import pydase.task
class DeviceConnection(pydase.data_service.DataService): class DeviceConnection(pydase.data_service.DataService):
@ -52,7 +53,6 @@ class DeviceConnection(pydase.data_service.DataService):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self._connected = False self._connected = False
self._autostart_tasks["_handle_connection"] = () # type: ignore
self._reconnection_wait_time = 10.0 self._reconnection_wait_time = 10.0
def connect(self) -> None: def connect(self) -> None:
@ -70,6 +70,7 @@ class DeviceConnection(pydase.data_service.DataService):
""" """
return self._connected return self._connected
@pydase.task.task(autostart=True)
async def _handle_connection(self) -> None: async def _handle_connection(self) -> None:
"""Automatically tries reconnecting to the device if it is not connected. """Automatically tries reconnecting to the device if it is not connected.
This method leverages the `connect` method and the `connected` property to This method leverages the `connect` method and the `connected` property to