From 15bf0c728cbe6d02e580bd817c2f0bcf99fac68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexey=20ALERT=20Rubash=D1=91ff?= Date: Tue, 26 Nov 2024 18:45:28 +0200 Subject: [PATCH] Sync overkiz Atlantic Water Heater datetime before switching the away mode on (#127408) Set device datetime before turning on the away mode --- ...stic_hot_water_production_mlb_component.py | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/overkiz/water_heater/atlantic_domestic_hot_water_production_mlb_component.py b/homeassistant/components/overkiz/water_heater/atlantic_domestic_hot_water_production_mlb_component.py index 1b2a1e218d4..8ba2c1678c2 100644 --- a/homeassistant/components/overkiz/water_heater/atlantic_domestic_hot_water_production_mlb_component.py +++ b/homeassistant/components/overkiz/water_heater/atlantic_domestic_hot_water_production_mlb_component.py @@ -13,6 +13,7 @@ from homeassistant.components.water_heater import ( WaterHeaterEntityFeature, ) from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature +from homeassistant.util import dt as dt_util from .. import OverkizDataUpdateCoordinator from ..entity import OverkizEntity @@ -153,11 +154,11 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE async def async_turn_away_mode_on(self) -> None: """Turn away mode on. - This requires the start date and the end date to be also set. + This requires the start date and the end date to be also set, and those dates have to match the device datetime. The API accepts setting dates in the format of the core:DateTimeState state for the DHW - {'day': 11, 'hour': 21, 'minute': 12, 'month': 7, 'second': 53, 'weekday': 3, 'year': 2024}) - The dict is then passed as an away mode start date, and then as an end date, but with the year incremented by 1, - so the away mode is getting turned on for the next year. + {'day': 11, 'hour': 21, 'minute': 12, 'month': 7, 'second': 53, 'weekday': 3, 'year': 2024} + The dict is then passed as an actual device date, the away mode start date, and then as an end date, + but with the year incremented by 1, so the away mode is getting turned on for the next year. The weekday number seems to have no effect so the calculation of the future date's weekday number is redundant, but possible via homeassistant dt_util to form both start and end dates dictionaries from scratch based on datetime.now() and datetime.timedelta into the future. @@ -167,13 +168,19 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE With `refresh_afterwards=False` on the first commands, and `refresh_afterwards=True` only the last command, the API is not choking and the transition is smooth without the unavailability state. """ - now_date = cast( - dict, - self.executor.select_state(OverkizState.CORE_DATETIME), - ) + now = dt_util.now() + now_date = { + "month": now.month, + "hour": now.hour, + "year": now.year, + "weekday": now.weekday(), + "day": now.day, + "minute": now.minute, + "second": now.second, + } await self.executor.async_execute_command( - OverkizCommand.SET_ABSENCE_MODE, - OverkizCommandParam.PROG, + OverkizCommand.SET_DATE_TIME, + now_date, refresh_afterwards=False, ) await self.executor.async_execute_command( @@ -183,7 +190,11 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE await self.executor.async_execute_command( OverkizCommand.SET_ABSENCE_END_DATE, now_date, refresh_afterwards=False ) - + await self.executor.async_execute_command( + OverkizCommand.SET_ABSENCE_MODE, + OverkizCommandParam.PROG, + refresh_afterwards=False, + ) await self.coordinator.async_refresh() async def async_turn_away_mode_off(self) -> None: