Skip to content

Commit

Permalink
Create more relevant names for myuplink DeviceInfo (home-assistant#11…
Browse files Browse the repository at this point in the history
  • Loading branch information
astrandb authored Mar 15, 2024
1 parent e41133e commit 86607d2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
24 changes: 14 additions & 10 deletions homeassistant/components/myuplink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion tests/components/myuplink/fixtures/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"systems": [
{
"systemId": "123456-7890-1234",
"name": "Gotham City",
"name": "Batcave",
"securityLevel": "admin",
"hasAlarm": false,
"country": "Sweden",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/myuplink/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
}
4 changes: 2 additions & 2 deletions tests/components/myuplink/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
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"


Expand Down
4 changes: 2 additions & 2 deletions tests/components/myuplink/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/myuplink/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
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"


Expand Down
2 changes: 1 addition & 1 deletion tests/components/myuplink/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 86607d2

Please sign in to comment.