mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add missing ViCare diagnostics tests (#90821)
Co-authored-by: Hans Oischinger <hans.oischinger@gmail.com>
This commit is contained in:
parent
98b1005b63
commit
7906e39df7
@ -1,6 +1,18 @@
|
||||
"""Test for ViCare."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.vicare.const import CONF_HEATING_TYPE
|
||||
from homeassistant.const import CONF_CLIENT_ID, CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
MODULE = "homeassistant.components.vicare"
|
||||
|
||||
ENTRY_CONFIG: Final[dict[str, str]] = {
|
||||
CONF_USERNAME: "foo@bar.com",
|
||||
CONF_PASSWORD: "1234",
|
||||
CONF_CLIENT_ID: "5678",
|
||||
CONF_HEATING_TYPE: "auto",
|
||||
}
|
||||
|
||||
MOCK_MAC = "B874241B7B9"
|
||||
|
@ -1,12 +1,73 @@
|
||||
"""Fixtures for ViCare integration tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
||||
import pytest
|
||||
|
||||
from . import MODULE
|
||||
from homeassistant.components.vicare.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import ENTRY_CONFIG, MODULE
|
||||
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
|
||||
class MockPyViCare:
|
||||
"""Mocked PyVicare class based on a json dump."""
|
||||
|
||||
def __init__(self, fixtures: list[str]) -> None:
|
||||
"""Init a single device from json dump."""
|
||||
self.devices = []
|
||||
for idx, fixture in enumerate(fixtures):
|
||||
self.devices.append(
|
||||
PyViCareDeviceConfig(
|
||||
MockViCareService(fixture),
|
||||
f"deviceId{idx}",
|
||||
f"model{idx}",
|
||||
f"online{idx}",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class MockViCareService:
|
||||
"""PyVicareService mock using a json dump."""
|
||||
|
||||
def __init__(self, fixture: str) -> None:
|
||||
"""Initialize the mock from a json dump."""
|
||||
self._test_data = load_json_object_fixture(fixture)
|
||||
self.fetch_all_features = Mock(return_value=self._test_data)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Return the default mocked config entry."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="ViCare",
|
||||
entry_id="1234",
|
||||
data=ENTRY_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_vicare_gas_boiler(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> AsyncGenerator[MockConfigEntry, None]:
|
||||
"""Return a mocked ViCare API representing a single gas boiler device."""
|
||||
fixtures = ["vicare/Vitodens300W.json"]
|
||||
with patch(
|
||||
f"{MODULE}.vicare_login",
|
||||
return_value=MockPyViCare(fixtures),
|
||||
):
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
yield mock_config_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
3885
tests/components/vicare/fixtures/Vitodens300W.json
Normal file
3885
tests/components/vicare/fixtures/Vitodens300W.json
Normal file
File diff suppressed because it is too large
Load Diff
4716
tests/components/vicare/snapshots/test_diagnostics.ambr
Normal file
4716
tests/components/vicare/snapshots/test_diagnostics.ambr
Normal file
File diff suppressed because it is too large
Load Diff
24
tests/components/vicare/test_diagnostics.py
Normal file
24
tests/components/vicare/test_diagnostics.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""Test ViCare diagnostics."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_vicare_gas_boiler: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
diag = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_vicare_gas_boiler
|
||||
)
|
||||
|
||||
assert diag == snapshot
|
Loading…
x
Reference in New Issue
Block a user