From 86607d2bbbb131aad246ff5cef5bf1908a5956bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Fri, 15 Mar 2024 12:11:13 +0100 Subject: [PATCH] Create more relevant names for myuplink DeviceInfo (#111502) --- homeassistant/components/myuplink/__init__.py | 24 +++++++++++-------- .../components/myuplink/fixtures/systems.json | 2 +- .../components/myuplink/test_binary_sensor.py | 4 ++-- tests/components/myuplink/test_number.py | 4 ++-- tests/components/myuplink/test_sensor.py | 4 ++-- tests/components/myuplink/test_switch.py | 4 ++-- tests/components/myuplink/test_update.py | 2 +- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/myuplink/__init__.py b/homeassistant/components/myuplink/__init__.py index 4e3305cf713..42bb9007789 100644 --- a/homeassistant/components/myuplink/__init__.py +++ b/homeassistant/components/myuplink/__init__.py @@ -5,7 +5,7 @@ from __future__ import annotations from http import HTTPStatus from aiohttp import ClientError, ClientResponseError -from myuplink import MyUplinkAPI +from myuplink import MyUplinkAPI, get_manufacturer, get_model, get_system_name from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform @@ -83,12 +83,16 @@ def create_devices( """Update all devices.""" device_registry = dr.async_get(hass) - for device_id, device in coordinator.data.devices.items(): - device_registry.async_get_or_create( - config_entry_id=config_entry.entry_id, - identifiers={(DOMAIN, device_id)}, - name=device.productName, - manufacturer=device.productName.split(" ")[0], - model=device.productName, - sw_version=device.firmwareCurrent, - ) + for system in coordinator.data.systems: + devices_in_system = [x.id for x in system.devices] + for device_id, device in coordinator.data.devices.items(): + if device_id in devices_in_system: + device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, + identifiers={(DOMAIN, device_id)}, + name=get_system_name(system), + manufacturer=get_manufacturer(device), + model=get_model(device), + sw_version=device.firmwareCurrent, + serial_number=device.product_serial_number, + ) diff --git a/tests/components/myuplink/fixtures/systems.json b/tests/components/myuplink/fixtures/systems.json index 151e9f55a8d..c009816a88f 100644 --- a/tests/components/myuplink/fixtures/systems.json +++ b/tests/components/myuplink/fixtures/systems.json @@ -5,7 +5,7 @@ "systems": [ { "systemId": "123456-7890-1234", - "name": "Gotham City", + "name": "Batcave", "securityLevel": "admin", "hasAlarm": false, "country": "Sweden", diff --git a/tests/components/myuplink/test_binary_sensor.py b/tests/components/myuplink/test_binary_sensor.py index 24bfe49985d..19eb4a4f292 100644 --- a/tests/components/myuplink/test_binary_sensor.py +++ b/tests/components/myuplink/test_binary_sensor.py @@ -17,9 +17,9 @@ async def test_sensor_states( """Test sensor state.""" await setup_integration(hass, mock_config_entry) - state = hass.states.get("binary_sensor.f730_cu_3x400v_pump_heating_medium_gp1") + state = hass.states.get("binary_sensor.gotham_city_pump_heating_medium_gp1") assert state is not None assert state.state == "on" assert state.attributes == { - "friendly_name": "F730 CU 3x400V Pump: Heating medium (GP1)", + "friendly_name": "Gotham City Pump: Heating medium (GP1)", } diff --git a/tests/components/myuplink/test_number.py b/tests/components/myuplink/test_number.py index 2bd2ca61496..41dc0dae164 100644 --- a/tests/components/myuplink/test_number.py +++ b/tests/components/myuplink/test_number.py @@ -14,8 +14,8 @@ from homeassistant.helpers import entity_registry as er TEST_PLATFORM = Platform.NUMBER pytestmark = pytest.mark.parametrize("platforms", [(TEST_PLATFORM,)]) -ENTITY_ID = "number.f730_cu_3x400v_degree_minutes" -ENTITY_FRIENDLY_NAME = "F730 CU 3x400V Degree minutes" +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" diff --git a/tests/components/myuplink/test_sensor.py b/tests/components/myuplink/test_sensor.py index eb8c0f82bbd..8fecb787122 100644 --- a/tests/components/myuplink/test_sensor.py +++ b/tests/components/myuplink/test_sensor.py @@ -17,11 +17,11 @@ async def test_sensor_states( """Test sensor state.""" await setup_integration(hass, mock_config_entry) - state = hass.states.get("sensor.f730_cu_3x400v_average_outdoor_temp_bt1") + state = hass.states.get("sensor.gotham_city_average_outdoor_temp_bt1") assert state is not None assert state.state == "-12.2" assert state.attributes == { - "friendly_name": "F730 CU 3x400V Average outdoor temp (BT1)", + "friendly_name": "Gotham City Average outdoor temp (BT1)", "device_class": "temperature", "state_class": "measurement", "unit_of_measurement": "°C", diff --git a/tests/components/myuplink/test_switch.py b/tests/components/myuplink/test_switch.py index e60aa4ebc4b..71c7f41c214 100644 --- a/tests/components/myuplink/test_switch.py +++ b/tests/components/myuplink/test_switch.py @@ -19,8 +19,8 @@ from homeassistant.helpers import entity_registry as er TEST_PLATFORM = Platform.SWITCH 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_ID = "switch.gotham_city_temporary_lux" +ENTITY_FRIENDLY_NAME = "Gotham City Tempo\xadrary lux" ENTITY_UID = "robin-r-1234-20240201-123456-aa-bb-cc-dd-ee-ff-50004" diff --git a/tests/components/myuplink/test_update.py b/tests/components/myuplink/test_update.py index f25993e8ef6..82f6ac17f69 100644 --- a/tests/components/myuplink/test_update.py +++ b/tests/components/myuplink/test_update.py @@ -17,6 +17,6 @@ async def test_update_states( """Test update state.""" await setup_integration(hass, mock_config_entry) - state = hass.states.get("update.f730_cu_3x400v_firmware") + state = hass.states.get("update.gotham_city_firmware") assert state is not None assert state.state == "off"