diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 25696ec116a..6ab086ddda3 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -7,6 +7,7 @@ from homeassistant.components import ( image_processing, input_number, light, + timer, vacuum, ) from homeassistant.components.alarm_control_panel import ATTR_CODE_FORMAT, FORMAT_NUMBER @@ -25,6 +26,7 @@ from homeassistant.const import ( STATE_ALARM_ARMED_CUSTOM_BYPASS, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_NIGHT, + STATE_IDLE, STATE_LOCKED, STATE_OFF, STATE_ON, @@ -365,6 +367,8 @@ class AlexaPowerController(AlexaCapability): is_on = self.entity.state != climate.HVAC_MODE_OFF elif self.entity.domain == vacuum.DOMAIN: is_on = self.entity.state == vacuum.STATE_CLEANING + elif self.entity.domain == timer.DOMAIN: + is_on = self.entity.state != STATE_IDLE else: is_on = self.entity.state != STATE_OFF diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py index df3be7ee85e..aa9fe40164c 100644 --- a/homeassistant/components/alexa/entities.py +++ b/homeassistant/components/alexa/entities.py @@ -727,6 +727,7 @@ class TimerCapabilities(AlexaEntity): def interfaces(self): """Yield the supported interfaces.""" yield AlexaTimeHoldController(self.entity, allow_remote_resume=True) + yield AlexaPowerController(self.entity) yield Alexa(self.entity) diff --git a/homeassistant/components/alexa/handlers.py b/homeassistant/components/alexa/handlers.py index a77051cb03b..67083607769 100644 --- a/homeassistant/components/alexa/handlers.py +++ b/homeassistant/components/alexa/handlers.py @@ -125,6 +125,8 @@ async def async_api_turn_on(hass, config, directive, context): supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0) if not supported & vacuum.SUPPORT_TURN_ON and supported & vacuum.SUPPORT_START: service = vacuum.SERVICE_START + elif domain == timer.DOMAIN: + service = timer.SERVICE_START elif domain == media_player.DOMAIN: supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0) power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF @@ -160,6 +162,8 @@ async def async_api_turn_off(hass, config, directive, context): and supported & vacuum.SUPPORT_RETURN_HOME ): service = vacuum.SERVICE_RETURN_TO_BASE + elif domain == timer.DOMAIN: + service = timer.SERVICE_CANCEL elif domain == media_player.DOMAIN: supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0) power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index f723832938a..fa8f7fbdc9a 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -3348,7 +3348,7 @@ async def test_timer_hold(hass): assert appliance["friendlyName"] == "Laundry" capabilities = assert_endpoint_capabilities( - appliance, "Alexa", "Alexa.TimeHoldController" + appliance, "Alexa", "Alexa.TimeHoldController", "Alexa.PowerController" ) time_hold_capability = get_capability(capabilities, "Alexa.TimeHoldController") @@ -3370,11 +3370,48 @@ async def test_timer_resume(hass): ) await discovery_test(device, hass) + properties = await reported_properties(hass, "timer#laundry") + properties.assert_equal("Alexa.PowerController", "powerState", "ON") + await assert_request_calls_service( "Alexa.TimeHoldController", "Resume", "timer#laundry", "timer.start", hass ) +async def test_timer_start(hass): + """Test timer start.""" + device = ( + "timer.laundry", + "idle", + {"friendly_name": "Laundry", "duration": "00:01:00", "remaining": "00:50:00"}, + ) + await discovery_test(device, hass) + + properties = await reported_properties(hass, "timer#laundry") + properties.assert_equal("Alexa.PowerController", "powerState", "OFF") + + await assert_request_calls_service( + "Alexa.PowerController", "TurnOn", "timer#laundry", "timer.start", hass + ) + + +async def test_timer_cancel(hass): + """Test timer cancel.""" + device = ( + "timer.laundry", + "active", + {"friendly_name": "Laundry", "duration": "00:01:00", "remaining": "00:50:00"}, + ) + await discovery_test(device, hass) + + properties = await reported_properties(hass, "timer#laundry") + properties.assert_equal("Alexa.PowerController", "powerState", "ON") + + await assert_request_calls_service( + "Alexa.PowerController", "TurnOff", "timer#laundry", "timer.cancel", hass + ) + + async def test_vacuum_discovery(hass): """Test vacuum discovery.""" device = (