diff --git a/tests/components/shelly/test_binary_sensor.py b/tests/components/shelly/test_binary_sensor.py index 8bbf87d6ed3408..b90d89b8e4814a 100644 --- a/tests/components/shelly/test_binary_sensor.py +++ b/tests/components/shelly/test_binary_sensor.py @@ -357,16 +357,25 @@ async def test_rpc_restored_sleeping_binary_sensor_no_last_state( assert hass.states.get(entity_id).state == STATE_OFF -async def test_rpc_device_virtual_binary_sensor_with_name( +@pytest.mark.parametrize( + ("name", "entity_id"), + [ + ("Virtual binary sensor", "binary_sensor.test_name_virtual_binary_sensor"), + (None, "binary_sensor.test_name_boolean_203"), + ], +) +async def test_rpc_device_virtual_binary_sensor( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch, + name: str | None, + entity_id: str, ) -> None: """Test a virtual binary sensor for RPC device.""" config = deepcopy(mock_rpc_device.config) config["boolean:203"] = { - "name": "Virtual binary sensor", + "name": name, "meta": {"ui": {"view": "label"}}, } monkeypatch.setattr(mock_rpc_device, "config", config) @@ -375,8 +384,6 @@ async def test_rpc_device_virtual_binary_sensor_with_name( status["boolean:203"] = {"value": True} monkeypatch.setattr(mock_rpc_device, "status", status) - entity_id = "binary_sensor.test_name_virtual_binary_sensor" - await init_integration(hass, 3) state = hass.states.get(entity_id) @@ -392,34 +399,6 @@ async def test_rpc_device_virtual_binary_sensor_with_name( assert hass.states.get(entity_id).state == STATE_OFF -async def test_rpc_device_virtual_binary_sensor_without_name( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - mock_rpc_device: Mock, - monkeypatch: pytest.MonkeyPatch, -) -> None: - """Test a virtual binary sensor for RPC device.""" - config = deepcopy(mock_rpc_device.config) - config["boolean:203"] = {"name": None, "meta": {"ui": {"view": "label"}}} - monkeypatch.setattr(mock_rpc_device, "config", config) - - status = deepcopy(mock_rpc_device.status) - status["boolean:203"] = {"value": True} - monkeypatch.setattr(mock_rpc_device, "status", status) - - entity_id = "binary_sensor.test_name_boolean_203" - - await init_integration(hass, 3) - - state = hass.states.get(entity_id) - assert state - assert state.state == STATE_ON - - entry = entity_registry.async_get(entity_id) - assert entry - assert entry.unique_id == "123456789ABC-boolean:203-boolean" - - async def test_rpc_remove_virtual_binary_sensor_when_mode_toggle( hass: HomeAssistant, entity_registry: er.EntityRegistry, diff --git a/tests/components/shelly/test_switch.py b/tests/components/shelly/test_switch.py index 0906395f901234..124562be8d542b 100644 --- a/tests/components/shelly/test_switch.py +++ b/tests/components/shelly/test_switch.py @@ -433,16 +433,25 @@ async def test_wall_display_relay_mode( assert entry.unique_id == "123456789ABC-switch:0" -async def test_rpc_device_virtual_switch_with_name( +@pytest.mark.parametrize( + ("name", "entity_id"), + [ + ("Virtual switch", "switch.test_name_virtual_switch"), + (None, "switch.test_name_boolean_200"), + ], +) +async def test_rpc_device_virtual_switch( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch, + name: str | None, + entity_id: str, ) -> None: """Test a virtual switch for RPC device.""" config = deepcopy(mock_rpc_device.config) config["boolean:200"] = { - "name": "Virtual switch", + "name": name, "meta": {"ui": {"view": "toggle"}}, } monkeypatch.setattr(mock_rpc_device, "config", config) @@ -451,8 +460,6 @@ async def test_rpc_device_virtual_switch_with_name( status["boolean:200"] = {"value": True} monkeypatch.setattr(mock_rpc_device, "status", status) - entity_id = "switch.test_name_virtual_switch" - await init_integration(hass, 3) state = hass.states.get(entity_id) @@ -484,34 +491,6 @@ async def test_rpc_device_virtual_switch_with_name( assert hass.states.get(entity_id).state == STATE_ON -async def test_rpc_device_virtual_switch_without_name( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - mock_rpc_device: Mock, - monkeypatch: pytest.MonkeyPatch, -) -> None: - """Test a virtual switch for RPC device.""" - config = deepcopy(mock_rpc_device.config) - config["boolean:200"] = {"name": None, "meta": {"ui": {"view": "toggle"}}} - monkeypatch.setattr(mock_rpc_device, "config", config) - - status = deepcopy(mock_rpc_device.status) - status["boolean:200"] = {"value": True} - monkeypatch.setattr(mock_rpc_device, "status", status) - - entity_id = "switch.test_name_boolean_200" - - await init_integration(hass, 3) - - state = hass.states.get(entity_id) - assert state - assert state.state == STATE_ON - - entry = entity_registry.async_get(entity_id) - assert entry - assert entry.unique_id == "123456789ABC-boolean:200-boolean" - - async def test_rpc_device_virtual_binary_sensor( hass: HomeAssistant, mock_rpc_device: Mock,