mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Improve test coverage for PVOutput (#63048)
This commit is contained in:
@@ -4,10 +4,12 @@ from __future__ import annotations
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from pvo import Status, System
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.pvoutput.const import CONF_SYSTEM_ID, DOMAIN
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -39,3 +41,45 @@ def mock_pvoutput_config_flow() -> Generator[None, MagicMock, None]:
|
||||
"homeassistant.components.pvoutput.config_flow.PVOutput", autospec=True
|
||||
) as pvoutput_mock:
|
||||
yield pvoutput_mock.return_value
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_pvoutput() -> Generator[None, MagicMock, None]:
|
||||
"""Return a mocked PVOutput client."""
|
||||
status = Status(
|
||||
reported_date="20211229",
|
||||
reported_time="22:37",
|
||||
energy_consumption=1000,
|
||||
energy_generation=500,
|
||||
normalized_output=0.5,
|
||||
power_consumption=2500,
|
||||
power_generation=1500,
|
||||
temperature=20.2,
|
||||
voltage=220.5,
|
||||
)
|
||||
|
||||
system = System(
|
||||
inverter_brand="Super Inverters Inc.",
|
||||
system_name="Frenck's Solar Farm",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.pvoutput.coordinator.PVOutput", autospec=True
|
||||
) as pvoutput_mock:
|
||||
pvoutput = pvoutput_mock.return_value
|
||||
pvoutput.status.return_value = status
|
||||
pvoutput.system.return_value = system
|
||||
yield pvoutput
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_pvoutput: MagicMock
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the PVOutput integration for testing."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return mock_config_entry
|
||||
|
||||
Reference in New Issue
Block a user