1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Add switch tests to vesync (#163325)

This commit is contained in:
cdnninja
2026-03-23 11:46:35 -06:00
committed by GitHub
parent 579dd6785d
commit f9525ebda7

View File

@@ -58,51 +58,6 @@ async def test_switch_state(
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id)
@pytest.mark.parametrize(
("action", "command"),
[
(
SERVICE_TURN_ON,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_display",
),
(
SERVICE_TURN_OFF,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_display",
),
],
)
async def test_turn_on_off_display_success(
hass: HomeAssistant,
humidifier_config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
action: str,
command: str,
) -> None:
"""Test switch turn on and off command with success response."""
mock_devices_response(aioclient_mock, "Humidifier 200s")
with (
patch(
command,
return_value=True,
) as method_mock,
patch(
"homeassistant.components.vesync.switch.VeSyncSwitchEntity.async_write_ha_state"
) as update_mock,
):
await hass.services.async_call(
SWITCH_DOMAIN,
action,
{ATTR_ENTITY_ID: ENTITY_SWITCH_DISPLAY},
blocking=True,
)
await hass.async_block_till_done()
method_mock.assert_called_once()
update_mock.assert_called_once()
@pytest.mark.parametrize(
("action", "command"),
[
@@ -143,3 +98,112 @@ async def test_turn_on_off_display_raises_error(
await hass.async_block_till_done()
method_mock.assert_called_once()
@pytest.mark.parametrize(
("device_name", "entity_id", "action", "command"),
[
# device_status switch for outlet
(
"Outlet",
"switch.outlet",
SERVICE_TURN_ON,
"pyvesync.devices.vesyncoutlet.VeSyncOutlet.turn_on",
),
(
"Outlet",
"switch.outlet",
SERVICE_TURN_OFF,
"pyvesync.devices.vesyncoutlet.VeSyncOutlet.turn_off",
),
# display switch for humidifier
(
"Humidifier 200s",
"switch.humidifier_200s_display",
SERVICE_TURN_ON,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_display",
),
(
"Humidifier 200s",
"switch.humidifier_200s_display",
SERVICE_TURN_OFF,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_display",
),
# auto_off_config switch for humidifier
(
"Humidifier 200s",
"switch.humidifier_200s_auto_off",
SERVICE_TURN_ON,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_automatic_stop",
),
(
"Humidifier 200s",
"switch.humidifier_200s_auto_off",
SERVICE_TURN_OFF,
"pyvesync.devices.vesynchumidifier.VeSyncHumid200S.toggle_automatic_stop",
),
# child_lock switch for humidifier
(
"Humidifier 6000s",
"switch.humidifier_6000s_child_lock",
SERVICE_TURN_ON,
"pyvesync.devices.vesynchumidifier.VeSyncSuperior6000S.toggle_child_lock",
),
(
"Humidifier 6000s",
"switch.humidifier_6000s_child_lock",
SERVICE_TURN_OFF,
"pyvesync.devices.vesynchumidifier.VeSyncSuperior6000S.toggle_child_lock",
),
# drying_mode_power_off switch for humidifier with drying mode
(
"Humidifier 6000s",
"switch.humidifier_6000s_enable_drying_mode_while_power_is_off",
SERVICE_TURN_ON,
"pyvesync.devices.vesynchumidifier.VeSyncSuperior6000S.toggle_drying_mode",
),
(
"Humidifier 6000s",
"switch.humidifier_6000s_enable_drying_mode_while_power_is_off",
SERVICE_TURN_OFF,
"pyvesync.devices.vesynchumidifier.VeSyncSuperior6000S.toggle_drying_mode",
),
],
)
async def test_switch_operations(
hass: HomeAssistant,
config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
device_name: str,
entity_id: str,
action: str,
command: str,
) -> None:
"""Test all switch operations with appropriate devices and parameters."""
# Configure the API devices call for the specific device
mock_devices_response(aioclient_mock, device_name)
# Setup platform
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
with (
patch(
command,
return_value=True,
) as method_mock,
patch(
"homeassistant.components.vesync.switch.VeSyncSwitchEntity.async_write_ha_state"
) as update_mock,
):
await hass.services.async_call(
SWITCH_DOMAIN,
action,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
await hass.async_block_till_done()
method_mock.assert_called_once()
update_mock.assert_called_once()