diff --git a/homeassistant/components/homekit/type_fans.py b/homeassistant/components/homekit/type_fans.py index 7ed7256d48c..d7215be9508 100644 --- a/homeassistant/components/homekit/type_fans.py +++ b/homeassistant/components/homekit/type_fans.py @@ -7,6 +7,7 @@ from homeassistant.components.fan import ( ATTR_DIRECTION, ATTR_OSCILLATING, ATTR_PERCENTAGE, + ATTR_PERCENTAGE_STEP, DIRECTION_FORWARD, DIRECTION_REVERSE, DOMAIN, @@ -33,6 +34,7 @@ from .const import ( CHAR_ROTATION_DIRECTION, CHAR_ROTATION_SPEED, CHAR_SWING_MODE, + PROP_MIN_STEP, SERV_FANV2, ) @@ -53,6 +55,7 @@ class Fan(HomeAccessory): state = self.hass.states.get(self.entity_id) features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) + percentage_step = state.attributes.get(ATTR_PERCENTAGE_STEP, 1) if features & SUPPORT_DIRECTION: chars.append(CHAR_ROTATION_DIRECTION) @@ -77,7 +80,11 @@ class Fan(HomeAccessory): # Initial value is set to 100 because 0 is a special value (off). 100 is # an arbitrary non-zero value. It is updated immediately by async_update_state # to set to the correct initial value. - self.char_speed = serv_fan.configure_char(CHAR_ROTATION_SPEED, value=100) + self.char_speed = serv_fan.configure_char( + CHAR_ROTATION_SPEED, + value=100, + properties={PROP_MIN_STEP: percentage_step}, + ) if CHAR_SWING_MODE in chars: self.char_swing = serv_fan.configure_char(CHAR_SWING_MODE, value=0) diff --git a/tests/components/homekit/test_type_fans.py b/tests/components/homekit/test_type_fans.py index 8111d256594..e99f9d0b95a 100644 --- a/tests/components/homekit/test_type_fans.py +++ b/tests/components/homekit/test_type_fans.py @@ -6,6 +6,7 @@ from homeassistant.components.fan import ( ATTR_DIRECTION, ATTR_OSCILLATING, ATTR_PERCENTAGE, + ATTR_PERCENTAGE_STEP, DIRECTION_FORWARD, DIRECTION_REVERSE, DOMAIN, @@ -13,7 +14,7 @@ from homeassistant.components.fan import ( SUPPORT_OSCILLATE, SUPPORT_SET_SPEED, ) -from homeassistant.components.homekit.const import ATTR_VALUE +from homeassistant.components.homekit.const import ATTR_VALUE, PROP_MIN_STEP from homeassistant.components.homekit.type_fans import Fan from homeassistant.const import ( ATTR_ENTITY_ID, @@ -254,6 +255,7 @@ async def test_fan_speed(hass, hk_driver, events): { ATTR_SUPPORTED_FEATURES: SUPPORT_SET_SPEED, ATTR_PERCENTAGE: 0, + ATTR_PERCENTAGE_STEP: 25, }, ) await hass.async_block_till_done() @@ -263,6 +265,7 @@ async def test_fan_speed(hass, hk_driver, events): # Initial value can be anything but 0. If it is 0, it might cause HomeKit to set the # speed to 100 when turning on a fan on a freshly booted up server. assert acc.char_speed.value != 0 + assert acc.char_speed.properties[PROP_MIN_STEP] == 25 await acc.run_handler() await hass.async_block_till_done()