core/tests/components/switcher_kis/test_cover.py

286 lines
8.7 KiB
Python
Raw Normal View History

"""Test the Switcher cover platform."""
from unittest.mock import patch
from aioswitcher.api import SwitcherBaseResponse
from aioswitcher.device import ShutterDirection
import pytest
from homeassistant.components.cover import (
ATTR_CURRENT_POSITION,
ATTR_POSITION,
DOMAIN as COVER_DOMAIN,
SERVICE_CLOSE_COVER,
SERVICE_OPEN_COVER,
SERVICE_SET_COVER_POSITION,
SERVICE_STOP_COVER,
CoverState,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import slugify
from . import init_integration
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
from .consts import (
DUMMY_DUAL_SHUTTER_SINGLE_LIGHT_DEVICE as DEVICE3,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
DUMMY_SHUTTER_DEVICE as DEVICE,
DUMMY_SINGLE_SHUTTER_DUAL_LIGHT_DEVICE as DEVICE2,
DUMMY_TOKEN as TOKEN,
DUMMY_USERNAME as USERNAME,
)
ENTITY_ID = f"{COVER_DOMAIN}.{slugify(DEVICE.name)}"
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
ENTITY_ID2 = f"{COVER_DOMAIN}.{slugify(DEVICE2.name)}"
ENTITY_ID3 = f"{COVER_DOMAIN}.{slugify(DEVICE3.name)}_cover_1"
ENTITY_ID3_2 = f"{COVER_DOMAIN}.{slugify(DEVICE3.name)}_cover_2"
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
@pytest.mark.parametrize(
(
"device",
"entity_id",
"cover_id",
"position_open",
"position_close",
"direction_open",
"direction_close",
"direction_stop",
),
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
[
(
DEVICE,
ENTITY_ID,
0,
[77],
[0],
[ShutterDirection.SHUTTER_UP],
[ShutterDirection.SHUTTER_DOWN],
[ShutterDirection.SHUTTER_STOP],
),
(
DEVICE2,
ENTITY_ID2,
0,
[77],
[0],
[ShutterDirection.SHUTTER_UP],
[ShutterDirection.SHUTTER_DOWN],
[ShutterDirection.SHUTTER_STOP],
),
(
DEVICE3,
ENTITY_ID3,
0,
[77, 0],
[0, 0],
[ShutterDirection.SHUTTER_UP, ShutterDirection.SHUTTER_STOP],
[ShutterDirection.SHUTTER_DOWN, ShutterDirection.SHUTTER_STOP],
[ShutterDirection.SHUTTER_STOP, ShutterDirection.SHUTTER_STOP],
),
(
DEVICE3,
ENTITY_ID3_2,
1,
[0, 77],
[0, 0],
[ShutterDirection.SHUTTER_STOP, ShutterDirection.SHUTTER_UP],
[ShutterDirection.SHUTTER_STOP, ShutterDirection.SHUTTER_DOWN],
[ShutterDirection.SHUTTER_STOP, ShutterDirection.SHUTTER_STOP],
),
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
],
)
@pytest.mark.parametrize("mock_bridge", [[DEVICE, DEVICE2, DEVICE3]], indirect=True)
async def test_cover(
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
hass: HomeAssistant,
mock_bridge,
mock_api,
monkeypatch: pytest.MonkeyPatch,
device,
entity_id: str,
cover_id: int,
position_open: list[int],
position_close: list[int],
direction_open: list[ShutterDirection],
direction_close: list[ShutterDirection],
direction_stop: list[ShutterDirection],
) -> None:
"""Test cover services."""
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
await init_integration(hass, USERNAME, TOKEN)
assert mock_bridge
# Test initial state - open
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPEN
# Test set position
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.set_position"
) as mock_control_device:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_SET_COVER_POSITION,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id, ATTR_POSITION: 77},
blocking=True,
)
monkeypatch.setattr(device, "position", position_open)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
assert mock_api.call_count == 2
mock_control_device.assert_called_once_with(77, cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPEN
assert state.attributes[ATTR_CURRENT_POSITION] == 77
# Test open
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.set_position"
) as mock_control_device:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_OPEN_COVER,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
monkeypatch.setattr(device, "direction", direction_open)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
assert mock_api.call_count == 4
mock_control_device.assert_called_once_with(100, cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPENING
# Test close
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.set_position"
) as mock_control_device:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_CLOSE_COVER,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
monkeypatch.setattr(device, "direction", direction_close)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
assert mock_api.call_count == 6
mock_control_device.assert_called_once_with(0, cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.CLOSING
# Test stop
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.stop_shutter"
) as mock_control_device:
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_STOP_COVER,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
monkeypatch.setattr(device, "direction", direction_stop)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
assert mock_api.call_count == 8
mock_control_device.assert_called_once_with(cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPEN
# Test closed on position == 0
monkeypatch.setattr(device, "position", position_close)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.CLOSED
assert state.attributes[ATTR_CURRENT_POSITION] == 0
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
@pytest.mark.parametrize(
("device", "entity_id", "cover_id"),
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
[
(DEVICE, ENTITY_ID, 0),
(DEVICE2, ENTITY_ID2, 0),
(DEVICE3, ENTITY_ID3, 0),
(DEVICE3, ENTITY_ID3_2, 1),
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
],
)
@pytest.mark.parametrize("mock_bridge", [[DEVICE, DEVICE2, DEVICE3]], indirect=True)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
async def test_cover_control_fail(
hass: HomeAssistant,
mock_bridge,
mock_api,
device,
entity_id: str,
cover_id: int,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
) -> None:
"""Test cover control fail."""
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
await init_integration(hass, USERNAME, TOKEN)
assert mock_bridge
# Test initial state - open
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPEN
# Test exception during set position
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.set_position",
side_effect=RuntimeError("fake error"),
) as mock_control_device:
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_SET_COVER_POSITION,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id, ATTR_POSITION: 44},
blocking=True,
)
assert mock_api.call_count == 2
mock_control_device.assert_called_once_with(44, cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == STATE_UNAVAILABLE
# Make device available again
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
mock_bridge.mock_callbacks([device])
await hass.async_block_till_done()
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == CoverState.OPEN
# Test error response during set position
with patch(
"homeassistant.components.switcher_kis.entity.SwitcherApi.set_position",
return_value=SwitcherBaseResponse(None),
) as mock_control_device:
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
COVER_DOMAIN,
SERVICE_SET_COVER_POSITION,
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
{ATTR_ENTITY_ID: entity_id, ATTR_POSITION: 27},
blocking=True,
)
assert mock_api.call_count == 4
mock_control_device.assert_called_once_with(27, cover_id)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
state = hass.states.get(entity_id)
assert state.state == STATE_UNAVAILABLE
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
@pytest.mark.parametrize("mock_bridge", [[DEVICE2, DEVICE3]], indirect=True)
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
async def test_cover2_no_token(
hass: HomeAssistant, mock_bridge, mock_api, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test cover with token needed without token specified."""
Add Switcher Runner S11 support (#123578) * switcher start s11 integration * switcher linting * switcher starting reauth logic * switcher fix linting * switcher fix linting * switcher remove get_circuit_number * switcher adding support for validate token * switcher fix initial auth for new devices and fix strings * switcher fix linting * switcher fix utils * Revert "switcher fix utils" This reverts commit b162a943b94fb0a581140feb21fe871df578c16a. * switcher revert and test * switcher fix validate logic and strings * switcher add tests to improve coverage * switcher adding tests * switcher adding test * switcher revert back things * switcher fix based on requested changes * switcher tests fixes * switcher fix based on requested changes * switcher remove single_instance_allowed code and added tests * Update config_flow.py * switcher fix comment * switcher fix tests * switcher lint * switcehr fix based on requested changes * switche fix lint * switcher small rename fix * switcher fix based on requested changes * switcher fix based on requested changes * switcher fix based on requested changes * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py Co-authored-by: Shay Levy <levyshay1@gmail.com> * Update tests/components/switcher_kis/test_config_flow.py --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 20:19:57 +00:00
await init_integration(hass)
assert mock_bridge
assert mock_api.call_count == 0