From 0fe939cd7cebed6682fb16ec61d97547ad07c4ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexey=20ALERT=20Rubash=D1=91ff?=
 <alexey.rubasheff@gmail.com>
Date: Mon, 26 Aug 2024 22:31:07 +0300
Subject: [PATCH] Update overkiz Atlantic Water Heater operation mode switching
 (#124619)

* conventional operation state usage

* MartinHjelmare indentation request

* Manual Mode binary sensor

* Removed usage of unconventional operation states

* Removed usage of unconventional operation state

* STATE_OFF operation mode support
---
 .../components/overkiz/binary_sensor.py       | 18 +++++++---
 ...stic_hot_water_production_mlb_component.py | 35 ++++++++-----------
 2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/homeassistant/components/overkiz/binary_sensor.py b/homeassistant/components/overkiz/binary_sensor.py
index 8ea86e03e8c..57df3cd4e09 100644
--- a/homeassistant/components/overkiz/binary_sensor.py
+++ b/homeassistant/components/overkiz/binary_sensor.py
@@ -115,14 +115,24 @@ BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [
     OverkizBinarySensorDescription(
         key=OverkizState.MODBUSLINK_DHW_ABSENCE_MODE,
         name="Absence mode",
-        value_fn=lambda state: state
-        in (OverkizCommandParam.ON, OverkizCommandParam.PROG),
+        value_fn=(
+            lambda state: state in (OverkizCommandParam.ON, OverkizCommandParam.PROG)
+        ),
     ),
     OverkizBinarySensorDescription(
         key=OverkizState.MODBUSLINK_DHW_BOOST_MODE,
         name="Boost mode",
-        value_fn=lambda state: state
-        in (OverkizCommandParam.ON, OverkizCommandParam.PROG),
+        value_fn=(
+            lambda state: state in (OverkizCommandParam.ON, OverkizCommandParam.PROG)
+        ),
+    ),
+    OverkizBinarySensorDescription(
+        key=OverkizState.MODBUSLINK_DHW_MODE,
+        name="Manual mode",
+        value_fn=(
+            lambda state: state
+            in (OverkizCommandParam.MANUAL, OverkizCommandParam.MANUAL_ECO_INACTIVE)
+        ),
     ),
 ]
 
diff --git a/homeassistant/components/overkiz/water_heater_entities/atlantic_domestic_hot_water_production_mlb_component.py b/homeassistant/components/overkiz/water_heater_entities/atlantic_domestic_hot_water_production_mlb_component.py
index de995a2bd1a..0f57d13433b 100644
--- a/homeassistant/components/overkiz/water_heater_entities/atlantic_domestic_hot_water_production_mlb_component.py
+++ b/homeassistant/components/overkiz/water_heater_entities/atlantic_domestic_hot_water_production_mlb_component.py
@@ -6,6 +6,7 @@ from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
 
 from homeassistant.components.water_heater import (
     STATE_ECO,
+    STATE_ELECTRIC,
     STATE_OFF,
     STATE_PERFORMANCE,
     WaterHeaterEntity,
@@ -28,9 +29,10 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE
         | WaterHeaterEntityFeature.ON_OFF
     )
     _attr_operation_list = [
-        OverkizCommandParam.PERFORMANCE,
-        OverkizCommandParam.ECO,
-        OverkizCommandParam.MANUAL,
+        STATE_ECO,
+        STATE_OFF,
+        STATE_PERFORMANCE,
+        STATE_ELECTRIC,
     ]
 
     def __init__(
@@ -116,20 +118,20 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE
             cast(str, self.executor.select_state(OverkizState.MODBUSLINK_DHW_MODE))
             == OverkizCommandParam.MANUAL_ECO_INACTIVE
         ):
-            return OverkizCommandParam.MANUAL
+            # STATE_ELECTRIC is a substitution for OverkizCommandParam.MANUAL
+            # to keep up with the conventional state usage only
+            # https://developers.home-assistant.io/docs/core/entity/water-heater/#states
+            return STATE_ELECTRIC
 
         return STATE_OFF
 
     async def async_set_operation_mode(self, operation_mode: str) -> None:
         """Set new operation mode."""
-        if operation_mode in (STATE_PERFORMANCE, OverkizCommandParam.BOOST):
+        if operation_mode == STATE_PERFORMANCE:
             if self.is_away_mode_on:
                 await self.async_turn_away_mode_off()
             await self.async_turn_boost_mode_on()
-        elif operation_mode in (
-            OverkizCommandParam.ECO,
-            OverkizCommandParam.MANUAL_ECO_ACTIVE,
-        ):
+        elif operation_mode == STATE_ECO:
             if self.is_away_mode_on:
                 await self.async_turn_away_mode_off()
             if self.is_boost_mode_on:
@@ -137,10 +139,7 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE
             await self.executor.async_execute_command(
                 OverkizCommand.SET_DHW_MODE, OverkizCommandParam.AUTO_MODE
             )
-        elif operation_mode in (
-            OverkizCommandParam.MANUAL,
-            OverkizCommandParam.MANUAL_ECO_INACTIVE,
-        ):
+        elif operation_mode == STATE_ELECTRIC:
             if self.is_away_mode_on:
                 await self.async_turn_away_mode_off()
             if self.is_boost_mode_on:
@@ -148,14 +147,8 @@ class AtlanticDomesticHotWaterProductionMBLComponent(OverkizEntity, WaterHeaterE
             await self.executor.async_execute_command(
                 OverkizCommand.SET_DHW_MODE, OverkizCommandParam.MANUAL_ECO_INACTIVE
             )
-        else:
-            if self.is_away_mode_on:
-                await self.async_turn_away_mode_off()
-            if self.is_boost_mode_on:
-                await self.async_turn_boost_mode_off()
-            await self.executor.async_execute_command(
-                OverkizCommand.SET_DHW_MODE, operation_mode
-            )
+        elif operation_mode == STATE_OFF:
+            await self.async_turn_away_mode_on()
 
     async def async_turn_away_mode_on(self) -> None:
         """Turn away mode on."""
-- 
GitLab