Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Jun 1, 2024
1 parent 5dc7d3e commit e73deb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions custom_components/jablotron100/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def async_alarm_disarm(self, code: str | None = None) -> None:
if code is None and self._code_required_for_disarm:
return

self._jablotron.modify_alarm_control_panel_section_state(self._control.section, STATE_ALARM_DISARMED, code)
await self._jablotron.modify_alarm_control_panel_section_state(self._control.section, STATE_ALARM_DISARMED, code)

async def async_alarm_arm_away(self, code: str | None = None) -> None:
if self._get_state() == STATE_ALARM_ARMED_AWAY:
Expand All @@ -88,7 +88,7 @@ async def async_alarm_arm_away(self, code: str | None = None) -> None:
if code is None and self._attr_code_arm_required:
return

self._jablotron.modify_alarm_control_panel_section_state(self._control.section, STATE_ALARM_ARMED_AWAY, code)
await self._jablotron.modify_alarm_control_panel_section_state(self._control.section, STATE_ALARM_ARMED_AWAY, code)

async def async_alarm_arm_home(self, code: str | None = None) -> None:
await self._arm_partially(STATE_ALARM_ARMED_HOME, code)
Expand All @@ -112,7 +112,7 @@ async def _arm_partially(self, state: StateType, code: str | None = None) -> Non
if code is None and self._attr_code_arm_required:
return

self._jablotron.modify_alarm_control_panel_section_state(self._control.section, state, code)
await self._jablotron.modify_alarm_control_panel_section_state(self._control.section, state, code)

def _detect_supported_features(self) -> AlarmControlPanelEntityFeature:
if self._partially_arming_mode == PartiallyArmingMode.NOT_SUPPORTED:
Expand Down
10 changes: 8 additions & 2 deletions custom_components/jablotron100/jablotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ def shutdown(self) -> None:
def subscribe_hass_entity_for_updates(self, control_id: str, hass_entity: JablotronEntity) -> None:
self.hass_entities[control_id] = hass_entity

def modify_alarm_control_panel_section_state(self, section: int, state: StateType, code: str | None) -> None:
async def modify_alarm_control_panel_section_state(self, section: int, state: StateType, code: str | None) -> None:
await self._hass.async_add_executor_job(self.sync_modify_alarm_control_panel_section_state, section, state, code)

def sync_modify_alarm_control_panel_section_state(self, section: int, state: StateType, code: str | None) -> None:
if code is None:
code = self._config[CONF_PASSWORD]

Expand Down Expand Up @@ -368,7 +371,10 @@ def after_login_callback(_) -> None:
else:
after_login_callback(None)

def toggle_pg_output(self, pg_output_number: int, state: str) -> None:
async def toggle_pg_output(self, pg_output_number: int, state: str) -> None:
await self._hass.async_add_executor_job(self.sync_toggle_pg_output, pg_output_number, state)

def sync_toggle_pg_output(self, pg_output_number: int, state: str) -> None:
pg_output_number_packet = self.int_to_bytes(pg_output_number - 1)
state_packet = PG_OUTPUT_TURN_ON if state == STATE_ON else PG_OUTPUT_TURN_OFF

Expand Down
4 changes: 2 additions & 2 deletions custom_components/jablotron100/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def _update_attributes(self) -> None:
self._attr_is_on = self._get_state() == STATE_ON

async def async_turn_on(self, **kwargs) -> None:
self._jablotron.toggle_pg_output(self._control.pg_output_number, STATE_ON)
await self._jablotron.toggle_pg_output(self._control.pg_output_number, STATE_ON)
self.update_state(STATE_ON)

async def async_turn_off(self, **kwargs) -> None:
self._jablotron.toggle_pg_output(self._control.pg_output_number, STATE_OFF)
await self._jablotron.toggle_pg_output(self._control.pg_output_number, STATE_OFF)
self.update_state(STATE_OFF)

0 comments on commit e73deb4

Please sign in to comment.