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
This commit is contained in:
Alexey ALERT Rubashёff 2024-08-26 22:31:07 +03:00 committed by GitHub
parent b960ebeb8b
commit 0fe939cd7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 25 deletions

View file

@ -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)
),
),
]

View file

@ -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."""