Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions homeassistant/components/homekit/type_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def _set_chars(self, char_values):
_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
Expand Down
15 changes: 7 additions & 8 deletions tests/components/homekit/test_type_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down