Add tests for number of devices created in myuplink (#111816)

* Add tests for number of devices created

* Change default fixture to 2 devices in one system

* Update snapshot

* Change deviuce to test

* Merge tests to one module
pull/106964/head^2
Åke Strandberg 2024-03-03 14:27:24 +01:00 committed by GitHub
parent f02e60533d
commit 073fcfcd6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1123 additions and 4 deletions

View File

@ -93,7 +93,7 @@ def load_systems_jv_file(load_systems_file: str) -> dict[str, Any]:
@pytest.fixture(scope="session")
def load_systems_file() -> str:
"""Load fixture file for systems."""
return load_fixture("systems.json", DOMAIN)
return load_fixture("systems-2dev.json", DOMAIN)
@pytest.fixture

View File

@ -0,0 +1,40 @@
{
"id": "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff",
"connectionState": "Connected",
"firmware": {
"currentFwVersion": "9682R7",
"desiredFwVersion": "9682R7"
},
"product": {
"serialNumber": "222222",
"name": "F730 CU 3x400V"
},
"availableFeatures": {
"settings": true,
"reboot": true,
"forcesync": true,
"forceUpdate": false,
"requestUpdate": false,
"resetAlarm": true,
"triggerEvent": true,
"getMenu": false,
"getMenuChain": false,
"getGuideQuestion": false,
"sendHaystack": true,
"setSmartMode": false,
"setAidMode": true,
"getZones": false,
"processIntent": false,
"boostHotWater": true,
"boostVentilation": true,
"getScheduleConfig": false,
"getScheduleModes": false,
"getScheduleWeekly": false,
"getScheduleVacation": false,
"setScheduleModes": false,
"setScheduleWeekly": false,
"setScheduleOverride": false,
"setScheduleVacation": false,
"setVentilationMode": false
}
}

View File

@ -0,0 +1,34 @@
{
"page": 1,
"itemsPerPage": 10,
"numItems": 1,
"systems": [
{
"systemId": "123456-7890-1234",
"name": "Gotham City",
"securityLevel": "admin",
"hasAlarm": false,
"country": "Sweden",
"devices": [
{
"id": "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff",
"connectionState": "Connected",
"currentFwVersion": "9682R7",
"product": {
"serialNumber": "222222",
"name": "F730 CU 3x400V"
}
},
{
"id": "batman-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff",
"connectionState": "Connected",
"currentFwVersion": "9682R7",
"product": {
"serialNumber": "123456",
"name": "F730 CU 3x400V"
}
}
]
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -8,10 +8,11 @@ import pytest
from homeassistant.components.myuplink.const import DOMAIN, OAUTH2_TOKEN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from . import setup_integration
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
@ -66,3 +67,33 @@ async def test_expired_token_refresh_failure(
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is expected_state
@pytest.mark.parametrize(
"load_systems_file",
[load_fixture("systems.json", DOMAIN)],
)
async def test_devices_created_count(
hass: HomeAssistant,
mock_myuplink_client: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test that one device is created."""
await setup_integration(hass, mock_config_entry)
device_registry = dr.async_get(hass)
assert len(device_registry.devices) == 1
async def test_devices_multiple_created_count(
hass: HomeAssistant,
mock_myuplink_client: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test that multiple device are created."""
await setup_integration(hass, mock_config_entry)
device_registry = dr.async_get(hass)
assert len(device_registry.devices) == 2

View File

@ -16,7 +16,7 @@ pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
ENTITY_ID = "number.f730_cu_3x400v_degree_minutes"
ENTITY_FRIENDLY_NAME = "F730 CU 3x400V Degree minutes"
ENTITY_UID = "batman-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-40940"
ENTITY_UID = "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-40940"
async def test_entity_registry(

View File

@ -21,7 +21,7 @@ pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
ENTITY_ID = "switch.f730_cu_3x400v_temporary_lux"
ENTITY_FRIENDLY_NAME = "F730 CU 3x400V Tempo­rary lux"
ENTITY_UID = "batman-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-50004"
ENTITY_UID = "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-50004"
async def test_entity_registry(