Prevent homekit fans from going to 100% than speed when turning on (#34875)

This commit is contained in:
J. Nick Koston 2020-04-29 16:00:31 -05:00 committed by GitHub
parent 5516063f46
commit 6ce0819287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -94,13 +94,13 @@ class Fan(HomeAccessory):
_LOGGER.debug("Fan _set_chars: %s", char_values)
if CHAR_ACTIVE in char_values:
if char_values[CHAR_ACTIVE]:
is_on = False
state = self.hass.states.get(self.entity_id)
if state and state.state == STATE_ON:
is_on = True
# Only set the state to active if we
# did not get a rotation speed or its off
if not is_on or CHAR_ROTATION_SPEED not in char_values:
# If the device supports set speed we
# do not want to turn on as it will take
# the fan to 100% than to the desired speed.
#
# Setting the speed will take care of turning
# on the fan if SUPPORT_SET_SPEED is set.
if not self.char_speed or CHAR_ROTATION_SPEED not in char_values:
self.set_state(1)
else:
# Its off, nothing more to do as setting the

View File

@ -419,8 +419,7 @@ async def test_fan_set_all_one_shot(hass, hk_driver, cls, events):
)
await hass.async_block_till_done()
acc.speed_mapping.speed_to_states.assert_called_with(42)
assert call_turn_on
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
assert not call_turn_on
assert call_set_speed[0]
assert call_set_speed[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_speed[0].data[ATTR_SPEED] == "ludicrous"
@ -430,11 +429,11 @@ async def test_fan_set_all_one_shot(hass, hk_driver, cls, events):
assert call_set_direction[0]
assert call_set_direction[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_direction[0].data[ATTR_DIRECTION] == DIRECTION_REVERSE
assert len(events) == 4
assert len(events) == 3
assert events[1].data[ATTR_VALUE] is True
assert events[2].data[ATTR_VALUE] == DIRECTION_REVERSE
assert events[3].data[ATTR_VALUE] == "ludicrous"
assert events[0].data[ATTR_VALUE] is True
assert events[1].data[ATTR_VALUE] == DIRECTION_REVERSE
assert events[2].data[ATTR_VALUE] == "ludicrous"
hass.states.async_set(
entity_id,
@ -482,7 +481,7 @@ async def test_fan_set_all_one_shot(hass, hk_driver, cls, events):
# and we set a fan speed
await hass.async_block_till_done()
acc.speed_mapping.speed_to_states.assert_called_with(42)
assert len(events) == 7
assert len(events) == 6
assert call_set_speed[1]
assert call_set_speed[1].data[ATTR_ENTITY_ID] == entity_id
assert call_set_speed[1].data[ATTR_SPEED] == "ludicrous"
@ -526,7 +525,7 @@ async def test_fan_set_all_one_shot(hass, hk_driver, cls, events):
)
await hass.async_block_till_done()
assert len(events) == 8
assert len(events) == 7
assert call_turn_off
assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
assert len(call_set_speed) == 2