init home-assistant
This commit is contained in:
1
home-assistant/tests/components/airvisual/__init__.py
Normal file
1
home-assistant/tests/components/airvisual/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Define tests for the AirVisual component."""
|
||||
171
home-assistant/tests/components/airvisual/conftest.py
Normal file
171
home-assistant/tests/components/airvisual/conftest.py
Normal file
@@ -0,0 +1,171 @@
|
||||
"""Define test fixtures for AirVisual."""
|
||||
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.airvisual import (
|
||||
CONF_CITY,
|
||||
CONF_INTEGRATION_TYPE,
|
||||
DOMAIN,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
)
|
||||
from homeassistant.components.airvisual.config_flow import async_get_geography_id
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_COUNTRY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_SHOW_ON_MAP,
|
||||
CONF_STATE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.json import JsonObjectType
|
||||
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
TEST_API_KEY = "abcde12345"
|
||||
TEST_LATITUDE = 51.528308
|
||||
TEST_LONGITUDE = -0.3817765
|
||||
TEST_LATITUDE2 = 37.514626
|
||||
TEST_LONGITUDE2 = 127.057414
|
||||
|
||||
COORDS_CONFIG = {
|
||||
CONF_API_KEY: TEST_API_KEY,
|
||||
CONF_LATITUDE: TEST_LATITUDE,
|
||||
CONF_LONGITUDE: TEST_LONGITUDE,
|
||||
}
|
||||
|
||||
COORDS_CONFIG2 = {
|
||||
CONF_API_KEY: TEST_API_KEY,
|
||||
CONF_LATITUDE: TEST_LATITUDE2,
|
||||
CONF_LONGITUDE: TEST_LONGITUDE2,
|
||||
}
|
||||
|
||||
TEST_CITY = "Beijing"
|
||||
TEST_STATE = "Beijing"
|
||||
TEST_COUNTRY = "China"
|
||||
|
||||
NAME_CONFIG = {
|
||||
CONF_API_KEY: TEST_API_KEY,
|
||||
CONF_CITY: TEST_CITY,
|
||||
CONF_STATE: TEST_STATE,
|
||||
CONF_COUNTRY: TEST_COUNTRY,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="cloud_api")
|
||||
def cloud_api_fixture(data_cloud: JsonObjectType) -> Mock:
|
||||
"""Define a mock CloudAPI object."""
|
||||
return Mock(
|
||||
air_quality=Mock(
|
||||
city=AsyncMock(return_value=data_cloud),
|
||||
nearest_city=AsyncMock(return_value=data_cloud),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
config_entry_version: int,
|
||||
integration_type: str,
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
entry_id="3bd2acb0e4f0476d40865546d0d91921",
|
||||
unique_id=async_get_geography_id(config),
|
||||
data={**config, CONF_INTEGRATION_TYPE: integration_type},
|
||||
options={CONF_SHOW_ON_MAP: True},
|
||||
version=config_entry_version,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
return entry
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_version")
|
||||
def config_entry_version_fixture() -> int:
|
||||
"""Define a config entry version fixture."""
|
||||
return 2
|
||||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture() -> dict[str, Any]:
|
||||
"""Define a config entry data fixture."""
|
||||
return COORDS_CONFIG
|
||||
|
||||
|
||||
@pytest.fixture(name="data_cloud", scope="package")
|
||||
def data_cloud_fixture() -> JsonObjectType:
|
||||
"""Define an update coordinator data example."""
|
||||
return load_json_object_fixture("data.json", "airvisual")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_pro", scope="package")
|
||||
def data_pro_fixture() -> JsonObjectType:
|
||||
"""Define an update coordinator data example for the Pro."""
|
||||
return load_json_object_fixture("data.json", "airvisual_pro")
|
||||
|
||||
|
||||
@pytest.fixture(name="integration_type")
|
||||
def integration_type_fixture() -> str:
|
||||
"""Define an integration type."""
|
||||
return INTEGRATION_TYPE_GEOGRAPHY_COORDS
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_pyairvisual")
|
||||
async def mock_pyairvisual_fixture(
|
||||
cloud_api: Mock, node_samba: Mock
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Define a fixture to patch pyairvisual."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.airvisual.CloudAPI",
|
||||
return_value=cloud_api,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.airvisual.config_flow.CloudAPI",
|
||||
return_value=cloud_api,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.airvisual_pro.NodeSamba",
|
||||
return_value=node_samba,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.airvisual_pro.config_flow.NodeSamba",
|
||||
return_value=node_samba,
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="node_samba")
|
||||
def node_samba_fixture(data_pro: JsonObjectType) -> Mock:
|
||||
"""Define a mock NodeSamba object."""
|
||||
return Mock(
|
||||
async_connect=AsyncMock(),
|
||||
async_disconnect=AsyncMock(),
|
||||
async_get_latest_measurements=AsyncMock(return_value=data_pro),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_config_entry")
|
||||
async def setup_config_entry_fixture(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, mock_pyairvisual: None
|
||||
) -> None:
|
||||
"""Define a fixture to set up airvisual."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.airvisual.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
||||
30
home-assistant/tests/components/airvisual/fixtures/data.json
Normal file
30
home-assistant/tests/components/airvisual/fixtures/data.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"city": "Edgewater",
|
||||
"state": "Colorado",
|
||||
"country": "USA",
|
||||
"location": {
|
||||
"type": "Point",
|
||||
"coordinates": [-105.06415, 39.75304]
|
||||
},
|
||||
"current": {
|
||||
"weather": {
|
||||
"ts": "2021-09-03T21:00:00.000Z",
|
||||
"tp": 23,
|
||||
"pr": 999,
|
||||
"hu": 45,
|
||||
"ws": 0.45,
|
||||
"wd": 252,
|
||||
"ic": "10d"
|
||||
},
|
||||
"pollution": {
|
||||
"ts": "2021-09-04T00:00:00.000Z",
|
||||
"aqius": 52,
|
||||
"mainus": "p2",
|
||||
"aqicn": 18,
|
||||
"maincn": "p2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'city': '**REDACTED**',
|
||||
'country': '**REDACTED**',
|
||||
'current': dict({
|
||||
'pollution': dict({
|
||||
'aqicn': 18,
|
||||
'aqius': 52,
|
||||
'maincn': 'p2',
|
||||
'mainus': 'p2',
|
||||
'ts': '2021-09-04T00:00:00.000Z',
|
||||
}),
|
||||
'weather': dict({
|
||||
'hu': 45,
|
||||
'ic': '10d',
|
||||
'pr': 999,
|
||||
'tp': 23,
|
||||
'ts': '2021-09-03T21:00:00.000Z',
|
||||
'wd': 252,
|
||||
'ws': 0.45,
|
||||
}),
|
||||
}),
|
||||
'location': dict({
|
||||
'coordinates': '**REDACTED**',
|
||||
'type': 'Point',
|
||||
}),
|
||||
'state': '**REDACTED**',
|
||||
}),
|
||||
'entry': dict({
|
||||
'data': dict({
|
||||
'api_key': '**REDACTED**',
|
||||
'integration_type': 'Geographical Location by Latitude/Longitude',
|
||||
'latitude': '**REDACTED**',
|
||||
'longitude': '**REDACTED**',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'airvisual',
|
||||
'entry_id': '3bd2acb0e4f0476d40865546d0d91921',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
'show_on_map': True,
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '**REDACTED**',
|
||||
'unique_id': '**REDACTED**',
|
||||
'version': 3,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
168
home-assistant/tests/components/airvisual/test_config_flow.py
Normal file
168
home-assistant/tests/components/airvisual/test_config_flow.py
Normal file
@@ -0,0 +1,168 @@
|
||||
"""Define tests for the AirVisual config flow."""
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pyairvisual.cloud_api import (
|
||||
InvalidKeyError,
|
||||
KeyExpiredError,
|
||||
NotFoundError,
|
||||
UnauthorizedError,
|
||||
)
|
||||
from pyairvisual.errors import AirVisualError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.airvisual import (
|
||||
CONF_CITY,
|
||||
CONF_INTEGRATION_TYPE,
|
||||
DOMAIN,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_SHOW_ON_MAP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .conftest import (
|
||||
COORDS_CONFIG,
|
||||
NAME_CONFIG,
|
||||
TEST_CITY,
|
||||
TEST_COUNTRY,
|
||||
TEST_LATITUDE,
|
||||
TEST_LONGITUDE,
|
||||
TEST_STATE,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("integration_type", "input_form_step", "patched_method", "config", "entry_title"),
|
||||
[
|
||||
(
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
"geography_by_coords",
|
||||
"nearest_city",
|
||||
COORDS_CONFIG,
|
||||
f"Cloud API ({TEST_LATITUDE}, {TEST_LONGITUDE})",
|
||||
),
|
||||
(
|
||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
"geography_by_name",
|
||||
"city",
|
||||
NAME_CONFIG,
|
||||
f"Cloud API ({TEST_CITY}, {TEST_STATE}, {TEST_COUNTRY})",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("response", "errors"),
|
||||
[
|
||||
(AsyncMock(side_effect=AirVisualError), {"base": "unknown"}),
|
||||
(AsyncMock(side_effect=InvalidKeyError), {CONF_API_KEY: "invalid_api_key"}),
|
||||
(AsyncMock(side_effect=KeyExpiredError), {CONF_API_KEY: "invalid_api_key"}),
|
||||
(AsyncMock(side_effect=NotFoundError), {CONF_CITY: "location_not_found"}),
|
||||
(AsyncMock(side_effect=UnauthorizedError), {CONF_API_KEY: "invalid_api_key"}),
|
||||
],
|
||||
)
|
||||
async def test_create_entry(
|
||||
hass: HomeAssistant,
|
||||
cloud_api,
|
||||
config,
|
||||
entry_title,
|
||||
errors,
|
||||
input_form_step,
|
||||
integration_type,
|
||||
mock_pyairvisual,
|
||||
patched_method,
|
||||
response,
|
||||
) -> None:
|
||||
"""Test creating a config entry."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={"type": integration_type}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == input_form_step
|
||||
|
||||
# Test errors that can arise:
|
||||
with patch.object(cloud_api.air_quality, patched_method, response):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == errors
|
||||
|
||||
# Test that we can recover and finish the flow after errors occur:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == entry_title
|
||||
assert result["data"] == {**config, CONF_INTEGRATION_TYPE: integration_type}
|
||||
|
||||
|
||||
async def test_duplicate_error(hass: HomeAssistant, config, setup_config_entry) -> None:
|
||||
"""Test that errors are shown when duplicate entries are added."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={"type": INTEGRATION_TYPE_GEOGRAPHY_COORDS},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "geography_by_coords"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_options_flow(
|
||||
hass: HomeAssistant, config_entry, setup_config_entry
|
||||
) -> None:
|
||||
"""Test config flow options."""
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_SHOW_ON_MAP: False}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert config_entry.options == {CONF_SHOW_ON_MAP: False}
|
||||
|
||||
|
||||
async def test_step_reauth(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, setup_config_entry
|
||||
) -> None:
|
||||
"""Test that the reauth step works."""
|
||||
result = await config_entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
new_api_key = "defgh67890"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_API_KEY: new_api_key}
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
assert hass.config_entries.async_entries()[0].data[CONF_API_KEY] == new_api_key
|
||||
await hass.async_block_till_done()
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Test AirVisual diagnostics."""
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
config_entry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
setup_config_entry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
) == snapshot(exclude=props("created_at", "modified_at"))
|
||||
142
home-assistant/tests/components/airvisual/test_init.py
Normal file
142
home-assistant/tests/components/airvisual/test_init.py
Normal file
@@ -0,0 +1,142 @@
|
||||
"""Define tests for AirVisual init."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.airvisual import (
|
||||
CONF_CITY,
|
||||
CONF_GEOGRAPHIES,
|
||||
CONF_INTEGRATION_TYPE,
|
||||
DOMAIN,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
INTEGRATION_TYPE_NODE_PRO,
|
||||
)
|
||||
|
||||
# pylint: disable-next=hass-component-root-import
|
||||
from homeassistant.components.airvisual_pro.const import DOMAIN as AIRVISUAL_PRO_DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_COUNTRY,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_PASSWORD,
|
||||
CONF_STATE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||
|
||||
from .conftest import (
|
||||
COORDS_CONFIG,
|
||||
COORDS_CONFIG2,
|
||||
NAME_CONFIG,
|
||||
TEST_API_KEY,
|
||||
TEST_CITY,
|
||||
TEST_COUNTRY,
|
||||
TEST_LATITUDE,
|
||||
TEST_LATITUDE2,
|
||||
TEST_LONGITUDE,
|
||||
TEST_LONGITUDE2,
|
||||
TEST_STATE,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_migration_1_2(hass: HomeAssistant, mock_pyairvisual) -> None:
|
||||
"""Test migrating from version 1 to 2."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=TEST_API_KEY,
|
||||
data={
|
||||
CONF_API_KEY: TEST_API_KEY,
|
||||
CONF_GEOGRAPHIES: [
|
||||
{
|
||||
CONF_LATITUDE: TEST_LATITUDE,
|
||||
CONF_LONGITUDE: TEST_LONGITUDE,
|
||||
},
|
||||
{
|
||||
CONF_CITY: TEST_CITY,
|
||||
CONF_STATE: TEST_STATE,
|
||||
CONF_COUNTRY: TEST_COUNTRY,
|
||||
},
|
||||
{
|
||||
CONF_LATITUDE: TEST_LATITUDE2,
|
||||
CONF_LONGITUDE: TEST_LONGITUDE2,
|
||||
},
|
||||
],
|
||||
},
|
||||
version=1,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(config_entries) == 3
|
||||
|
||||
# Ensure that after migration, each configuration has its own config entry:
|
||||
identifier1 = f"{TEST_LATITUDE}, {TEST_LONGITUDE}"
|
||||
assert config_entries[0].unique_id == identifier1
|
||||
assert config_entries[0].title == f"Cloud API ({identifier1})"
|
||||
assert config_entries[0].data == {
|
||||
**COORDS_CONFIG,
|
||||
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
}
|
||||
|
||||
identifier2 = f"{TEST_CITY}, {TEST_STATE}, {TEST_COUNTRY}"
|
||||
assert config_entries[1].unique_id == identifier2
|
||||
assert config_entries[1].title == f"Cloud API ({identifier2})"
|
||||
assert config_entries[1].data == {
|
||||
**NAME_CONFIG,
|
||||
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
}
|
||||
|
||||
identifier3 = f"{TEST_LATITUDE2}, {TEST_LONGITUDE2}"
|
||||
assert config_entries[2].unique_id == identifier3
|
||||
assert config_entries[2].title == f"Cloud API ({identifier3})"
|
||||
assert config_entries[2].data == {
|
||||
**COORDS_CONFIG2,
|
||||
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
}
|
||||
|
||||
|
||||
async def test_migration_2_3(
|
||||
hass: HomeAssistant,
|
||||
mock_pyairvisual,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test migrating from version 2 to 3."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="192.168.1.100",
|
||||
data={
|
||||
CONF_IP_ADDRESS: "192.168.1.100",
|
||||
CONF_PASSWORD: "abcde12345",
|
||||
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_NODE_PRO,
|
||||
},
|
||||
version=2,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
device_registry.async_get_or_create(
|
||||
name="192.168.1.100",
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, "SERIAL_NUMBER")},
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.airvisual.automation.automations_with_device",
|
||||
return_value=["automation.test_automation"],
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Ensure that after migration, the AirVisual Pro device has been moved to the
|
||||
# `airvisual_pro` domain and an issue has been created:
|
||||
for domain, entry_count in ((DOMAIN, 0), (AIRVISUAL_PRO_DOMAIN, 1)):
|
||||
assert len(hass.config_entries.async_entries(domain)) == entry_count
|
||||
|
||||
assert len(issue_registry.issues) == 1
|
||||
Reference in New Issue
Block a user