mirror of
https://github.com/home-assistant/core.git
synced 2026-04-21 00:49:54 +02:00
Increase Shelly code coverage for Gen2+ (input w/ custom name) (#157079)
This commit is contained in:
@@ -84,19 +84,17 @@ class RpcBinarySensor(ShellyRpcAttributeEntity, BinarySensorEntity):
|
||||
super().__init__(coordinator, key, attribute, description)
|
||||
|
||||
if description.role != ROLE_GENERIC:
|
||||
if not description.role and description.key == "input":
|
||||
_, component, component_id = get_rpc_key(key)
|
||||
if not get_rpc_custom_name(coordinator.device, key) and (
|
||||
component.lower() == "input" and component_id.isnumeric()
|
||||
):
|
||||
self._attr_translation_placeholders = {"input_number": component_id}
|
||||
self._attr_translation_key = "input_with_number"
|
||||
else:
|
||||
return
|
||||
|
||||
if hasattr(self, "_attr_name"):
|
||||
delattr(self, "_attr_name")
|
||||
|
||||
if not description.role and description.key == "input":
|
||||
if custom_name := get_rpc_custom_name(coordinator.device, key):
|
||||
self._attr_name = custom_name
|
||||
else:
|
||||
_, _, component_id = get_rpc_key(key)
|
||||
self._attr_translation_placeholders = {"input_number": component_id}
|
||||
self._attr_translation_key = "input_with_number"
|
||||
|
||||
if not description.role and description.key != "input":
|
||||
translation_placeholders, translation_key = (
|
||||
get_entity_translation_attributes(
|
||||
|
||||
@@ -272,6 +272,34 @@ async def test_rpc_binary_sensor(
|
||||
assert entry.unique_id == "123456789ABC-cover:0-overpower"
|
||||
|
||||
|
||||
async def test_rpc_binary_sensor_input_custom_name(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC binary sensor."""
|
||||
monkeypatch.setitem(
|
||||
mock_rpc_device.config,
|
||||
"input:1",
|
||||
{
|
||||
"id": 1,
|
||||
"type": "switch",
|
||||
"invert": False,
|
||||
"factory_reset": True,
|
||||
"name": "test channel",
|
||||
},
|
||||
)
|
||||
monkeypatch.setitem(
|
||||
mock_rpc_device.status,
|
||||
"input:1",
|
||||
{"id": 1, "state": True},
|
||||
)
|
||||
await init_integration(hass, 2)
|
||||
|
||||
assert (state := hass.states.get(f"{BINARY_SENSOR_DOMAIN}.test_name_test_channel"))
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_rpc_binary_sensor_removal(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
|
||||
Reference in New Issue
Block a user