Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mapping of myuplink entities #129137

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions homeassistant/components/myuplink/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from .helpers import find_matching_platform

CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, BinarySensorEntityDescription]] = {
"F730": {
"43161": BinarySensorEntityDescription(
key="elect_add",
translation_key="elect_add",
),
},
"NIBEF": {
"43161": BinarySensorEntityDescription(
key="elect_add",
Expand Down
59 changes: 59 additions & 0 deletions homeassistant/components/myuplink/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,63 @@ def skip_entity(model: str, device_point: DevicePoint) -> bool:
):
return False
return True
if "F730" in model:
if any(
d in device_point.parameter_name.lower()
for d in (
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
)
):
return True
if device_point.parameter_id in [
"40940",
"47007",
"47015",
"47020",
"47021",
"47022",
"47023",
"47024",
"47025",
"47026",
"47027",
"47028",
"47032",
"47050",
"47051",
"47206",
"47209",
"47271",
"47272",
"47273",
"47274",
"47375",
"47376",
"47538",
"47539",
"47635",
"47669",
"47703",
"47737",
"47771",
"47772",
"47805",
"47806",
"47839",
"47840",
"47907",
"47941",
"47975",
"48009",
"48042",
"48072",
"50113",
]:
return True
return False
7 changes: 7 additions & 0 deletions homeassistant/components/myuplink/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
}

CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, NumberEntityDescription]] = {
"F730": {
"40940": NumberEntityDescription(
key="degree_minutes",
translation_key="degree_minutes",
native_unit_of_measurement="DM",
),
},
"NIBEF": {
"40940": NumberEntityDescription(
key="degree_minutes",
Expand Down
26 changes: 26 additions & 0 deletions homeassistant/components/myuplink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@
MARKER_FOR_UNKNOWN_VALUE = -32768

CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, SensorEntityDescription]] = {
"F730": {
"43108": SensorEntityDescription(
key="fan_mode",
translation_key="fan_mode",
),
"43427": SensorEntityDescription(
key="status_compressor",
translation_key="status_compressor",
device_class=SensorDeviceClass.ENUM,
),
"49993": SensorEntityDescription(
key="elect_add",
translation_key="elect_add",
device_class=SensorDeviceClass.ENUM,
),
"49994": SensorEntityDescription(
key="priority",
translation_key="priority",
device_class=SensorDeviceClass.ENUM,
),
"50095": SensorEntityDescription(
key="status",
translation_key="status",
device_class=SensorDeviceClass.ENUM,
),
},
"NIBEF": {
"43108": SensorEntityDescription(
key="fan_mode",
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/myuplink/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"alarm": {
"name": "Alarm"
}
},
"sensor": {
"status": {
"name": "Status"
}
}
}
}
10 changes: 10 additions & 0 deletions homeassistant/components/myuplink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
from .helpers import find_matching_platform, skip_entity

CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, SwitchEntityDescription]] = {
"F730": {
"50004": SwitchEntityDescription(
key="temporary_lux",
translation_key="temporary_lux",
),
"50005": SwitchEntityDescription(
key="boost_ventilation",
translation_key="boost_ventilation",
),
},
"NIBEF": {
"50004": SwitchEntityDescription(
key="temporary_lux",
Expand Down
51 changes: 51 additions & 0 deletions tests/components/myuplink/fixtures/device_points_nibe_f730.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,5 +989,56 @@
],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "147641",
"parameterName": "Start Wednesday",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:52:01+00:00",
"value": 0,
"strVal": "0",
"smartHomeCategories": [],
"minValue": 0,
"maxValue": 86400,
"stepValue": 900,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "148072",
"parameterName": "start diff additional heat",
"parameterUnit": "DM",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 700,
"strVal": "700DM",
"smartHomeCategories": [],
"minValue": 100,
"maxValue": 2000,
"stepValue": 10,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "47011",
"parameterName": "Heating offset climate system 1",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 1,
"strVal": "1",
"smartHomeCategories": ["sh-indoorSpOffsHeat"],
"minValue": -10,
"maxValue": 10,
"stepValue": 1,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
}
]
102 changes: 102 additions & 0 deletions tests/components/myuplink/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,57 @@
],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "147641",
"parameterName": "Start Wednesday",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:52:01+00:00",
"value": 0,
"strVal": "0",
"smartHomeCategories": [],
"minValue": 0,
"maxValue": 86400,
"stepValue": 900,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "148072",
"parameterName": "start diff additional heat",
"parameterUnit": "DM",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 700,
"strVal": "700DM",
"smartHomeCategories": [],
"minValue": 100,
"maxValue": 2000,
"stepValue": 10,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "47011",
"parameterName": "Heating offset climate system 1",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 1,
"strVal": "1",
"smartHomeCategories": ["sh-indoorSpOffsHeat"],
"minValue": -10,
"maxValue": 10,
"stepValue": 1,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
}
]

