Use start and end session nomenclature

Helps when we also inherit from QObject, which already has connect and
disconnect methods.
This commit is contained in:
atse 2023-08-09 11:13:43 +08:00
parent 05bc5d8809
commit c6815950d2
3 changed files with 11 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from pytec.aioclient import Client
async def main():
tec = Client()
await tec.connect() #(host="192.168.1.26", port=23)
await tec.start_session() #(host="192.168.1.26", port=23)
await tec.set_param("s-h", 1, "t0", 20)
print(await tec.get_pwm())
print(await tec.get_pid())

View File

@ -17,15 +17,15 @@ class Client:
self._report_mode_on = False
self.timeout = None
async def connect(self, host='192.168.1.26', port=23, timeout=None):
"""Connect to the Thermostat with host and port.
async def start_session(self, host='192.168.1.26', port=23, timeout=None):
"""Start session to Thermostat at specified host and port.
Throws StoppedConnecting if disconnect was called while connecting.
Throws asyncio.TimeoutError if timeout was exceeded.
Example::
client = Client()
try:
await client.connect()
await client.start_session()
except StoppedConnecting:
print("Stopped connecting")
"""
@ -50,8 +50,8 @@ class Client:
"""Returns True if client is connected"""
return self._writer is not None
async def disconnect(self):
"""Disconnect the client if connected, cancel connection if connecting"""
async def end_session(self):
"""End session to Thermostat if connected, cancel connection if connecting"""
if self._connecting_task is not None:
self._connecting_task.cancel()
@ -249,7 +249,7 @@ class Client:
self._writer.write("reset\n".encode('utf-8'))
await self._writer.drain()
await self.disconnect()
await self.end_session()
async def dfu(self):
"""Put the Thermostat in DFU update mode
@ -262,7 +262,7 @@ class Client:
self._writer.write("dfu\n".encode('utf-8'))
await self._writer.drain()
await self.disconnect()
await self.end_session()
async def ipv4(self):
"""Get the IPv4 settings of the Thermostat"""

View File

@ -570,7 +570,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.port_set_spin.setEnabled(False)
try:
await self.client.connect(host=host, port=port, timeout=30)
await self.client.start_session(host=host, port=port, timeout=30)
except StoppedConnecting:
return
await self._on_connection_changed(True)
@ -581,9 +581,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
logging.error(f"Failed communicating to {host}:{port}: {e}")
await self.bail()
@asyncSlot()
async def bail(self):
await self._on_connection_changed(False)
await self.client.disconnect()
await self.client.end_session()
@pyqtSlot(list)
def plot(self, report):