mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 00:27:19 +00:00
Adjust cover tests
This commit is contained in:
parent
27a266d054
commit
855de74646
@ -8,9 +8,17 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
DOMAIN as COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceNotSupported
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import DEVICE_MOCKS, initialize_entry
|
||||
@ -57,6 +65,107 @@ async def test_platform_setup_no_discovery(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cl_am43_corded_motor_zigbee_cover"],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_open_service(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
) -> None:
|
||||
"""Test open service."""
|
||||
entity_id = "cover.kitchen_blinds_curtain"
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
{"code": "control", "value": "open"},
|
||||
{"code": "percent_control", "value": 0},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cl_am43_corded_motor_zigbee_cover"],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_close_service(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
) -> None:
|
||||
"""Test close service."""
|
||||
entity_id = "cover.kitchen_blinds_curtain"
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
{"code": "control", "value": "close"},
|
||||
{"code": "percent_control", "value": 100},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cl_am43_corded_motor_zigbee_cover"],
|
||||
)
|
||||
async def test_set_position(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
) -> None:
|
||||
"""Test set position service (not available on this device)."""
|
||||
entity_id = "cover.kitchen_blinds_curtain"
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"position": 25,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
{"code": "percent_control", "value": 75},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cl_am43_corded_motor_zigbee_cover"],
|
||||
@ -89,3 +198,31 @@ async def test_percent_state_on_cover(
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
assert state.attributes["current_position"] == percent_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cl_am43_corded_motor_zigbee_cover"],
|
||||
)
|
||||
async def test_set_tilt_position_not_supported(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
) -> None:
|
||||
"""Test set tilt position service (not available on this device)."""
|
||||
entity_id = "cover.kitchen_blinds_curtain"
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
with pytest.raises(ServiceNotSupported):
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"tilt_position": 50,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user