mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 20:57:51 +00:00

* Add integration for AirVisual Pro * Tests * A few more redactions * Loggers * Consistency * Remove unnecessary f-string * Use `entry.as_dict()` in diagnostics * One call * Integration types * Cleanup * Import cleanup * Code review * Code review * Code review
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""Define test fixtures for AirVisual Pro."""
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.airvisual_pro.const import DOMAIN
|
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
@pytest.fixture(name="config_entry")
|
|
def config_entry_fixture(hass, config, unique_id):
|
|
"""Define a config entry fixture."""
|
|
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id, data=config)
|
|
entry.add_to_hass(hass)
|
|
return entry
|
|
|
|
|
|
@pytest.fixture(name="config")
|
|
def config_fixture(hass):
|
|
"""Define a config entry data fixture."""
|
|
return {
|
|
CONF_IP_ADDRESS: "192.168.1.101",
|
|
CONF_PASSWORD: "password123",
|
|
}
|
|
|
|
|
|
@pytest.fixture(name="data", scope="session")
|
|
def data_fixture():
|
|
"""Define an update coordinator data example."""
|
|
return json.loads(load_fixture("data.json", "airvisual_pro"))
|
|
|
|
|
|
@pytest.fixture(name="setup_airvisual_pro")
|
|
async def setup_airvisual_pro_fixture(hass, config, data):
|
|
"""Define a fixture to set up AirVisual Pro."""
|
|
with patch("homeassistant.components.airvisual_pro.NodeSamba.async_connect"), patch(
|
|
"homeassistant.components.airvisual_pro.NodeSamba.async_get_latest_measurements",
|
|
return_value=data,
|
|
), patch(
|
|
"homeassistant.components.airvisual_pro.NodeSamba.async_disconnect"
|
|
), patch(
|
|
"homeassistant.components.airvisual.PLATFORMS", []
|
|
):
|
|
assert await async_setup_component(hass, DOMAIN, config)
|
|
await hass.async_block_till_done()
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="unique_id")
|
|
def unique_id_fixture(hass):
|
|
"""Define a config entry unique ID fixture."""
|
|
return "192.168.1.101"
|