From 99b21613656f4f736d5dc00f300dc4aa71bed5b7 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 23 Dec 2021 07:36:45 +0100 Subject: [PATCH] Add input_button support to Alexa (#62592) --- homeassistant/components/alexa/entities.py | 2 ++ homeassistant/components/alexa/handlers.py | 3 +++ tests/components/alexa/test_smart_home.py | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py index 17cdab18df1..1ab24927bcb 100644 --- a/homeassistant/components/alexa/entities.py +++ b/homeassistant/components/alexa/entities.py @@ -16,6 +16,7 @@ from homeassistant.components import ( group, image_processing, input_boolean, + input_button, input_number, light, lock, @@ -426,6 +427,7 @@ class SwitchCapabilities(AlexaEntity): @ENTITY_ADAPTERS.register(button.DOMAIN) +@ENTITY_ADAPTERS.register(input_button.DOMAIN) class ButtonCapabilities(AlexaEntity): """Class to represent Button capabilities.""" diff --git a/homeassistant/components/alexa/handlers.py b/homeassistant/components/alexa/handlers.py index edd510f7844..c0b0782f62e 100644 --- a/homeassistant/components/alexa/handlers.py +++ b/homeassistant/components/alexa/handlers.py @@ -9,6 +9,7 @@ from homeassistant.components import ( cover, fan, group, + input_button, input_number, light, media_player, @@ -317,6 +318,8 @@ async def async_api_activate(hass, config, directive, context): service = SERVICE_TURN_ON if domain == button.DOMAIN: service = button.SERVICE_PRESS + elif domain == input_button.DOMAIN: + service = input_button.SERVICE_PRESS await hass.services.async_call( domain, diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 12708c9b55a..d74233c2bd9 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -3939,12 +3939,20 @@ async def test_initialize_camera_stream(hass, mock_camera, mock_stream): ) -async def test_button(hass): +@pytest.mark.parametrize( + "domain", + ["button", "input_button"], +) +async def test_button(hass, domain): """Test button discovery.""" - device = ("button.ring_doorbell", STATE_UNKNOWN, {"friendly_name": "Ring Doorbell"}) + device = ( + f"{domain}.ring_doorbell", + STATE_UNKNOWN, + {"friendly_name": "Ring Doorbell"}, + ) appliance = await discovery_test(device, hass) - assert appliance["endpointId"] == "button#ring_doorbell" + assert appliance["endpointId"] == f"{domain}#ring_doorbell" assert appliance["displayCategories"][0] == "ACTIVITY_TRIGGER" assert appliance["friendlyName"] == "Ring Doorbell" @@ -3955,5 +3963,5 @@ async def test_button(hass): assert scene_capability["supportsDeactivation"] is False await assert_scene_controller_works( - "button#ring_doorbell", "button.press", False, hass + f"{domain}#ring_doorbell", f"{domain}.press", False, hass )