From e73deb494b666234a84ec9902c913aa8e8d5d49b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= Date: Sat, 1 Jun 2024 11:57:35 +0200 Subject: [PATCH] Fix --- custom_components/jablotron100/alarm_control_panel.py | 6 +++--- custom_components/jablotron100/jablotron.py | 10 ++++++++-- custom_components/jablotron100/switch.py | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/custom_components/jablotron100/alarm_control_panel.py b/custom_components/jablotron100/alarm_control_panel.py index a49e6d7..58f760c 100644 --- a/custom_components/jablotron100/alarm_control_panel.py +++ b/custom_components/jablotron100/alarm_control_panel.py @@ -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: @@ -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) @@ -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: diff --git a/custom_components/jablotron100/jablotron.py b/custom_components/jablotron100/jablotron.py index 844bc22..ffdfd74 100644 --- a/custom_components/jablotron100/jablotron.py +++ b/custom_components/jablotron100/jablotron.py @@ -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] @@ -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 diff --git a/custom_components/jablotron100/switch.py b/custom_components/jablotron100/switch.py index d456f78..cc8c18a 100644 --- a/custom_components/jablotron100/switch.py +++ b/custom_components/jablotron100/switch.py @@ -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)