driver: retrieve hw_rev after conn is established

This commit is contained in:
linuswck 2024-09-03 16:40:59 +08:00
parent c267c30b89
commit 27bf573010
1 changed files with 10 additions and 3 deletions

View File

@ -606,6 +606,7 @@ class Kirdy:
self.device = Device(self._send_cmd, self._send_raw_cmd) self.device = Device(self._send_cmd, self._send_raw_cmd)
self.laser = Laser(self._send_cmd) self.laser = Laser(self._send_cmd)
self.thermostat = Thermostat(self._send_cmd, self._send_raw_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._task_queue, self._int_msg_queue, self._report_queue = None, None, None
self._timeout = 5.0 self._timeout = 5.0
@ -625,6 +626,8 @@ class Kirdy:
self.connected_event = None self.connected_event = None
def get_hw_rev(self):
return self.hw_rev
def set_report_sig(self, sig): def set_report_sig(self, sig):
""" """
@ -756,10 +759,17 @@ class Kirdy:
while True: while True:
if self._state == State.disconnected: if self._state == State.disconnected:
try: try:
self.hw_rev = None
await self.__coninit(self._timeout) await self.__coninit(self._timeout)
self.read_response_task = asyncio.create_task(self._read_response_handler()) self.read_response_task = asyncio.create_task(self._read_response_handler())
task = None task = None
logging.info("Connected to %s:%d", self._host, self._ctrl_port) 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() self.connected_event.set()
# State Transition # State Transition
@ -850,9 +860,6 @@ class Kirdy:
writer_sock = self._writer.get_extra_info("socket") writer_sock = self._writer.get_extra_info("socket")
writer_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 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): async def _read_response(self, buffer_size=16384):
raw_response = b'' raw_response = b''
while len(raw_response) == 0: while len(raw_response) == 0: