mirror of
https://github.com/home-assistant/core.git
synced 2026-09-05 10:05:52 -05:00
Fix Shelly Wall Display virtual button platform (#152582)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': None,
|
||||
'entity_id': 'button.test_name_button',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'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': <ANY>,
|
||||
'entity_id': 'button.test_name_button',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user