From 27bf573010b4a5e751a8b10dfbbba22630d3f41d Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 3 Sep 2024 16:40:59 +0800 Subject: [PATCH] driver: retrieve hw_rev after conn is established --- pykirdy/driver/kirdy.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pykirdy/driver/kirdy.py b/pykirdy/driver/kirdy.py index 0c858d7..b545d63 100644 --- a/pykirdy/driver/kirdy.py +++ b/pykirdy/driver/kirdy.py @@ -606,6 +606,7 @@ class Kirdy: self.device = Device(self._send_cmd, self._send_raw_cmd) self.laser = Laser(self._send_cmd) self.thermostat = Thermostat(self._send_cmd, self._send_raw_cmd) + self.hw_rev = None self._task_queue, self._int_msg_queue, self._report_queue = None, None, None self._timeout = 5.0 @@ -625,6 +626,8 @@ class Kirdy: self.connected_event = None + def get_hw_rev(self): + return self.hw_rev def set_report_sig(self, sig): """ @@ -756,10 +759,17 @@ class Kirdy: while True: if self._state == State.disconnected: try: + self.hw_rev = None await self.__coninit(self._timeout) self.read_response_task = asyncio.create_task(self._read_response_handler()) task = None logging.info("Connected to %s:%d", self._host, self._ctrl_port) + + hw_rev = await self.device.get_hw_rev() + self.hw_rev = hw_rev["hw_rev"] + + if self._connected_sig is not None: + self._connected_sig.emit(True) self.connected_event.set() # State Transition @@ -849,9 +859,6 @@ class Kirdy: self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(self._host, self._ctrl_port), timeout) writer_sock = self._writer.get_extra_info("socket") writer_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - - if self._connected_sig is not None: - self._connected_sig.emit(True) async def _read_response(self, buffer_size=16384): raw_response = b''