Set required_features field when registering fan services (#30516)

* Set required_features on fan services

* Fix mqtt fan test

* Update fan.py
This commit is contained in:
Jc2k 2020-01-06 16:10:51 +00:00 committed by Martin Hjelmare
parent a58c796641
commit 8257ea30c0
3 changed files with 35 additions and 31 deletions

View File

@ -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_TURN_OFF, {}, "async_turn_off")
component.async_register_entity_service(SERVICE_TOGGLE, {}, "async_toggle") component.async_register_entity_service(SERVICE_TOGGLE, {}, "async_toggle")
component.async_register_entity_service( 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( component.async_register_entity_service(
SERVICE_OSCILLATE, SERVICE_OSCILLATE,
{vol.Required(ATTR_OSCILLATING): cv.boolean}, {vol.Required(ATTR_OSCILLATING): cv.boolean},
"async_oscillate", "async_oscillate",
[SUPPORT_OSCILLATE],
) )
component.async_register_entity_service( component.async_register_entity_service(
SERVICE_SET_DIRECTION, SERVICE_SET_DIRECTION,
{vol.Optional(ATTR_DIRECTION): cv.string}, {vol.Optional(ATTR_DIRECTION): cv.string},
"async_set_direction", "async_set_direction",
[SUPPORT_DIRECTION],
) )
return True return True

View File

@ -121,7 +121,6 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
async def async_set_direction(self, direction): async def async_set_direction(self, direction):
"""Set the direction of the fan.""" """Set the direction of the fan."""
if self.supported_features & SUPPORT_DIRECTION:
await self._accessory.put_characteristics( await self._accessory.put_characteristics(
[ [
{ {
@ -137,7 +136,6 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
if speed == SPEED_OFF: if speed == SPEED_OFF:
return await self.async_turn_off() return await self.async_turn_off()
if self.supported_features & SUPPORT_SET_SPEED:
await self._accessory.put_characteristics( await self._accessory.put_characteristics(
[ [
{ {
@ -150,7 +148,6 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
async def async_oscillate(self, oscillating: bool): async def async_oscillate(self, oscillating: bool):
"""Oscillate the fan.""" """Oscillate the fan."""
if self.supported_features & SUPPORT_OSCILLATE:
await self._accessory.put_characteristics( await self._accessory.put_characteristics(
[ [
{ {

View File

@ -171,9 +171,11 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
"payload_off": "StAtE_OfF", "payload_off": "StAtE_OfF",
"payload_on": "StAtE_On", "payload_on": "StAtE_On",
"oscillation_command_topic": "oscillation-command-topic", "oscillation_command_topic": "oscillation-command-topic",
"oscillation_state_topic": "oscillation-state-topic",
"payload_oscillation_off": "OsC_OfF", "payload_oscillation_off": "OsC_OfF",
"payload_oscillation_on": "OsC_On", "payload_oscillation_on": "OsC_On",
"speed_command_topic": "speed-command-topic", "speed_command_topic": "speed-command-topic",
"speed_state_topic": "speed-state-topic",
"payload_off_speed": "speed_OfF", "payload_off_speed": "speed_OfF",
"payload_low_speed": "speed_lOw", "payload_low_speed": "speed_lOw",
"payload_medium_speed": "speed_mEdium", "payload_medium_speed": "speed_mEdium",