Skip to content

Commit

Permalink
JA-80T functionality tahvane1#17
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsaxon committed Mar 20, 2022
1 parent 6886095 commit 4b45f45
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions custom_components/jablotron80/jablotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -758,15 +766,16 @@ 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
send_cmd.confirm(True)

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()
Expand Down

0 comments on commit 4b45f45

Please sign in to comment.