mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Filter out irrelevant entities on SMO20 devices in myuplink (#113493)
This commit is contained in:
parent
c69ab425c5
commit
eb1f37ea9b
@ -31,3 +31,19 @@ def find_matching_platform(
|
||||
return Platform.SENSOR
|
||||
|
||||
return Platform.SENSOR
|
||||
|
||||
|
||||
def skip_entity(model: str, device_point: DevicePoint) -> bool:
|
||||
"""Check if entity should be skipped for this device model."""
|
||||
if model == "SMO 20":
|
||||
if len(device_point.smart_home_categories) > 0 or device_point.parameter_id in (
|
||||
"40940",
|
||||
"47011",
|
||||
"47015",
|
||||
"47028",
|
||||
"47032",
|
||||
"50004",
|
||||
):
|
||||
return False
|
||||
return True
|
||||
return False
|
||||
|
@ -13,7 +13,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from . import MyUplinkDataCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import MyUplinkEntity
|
||||
from .helpers import find_matching_platform
|
||||
from .helpers import find_matching_platform, skip_entity
|
||||
|
||||
DEVICE_POINT_UNIT_DESCRIPTIONS: dict[str, NumberEntityDescription] = {
|
||||
"DM": NumberEntityDescription(
|
||||
@ -65,6 +65,8 @@ async def async_setup_entry(
|
||||
# Setup device point number entities
|
||||
for device_id, point_data in coordinator.data.points.items():
|
||||
for point_id, device_point in point_data.items():
|
||||
if skip_entity(device_point.category, device_point):
|
||||
continue
|
||||
description = get_description(device_point)
|
||||
if find_matching_platform(device_point, description) == Platform.NUMBER:
|
||||
entities.append(
|
||||
|
@ -27,7 +27,7 @@ from homeassistant.helpers.typing import StateType
|
||||
from . import MyUplinkDataCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import MyUplinkEntity
|
||||
from .helpers import find_matching_platform
|
||||
from .helpers import find_matching_platform, skip_entity
|
||||
|
||||
DEVICE_POINT_UNIT_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
|
||||
"°C": SensorEntityDescription(
|
||||
@ -155,6 +155,8 @@ async def async_setup_entry(
|
||||
# Setup device point sensors
|
||||
for device_id, point_data in coordinator.data.points.items():
|
||||
for point_id, device_point in point_data.items():
|
||||
if skip_entity(device_point.category, device_point):
|
||||
continue
|
||||
if find_matching_platform(device_point) == Platform.SENSOR:
|
||||
description = get_description(device_point)
|
||||
entity_class = MyUplinkDevicePointSensor
|
||||
|
@ -15,7 +15,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from . import MyUplinkDataCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import MyUplinkEntity
|
||||
from .helpers import find_matching_platform
|
||||
from .helpers import find_matching_platform, skip_entity
|
||||
|
||||
CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, SwitchEntityDescription]] = {
|
||||
"NIBEF": {
|
||||
@ -58,6 +58,8 @@ async def async_setup_entry(
|
||||
# Setup device point switches
|
||||
for device_id, point_data in coordinator.data.points.items():
|
||||
for point_id, device_point in point_data.items():
|
||||
if skip_entity(device_point.category, device_point):
|
||||
continue
|
||||
if find_matching_platform(device_point) == Platform.SWITCH:
|
||||
description = get_description(device_point)
|
||||
|
||||
|
13470
tests/components/myuplink/fixtures/device_points_nibe_smo20.json
Normal file
13470
tests/components/myuplink/fixtures/device_points_nibe_smo20.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -5,12 +5,15 @@ 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,)])
|
||||
|
||||
@ -84,3 +87,19 @@ async def test_api_failure(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_myuplink_client.async_set_device_points.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"load_device_points_file",
|
||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
||||
)
|
||||
async def test_entity_registry_smo20(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_myuplink_client: MagicMock,
|
||||
setup_platform: None,
|
||||
) -> None:
|
||||
"""Test that the entities are registered in the entity registry."""
|
||||
|
||||
entry = entity_registry.async_get("number.f730_cu_3x400v_change_in_curve")
|
||||
assert entry.unique_id == "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-47028"
|
||||
|
@ -5,6 +5,7 @@ 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,
|
||||
@ -16,6 +17,8 @@ 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,)])
|
||||
|
||||
@ -94,3 +97,19 @@ async def test_api_failure(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_myuplink_client.async_set_device_points.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"load_device_points_file",
|
||||
[load_fixture("device_points_nibe_smo20.json", DOMAIN)],
|
||||
)
|
||||
async def test_entity_registry_smo20(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_myuplink_client: MagicMock,
|
||||
setup_platform: None,
|
||||
) -> None:
|
||||
"""Test that the entities are registered in the entity registry."""
|
||||
|
||||
entry = entity_registry.async_get(ENTITY_ID)
|
||||
assert entry.unique_id == ENTITY_UID
|
||||
|
Loading…
x
Reference in New Issue
Block a user