2020-12-02 12:50:48 +00:00
|
|
|
"""The tests for the Number component."""
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import MagicMock
|
2020-12-02 12:50:48 +00:00
|
|
|
|
2021-01-01 21:31:56 +00:00
|
|
|
from homeassistant.components.number import NumberEntity
|
2020-12-03 17:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MockDefaultNumberEntity(NumberEntity):
|
|
|
|
"""Mock NumberEntity device to use in tests."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def value(self):
|
|
|
|
"""Return the current value."""
|
|
|
|
return 0.5
|
|
|
|
|
2020-12-02 12:50:48 +00:00
|
|
|
|
|
|
|
class MockNumberEntity(NumberEntity):
|
|
|
|
"""Mock NumberEntity device to use in tests."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def max_value(self) -> float:
|
|
|
|
"""Return the max value."""
|
|
|
|
return 1.0
|
|
|
|
|
|
|
|
@property
|
2020-12-03 17:35:17 +00:00
|
|
|
def value(self):
|
2020-12-02 12:50:48 +00:00
|
|
|
"""Return the current value."""
|
2020-12-03 17:35:17 +00:00
|
|
|
return 0.5
|
2020-12-02 12:50:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_step(hass):
|
|
|
|
"""Test the step calculation."""
|
2020-12-03 17:35:17 +00:00
|
|
|
number = MockDefaultNumberEntity()
|
2020-12-02 12:50:48 +00:00
|
|
|
assert number.step == 1.0
|
|
|
|
|
|
|
|
number_2 = MockNumberEntity()
|
|
|
|
assert number_2.step == 0.1
|
|
|
|
|
|
|
|
|
|
|
|
async def test_sync_set_value(hass):
|
|
|
|
"""Test if async set_value calls sync set_value."""
|
2020-12-03 17:35:17 +00:00
|
|
|
number = MockDefaultNumberEntity()
|
2020-12-02 12:50:48 +00:00
|
|
|
number.hass = hass
|
|
|
|
|
|
|
|
number.set_value = MagicMock()
|
|
|
|
await number.async_set_value(42)
|
|
|
|
|
|
|
|
assert number.set_value.called
|
|
|
|
assert number.set_value.call_args[0][0] == 42
|