Fix thermostat fan modes to respect fanModeSequence#708
Fix thermostat fan modes to respect fanModeSequence#708
Conversation
|
To regenerate device diagnostics files (to see what this change would affect in real devices), run the following: python -m tools.regenerate_diagnosticsIt looks like four devices (in the testing DB) change their exposed fan modes. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #708 +/- ##
==========================================
+ Coverage 97.62% 97.63% +0.01%
==========================================
Files 62 62
Lines 10951 10965 +14
==========================================
+ Hits 10691 10706 +15
+ Misses 260 259 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Should resolve #226 |
|
I noticed that one of the test devices was my thermostat. I can confirm this shows up properly:
But the fan mode doesn't really do anything for my specific thermostat even when switching the fan mode from "auto" to "on", it doesn't actually support fan mode independent from heat and cool. This is probably just a device-specific bug. @dmulcahey @TheJulianJES Do you have a device to test this change with? |
|
I'll have a closer look later, but I think the issue is still present in Matter: https://github.com/home-assistant/core/blob/9ddefaaacd1df9da4f5a4f673eea2348b524d0ac/homeassistant/components/matter/climate.py#L121-L159 (assuming it's even the same issue here, which it might not be...) |

Summary
Thermostatentity to read thefan_mode_sequenceattribute from the ZCL Fan Control cluster (0x0202) instead of hardcoding fan modes to[auto, on]. Devices now correctly expose Low, Medium, High, and Auto fan speeds based on the ZCL spec (Table 6-20).fan_modegetter to read the actualfan_modeattribute from the Fan Control cluster handler instead of guessing from the thermostat'srunning_statebitmap.async_set_fan_modeto map all supported fan mode strings (low, medium, high, on, auto) to their correspondingFanModeZCL enum values.HVACMode.FAN_ONLYas an available HVAC mode when a Fan Control cluster is present on the endpoint, sinceSEQ_OF_OPERATION(derived fromcontrolSequenceOfOperation) never includes it per ZCL spec.Problem
The
Thermostatentity hardcodes fan modes to[auto, on]and completely ignores thefan_mode_sequenceattribute (attribute 0x0001) from the Fan Control cluster. Per ZCL 8 (Table 6-20),FanModeSequenceTypedefines which fan modes a device supports:Devices reporting e.g.
fan_mode_sequence = 0x02(Low/Medium/High/Auto) were stuck with only Auto/On in the UI.Additionally, the thermostat never exposes
HVACMode.FAN_ONLYeven when the device supportsSystemMode.Fan_only(0x07). The mappingsHVAC_MODE_2_SYSTEMandSYSTEM_MODE_2_HVACalready handleFAN_ONLY <-> Fan_only, buthvac_modesderives its list solely fromSEQ_OF_OPERATIONwhich never includes it, sincecontrolSequenceOfOperationonly covers cooling/heating per the ZCL spec.Changes
zha/application/platforms/climate/const.pyFanModefrom zigpySEQ_FAN_MODESdict mappingfan_mode_sequencevalues (0x00–0x04) to fan mode string listsFAN_MODE_TO_ZCLdict mapping fan mode strings toFanModeenum valuesZCL_TO_FAN_MODEreverse mapping dictzha/application/platforms/climate/__init__.pyfan_modes: Readfan_mode_sequencefrom the fan cluster handler, look up modes viaSEQ_FAN_MODES, fall back to[on, auto]for unknown sequencesfan_mode: Read actualfan_modeattribute from the fan cluster handler, map back viaZCL_TO_FAN_MODE, fall back torunning_stateheuristic when unavailableasync_set_fan_mode: UseFAN_MODE_TO_ZCLmapping instead of hardcodedOn/Autobranchhvac_modes: AppendHVACMode.FAN_ONLYwhen a fan cluster handler is presentBackwards compatibility
fan_mode_sequence = 0x04still get[on, auto](unchanged)fan_mode_sequencevalues fall back to[on, auto]HVAC_MODE_2_SYSTEM,SYSTEM_MODE_2_HVAC, orasync_set_hvac_modeTest plan
fan_mode_sequence = 0x02exposes: Low, Medium, High, Autofan_mode_sequence = 0x04(or unknown) exposes: On, Auto (backwards compatible)FanMode.Low(0x01) to the deviceFanMode.High(0x03) to the devicefan_modeattribute from the Fan Control clusterSystemMode.Fan_only(0x07) to the thermostatAffected devices
Any thermostat with a Fan Control cluster (0x0202) that reports
fan_mode_sequence != 0x04, such as Tuya HVAC thermostats with cooling/heating/fan modes (e.g._TZE204_mpbki2zm).