Add tests for vera component (#28340)
* Adding tests for vera component. Fixing update bug in the vera climate platform. * Updating requrements file. * Moving vera stop to a job. Sorting imports. * Addressing simple PR feedback. * Splitting tests into platforms. * Mocking controller instead of using requests_mock. * Updating pyvera to use version that stops threads quickly. * Updating requirements files. * Mocking the pyvera module, not the API. * Addressing PR feedback. Handling start/stop of patch in fixture. Removing unecessary code. * Using generator
This commit is contained in:
parent
076e0273a2
commit
e577f047f7
17 changed files with 831 additions and 3 deletions
76
tests/components/vera/test_cover.py
Normal file
76
tests/components/vera/test_cover.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
"""Vera tests."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pyvera import CATEGORY_CURTAIN, VeraCurtain
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import ComponentFactory
|
||||
|
||||
|
||||
async def test_cover(
|
||||
hass: HomeAssistant, vera_component_factory: ComponentFactory
|
||||
) -> None:
|
||||
"""Test function."""
|
||||
vera_device = MagicMock(spec=VeraCurtain) # type: VeraCurtain
|
||||
vera_device.device_id = 1
|
||||
vera_device.name = "dev1"
|
||||
vera_device.category = CATEGORY_CURTAIN
|
||||
vera_device.is_closed = False
|
||||
vera_device.get_level.return_value = 0
|
||||
entity_id = "cover.dev1_1"
|
||||
|
||||
component_data = await vera_component_factory.configure_component(
|
||||
hass=hass, devices=(vera_device,),
|
||||
)
|
||||
controller = component_data.controller
|
||||
update_callback = controller.register.call_args_list[0][0][1]
|
||||
|
||||
assert hass.states.get(entity_id).state == "closed"
|
||||
assert hass.states.get(entity_id).attributes["current_position"] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": entity_id},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
vera_device.open.assert_called()
|
||||
vera_device.is_open.return_value = True
|
||||
vera_device.get_level.return_value = 100
|
||||
update_callback(vera_device)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "open"
|
||||
assert hass.states.get(entity_id).attributes["current_position"] == 100
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "set_cover_position", {"entity_id": entity_id, "position": 50},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
vera_device.set_level.assert_called_with(50)
|
||||
vera_device.is_open.return_value = True
|
||||
vera_device.get_level.return_value = 50
|
||||
update_callback(vera_device)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "open"
|
||||
assert hass.states.get(entity_id).attributes["current_position"] == 50
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "stop_cover", {"entity_id": entity_id},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
vera_device.stop.assert_called()
|
||||
update_callback(vera_device)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "open"
|
||||
assert hass.states.get(entity_id).attributes["current_position"] == 50
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": entity_id},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
vera_device.close.assert_called()
|
||||
vera_device.is_open.return_value = False
|
||||
vera_device.get_level.return_value = 00
|
||||
update_callback(vera_device)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == "closed"
|
||||
assert hass.states.get(entity_id).attributes["current_position"] == 00
|
Loading…
Add table
Add a link
Reference in a new issue