Add support for fan direction in bond integration (#37789)
* Add support for fan direction in bond integration * Add support for fan direction (PR feedback)
This commit is contained in:
parent
53844488d8
commit
e9440c49d5
3 changed files with 98 additions and 9 deletions
|
@ -1,11 +1,17 @@
|
|||
"""Tests for the Bond fan device."""
|
||||
from datetime import timedelta
|
||||
|
||||
from bond import DeviceTypes
|
||||
from bond import DeviceTypes, Directions
|
||||
|
||||
from homeassistant import core
|
||||
from homeassistant.components import fan
|
||||
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||
from homeassistant.components.fan import (
|
||||
ATTR_DIRECTION,
|
||||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
DOMAIN as FAN_DOMAIN,
|
||||
SERVICE_SET_DIRECTION,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from homeassistant.util import utcnow
|
||||
|
@ -21,7 +27,7 @@ def ceiling_fan(name: str):
|
|||
return {
|
||||
"name": name,
|
||||
"type": DeviceTypes.CEILING_FAN,
|
||||
"actions": ["SetSpeed"],
|
||||
"actions": ["SetSpeed", "SetDirection"],
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,3 +96,46 @@ async def test_update_reports_fan_off(hass: core.HomeAssistant):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("fan.name_1").state == "off"
|
||||
|
||||
|
||||
async def test_update_reports_direction_forward(hass: core.HomeAssistant):
|
||||
"""Tests that update command sets correct direction when Bond API reports fan direction is forward."""
|
||||
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.bond.Bond.getDeviceState",
|
||||
return_value={"direction": Directions.FORWARD},
|
||||
):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("fan.name_1").attributes[ATTR_DIRECTION] == DIRECTION_FORWARD
|
||||
|
||||
|
||||
async def test_update_reports_direction_reverse(hass: core.HomeAssistant):
|
||||
"""Tests that update command sets correct direction when Bond API reports fan direction is reverse."""
|
||||
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.bond.Bond.getDeviceState",
|
||||
return_value={"direction": Directions.REVERSE},
|
||||
):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("fan.name_1").attributes[ATTR_DIRECTION] == DIRECTION_REVERSE
|
||||
|
||||
|
||||
async def test_set_fan_direction(hass: core.HomeAssistant):
|
||||
"""Tests that set direction command delegates to API."""
|
||||
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
|
||||
|
||||
with patch("homeassistant.components.bond.Bond.setDirection") as mock_set_direction:
|
||||
await hass.services.async_call(
|
||||
FAN_DOMAIN,
|
||||
SERVICE_SET_DIRECTION,
|
||||
{ATTR_ENTITY_ID: "fan.name_1", ATTR_DIRECTION: DIRECTION_FORWARD},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_set_direction.assert_called_once()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue