diff --git a/homeassistant/components/shelly/event.py b/homeassistant/components/shelly/event.py index 2abedf3cf9a..92624db3ce3 100644 --- a/homeassistant/components/shelly/event.py +++ b/homeassistant/components/shelly/event.py @@ -22,7 +22,7 @@ from .coordinator import ShellyRpcCoordinator, get_entry_data from .utils import ( async_remove_shelly_entity, get_device_entry_gen, - get_rpc_input_name, + get_rpc_entity_name, get_rpc_key_instances, is_rpc_momentary_input, ) @@ -90,7 +90,7 @@ class ShellyRpcEvent(CoordinatorEntity[ShellyRpcCoordinator], EventEntity): connections={(CONNECTION_NETWORK_MAC, coordinator.mac)} ) self._attr_unique_id = f"{coordinator.mac}-{key}" - self._attr_name = get_rpc_input_name(coordinator.device, key) + self._attr_name = get_rpc_entity_name(coordinator.device, key) self.entity_description = description async def async_added_to_hass(self) -> None: diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 5633f674168..b64b76534be 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -285,22 +285,10 @@ def get_model_name(info: dict[str, Any]) -> str: return cast(str, MODEL_NAMES.get(info["type"], info["type"])) -def get_rpc_input_name(device: RpcDevice, key: str) -> str: - """Get input name based from the device configuration.""" - input_config = device.config[key] - - if input_name := input_config.get("name"): - return f"{device.name} {input_name}" - - return f"{device.name} {key.replace(':', ' ').capitalize()}" - - def get_rpc_channel_name(device: RpcDevice, key: str) -> str: """Get name based on device and channel name.""" key = key.replace("emdata", "em") key = key.replace("em1data", "em1") - if device.config.get("switch:0"): - key = key.replace("input", "switch") device_name = device.name entity_name: str | None = None if key in device.config: diff --git a/tests/components/shelly/conftest.py b/tests/components/shelly/conftest.py index 00f88561880..438ca9b5ace 100644 --- a/tests/components/shelly/conftest.py +++ b/tests/components/shelly/conftest.py @@ -144,7 +144,7 @@ MOCK_BLOCKS = [ ] MOCK_CONFIG = { - "input:0": {"id": 0, "type": "button"}, + "input:0": {"id": 0, "name": "Test name input 0", "type": "button"}, "light:0": {"name": "test light_0"}, "switch:0": {"name": "test switch_0"}, "cover:0": {"name": "test cover_0"}, diff --git a/tests/components/shelly/test_logbook.py b/tests/components/shelly/test_logbook.py index 07db4776166..b73a5b552c5 100644 --- a/tests/components/shelly/test_logbook.py +++ b/tests/components/shelly/test_logbook.py @@ -108,7 +108,7 @@ async def test_humanify_shelly_click_event_rpc_device( assert event1["domain"] == DOMAIN assert ( event1["message"] - == "'single_push' click event for test switch_0 Input was fired" + == "'single_push' click event for Test name input 0 Input was fired" ) assert event2["name"] == "Shelly" diff --git a/tests/components/shelly/test_utils.py b/tests/components/shelly/test_utils.py index a163519c9d1..3d273ff3059 100644 --- a/tests/components/shelly/test_utils.py +++ b/tests/components/shelly/test_utils.py @@ -8,7 +8,6 @@ from homeassistant.components.shelly.utils import ( get_device_uptime, get_number_of_channels, get_rpc_channel_name, - get_rpc_input_name, get_rpc_input_triggers, is_block_momentary_input, ) @@ -207,20 +206,8 @@ async def test_get_block_input_triggers(mock_block_device, monkeypatch) -> None: async def test_get_rpc_channel_name(mock_rpc_device) -> None: """Test get RPC channel name.""" - assert get_rpc_channel_name(mock_rpc_device, "input:0") == "test switch_0" - assert get_rpc_channel_name(mock_rpc_device, "input:3") == "Test name switch_3" - - -async def test_get_rpc_input_name(mock_rpc_device, monkeypatch) -> None: - """Test get RPC input name.""" - assert get_rpc_input_name(mock_rpc_device, "input:0") == "Test name Input 0" - - monkeypatch.setitem( - mock_rpc_device.config, - "input:0", - {"id": 0, "type": "button", "name": "Input name"}, - ) - assert get_rpc_input_name(mock_rpc_device, "input:0") == "Test name Input name" + assert get_rpc_channel_name(mock_rpc_device, "input:0") == "Test name input 0" + assert get_rpc_channel_name(mock_rpc_device, "input:3") == "Test name input_3" async def test_get_rpc_input_triggers(mock_rpc_device, monkeypatch) -> None: