2018-09-26 08:53:24 +02:00
|
|
|
"""Tests for fan platforms."""
|
|
|
|
|
2018-10-24 12:10:05 +02:00
|
|
|
import pytest
|
2018-09-26 08:53:24 +02:00
|
|
|
|
2021-01-27 17:44:36 -06:00
|
|
|
from homeassistant.components.fan import FanEntity, NotValidPresetModeError
|
2019-12-08 16:58:47 +01:00
|
|
|
|
2018-09-26 08:53:24 +02:00
|
|
|
|
|
|
|
class BaseFan(FanEntity):
|
|
|
|
"""Implementation of the abstract FanEntity."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize the fan."""
|
|
|
|
|
|
|
|
|
2020-10-14 02:07:26 -07:00
|
|
|
def test_fanentity():
|
|
|
|
"""Test fan entity methods."""
|
|
|
|
fan = BaseFan()
|
|
|
|
assert fan.state == "off"
|
|
|
|
assert len(fan.speed_list) == 0
|
2021-01-27 17:44:36 -06:00
|
|
|
assert len(fan.preset_modes) == 0
|
2020-10-14 02:07:26 -07:00
|
|
|
assert fan.supported_features == 0
|
|
|
|
assert fan.capability_attributes == {}
|
|
|
|
# Test set_speed not required
|
2020-11-19 12:05:52 +01:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.oscillate(True)
|
2020-10-14 02:07:26 -07:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.set_speed("slow")
|
2021-01-27 17:44:36 -06:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.set_percentage(0)
|
|
|
|
with pytest.raises(NotValidPresetModeError):
|
|
|
|
fan.set_preset_mode("auto")
|
2020-10-14 02:07:26 -07:00
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.turn_on()
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
fan.turn_off()
|
2021-01-27 17:44:36 -06:00
|
|
|
|
|
|
|
|
|
|
|
async def test_async_fanentity(hass):
|
|
|
|
"""Test async fan entity methods."""
|
|
|
|
fan = BaseFan()
|
|
|
|
fan.hass = hass
|
|
|
|
assert fan.state == "off"
|
|
|
|
assert len(fan.speed_list) == 0
|
|
|
|
assert len(fan.preset_modes) == 0
|
|
|
|
assert fan.supported_features == 0
|
|
|
|
assert fan.capability_attributes == {}
|
|
|
|
# Test set_speed not required
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_oscillate(True)
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_set_speed("slow")
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
await fan.async_set_percentage(0)
|
|
|
|
with pytest.raises(NotValidPresetModeError):
|
|
|
|
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()
|