2023-11-07 20:53:22 +00:00
|
|
|
"""Common fixtures for the V2C tests."""
|
2024-03-08 13:44:56 +00:00
|
|
|
|
2024-07-01 09:54:42 +00:00
|
|
|
from collections.abc import Generator
|
2023-11-07 20:53:22 +00:00
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
|
|
|
|
import pytest
|
2024-05-11 19:28:37 +00:00
|
|
|
from pytrydan.models.trydan import TrydanData
|
|
|
|
|
2024-06-10 06:47:08 +00:00
|
|
|
from homeassistant.components.v2c.const import DOMAIN
|
2024-05-11 19:28:37 +00:00
|
|
|
from homeassistant.const import CONF_HOST
|
2024-06-05 06:55:49 +00:00
|
|
|
from homeassistant.helpers.json import json_dumps
|
2024-05-11 19:28:37 +00:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
2023-11-07 20:53:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2024-06-06 15:33:27 +00:00
|
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
2023-11-07 20:53:22 +00:00
|
|
|
"""Override async_setup_entry."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.v2c.async_setup_entry", return_value=True
|
|
|
|
) as mock_setup_entry:
|
|
|
|
yield mock_setup_entry
|
2024-05-11 19:28:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
|
|
"""Define a config entry fixture."""
|
|
|
|
return MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
entry_id="da58ee91f38c2406c2a36d0a1a7f8569",
|
|
|
|
title="EVSE 1.1.1.1",
|
|
|
|
data={CONF_HOST: "1.1.1.1"},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2024-06-06 15:33:27 +00:00
|
|
|
def mock_v2c_client() -> Generator[AsyncMock]:
|
2024-05-11 19:28:37 +00:00
|
|
|
"""Mock a V2C client."""
|
|
|
|
with (
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.v2c.Trydan",
|
|
|
|
autospec=True,
|
|
|
|
) as mock_client,
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.v2c.config_flow.Trydan",
|
|
|
|
new=mock_client,
|
|
|
|
),
|
|
|
|
):
|
|
|
|
client = mock_client.return_value
|
|
|
|
get_data_json = load_json_object_fixture("get_data.json", DOMAIN)
|
2024-06-05 06:55:49 +00:00
|
|
|
client.raw_data = {
|
|
|
|
"content": json_dumps(get_data_json).encode("utf-8"),
|
|
|
|
"status_code": 200,
|
|
|
|
}
|
2024-05-11 19:28:37 +00:00
|
|
|
client.get_data.return_value = TrydanData.from_api(get_data_json)
|
2024-06-05 06:55:49 +00:00
|
|
|
client.data = client.get_data.return_value
|
2024-05-30 18:42:48 +00:00
|
|
|
client.firmware_version = get_data_json["FirmwareVersion"]
|
2024-05-11 19:28:37 +00:00
|
|
|
yield client
|