diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 2179620a6ea0..ab510b660e29 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -648,7 +648,10 @@ def get_virtual_component_ids(config: dict[str, Any], platform: str) -> list[str ids.extend( k for k, v in config.items() - if k.startswith(comp_type) and v["meta"]["ui"]["view"] in component["modes"] + if k.startswith(comp_type) + # default to button view if not set, workaround for Wall Display + and v.get("meta", {"ui": {"view": "button"}})["ui"]["view"] + in component["modes"] ) return ids diff --git a/tests/components/shelly/snapshots/test_button.ambr b/tests/components/shelly/snapshots/test_button.ambr index cd0f88e37972..e3755bd5dd5d 100644 --- a/tests/components/shelly/snapshots/test_button.ambr +++ b/tests/components/shelly/snapshots/test_button.ambr @@ -144,3 +144,51 @@ 'state': 'unknown', }) # --- +# name: test_wall_display_virtual_button[button.test_name_button-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'button', + 'entity_category': None, + 'entity_id': 'button.test_name_button', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Button', + 'platform': 'shelly', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '123456789ABC-button:200', + 'unit_of_measurement': None, + }) +# --- +# name: test_wall_display_virtual_button[button.test_name_button-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test name Button', + }), + 'context': , + 'entity_id': 'button.test_name_button', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- diff --git a/tests/components/shelly/test_button.py b/tests/components/shelly/test_button.py index 3bf70f20f2e5..6b8403ec392f 100644 --- a/tests/components/shelly/test_button.py +++ b/tests/components/shelly/test_button.py @@ -342,3 +342,40 @@ async def test_rpc_remove_virtual_button_when_orphaned( entry = entity_registry.async_get(entity_id) assert not entry + + +async def test_wall_display_virtual_button( + hass: HomeAssistant, + entity_registry: EntityRegistry, + mock_rpc_device: Mock, + monkeypatch: pytest.MonkeyPatch, + snapshot: SnapshotAssertion, +) -> None: + """Test a Wall Display virtual button. + + Wall display does not have "meta" key in the config and defaults to "button" view. + """ + config = deepcopy(mock_rpc_device.config) + config["button:200"] = {"name": "Button"} + monkeypatch.setattr(mock_rpc_device, "config", config) + + status = deepcopy(mock_rpc_device.status) + status["button:200"] = {"value": None} + monkeypatch.setattr(mock_rpc_device, "status", status) + + await init_integration(hass, 3) + entity_id = "button.test_name_button" + + assert (state := hass.states.get(entity_id)) + assert state == snapshot(name=f"{entity_id}-state") + + assert (entry := entity_registry.async_get(entity_id)) + assert entry == snapshot(name=f"{entity_id}-entry") + + await hass.services.async_call( + BUTTON_DOMAIN, + SERVICE_PRESS, + {ATTR_ENTITY_ID: entity_id}, + blocking=True, + ) + mock_rpc_device.button_trigger.assert_called_once_with(200, "single_push")