mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix trait processing Fan state without percentage_step (#77351)
* Fix trait processing Fan without percentage_step * Update homeassistant/components/google_assistant/trait.py Co-authored-by: Joakim Plate <elupus@ecce.se> * Fix test * Fix formatting Co-authored-by: Joakim Plate <elupus@ecce.se>
This commit is contained in:
parent
b2e958292c
commit
448b720eb7
@ -1397,7 +1397,9 @@ class FanSpeedTrait(_Trait):
|
||||
if state.domain == fan.DOMAIN:
|
||||
speed_count = min(
|
||||
FAN_SPEED_MAX_SPEED_COUNT,
|
||||
round(100 / self.state.attributes.get(fan.ATTR_PERCENTAGE_STEP) or 1.0),
|
||||
round(
|
||||
100 / (self.state.attributes.get(fan.ATTR_PERCENTAGE_STEP) or 1.0)
|
||||
),
|
||||
)
|
||||
self._ordered_speed = [
|
||||
f"{speed}/{speed_count}" for speed in range(1, speed_count + 1)
|
||||
|
@ -1618,6 +1618,32 @@ async def test_fan_speed(hass):
|
||||
assert calls[0].data == {"entity_id": "fan.living_room_fan", "percentage": 10}
|
||||
|
||||
|
||||
async def test_fan_speed_without_percentage_step(hass):
|
||||
"""Test FanSpeed trait speed control percentage step for fan domain."""
|
||||
assert helpers.get_google_type(fan.DOMAIN, None) is not None
|
||||
assert trait.FanSpeedTrait.supported(fan.DOMAIN, fan.SUPPORT_SET_SPEED, None, None)
|
||||
|
||||
trt = trait.FanSpeedTrait(
|
||||
hass,
|
||||
State(
|
||||
"fan.living_room_fan",
|
||||
STATE_ON,
|
||||
),
|
||||
BASIC_CONFIG,
|
||||
)
|
||||
|
||||
assert trt.sync_attributes() == {
|
||||
"reversible": False,
|
||||
"supportsFanSpeedPercent": True,
|
||||
"availableFanSpeeds": ANY,
|
||||
}
|
||||
# If a fan state has (temporary) no percentage_step attribute return 1 available
|
||||
assert trt.query_attributes() == {
|
||||
"currentFanSpeedPercent": 0,
|
||||
"currentFanSpeedSetting": "1/5",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"percentage,percentage_step, speed, speeds, percentage_result",
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user