mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add test to Homematic IP Cloud cover (#27535)
This commit is contained in:
parent
eb77db6569
commit
bb1be5327e
141
tests/components/homematicip_cloud/test_cover.py
Normal file
141
tests/components/homematicip_cloud/test_cover.py
Normal file
@ -0,0 +1,141 @@
|
||||
"""Tests for HomematicIP Cloud cover."""
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
ATTR_CURRENT_TILT_POSITION,
|
||||
)
|
||||
from homeassistant.const import STATE_CLOSED, STATE_OPEN
|
||||
|
||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||
|
||||
|
||||
async def test_hmip_cover_shutter(hass, default_mock_hap):
|
||||
"""Test HomematicipCoverShutte."""
|
||||
entity_id = "cover.sofa_links"
|
||||
entity_name = "Sofa links"
|
||||
device_model = "HmIP-FBL"
|
||||
|
||||
ha_state, hmip_device = get_and_check_entity_basics(
|
||||
hass, default_mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == "closed"
|
||||
assert ha_state.attributes["current_position"] == 0
|
||||
assert ha_state.attributes["current_tilt_position"] == 0
|
||||
service_call_counter = len(hmip_device.mock_calls)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 1
|
||||
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (0,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_position",
|
||||
{"entity_id": entity_id, "position": "50"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 3
|
||||
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (0.5,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0.5)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 50
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 5
|
||||
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (1,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_CLOSED
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 7
|
||||
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
|
||||
assert hmip_device.mock_calls[-1][1] == ()
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_hmip_cover_slats(hass, default_mock_hap):
|
||||
"""Test HomematicipCoverSlats."""
|
||||
entity_id = "cover.sofa_links"
|
||||
entity_name = "Sofa links"
|
||||
device_model = "HmIP-FBL"
|
||||
|
||||
ha_state, hmip_device = get_and_check_entity_basics(
|
||||
hass, default_mock_hap, entity_id, entity_name, device_model
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_CLOSED
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
service_call_counter = len(hmip_device.mock_calls)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover_tilt", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 1
|
||||
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (0,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0)
|
||||
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_tilt_position",
|
||||
{"entity_id": entity_id, "tilt_position": "50"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 4
|
||||
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (0.5,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0.5)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 50
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover_tilt", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 6
|
||||
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
|
||||
assert hmip_device.mock_calls[-1][1] == (1,)
|
||||
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 1)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
||||
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert ha_state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "stop_cover_tilt", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(hmip_device.mock_calls) == service_call_counter + 8
|
||||
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
|
||||
assert hmip_device.mock_calls[-1][1] == ()
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OPEN
|
Loading…
x
Reference in New Issue
Block a user