From 9f9d602fbc0a3b91732d2d3d7c187b5c14899816 Mon Sep 17 00:00:00 2001 From: basbruss <4a3.brussee.bas@gmail.com> Date: Tue, 11 Jun 2024 13:12:37 +0200 Subject: [PATCH] Apply always inverse state if selected --- custom_components/adaptive_cover/coordinator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_cover/coordinator.py b/custom_components/adaptive_cover/coordinator.py index 8692f50..23e9131 100644 --- a/custom_components/adaptive_cover/coordinator.py +++ b/custom_components/adaptive_cover/coordinator.py @@ -294,7 +294,10 @@ async def async_handle_timed_refresh(self, options): if self.control_toggle: for cover in self.entities: await self.async_set_manual_position( - cover, options.get(CONF_SUNSET_POS) + cover, + inverse_state(options.get(CONF_SUNSET_POS)) + if self._inverse_state + else options.get(CONF_SUNSET_POS), ) else: _LOGGER.debug("Timed refresh but control toggle is off") @@ -551,7 +554,7 @@ def state(self) -> int: if self._switch_mode: state = self.climate_state if self._inverse_state: - state = 100 - state + state = inverse_state(state) _LOGGER.debug("Calculated position: %s", state) return state @@ -706,3 +709,8 @@ def binary_cover_manual(self): def manual_controlled(self): """Get the list of covers under manual control.""" return [k for k, v in self.manual_control.items() if v] + + +def inverse_state(state: int) -> int: + """Inverse state.""" + return 100 - state