Skip to content

Commit 7d7fd59

Browse files
author
Tom Lasswell
committed
feat: Enhance purifier mode parsing to support CAPABILITY_WORK_MODE structure
Add support for H7127 and similar purifiers that use CAPABILITY_WORK_MODE with nested modeValue options (Sleep/Low/High in gearMode). Maintains backward compatibility with simpler CAPABILITY_MODE structure. Both patterns are now supported.
1 parent d6fa3a0 commit 7d7fd59

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

custom_components/govee/models/device.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,34 @@ def get_fan_speed_options(self) -> list[dict[str, Any]]:
406406
def get_purifier_mode_options(self) -> list[dict[str, Any]]:
407407
"""Extract purifier mode options from capability.
408408
409+
Supports two patterns:
410+
1. Simple CAPABILITY_MODE with options (e.g., H6006)
411+
2. Complex CAPABILITY_WORK_MODE with nested modeValue options (e.g., H7127)
412+
409413
Returns list of {"name": "Sleep", "value": 1} dicts.
414+
For work_mode capabilities, extracts gearMode options.
410415
"""
416+
# Pattern 1: Simple CAPABILITY_MODE (e.g., H6006)
411417
for cap in self.capabilities:
412418
if cap.type == CAPABILITY_MODE and cap.instance == INSTANCE_PURIFIER_MODE:
413419
options: list[dict[str, Any]] = cap.parameters.get("options", [])
414420
return options
421+
422+
# Pattern 2: Complex CAPABILITY_WORK_MODE (e.g., H7127)
423+
# Some purifiers use work_mode like fans, with modeValue options
424+
for cap in self.capabilities:
425+
if cap.type == CAPABILITY_WORK_MODE and cap.instance == "workMode":
426+
# Extract gear mode options from modeValue field in STRUCT
427+
fields = cap.parameters.get("fields", [])
428+
for f in fields:
429+
if f.get("fieldName") == "modeValue":
430+
options = f.get("options", [])
431+
# Find the gearMode options within the nested structure
432+
for opt in options:
433+
if opt.get("name") == "gearMode":
434+
gear_options = opt.get("options", [])
435+
if gear_options:
436+
return gear_options
415437
return []
416438

417439
@property

0 commit comments

Comments
 (0)