Expand Down Expand Up @@ -2093,6 +2144,57 @@
],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "147641",
"parameterName": "Start Wednesday",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:52:01+00:00",
"value": 0,
"strVal": "0",
"smartHomeCategories": [],
"minValue": 0,
"maxValue": 86400,
"stepValue": 900,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "148072",
"parameterName": "start diff additional heat",
"parameterUnit": "DM",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 700,
"strVal": "700DM",
"smartHomeCategories": [],
"minValue": 100,
"maxValue": 2000,
"stepValue": 10,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
},
{
"category": "F730 CU 3x400V",
"parameterId": "47011",
"parameterName": "Heating offset climate system 1",
"parameterUnit": "",
"writable": true,
"timestamp": "2024-10-18T09:51:39+00:00",
"value": 1,
"strVal": "1",
"smartHomeCategories": ["sh-indoorSpOffsHeat"],
"minValue": -10,
"maxValue": 10,
"stepValue": 1,
"enumValues": [],
"scaleValue": "1",
"zoneId": null
}
]

Expand Down
19 changes: 9 additions & 10 deletions tests/components/myuplink/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
TEST_PLATFORM = Platform.NUMBER
pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)])

ENTITY_ID = "number.gotham_city_degree_minutes"
ENTITY_FRIENDLY_NAME = "Gotham City Degree minutes"
ENTITY_UID = "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-40940"
ENTITY_ID = "number.gotham_city_heating_offset_climate_system_1"
ENTITY_FRIENDLY_NAME = "Gotham City Heating offset climate system 1"
ENTITY_UID = "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-47011"


async def test_entity_registry(
Expand All @@ -36,17 +36,16 @@ async def test_attributes(
mock_myuplink_client: MagicMock,
setup_platform: None,
) -> None:
"""Test the switch attributes are correct."""
"""Test the entity attributes are correct."""

state = hass.states.get(ENTITY_ID)
assert state.state == "-875.0"
assert state.state == "1.0"
assert state.attributes == {
"friendly_name": ENTITY_FRIENDLY_NAME,
"min": -3000,
"max": 3000,
"min": -10.0,
"max": 10.0,
"mode": "auto",
"step": 1.0,
"unit_of_measurement": "DM",
}


Expand All @@ -60,7 +59,7 @@ async def test_set_value(
await hass.services.async_call(
TEST_PLATFORM,
SERVICE_SET_VALUE,
{ATTR_ENTITY_ID: ENTITY_ID, "value": -125},
{ATTR_ENTITY_ID: ENTITY_ID, "value": 1},
blocking=True,
)
await hass.async_block_till_done()
Expand All @@ -79,7 +78,7 @@ async def test_api_failure(
await hass.services.async_call(
TEST_PLATFORM,
SERVICE_SET_VALUE,
{ATTR_ENTITY_ID: ENTITY_ID, "value": -125},
{ATTR_ENTITY_ID: ENTITY_ID, "value": 1},
blocking=True,
)
mock_myuplink_client.async_set_device_points.assert_called_once()
Expand Down