mirror of
https://github.com/home-assistant/core
synced 2024-07-27 18:58:57 +02:00
Improve zwave.cover tests (#93458)
* Improve zwave.cover tests * Update conftest.py
This commit is contained in:
parent
08c8c22fac
commit
3e84c374f4
@ -946,7 +946,7 @@ def motorized_barrier_cover_fixture(client, gdc_zw062_state):
|
||||
|
||||
|
||||
@pytest.fixture(name="iblinds_v2")
|
||||
def iblinds_cover_fixture(client, iblinds_v2_state):
|
||||
def iblinds_v2_cover_fixture(client, iblinds_v2_state):
|
||||
"""Mock an iBlinds v2.0 window cover node."""
|
||||
node = Node(client, copy.deepcopy(iblinds_v2_state))
|
||||
client.driver.controller.nodes[node.node_id] = node
|
||||
|
@ -10,14 +10,22 @@ from zwave_js_server.model.node import Node
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
ATTR_CURRENT_TILT_POSITION,
|
||||
ATTR_POSITION,
|
||||
ATTR_TILT_POSITION,
|
||||
DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_CLOSE_COVER_TILT,
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_OPEN_COVER_TILT,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
SERVICE_STOP_COVER,
|
||||
CoverDeviceClass,
|
||||
)
|
||||
from homeassistant.components.zwave_js.helpers import ZwaveValueMatcher
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_CLOSED,
|
||||
STATE_CLOSING,
|
||||
STATE_OPEN,
|
||||
@ -46,14 +54,14 @@ async def test_window_cover(
|
||||
assert state
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == CoverDeviceClass.WINDOW
|
||||
|
||||
assert state.state == "closed"
|
||||
assert state.state == STATE_CLOSED
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
# Test setting position
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_position",
|
||||
{"entity_id": WINDOW_COVER_ENTITY, "position": 50},
|
||||
DOMAIN,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 50},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -72,9 +80,9 @@ async def test_window_cover(
|
||||
|
||||
# Test setting position
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_position",
|
||||
{"entity_id": WINDOW_COVER_ENTITY, "position": 0},
|
||||
DOMAIN,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 0},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -93,9 +101,9 @@ async def test_window_cover(
|
||||
|
||||
# Test opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"open_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -113,9 +121,9 @@ async def test_window_cover(
|
||||
client.async_send_command.reset_mock()
|
||||
# Test stop after opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"stop_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -152,13 +160,13 @@ async def test_window_cover(
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||
assert state.state == "open"
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
# Test closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"close_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
@ -176,9 +184,9 @@ async def test_window_cover(
|
||||
|
||||
# Test stop after closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"stop_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -215,10 +223,10 @@ async def test_window_cover(
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||
assert state.state == "closed"
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_fibaro_FGR222_shutter_cover(
|
||||
async def test_fibaro_fgr222_shutter_cover(
|
||||
hass: HomeAssistant, client, fibaro_fgr222_shutter, integration
|
||||
) -> None:
|
||||
"""Test tilt function of the Fibaro Shutter devices."""
|
||||
@ -226,14 +234,14 @@ async def test_fibaro_FGR222_shutter_cover(
|
||||
assert state
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == CoverDeviceClass.SHUTTER
|
||||
|
||||
assert state.state == "open"
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
# Test opening tilts
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"open_cover_tilt",
|
||||
{"entity_id": FIBARO_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: FIBARO_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -252,9 +260,9 @@ async def test_fibaro_FGR222_shutter_cover(
|
||||
client.async_send_command.reset_mock()
|
||||
# Test closing tilts
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"close_cover_tilt",
|
||||
{"entity_id": FIBARO_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_CLOSE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: FIBARO_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -270,6 +278,27 @@ async def test_fibaro_FGR222_shutter_cover(
|
||||
}
|
||||
assert args["value"] == 0
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
# Test setting tilt position
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: FIBARO_SHUTTER_COVER_ENTITY, ATTR_TILT_POSITION: 12},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
args = client.async_send_command.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 42
|
||||
assert args["valueId"] == {
|
||||
"endpoint": 0,
|
||||
"commandClass": 145,
|
||||
"property": "fibaro",
|
||||
"propertyKey": "venetianBlindsTilt",
|
||||
}
|
||||
assert args["value"] == 12
|
||||
|
||||
# Test some tilt
|
||||
event = Event(
|
||||
type="value updated",
|
||||
@ -306,14 +335,14 @@ async def test_aeotec_nano_shutter_cover(
|
||||
assert state
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == CoverDeviceClass.WINDOW
|
||||
|
||||
assert state.state == "closed"
|
||||
assert state.state == STATE_CLOSED
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
# Test opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"open_cover",
|
||||
{"entity_id": AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -331,9 +360,9 @@ async def test_aeotec_nano_shutter_cover(
|
||||
client.async_send_command.reset_mock()
|
||||
# Test stop after opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"stop_cover",
|
||||
{"entity_id": AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -371,13 +400,13 @@ async def test_aeotec_nano_shutter_cover(
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
state = hass.states.get(AEOTEC_SHUTTER_COVER_ENTITY)
|
||||
assert state.state == "open"
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
# Test closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"close_cover",
|
||||
{"entity_id": AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
@ -395,9 +424,9 @@ async def test_aeotec_nano_shutter_cover(
|
||||
|
||||
# Test stop after closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"stop_cover",
|
||||
{"entity_id": AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
DOMAIN,
|
||||
SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@ -447,7 +476,7 @@ async def test_motor_barrier_cover(
|
||||
|
||||
# Test open
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER, {"entity_id": GDC_COVER_ENTITY}, blocking=True
|
||||
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: GDC_COVER_ENTITY}, blocking=True
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
@ -469,7 +498,7 @@ async def test_motor_barrier_cover(
|
||||
|
||||
# Test close
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_CLOSE_COVER, {"entity_id": GDC_COVER_ENTITY}, blocking=True
|
||||
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: GDC_COVER_ENTITY}, blocking=True
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
@ -631,7 +660,7 @@ async def test_motor_barrier_cover_no_primary_value(
|
||||
assert ATTR_CURRENT_POSITION not in state.attributes
|
||||
|
||||
|
||||
async def test_fibaro_FGR222_shutter_cover_no_tilt(
|
||||
async def test_fibaro_fgr222_shutter_cover_no_tilt(
|
||||
hass: HomeAssistant, client, fibaro_fgr222_shutter_state, integration
|
||||
) -> None:
|
||||
"""Test tilt function of the Fibaro Shutter devices with tilt value is None."""
|
||||
|
Loading…
Reference in New Issue
Block a user