Fix multiple crashes, silent failures, and broken state in fan platform#1564
Open
mode0192 wants to merge 1 commit into
Open
Fix multiple crashes, silent failures, and broken state in fan platform#1564mode0192 wants to merge 1 commit into
mode0192 wants to merge 1 commit into
Conversation
This commit resolves 13 confirmed bugs and introduces several stability improvements to the fan platform. Major fixes include: - Fixed state property returning SPEED_OFF string instead of STATE_OFF constant. - Fixed send_command skipping the speed command entirely when oscillating. - Fixed power sensor listener not registering on a clean start. - Fixed startup and runtime crashes in _async_power_sensor_changed caused by old_state/new_state being None. - Removed conflicting @callback and async def decorators so the power sensor handler actually runs. - Added missing speed, direction, and oscillating attributes to extra_state_attributes so state properly persists and restores. - Added None guards to percentage, async_set_direction, and send_command to prevent cascading crashes. - Fixed CONF_DELAY validation to accept numeric values instead of strings. - Fixed async_oscillate to send a single IR toggle command instead of resending full speed commands. Improvements: - Added state restore fallbacks for newer HA versions (percentage). - Improved JSON loading to split JSONDecodeError from generic IO exceptions. - Added upfront validation for required JSON keys and command structure during setup. - Explicitly declared _attr_should_poll = False. - Renamed _temp_lock to _command_lock for clarity.
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.
This PR resolves 13 confirmed bugs and introduces several stability improvements to the fan platform.
Major fixes include:
stateproperty returningSPEED_OFFstring instead ofSTATE_OFFconstant.send_commandskipping the speed command entirely when oscillating._async_power_sensor_changedcaused byold_state/new_statebeing None.@callbackandasync defdecorators so the power sensor handler actually runs.extra_state_attributesso state properly persists and restores.Noneguards topercentage,async_set_direction, andsend_commandto prevent cascading crashes.CONF_DELAYvalidation to accept numeric values instead of strings.async_oscillateto send a single IR toggle command instead of resending full speed commands.Improvements:
percentage).JSONDecodeErrorfrom generic IO exceptions._attr_should_poll = False._temp_lockto_command_lockfor clarity.(Note for reviewers: The percentage attribute fallback and STATE_ON fallback during state restoration exist primarily as a migration bridge for users upgrading from the older version. Clean installs will seamlessly find the speed attribute and won't need to exercise these fallback paths.)