Skip to content

Commit 81ca0cb

Browse files
committed
update example HVAC action
1 parent df5d535 commit 81ca0cb

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

examples/control.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@
1818

1919
from bsblan import (
2020
BSBLAN,
21-
BSBLAN_HVAC_ACTION_COOLING,
22-
BSBLAN_HVAC_ACTION_DEFROSTING,
23-
BSBLAN_HVAC_ACTION_DRYING,
24-
BSBLAN_HVAC_ACTION_FAN,
25-
BSBLAN_HVAC_ACTION_HEATING,
26-
BSBLAN_HVAC_ACTION_OFF,
27-
BSBLAN_HVAC_ACTION_PREHEATING,
2821
BSBLANConfig,
2922
Device,
3023
DeviceTime,
24+
HeatingCircuitStatus,
3125
HotWaterConfig,
3226
HotWaterSchedule,
3327
HotWaterState,
@@ -36,6 +30,7 @@
3630
SetHotWaterParam,
3731
State,
3832
StaticState,
33+
get_hvac_action_category,
3934
)
4035
from bsblan.models import DHWTimeSwitchPrograms
4136

@@ -93,22 +88,9 @@ def get_hvac_action_name(status_code: int) -> str:
9388
... print(f"Current HVAC action: {action}")
9489
9590
"""
96-
# Map status code sets to action names
97-
action_mappings: list[tuple[set[int], str]] = [
98-
(BSBLAN_HVAC_ACTION_HEATING, "heating"),
99-
(BSBLAN_HVAC_ACTION_COOLING, "cooling"),
100-
(BSBLAN_HVAC_ACTION_PREHEATING, "preheating"),
101-
(BSBLAN_HVAC_ACTION_DEFROSTING, "defrosting"),
102-
(BSBLAN_HVAC_ACTION_DRYING, "drying"),
103-
(BSBLAN_HVAC_ACTION_FAN, "fan"),
104-
(BSBLAN_HVAC_ACTION_OFF, "off"),
105-
]
106-
107-
for action_set, action_name in action_mappings:
108-
if status_code in action_set:
109-
return action_name
110-
111-
return "idle"
91+
# Use the new enum-based approach
92+
category = get_hvac_action_category(status_code)
93+
return category.name.lower()
11294

11395

11496
async def print_state(state: State) -> None:
@@ -122,18 +104,25 @@ async def print_state(state: State) -> None:
122104
hvac_action_desc = await get_attribute(state.hvac_action, "desc", "Unknown Action")
123105
hvac_action_value = await get_attribute(state.hvac_action, "value", "N/A")
124106

125-
# Map the raw status code to a simplified action name
107+
# Map the raw status code to a simplified action name using the new enum approach
126108
hvac_action_mapped = "N/A"
109+
status_name = "N/A"
127110
if hvac_action_value != "N/A":
128111
try:
129-
hvac_action_mapped = get_hvac_action_name(int(hvac_action_value))
112+
status_code = int(hvac_action_value)
113+
# Get the category (heating, cooling, etc.)
114+
hvac_action_mapped = get_hvac_action_name(status_code)
115+
# Get the specific status name from the enum (if known)
116+
status = HeatingCircuitStatus.from_value(status_code)
117+
status_name = status.name if status else "UNKNOWN"
130118
except (ValueError, TypeError):
131119
hvac_action_mapped = "unknown"
132120

133121
attributes = {
134122
"HVAC Action (raw value)": str(hvac_action_value),
135123
"HVAC Action (device desc)": hvac_action_desc,
136-
"HVAC Action (mapped)": hvac_action_mapped,
124+
"HVAC Action (status name)": status_name,
125+
"HVAC Action (category)": hvac_action_mapped,
137126
"HVAC Mode": await get_attribute(state.hvac_mode, "desc", "Unknown Mode"),
138127
"Current Temperature": await get_attribute(
139128
state.current_temperature, "value", "N/A"

0 commit comments

Comments
 (0)