diff --git a/homeassistant/components/button/trigger.py b/homeassistant/components/button/trigger.py index dc2c5f76b625..f817a33fafc3 100644 --- a/homeassistant/components/button/trigger.py +++ b/homeassistant/components/button/trigger.py @@ -9,6 +9,7 @@ from homeassistant.components.event import ( EventDeviceClass, EventEntityStateAttribute, ) +from homeassistant.components.input_button import DOMAIN as INPUT_BUTTON_DOMAIN from homeassistant.core import HomeAssistant, State from homeassistant.helpers.automation import DomainSpec from homeassistant.helpers.trigger import ( @@ -30,6 +31,7 @@ class ButtonPressedTrigger(StatelessEntityTriggerBase): _domain_specs = { DOMAIN: DomainSpec(), EVENT_DOMAIN: DomainSpec(device_class=EventDeviceClass.BUTTON), + INPUT_BUTTON_DOMAIN: DomainSpec(), } @override diff --git a/homeassistant/components/button/triggers.yaml b/homeassistant/components/button/triggers.yaml index e8149d8e63d4..4058139322cc 100644 --- a/homeassistant/components/button/triggers.yaml +++ b/homeassistant/components/button/triggers.yaml @@ -7,6 +7,7 @@ pressed: target: entity: - domain: button + - domain: input_button - domain: event device_class: button double_pressed: diff --git a/tests/components/button/test_trigger.py b/tests/components/button/test_trigger.py index bc2bad88c6a0..6b26761ded23 100644 --- a/tests/components/button/test_trigger.py +++ b/tests/components/button/test_trigger.py @@ -44,9 +44,11 @@ def _button_event_state( @pytest.fixture -async def target_buttons(hass: HomeAssistant) -> dict[str, list[str]]: - """Create multiple button entities associated with different targets.""" - return await target_entities(hass, "button") +async def target_entities_indirect( + request: pytest.FixtureRequest, hass: HomeAssistant +) -> dict[str, list[str]]: + """Create multiple entities associated with different targets.""" + return await target_entities(hass, request.param) @pytest.fixture @@ -82,8 +84,25 @@ async def test_button_trigger_options_validation( @pytest.mark.parametrize( - ("trigger_target_config", "entity_id", "entities_in_target"), - parametrize_target_entities("button"), + ( + "target_entities_indirect", + "trigger_target_config", + "entity_id", + "entities_in_target", + ), + [ + *[ + ("button", config, entity_id, entities) + for (config, entity_id, entities) in parametrize_target_entities("button") + ], + *[ + ("input_button", config, entity_id, entities) + for (config, entity_id, entities) in parametrize_target_entities( + "input_button" + ) + ], + ], + indirect=["target_entities_indirect"], ) @pytest.mark.parametrize( ("trigger", "states"), @@ -198,7 +217,7 @@ async def test_button_trigger_options_validation( ) async def test_button_state_trigger( hass: HomeAssistant, - target_buttons: dict[str, list[str]], + target_entities_indirect: dict[str, list[str]], trigger_target_config: dict, entity_id: str, entities_in_target: int, @@ -207,10 +226,10 @@ async def test_button_state_trigger( ) -> None: """Test that the button state trigger fires when targeted button state changes.""" calls: list[str] = [] - other_entity_ids = set(target_buttons["included_entities"]) - {entity_id} + other_entity_ids = set(target_entities_indirect["included_entities"]) - {entity_id} # Set all buttons, including the tested button, to the initial state - for eid in target_buttons["included_entities"]: + for eid in target_entities_indirect["included_entities"]: set_or_remove_state(hass, eid, states[0]["included_state"]) await hass.async_block_till_done()