1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 04:50:05 +00:00
Files
core/tests/components/chacon_dio/conftest.py
cnico 092e362f01 Add new integration for Dio Chacon cover devices (#116267)
* Dio Chacon integration addition with config flow and cover entity

* Addition of model information for device

* Addition of light and service to force reloading states

* Logger improvements

* Convert light to switch and usage of v1.0.0 of the api

* 100% for tests coverage

* Invalid credential implementation and rebase on latest ha dev code

* Simplify PR with only one platform

* Ruff correction

* restore original .gitignore content

* Correction of cover state bug when using cover when using actions on cover group.

* Begin of corrections following review.

* unit tests correction

* Refactor with a coordinator as asked by review

* Implemented a post constructor callback init method via dio-chacon-api-1.0.2. Improved typing.

* Corrections for 2nd review

* Reimplemented without coordinator as reviewed with Joostlek

* Review improvement

* generalize callback in entity

* Other review improvements

* Refactored tests for readability

* Test 100% operationals

* Tests review corrections

* Tests review corrections

* Review tests improvements

* simplified tests with snapshots and callback method

* Final fixes

* Final fixes

* Final fixes

* Rename to chacon_dio

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
2024-07-04 16:45:20 +02:00

72 lines
1.9 KiB
Python

"""Common fixtures for the chacon_dio tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
from homeassistant.components.chacon_dio.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from tests.common import MockConfigEntry
MOCK_COVER_DEVICE = {
"L4HActuator_idmock1": {
"id": "L4HActuator_idmock1",
"name": "Shutter mock 1",
"type": "SHUTTER",
"model": "CERSwd-3B_1.0.6",
"connected": True,
"openlevel": 75,
"movement": "stop",
}
}
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.chacon_dio.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Mock the config entry."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="test_entry_unique_id",
data={
CONF_USERNAME: "dummylogin",
CONF_PASSWORD: "dummypass",
},
)
@pytest.fixture
def mock_dio_chacon_client() -> Generator[AsyncMock]:
"""Mock a Dio Chacon client."""
with (
patch(
"homeassistant.components.chacon_dio.DIOChaconAPIClient",
autospec=True,
) as mock_client,
patch(
"homeassistant.components.chacon_dio.config_flow.DIOChaconAPIClient",
new=mock_client,
),
):
client = mock_client.return_value
# Default values for the tests using this mock :
client.get_user_id.return_value = "dummy-user-id"
client.search_all_devices.return_value = MOCK_COVER_DEVICE
client.move_shutter_direction.return_value = {}
client.disconnect.return_value = {}
yield client