Skip to content

Commit

Permalink
Fixed section states when invalid code was inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Dec 18, 2020
1 parent bd71006 commit 037250b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions custom_components/jablotron100/jablotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ def modify_alarm_control_panel_section_state(self, section: int, state: str, cod
if code != self._config[CONF_PASSWORD]:
self._send_packet(Jablotron.create_packet_keapalive(self._config[CONF_PASSWORD]))

# Update states - should fix state when invalid code was inserted
self._send_packet(Jablotron.create_packet_command(JABLOTRON_COMMAND_GET_SECTIONS_AND_PG_OUTPUTS_STATES))

def toggle_pg_output(self, pg_output_number: int, state: str) -> None:
pg_output_number_packet = Jablotron.int_to_bytes(pg_output_number - 1)
state_packet = Jablotron.int_to_bytes(JABLOTRON_PG_OUTPUT_TURN_ON if state == STATE_ON else JABLOTRON_PG_OUTPUT_TURN_OFF)
Expand Down Expand Up @@ -843,6 +846,10 @@ def _read_packets(self) -> None:
elif Jablotron._is_device_info_packet(packet):
self._parse_device_info_packet(packet)

elif Jablotron._is_login_error_packet(packet):
# Login error - update section states to have actual states
self._send_packet(Jablotron.create_packet_command(JABLOTRON_COMMAND_GET_SECTIONS_AND_PG_OUTPUTS_STATES))

break

except Exception as ex:
Expand Down Expand Up @@ -1246,6 +1253,17 @@ def _data_to_store(self) -> dict:
def _is_sections_states_packet(packet: bytes) -> bool:
return packet[:1] == JABLOTRON_PACKET_SECTIONS_STATES

@staticmethod
def _is_login_error_packet(packet: bytes) -> bool:
if (
packet[:1] == JABLOTRON_PACKET_UI_CONTROL
and packet[2:3] == b"\x1b"
and packet[3:4] == b"\x03"
):
return True

return False

@staticmethod
def _is_pg_outputs_states_packet(packet: bytes) -> bool:
return packet[:1] == JABLOTRON_PACKET_PG_OUTPUTS_STATES
Expand Down

0 comments on commit 037250b

Please sign in to comment.