1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Use "Output" for Shelly RPC switch sub-device names (#158139)

This commit is contained in:
J. Nick Koston
2025-12-07 11:33:00 -06:00
committed by GitHub
parent 95a347dcf8
commit 25505752b7
5 changed files with 2582 additions and 2529 deletions
+2
View File
@@ -438,6 +438,8 @@ def get_rpc_sub_device_name(
return f"{device.name} Energy Meter {component_id}"
if component == "em" and emeter_phase is not None:
return f"{device.name} Phase {emeter_phase}"
if component == "switch":
return f"{device.name} Output {component_id}"
return f"{device.name} {component.title()} {component_id}"
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1186,7 +1186,7 @@ async def test_sub_device_area_from_main_device(
# verify sub-devices have the same area as main device
for relay_index in range(2):
entity_id = f"switch.test_name_switch_{relay_index}"
entity_id = f"switch.test_name_output_{relay_index}"
assert hass.states.get(entity_id) is not None
entry = entity_registry.async_get(entity_id)
assert entry
+8 -8
View File
@@ -45,7 +45,7 @@ async def test_shelly_2pm_gen3_no_relay_names(
config_entry = await init_integration(hass, gen=3, model=MODEL_2PM_G3)
# Relay 0 sub-device
entity_id = "switch.test_name_switch_0"
entity_id = "switch.test_name_output_0"
state = hass.states.get(entity_id)
assert state
@@ -55,9 +55,9 @@ async def test_shelly_2pm_gen3_no_relay_names(
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.name == "Test name Switch 0"
assert device_entry.name == "Test name Output 0"
entity_id = "sensor.test_name_switch_0_power"
entity_id = "sensor.test_name_output_0_power"
state = hass.states.get(entity_id)
assert state
@@ -67,10 +67,10 @@ async def test_shelly_2pm_gen3_no_relay_names(
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.name == "Test name Switch 0"
assert device_entry.name == "Test name Output 0"
# Relay 1 sub-device
entity_id = "switch.test_name_switch_1"
entity_id = "switch.test_name_output_1"
state = hass.states.get(entity_id)
assert state
@@ -80,9 +80,9 @@ async def test_shelly_2pm_gen3_no_relay_names(
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.name == "Test name Switch 1"
assert device_entry.name == "Test name Output 1"
entity_id = "sensor.test_name_switch_1_power"
entity_id = "sensor.test_name_output_1_power"
state = hass.states.get(entity_id)
assert state
@@ -92,7 +92,7 @@ async def test_shelly_2pm_gen3_no_relay_names(
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.name == "Test name Switch 1"
assert device_entry.name == "Test name Output 1"
# Main device
entity_id = "update.test_name_firmware"
+51
View File
@@ -34,6 +34,7 @@ from homeassistant.components.shelly.utils import (
get_release_url,
get_rpc_channel_name,
get_rpc_input_triggers,
get_rpc_sub_device_name,
is_block_momentary_input,
mac_address_from_name,
)
@@ -319,3 +320,53 @@ async def test_shelly_receiver_get() -> None:
ws_server.websocket_handler.assert_awaited_once_with(mock_request)
assert response == "test_response"
@pytest.mark.parametrize(
("key", "expected"),
[
("switch:0", "Test name Output 0"),
("switch:1", "Test name Output 1"),
("cover:0", "Test name Cover 0"),
("light:0", "Test name Light 0"),
("rgb:0", "Test name RGB light 0"),
("rgbw:1", "Test name RGBW light 1"),
("cct:0", "Test name CCT light 0"),
("em1:0", "Test name Energy Meter 0"),
],
)
async def test_get_rpc_sub_device_name(
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
key: str,
expected: str,
) -> None:
"""Test get RPC sub-device name."""
# Ensure the key has no custom name set
config = {key: {"name": None}}
monkeypatch.setattr(mock_rpc_device, "config", config)
assert get_rpc_sub_device_name(mock_rpc_device, key) == expected
async def test_get_rpc_sub_device_name_with_custom_name(
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test get RPC sub-device name with custom name."""
config = {"switch:0": {"name": "My Custom Output"}}
monkeypatch.setattr(mock_rpc_device, "config", config)
assert get_rpc_sub_device_name(mock_rpc_device, "switch:0") == "My Custom Output"
async def test_get_rpc_sub_device_name_with_emeter_phase(
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test get RPC sub-device name with emeter phase."""
config = {"em:0": {"name": None}}
monkeypatch.setattr(mock_rpc_device, "config", config)
assert get_rpc_sub_device_name(mock_rpc_device, "em:0", "A") == "Test name Phase A"
assert get_rpc_sub_device_name(mock_rpc_device, "em:0", "B") == "Test name Phase B"