forked from M-Labs/thermostat
{start,end}_session -> [dis]connect
This commit is contained in:
parent
22de1b623f
commit
3a1c7792c9
@ -4,7 +4,7 @@ from pytec.aioclient import AsyncioClient
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
tec = AsyncioClient()
|
tec = AsyncioClient()
|
||||||
await tec.start_session() # (host="192.168.1.26", port=23)
|
await tec.connect() # (host="192.168.1.26", port=23)
|
||||||
await tec.set_param("s-h", 1, "t0", 20)
|
await tec.set_param("s-h", 1, "t0", 20)
|
||||||
print(await tec.get_pwm())
|
print(await tec.get_pwm())
|
||||||
print(await tec.get_pid())
|
print(await tec.get_pid())
|
||||||
|
@ -15,12 +15,12 @@ class AsyncioClient:
|
|||||||
self._report_mode_on = False
|
self._report_mode_on = False
|
||||||
self.timeout = None
|
self.timeout = None
|
||||||
|
|
||||||
async def start_session(self, host="192.168.1.26", port=23):
|
async def connect(self, host="192.168.1.26", port=23):
|
||||||
"""Start session to Thermostat at specified host and port.
|
"""Connect to Thermostat at specified host and port.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
client = AsyncioClient()
|
client = AsyncioClient()
|
||||||
await client.start_session()
|
await client.connect()
|
||||||
"""
|
"""
|
||||||
self._reader, self._writer = await asyncio.open_connection(host, port)
|
self._reader, self._writer = await asyncio.open_connection(host, port)
|
||||||
await self._check_zero_limits()
|
await self._check_zero_limits()
|
||||||
@ -29,8 +29,8 @@ class AsyncioClient:
|
|||||||
"""Returns True if client is connected"""
|
"""Returns True if client is connected"""
|
||||||
return self._writer is not None
|
return self._writer is not None
|
||||||
|
|
||||||
async def end_session(self):
|
async def disconnect(self):
|
||||||
"""End session to Thermostat"""
|
"""Disconnect from the Thermostat"""
|
||||||
|
|
||||||
if self._writer is None:
|
if self._writer is None:
|
||||||
return
|
return
|
||||||
@ -243,7 +243,7 @@ class AsyncioClient:
|
|||||||
self._writer.write("reset\n".encode("utf-8"))
|
self._writer.write("reset\n".encode("utf-8"))
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
await self.end_session()
|
await self.disconnect()
|
||||||
|
|
||||||
async def dfu(self):
|
async def dfu(self):
|
||||||
"""Put the Thermostat in DFU update mode
|
"""Put the Thermostat in DFU update mode
|
||||||
@ -256,7 +256,7 @@ class AsyncioClient:
|
|||||||
self._writer.write("dfu\n".encode("utf-8"))
|
self._writer.write("dfu\n".encode("utf-8"))
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
await self.end_session()
|
await self.disconnect()
|
||||||
|
|
||||||
async def ipv4(self):
|
async def ipv4(self):
|
||||||
"""Get the IPv4 settings of the Thermostat"""
|
"""Get the IPv4 settings of the Thermostat"""
|
||||||
|
@ -29,7 +29,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
async def start_session(self, host, port):
|
async def start_session(self, host, port):
|
||||||
await self._client.start_session(host, port)
|
await self._client.connect(host, port)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
self._update_params_task = asyncio.create_task(self.update_params())
|
self._update_params_task = asyncio.create_task(self.update_params())
|
||||||
@ -97,7 +97,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
]
|
]
|
||||||
|
|
||||||
async def end_session(self):
|
async def end_session(self):
|
||||||
await self._client.end_session()
|
await self._client.disconnect()
|
||||||
self.connection_errored = False
|
self.connection_errored = False
|
||||||
|
|
||||||
async def set_ipv4(self, ipv4):
|
async def set_ipv4(self, ipv4):
|
||||||
|
Loading…
Reference in New Issue
Block a user