Skip to content

Fix multiple crashes, silent failures, and broken state in fan platform#1564

Open
mode0192 wants to merge 1 commit into
smartHomeHub:masterfrom
mode0192:fan.py-fix
Open

Fix multiple crashes, silent failures, and broken state in fan platform#1564
mode0192 wants to merge 1 commit into
smartHomeHub:masterfrom
mode0192:fan.py-fix

Conversation

@mode0192

@mode0192 mode0192 commented Jun 3, 2026

Copy link
Copy Markdown

This PR 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.

(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.)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant