* Support for firmware 2.1.7 * add device ID as unique_id * add device ID as unique_id * add test device id as unique_id * backward compatibility * move outside try * Sensor return type Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * not needed * make slave error enum state * fix enum * Update homeassistant/components/v2c/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/v2c/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/v2c/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * simplify tests * fix misspellings from upstream library * add sensor tests * just enough coverage for enum sensor * Refactor V2C tests (#117264) * Refactor V2C tests * fix rebase issues * ruff * review * fix https://github.com/home-assistant/core/issues/117296 --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Common fixtures for the V2C tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
from pytrydan.models.trydan import TrydanData
|
|
|
|
from homeassistant.components.v2c import DOMAIN
|
|
from homeassistant.const import CONF_HOST
|
|
|
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.v2c.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
@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
|
|
def mock_v2c_client() -> Generator[AsyncMock, None, None]:
|
|
"""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)
|
|
client.get_data.return_value = TrydanData.from_api(get_data_json)
|
|
client.firmware_version = get_data_json["FirmwareVersion"]
|
|
yield client
|