mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix MyUplink tests (#113534)
This commit is contained in:
parent
66aa2c038a
commit
be7c4295dc
@ -6,6 +6,7 @@ from typing import Any
|
|||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from myuplink import Device, DevicePoint, System
|
from myuplink import Device, DevicePoint, System
|
||||||
|
import orjson
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.application_credentials import (
|
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.
|
# Fixture group for device points API endpoint.
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture
|
||||||
def load_device_points_file() -> str:
|
def load_device_points_file() -> str:
|
||||||
"""Load fixture file for device-points endpoint."""
|
"""Load fixture file for device-points endpoint."""
|
||||||
return load_fixture("device_points_nibe_f730.json", DOMAIN)
|
return "device_points_nibe_f730.json"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@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."""
|
"""Load fixture file for device_points."""
|
||||||
return json_loads(load_device_points_file)
|
return load_fixture(load_device_points_file, DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device_points_fixture(load_device_points_file: str) -> list[DevicePoint]:
|
def device_points_fixture(load_device_points_jv_file: str) -> list[DevicePoint]:
|
||||||
"""Fixture for devce_points."""
|
"""Fixture for device_points."""
|
||||||
data = json_loads(load_device_points_file)
|
data = orjson.loads(load_device_points_jv_file)
|
||||||
return [DevicePoint(point_data) for point_data in data]
|
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(
|
def mock_myuplink_client(
|
||||||
load_device_file,
|
load_device_file,
|
||||||
device_fixture,
|
device_fixture,
|
||||||
load_device_points_file,
|
load_device_points_jv_file,
|
||||||
device_points_fixture,
|
device_points_fixture,
|
||||||
system_fixture,
|
system_fixture,
|
||||||
load_systems_jv_file,
|
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_json.return_value = load_device_file
|
||||||
|
|
||||||
client.async_get_device_points.return_value = device_points_fixture
|
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
|
yield client
|
||||||
|
|
||||||
|
@ -5,15 +5,12 @@ from unittest.mock import MagicMock
|
|||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.myuplink.const import DOMAIN
|
|
||||||
from homeassistant.components.number import SERVICE_SET_VALUE
|
from homeassistant.components.number import SERVICE_SET_VALUE
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from tests.common import load_fixture
|
|
||||||
|
|
||||||
TEST_PLATFORM = Platform.NUMBER
|
TEST_PLATFORM = Platform.NUMBER
|
||||||
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
||||||
|
|
||||||
@ -91,7 +88,7 @@ async def test_api_failure(
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"load_device_points_file",
|
"load_device_points_file",
|
||||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
["device_points_nibe_smo20.json"],
|
||||||
)
|
)
|
||||||
async def test_entity_registry_smo20(
|
async def test_entity_registry_smo20(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -101,5 +98,5 @@ async def test_entity_registry_smo20(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that the entities are registered in the entity registry."""
|
"""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"
|
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
|
from aiohttp import ClientError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.myuplink.const import DOMAIN
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
@ -17,8 +16,6 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from tests.common import load_fixture
|
|
||||||
|
|
||||||
TEST_PLATFORM = Platform.SWITCH
|
TEST_PLATFORM = Platform.SWITCH
|
||||||
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])
|
||||||
|
|
||||||
@ -101,7 +98,7 @@ async def test_api_failure(
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"load_device_points_file",
|
"load_device_points_file",
|
||||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
["device_points_nibe_smo20.json"],
|
||||||
)
|
)
|
||||||
async def test_entity_registry_smo20(
|
async def test_entity_registry_smo20(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user