2018-09-26 06:53:24 +00:00
|
|
|
"""Tests for fan platforms."""
|
2018-10-24 10:10:05 +00:00
|
|
|
import pytest
|
2018-09-26 06:53:24 +00:00
|
|
|
|
2021-12-04 05:57:46 +00:00
|
|
|
from homeassistant.components.fan import FanEntity
|
2023-02-08 12:33:52 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-12-08 15:58:47 +00:00
|
|
|
|
2018-09-26 06:53:24 +00:00
|
|
|
|
|
|
|
class BaseFan(FanEntity):
|
|
|
|
"""Implementation of the abstract FanEntity."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize the fan."""
|
|
|
|
|
|
|
|
|
2023-02-07 13:20:06 +00:00
|
|
|
def test_fanentity() -> None:
|
2020-10-14 09:07:26 +00:00
|
|
|
"""Test fan entity methods."""
|
|
|
|
fan = BaseFan()
|
|
|
|
assert fan.state == "off"
|
2021-12-04 05:57:46 +00:00
|
|
|
assert fan.preset_modes is None
|
2020-10-14 09:07:26 +00:00
|
|
|
assert fan.supported_features == 0
|
2021-02-19 07:05:09 +00:00
|
|
|
assert fan.percentage_step == 1
|
|
|
|
assert fan.speed_count == 100
|
2020-10-14 09:07:26 +00:00
|
|
|
assert fan.capability_attributes == {}
|
|
|
|
# Test set_speed not required
|
2020-11-19 11:05:52 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.oscillate(True)
|
2022-03-09 09:38:12 +00:00
|
|
|
with pytest.raises(AttributeError):
|
2021-12-04 05:57:46 +00:00
|
|
|
fan.set_speed("low")
|
2021-01-27 23:44:36 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.set_percentage(0)
|
2021-12-04 05:57:46 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
2021-01-27 23:44:36 +00:00
|
|
|
fan.set_preset_mode("auto")
|
2020-10-14 09:07:26 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.turn_on()
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.turn_off()
|
2021-01-27 23:44:36 +00:00
|
|
|
|
|
|
|
|
2023-02-08 12:33:52 +00:00
|
|
|
async def test_async_fanentity(hass: HomeAssistant) -> None:
|
2021-01-27 23:44:36 +00:00
|
|
|
"""Test async fan entity methods."""
|
|
|
|
fan = BaseFan()
|
|
|
|
fan.hass = hass
|
|
|
|
assert fan.state == "off"
|
2021-12-04 05:57:46 +00:00
|
|
|
assert fan.preset_modes is None
|
2021-01-27 23:44:36 +00:00
|
|
|
assert fan.supported_features == 0
|
2021-02-19 07:05:09 +00:00
|
|
|
assert fan.percentage_step == 1
|
|
|
|
assert fan.speed_count == 100
|
2021-01-27 23:44:36 +00:00
|
|
|
assert fan.capability_attributes == {}
|
|
|
|
# Test set_speed not required
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_oscillate(True)
|
2022-03-09 09:38:12 +00:00
|
|
|
with pytest.raises(AttributeError):
|
2021-12-04 05:57:46 +00:00
|
|
|
await fan.async_set_speed("low")
|
2021-01-27 23:44:36 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_set_percentage(0)
|
2021-12-04 05:57:46 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
2021-01-27 23:44:36 +00:00
|
|
|
await fan.async_set_preset_mode("auto")
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_turn_on()
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_turn_off()
|
2021-02-19 07:05:09 +00:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_increase_speed()
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_decrease_speed()
|
2021-11-16 00:25:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-02-15 13:09:50 +00:00
|
|
|
("attribute_name", "attribute_value"),
|
2021-11-16 00:25:22 +00:00
|
|
|
[
|
|
|
|
("current_direction", "forward"),
|
|
|
|
("oscillating", True),
|
|
|
|
("percentage", 50),
|
|
|
|
("preset_mode", "medium"),
|
|
|
|
("preset_modes", ["low", "medium", "high"]),
|
|
|
|
("speed_count", 50),
|
|
|
|
("supported_features", 1),
|
|
|
|
],
|
|
|
|
)
|
2023-02-13 08:45:11 +00:00
|
|
|
def test_fanentity_attributes(attribute_name, attribute_value) -> None:
|
2021-11-16 00:25:22 +00:00
|
|
|
"""Test fan entity attribute shorthand."""
|
|
|
|
fan = BaseFan()
|
|
|
|
setattr(fan, f"_attr_{attribute_name}", attribute_value)
|
|
|
|
assert getattr(fan, attribute_name) == attribute_value
|