diff --git a/custom_components/jablotron80/jablotron.py b/custom_components/jablotron80/jablotron.py index 17ea1ba..d457c18 100644 --- a/custom_components/jablotron80/jablotron.py +++ b/custom_components/jablotron80/jablotron.py @@ -693,13 +693,15 @@ def _forward_records(self,records: List[bytearray]) -> None: def _read_data(self, max_package_sections: int =15)->List[bytearray]: read_buffer = [] ret_val = [] - for j in range(max_package_sections): - data = self._connection.read(64) - #UNCOMMENT THESE LINES TO SEE RAW DATA (produces a lot of logs) - #if LOGGER.isEnabledFor(logging.DEBUG): - # formatted_data = " ".join(["%02x" % c for c in data]) - # LOGGER.debug(f'Received raw data {formatted_data}') - if self._type == CABLE_MODEL_JA82T and len(data) > 0 and data[0] == 0x82: + + if self._type == CABLE_MODEL_JA82T: + for j in range(max_package_sections): + data = self._connection.read(64) + #UNCOMMENT THESE LINES TO SEE RAW DATA (produces a lot of logs) + #if LOGGER.isEnabledFor(logging.DEBUG): + # formatted_data = " ".join(["%02x" % c for c in data]) + # LOGGER.debug(f'Received raw data {formatted_data}') + if len(data) > 0 and data[0] == 0x82: size = data[1] read_buffer.append(data[2:2+int(size)]) if data[1 + int(size)] == 0xff: @@ -711,16 +713,22 @@ def _read_data(self, max_package_sections: int =15)->List[bytearray]: ret_val.append(bytearray(ret_bytes)) ret_bytes.clear() return ret_val - elif self._type == CABLE_MODEL_JA80T: - ret_bytes = [] - read_buffer.append(data) - for i in b''.join(read_buffer): - ret_bytes.append(i) - if i == 0xff: - ret_val.append(bytearray(ret_bytes)) - ret_bytes.clear() - return ret_val - return ret_val + return ret_val + + elif self._type == CABLE_MODEL_JA80T: + data = self._connection.read_until(b'\xff') + #if LOGGER.isEnabledFor(logging.DEBUG): + # formatted_data = " ".join(["%02x" % c for c in data]) + # LOGGER.debug(f'Received raw data {formatted_data}') + ret_bytes = [] + read_buffer.append(data) + for i in b''.join(read_buffer): + ret_bytes.append(i) + if i == 0xff: + ret_val.append(bytearray(ret_bytes)) + ret_bytes.clear() + return ret_val + def read_send_packet_loop(self) -> None: # keep reading bytes untill 0xff which indicates end of packet @@ -758,7 +766,8 @@ def read_send_packet_loop(self) -> None: self._forward_records(records_tmp) for record in records_tmp: if (self._type == CABLE_MODEL_JA82T and record[:len(send_cmd.confirm_prefix)] == send_cmd.confirm_prefix) \ - or self._type == CABLE_MODEL_JA80T and record[:1] == b'\xff': + or (self._type == CABLE_MODEL_JA80T and (send_cmd.confirm_prefix == send_cmd.code or \ + record[:len(send_cmd.confirm_prefix)] == send_cmd.confirm_prefix)): LOGGER.info( f"confirmation for command {send_cmd} received") confirmed=True @@ -766,7 +775,7 @@ def read_send_packet_loop(self) -> None: if not confirmed: # no confirmation received - LOGGER.info( + LOGGER.warn( f"no confirmation for command {send_cmd} received") send_cmd.confirm(False) self._cmd_q.task_done()