Fix MyUplink tests (#113534)
This commit is contained in:
parent
66aa2c038a
commit
be7c4295dc
3 changed files with 13 additions and 18 deletions
|
@ -6,6 +6,7 @@ from typing import Any
|
|||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from myuplink import Device, DevicePoint, System
|
||||
import orjson
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.application_credentials import (
|
||||
|
@ -107,22 +108,22 @@ def system_fixture(load_systems_file: str) -> list[System]:
|
|||
# Fixture group for device points API endpoint.
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@pytest.fixture
|
||||
def load_device_points_file() -> str:
|
||||
"""Load fixture file for device-points endpoint."""
|
||||
return load_fixture("device_points_nibe_f730.json", DOMAIN)
|
||||
return "device_points_nibe_f730.json"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_device_points_jv_file():
|
||||
def load_device_points_jv_file(load_device_points_file) -> str:
|
||||
"""Load fixture file for device_points."""
|
||||
return json_loads(load_device_points_file)
|
||||
return load_fixture(load_device_points_file, DOMAIN)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device_points_fixture(load_device_points_file: str) -> list[DevicePoint]:
|
||||
"""Fixture for devce_points."""
|
||||
data = json_loads(load_device_points_file)
|
||||
def device_points_fixture(load_device_points_jv_file: str) -> list[DevicePoint]:
|
||||
"""Fixture for device_points."""
|
||||
data = orjson.loads(load_device_points_jv_file)
|
||||
return [DevicePoint(point_data) for point_data in data]
|
||||
|
||||
|
||||
|
@ -130,7 +131,7 @@ def device_points_fixture(load_device_points_file: str) -> list[DevicePoint]:
|
|||
def mock_myuplink_client(
|
||||
load_device_file,
|
||||
device_fixture,
|
||||
load_device_points_file,
|
||||
load_device_points_jv_file,
|
||||
device_points_fixture,
|
||||
system_fixture,
|
||||
load_systems_jv_file,
|
||||
|
@ -150,7 +151,7 @@ def mock_myuplink_client(
|
|||
client.async_get_device_json.return_value = load_device_file
|
||||
|
||||
client.async_get_device_points.return_value = device_points_fixture
|
||||
client.async_get_device_points_json.return_value = load_device_points_file
|
||||
client.async_get_device_points_json.return_value = load_device_points_jv_file
|
||||
|
||||
yield client
|
||||
|
||||
|
|
|
@ -5,15 +5,12 @@ from unittest.mock import MagicMock
|
|||
from aiohttp import ClientError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.myuplink.const import DOMAIN
|
||||
from homeassistant.components.number import SERVICE_SET_VALUE
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import load_fixture
|
||||
|
||||
TEST_PLATFORM = Platform.NUMBER
|
||||
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
||||
|
||||
|
@ -91,7 +88,7 @@ async def test_api_failure(
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
"load_device_points_file",
|
||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
||||
["device_points_nibe_smo20.json"],
|
||||
)
|
||||
async def test_entity_registry_smo20(
|
||||
hass: HomeAssistant,
|
||||
|
@ -101,5 +98,5 @@ async def test_entity_registry_smo20(
|
|||
) -> None:
|
||||
"""Test that the entities are registered in the entity registry."""
|
||||
|
||||
entry = entity_registry.async_get("number.f730_cu_3x400v_change_in_curve")
|
||||
entry = entity_registry.async_get("number.gotham_city_change_in_curve")
|
||||
assert entry.unique_id == "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-47028"
|
||||
|
|
|
@ -5,7 +5,6 @@ from unittest.mock import MagicMock
|
|||
from aiohttp import ClientError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.myuplink.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
|
@ -17,8 +16,6 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import load_fixture
|
||||
|
||||
TEST_PLATFORM = Platform.SWITCH
|
||||
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
||||
|
||||
|
@ -101,7 +98,7 @@ async def test_api_failure(
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
"load_device_points_file",
|
||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
||||
["device_points_nibe_smo20.json"],
|
||||
)
|
||||
async def test_entity_registry_smo20(
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Add table
Reference in a new issue