Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 439ca60

Browse files
authored
Fix Shelly Gen2 event get input name method (home-assistant#100733)
1 parent 44fd60b commit 439ca60

File tree

5 files changed

+6
-31
lines changed

5 files changed

+6
-31
lines changed

‎homeassistant/components/shelly/event.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .utils import (
2323
async_remove_shelly_entity,
2424
get_device_entry_gen,
25-
get_rpc_input_name,
25+
get_rpc_entity_name,
2626
get_rpc_key_instances,
2727
is_rpc_momentary_input,
2828
)
@@ -90,7 +90,7 @@ def __init__(
9090
connections={(CONNECTION_NETWORK_MAC, coordinator.mac)}
9191
)
9292
self._attr_unique_id = f"{coordinator.mac}-{key}"
93-
self._attr_name = get_rpc_input_name(coordinator.device, key)
93+
self._attr_name = get_rpc_entity_name(coordinator.device, key)
9494
self.entity_description = description
9595

9696
async def async_added_to_hass(self) -> None:

‎homeassistant/components/shelly/utils.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,10 @@ def get_model_name(info: dict[str, Any]) -> str:
285285
return cast(str, MODEL_NAMES.get(info["type"], info["type"]))
286286

287287

288-
def get_rpc_input_name(device: RpcDevice, key: str) -> str:
289-
"""Get input name based from the device configuration."""
290-
input_config = device.config[key]
291-
292-
if input_name := input_config.get("name"):
293-
return f"{device.name} {input_name}"
294-
295-
return f"{device.name} {key.replace(':', ' ').capitalize()}"
296-
297-
298288
def get_rpc_channel_name(device: RpcDevice, key: str) -> str:
299289
"""Get name based on device and channel name."""
300290
key = key.replace("emdata", "em")
301291
key = key.replace("em1data", "em1")
302-
if device.config.get("switch:0"):
303-
key = key.replace("input", "switch")
304292
device_name = device.name
305293
entity_name: str | None = None
306294
if key in device.config:

‎tests/components/shelly/conftest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def mock_light_set_state(
144144
]
145145

146146
MOCK_CONFIG = {
147-
"input:0": {"id": 0, "type": "button"},
147+
"input:0": {"id": 0, "name": "Test name input 0", "type": "button"},
148148
"light:0": {"name": "test light_0"},
149149
"switch:0": {"name": "test switch_0"},
150150
"cover:0": {"name": "test cover_0"},

‎tests/components/shelly/test_logbook.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def test_humanify_shelly_click_event_rpc_device(
108108
assert event1["domain"] == DOMAIN
109109
assert (
110110
event1["message"]
111-
== "'single_push' click event for test switch_0 Input was fired"
111+
== "'single_push' click event for Test name input 0 Input was fired"
112112
)
113113

114114
assert event2["name"] == "Shelly"

‎tests/components/shelly/test_utils.py‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
get_device_uptime,
99
get_number_of_channels,
1010
get_rpc_channel_name,
11-
get_rpc_input_name,
1211
get_rpc_input_triggers,
1312
is_block_momentary_input,
1413
)
@@ -207,20 +206,8 @@ async def test_get_block_input_triggers(mock_block_device, monkeypatch) -> None:
207206

208207
async def test_get_rpc_channel_name(mock_rpc_device) -> None:
209208
"""Test get RPC channel name."""
210-
assert get_rpc_channel_name(mock_rpc_device, "input:0") == "test switch_0"
211-
assert get_rpc_channel_name(mock_rpc_device, "input:3") == "Test name switch_3"
212-
213-
214-
async def test_get_rpc_input_name(mock_rpc_device, monkeypatch) -> None:
215-
"""Test get RPC input name."""
216-
assert get_rpc_input_name(mock_rpc_device, "input:0") == "Test name Input 0"
217-
218-
monkeypatch.setitem(
219-
mock_rpc_device.config,
220-
"input:0",
221-
{"id": 0, "type": "button", "name": "Input name"},
222-
)
223-
assert get_rpc_input_name(mock_rpc_device, "input:0") == "Test name Input name"
209+
assert get_rpc_channel_name(mock_rpc_device, "input:0") == "Test name input 0"
210+
assert get_rpc_channel_name(mock_rpc_device, "input:3") == "Test name input_3"
224211

225212

226213
async def test_get_rpc_input_triggers(mock_rpc_device, monkeypatch) -> None:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /