Skip to content

matter: enable fan percentage speed control for all FanControl devices#164546

Open
ldkud50 wants to merge 3 commits intohome-assistant:devfrom
ldkud50:dev
Open

matter: enable fan percentage speed control for all FanControl devices#164546
ldkud50 wants to merge 3 commits intohome-assistant:devfrom
ldkud50:dev

Conversation

@ldkud50
Copy link

@ldkud50 ldkud50 commented Mar 1, 2026

Description

PercentSetting (0x0002) and PercentCurrent (0x0003) are MANDATORY attributes on all Matter FanControl clusters (0x0202) per the Matter specification section 4.4.6. However, FanEntityFeature.SET_SPEED was only enabled when the device also had the kMultiSpeed feature flag, making the percentage slider unreachable for devices that only support percent-based control.

Changes

  • Enable FanEntityFeature.SET_SPEED unconditionally for all FanControl devices
  • Only set speed_count when kMultiSpeed is present (uses SpeedMax)
  • Add PercentSetting to optional_attributes in the discovery schema

Fixes

Fixes #138430
Fixes #156285

Copilot AI review requested due to automatic review settings March 1, 2026 23:43
@ldkud50 ldkud50 requested a review from a team as a code owner March 1, 2026 23:43
@home-assistant home-assistant bot added cla-needed integration: matter small-pr PRs with less than 30 lines. labels Mar 1, 2026
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ldkud50

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft March 1, 2026 23:43
@home-assistant
Copy link

home-assistant bot commented Mar 1, 2026

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

home-assistant bot commented Mar 1, 2026

Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of matter can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign matter Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Matter fan platform so percent-based speed control is exposed for all devices implementing the FanControl cluster, aligning Home Assistant behavior with the Matter spec and making the percentage slider available even when kMultiSpeed is not present.

Changes:

  • Enable FanEntityFeature.SET_SPEED unconditionally for Matter FanControl devices so percentage control is always available.
  • Only derive speed_count from SpeedMax when the kMultiSpeed feature flag is present.
  • Include PercentSetting in the discovery schema’s optional_attributes so it is subscribed to when present.
Comment on lines +258 to 263
# FIX: PercentSetting/PercentCurrent are MANDATORY on all FanControl clusters
# per the Matter spec. Enable SET_SPEED unconditionally so the percentage
# slider is always shown regardless of whether kMultiSpeed is set.
self._attr_supported_features |= FanEntityFeature.SET_SPEED

if feature_map & FanControlFeature.kMultiSpeed:
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling FanEntityFeature.SET_SPEED unconditionally changes the supported-features bitmask for fans without kMultiSpeed/kRocking/kAirflowDirection set. The existing Matter fan tests (e.g., tests/components/matter/test_fan.py::test_fan_supported_features) currently assert that SET_SPEED is only present when kMultiSpeed is set, so CI will fail unless those expectations (and any snapshots that include supported features) are updated to match the new behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 256 to +270
self._attr_supported_features = FanEntityFeature(0)

# FIX: PercentSetting/PercentCurrent are MANDATORY on all FanControl clusters
# per the Matter spec. Enable SET_SPEED unconditionally so the percentage
# slider is always shown regardless of whether kMultiSpeed is set.
self._attr_supported_features |= FanEntityFeature.SET_SPEED

if feature_map & FanControlFeature.kMultiSpeed:
self._attr_supported_features |= FanEntityFeature.SET_SPEED
self._attr_speed_count = int(
# kMultiSpeed devices also expose SpeedMax for step granularity
speed_max = int(
self.get_matter_attribute_value(clusters.FanControl.Attributes.SpeedMax)
)
if speed_max > 0:
self._attr_speed_count = speed_max

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_attr_speed_count is only set when kMultiSpeed is present, but it is never cleared when the feature map changes and kMultiSpeed is removed (or when SpeedMax becomes 0). Since the feature map is treated as dynamic in this method, a previously populated speed count can linger and incorrectly affect percentage_step/UI behavior. Reset _attr_speed_count (e.g., to None) when recalculating features before conditionally setting it for kMultiSpeed.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment