Skip to content

Commit

Permalink
🐛 Correct holiday mode management
Browse files Browse the repository at this point in the history
We set a boolean but outcome is a 3-state system

Fix #75

Change-Id: Ie1b4d192c0640c1181c2d523098ae1e3b1d1fa18
  • Loading branch information
kamaradclimber committed Dec 27, 2022
1 parent 33dee04 commit 0f422bd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions custom_components/aquarea/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class HeishaMonNumberEntityDescription(
# function to transform selected option in value sent via mqtt
state_to_mqtt: Optional[Callable] = None


def bit_to_bool(value: str) -> Optional[bool]:
if value == "1":
return True
Expand Down Expand Up @@ -485,6 +484,17 @@ def build_selects(mqtt_prefix: str) -> list[HeishaMonSelectEntityDescription]:
]


def read_holiday_status(value: str) -> str:
if value == "0":
return "Off"
elif value == "1":
return "Scheduled"
else:
return "Active"

def read_holiday_status_to_bool(value: str) -> bool:
return value != "0"

def build_switches(mqtt_prefix: str) -> list[HeishaMonSwitchEntityDescription]:
return [
HeishaMonSwitchEntityDescription(
Expand All @@ -501,7 +511,7 @@ def build_switches(mqtt_prefix: str) -> list[HeishaMonSwitchEntityDescription]:
command_topic=f"{mqtt_prefix}commands/SetHolidayMode",
name="Aquarea Holiday Mode",
entity_category=EntityCategory.CONFIG,
state=bit_to_bool,
state=read_holiday_status_to_bool,
),
HeishaMonSwitchEntityDescription(
heishamon_topic_id="SET10", # also corresponds to TOP2
Expand Down Expand Up @@ -771,6 +781,13 @@ def build_sensors(mqtt_prefix: str) -> list[HeishaMonSensorEntityDescription]:
state_class=SensorStateClass.MEASUREMENT,
# original template states "force_update" FIXME
),
HeishaMonSensorEntityDescription(
heishamon_topic_id="TOP19",
key=f"{mqtt_prefix}main/Holiday_Mode_State",
name="Aquarea Holiday Mode",
entity_category=EntityCategory.CONFIG,
state=read_holiday_status,
),
HeishaMonSensorEntityDescription(
heishamon_topic_id="TOP20",
key=f"{mqtt_prefix}main/ThreeWay_Valve_State",
Expand Down

0 comments on commit 0f422bd

Please sign in to comment.