hass-core/tests/components/arve/conftest.py
Illia cbaef096fa
Add Arve integration (#113156)
* add Arve integration

* Update homeassistant/components/arve/config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Various fixes, changed scan interval to one minute

* coordinator implementation

* Code cleanup

* Moved device info to the entity.py, ArveDeviceEntityDescription to sensor.py

* delete refresh before adding entities

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/test_config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/conftest.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Changed value_fn in sensors.py, added typing to description

* Code cleanups, platfrom test implementation

* New code cleanups, first two working tests

* Created platform test, generated snapshots

* Reworked integration to get all of the customer devices

* new fixes

* Added customer id, small cleanups

* Logic of setting unique_id to the config flow

* Added test of abortion on duplicate config_flow id

* Added "available" and "device" properties fro ArveDeviceEntity

* small _attr_unique_id fix

* Added new test, improved mocking, various fixes

* Various cleanups and fixes

* microfix

* Update homeassistant/components/arve/strings.json

* ruff fix

---------

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-04-08 17:24:32 +02:00

56 lines
1.6 KiB
Python

"""Common fixtures for the Arve tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch
from asyncarve import ArveCustomer, ArveDevices, ArveSensPro, ArveSensProData
import pytest
from homeassistant.components.arve.const import DOMAIN
from homeassistant.core import HomeAssistant
from . import USER_INPUT
from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.arve.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_config_entry(hass: HomeAssistant, mock_arve: MagicMock) -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
title="Arve", domain=DOMAIN, data=USER_INPUT, unique_id=mock_arve.customer_id
)
@pytest.fixture
def mock_arve():
"""Return a mocked Arve client."""
with (
patch(
"homeassistant.components.arve.coordinator.Arve", autospec=True
) as arve_mock,
patch("homeassistant.components.arve.config_flow.Arve", new=arve_mock),
):
arve = arve_mock.return_value
arve.customer_id = 12345
arve.get_customer_id.return_value = ArveCustomer(12345)
arve.get_devices.return_value = ArveDevices(["test-serial-number"])
arve.get_sensor_info.return_value = ArveSensPro("Test Sensor", "1.0", "prov1")
arve.device_sensor_data.return_value = ArveSensProData(
14, 595.75, 28.71, 0.16, 0.19, 26.02, 7
)
yield arve