From 76266ea47d41358f2fbf1b5843146f03b3e9dc62 Mon Sep 17 00:00:00 2001 From: Thomas Germain <12560542+thomasgermain@users.noreply.github.com> Date: Tue, 10 May 2022 17:36:37 +0200 Subject: [PATCH] fix set quick mode from climate (#134) --- custom_components/multimatic/coordinator.py | 33 ++++++++++++++++----- custom_components/multimatic/manifest.json | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/custom_components/multimatic/coordinator.py b/custom_components/multimatic/coordinator.py index a291e7b..8ca9ce4 100644 --- a/custom_components/multimatic/coordinator.py +++ b/custom_components/multimatic/coordinator.py @@ -278,7 +278,7 @@ async def set_room_operating_mode(self, entity, mode): room.quick_veto = None if isinstance(mode, QuickMode): - await self._manager.set_quick_mode(mode) + await self._hard_set_quick_mode(mode) self._quick_mode = mode touch_system = True else: @@ -301,7 +301,7 @@ async def set_zone_operating_mode(self, entity, mode): zone.quick_veto = None if isinstance(mode, QuickMode): - await self._manager.set_quick_mode(mode) + await self._hard_set_quick_mode(mode) self._quick_mode = mode touch_system = True else: @@ -337,11 +337,7 @@ async def set_holiday_mode(self, start_date, end_date, temperature): async def set_quick_mode(self, mode, duration): """Set quick mode (remove previous one).""" await self._remove_quick_mode_no_refresh() - if duration is None and mode == QuickModes.COOLING_FOR_X_DAYS.name: - duration = 1 - qmode = QuickModes.get(mode, duration) - await self._manager.set_quick_mode(qmode) - self._quick_mode = qmode + self._quick_mode = await self._hard_set_quick_mode(mode, duration) await self._refresh_entities() async def set_quick_veto(self, entity, temperature, duration=None): @@ -380,7 +376,7 @@ async def set_fan_operating_mode(self, entity, mode: Mode): touch_system = await self._remove_quick_mode_or_holiday(entity) if isinstance(mode, QuickMode): - await self._manager.set_quick_mode(mode) + await self._hard_set_quick_mode(mode) self._quick_mode = mode touch_system = True else: @@ -416,6 +412,27 @@ async def _hard_remove_quick_mode(self): await self._manager.remove_quick_mode() self._quick_mode = None + async def _hard_set_quick_mode( + self, mode: str | QuickMode, duration: int = None + ) -> QuickMode: + new_mode: QuickMode + + if isinstance(mode, QuickMode): + new_mode = mode + if ( + mode.name == QuickModes.COOLING_FOR_X_DAYS.name + and mode.duration is None + ): + new_mode = QuickModes.get(mode.name, 1) + else: + new_duration = duration + if mode == QuickModes.COOLING_FOR_X_DAYS.name and duration is None: + new_duration = 1 + new_mode = QuickModes.get(mode, new_duration) + + await self._manager.set_quick_mode(new_mode) + return new_mode + async def _remove_holiday_mode_no_refresh(self): await self._manager.remove_holiday_mode() self._holiday_mode = HolidayMode(False) diff --git a/custom_components/multimatic/manifest.json b/custom_components/multimatic/manifest.json index 4410be8..538915e 100644 --- a/custom_components/multimatic/manifest.json +++ b/custom_components/multimatic/manifest.json @@ -14,6 +14,6 @@ "codeowners": [ "@thomasgermain" ], - "version": "1.12.6", + "version": "1.12.7", "iot_class": "cloud_polling" }