Create more relevant names for myuplink DeviceInfo (#111502)

This commit is contained in:
Åke Strandberg 2024-03-15 12:11:13 +01:00 committed by GitHub
parent e41133e9f0
commit 86607d2bbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 24 additions and 20 deletions

View File

@ -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,
)

View File

@ -5,7 +5,7 @@
"systems": [
{
"systemId": "123456-7890-1234",
"name": "Gotham City",
"name": "Batcave",
"securityLevel": "admin",
"hasAlarm": false,
"country": "Sweden",

View File

@ -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)",
}

View File

@ -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"

View File

@ -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",

View File

@ -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"

View File

@ -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"