DRV-41: fix esphome_fan DESIGNATE_PRESET handler#60
Merged
Conversation
The Composer "Designate Preset" command was broken end-to-end: - The handler read tParams.SPEED but the C4 fan proxy sends tParams.PRESET, so PRESET_SPEED was always nil. - The captured value was never applied; on() ignored it and the user could not later issue "Turn On Fan" at the designated speed. - The value was not persisted, so driver restarts dropped it. - The proxy was never notified, so Navigator/Composer never reflected the designated preset. Fixes: - Read tParams.PRESET, clamp to [1, DISCRETE_LEVELS], persist via lib.persist, and NOTIFY the proxy on every change. - Hydrate PRESET_SPEED in OnDriverLateInit and re-emit the NOTIFY. - Apply the preset in on(): when PRESET_SPEED is set, the ENTITY_COMMAND includes has_speed_level/speed_level so all entry points (RFP.ON, TOGGLE from off, top-button, ON_BINDING DO_CLICK, BUTTON_ACTION) start at the designated speed. - Re-emit the PRESET_SPEED NOTIFY in GET_CURRENT_STATE so Navigator stays in sync when reconnecting. Reported by Dwayne Newsome via #56.
101dfd4 to
2ed35af
Compare
derek-miller
approved these changes
May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes DRV-41. Reported by Dwayne Newsome via #56.
Problem
RFP.DESIGNATE_PRESETindrivers/esphome_fan/driver.luawas broken end-to-end:tParams.SPEED, but the C4 fan proxy sendstParams.PRESET.PRESET_SPEEDwas alwaysnil.on()sent{has_state=true, state=true}only, so even with the key fixed,Turn On Fanwould ignore the designated preset.PRESET_SPEED, so Composer/Navigator never reflected the designated value.Symptom from Dwayne's trace:
Fix
tParams.PRESET, clamp to[1, DISCRETE_LEVELS], persist vialib.persist, andSendToProxy(PROXY_BINDING, "PRESET_SPEED", { SPEED = tostring(n) }, "NOTIFY")on every change.PRESET_SPEEDfrom persist inOnDriverLateInitand re-emit the NOTIFY so Navigator stays in sync across restarts.on()now includeshas_speed_level/speed_levelwhenPRESET_SPEEDis set, so every ON entry point (RFP.ON,RFP.TOGGLEfrom off,DO_CLICKon ON/TOGGLE bindings,BUTTON_ACTIONtop/toggle) starts at the designated speed.RFP.GET_CURRENT_STATEre-emits the PRESET_SPEED NOTIFY for Navigator reconnects.Behavior matches the reference drivers cited on the ticket (lutron_ra2_select_fan, confio_fan, lutron_leap_fan_controller, chowmain_*, DriverWorks_IR_generic_fan, control4_lux_2_wire_switch).
Test plan
Preset speed set to 5, Navigator preset chip reflects 5.PRESET_SPEED), not last speed, not nil.PersistGetValue("PRESET_SPEED")returns 5, NOTIFY is re-emitted onOnDriverLateInit.