diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index c3111a3aeb7..c2c9ef932e6 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -79,17 +79,22 @@ async def async_setup(hass, config: dict): component.async_register_entity_service(SERVICE_TURN_OFF, {}, "async_turn_off") component.async_register_entity_service(SERVICE_TOGGLE, {}, "async_toggle") component.async_register_entity_service( - SERVICE_SET_SPEED, {vol.Required(ATTR_SPEED): cv.string}, "async_set_speed" + SERVICE_SET_SPEED, + {vol.Required(ATTR_SPEED): cv.string}, + "async_set_speed", + [SUPPORT_SET_SPEED], ) component.async_register_entity_service( SERVICE_OSCILLATE, {vol.Required(ATTR_OSCILLATING): cv.boolean}, "async_oscillate", + [SUPPORT_OSCILLATE], ) component.async_register_entity_service( SERVICE_SET_DIRECTION, {vol.Optional(ATTR_DIRECTION): cv.string}, "async_set_direction", + [SUPPORT_DIRECTION], ) return True diff --git a/homeassistant/components/homekit_controller/fan.py b/homeassistant/components/homekit_controller/fan.py index 06cbb986714..efb41808429 100644 --- a/homeassistant/components/homekit_controller/fan.py +++ b/homeassistant/components/homekit_controller/fan.py @@ -121,45 +121,42 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity): async def async_set_direction(self, direction): """Set the direction of the fan.""" - if self.supported_features & SUPPORT_DIRECTION: - await self._accessory.put_characteristics( - [ - { - "aid": self._aid, - "iid": self._chars["rotation.direction"], - "value": DIRECTION_TO_HK[direction], - } - ] - ) + await self._accessory.put_characteristics( + [ + { + "aid": self._aid, + "iid": self._chars["rotation.direction"], + "value": DIRECTION_TO_HK[direction], + } + ] + ) async def async_set_speed(self, speed): """Set the speed of the fan.""" if speed == SPEED_OFF: return await self.async_turn_off() - if self.supported_features & SUPPORT_SET_SPEED: - await self._accessory.put_characteristics( - [ - { - "aid": self._aid, - "iid": self._chars["rotation.speed"], - "value": SPEED_TO_PCNT[speed], - } - ] - ) + await self._accessory.put_characteristics( + [ + { + "aid": self._aid, + "iid": self._chars["rotation.speed"], + "value": SPEED_TO_PCNT[speed], + } + ] + ) async def async_oscillate(self, oscillating: bool): """Oscillate the fan.""" - if self.supported_features & SUPPORT_OSCILLATE: - await self._accessory.put_characteristics( - [ - { - "aid": self._aid, - "iid": self._chars["swing-mode"], - "value": 1 if oscillating else 0, - } - ] - ) + await self._accessory.put_characteristics( + [ + { + "aid": self._aid, + "iid": self._chars["swing-mode"], + "value": 1 if oscillating else 0, + } + ] + ) async def async_turn_on(self, speed=None, **kwargs): """Turn the specified fan on.""" diff --git a/tests/components/mqtt/test_fan.py b/tests/components/mqtt/test_fan.py index 653a3267c46..65e170fba91 100644 --- a/tests/components/mqtt/test_fan.py +++ b/tests/components/mqtt/test_fan.py @@ -171,9 +171,11 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock): "payload_off": "StAtE_OfF", "payload_on": "StAtE_On", "oscillation_command_topic": "oscillation-command-topic", + "oscillation_state_topic": "oscillation-state-topic", "payload_oscillation_off": "OsC_OfF", "payload_oscillation_on": "OsC_On", "speed_command_topic": "speed-command-topic", + "speed_state_topic": "speed-state-topic", "payload_off_speed": "speed_OfF", "payload_low_speed": "speed_lOw", "payload_medium_speed": "speed_mEdium",