Fix Matter fan turn_on writing invalid PercentSetting=255 (#180541)

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Ludovic BOUÉ
2026-08-28 20:09:32 +00:00
committed by Franck Nijhof
co-authored by Claude Sonnet 5
parent 1a2b500366
commit 19a8aa4827
2 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -242,7 +242,7 @@ class MatterFan(MatterEntity, FanEntity):
# keep track of the last known mode for turn_on commands without preset
if self._attr_preset_mode is not None:
self._last_known_preset_mode = self._attr_preset_mode
if current_percent:
if current_percent and current_percent != 255:
self._last_known_percentage = current_percent
@callback
+7 -4
View File
@@ -2,6 +2,7 @@
from unittest.mock import MagicMock, call
from chip.clusters import Objects as clusters
from matter_server.client.models.node import MatterNode
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -133,8 +134,10 @@ async def test_fan_turn_on_with_percentage(
attribute_path="1/514/2",
value=50,
)
# test again where preset_mode is omitted in the service call
# which should select the last active percentage
# test again where percentage is omitted in the service call
# PercentCurrent is 255 (auto) on this fixture, which is not a valid
# value to write back, so it should fall back to the last known preset
# mode instead of blindly replaying the sentinel value.
matter_client.write_attribute.reset_mock()
await hass.services.async_call(
FAN_DOMAIN,
@@ -145,8 +148,8 @@ async def test_fan_turn_on_with_percentage(
assert matter_client.write_attribute.call_count == 1
assert matter_client.write_attribute.call_args == call(
node_id=matter_node.node_id,
attribute_path="1/514/2",
value=255,
attribute_path="1/514/0",
value=clusters.FanControl.Enums.FanModeEnum.kAuto,
)