Bump pytradfri to 8.0.1 and fix fan preset mode "Auto" bug (#63920)
* Move util functions * Fix errors * Revert changes * Fix tests * Use self.async_set_percentage() * Fix calculation functions and associated tests * Handle case of 0 * Update tests/components/tradfri/test_util.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/tradfri/test_util.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/tradfri/test_util.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Handle case of 0 * Update homeassistant/components/tradfri/fan.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
a978661545
commit
b52a8ba37a
6 changed files with 62 additions and 50 deletions
|
@ -1,22 +1,31 @@
|
|||
"""Tradfri utility function tests."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tradfri.fan import _from_fan_speed, _from_percentage
|
||||
from homeassistant.components.tradfri.fan import _from_fan_percentage, _from_fan_speed
|
||||
|
||||
|
||||
def test_from_fan_speed():
|
||||
@pytest.mark.parametrize(
|
||||
"fan_speed, expected_result",
|
||||
[
|
||||
(0, 0),
|
||||
(2, 2),
|
||||
(25, 49),
|
||||
(50, 100),
|
||||
],
|
||||
)
|
||||
def test_from_fan_speed(fan_speed, expected_result):
|
||||
"""Test that we can convert fan speed to percentage value."""
|
||||
assert _from_fan_speed(41) == 80
|
||||
assert _from_fan_speed(fan_speed) == expected_result
|
||||
|
||||
|
||||
def test_from_percentage():
|
||||
@pytest.mark.parametrize(
|
||||
"percentage, expected_result",
|
||||
[
|
||||
(1, 2),
|
||||
(100, 50),
|
||||
(50, 26),
|
||||
],
|
||||
)
|
||||
def test_from_percentage(percentage, expected_result):
|
||||
"""Test that we can convert percentage value to fan speed."""
|
||||
assert _from_percentage(84) == 40
|
||||
|
||||
|
||||
def test_from_percentage_limit():
|
||||
"""
|
||||
Test that we can convert percentage value to fan speed.
|
||||
|
||||
Handle special case of percent value being below 20.
|
||||
"""
|
||||
assert _from_percentage(10) == 0
|
||||
assert _from_fan_percentage(percentage) == expected_result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue