mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Alexa: Add support for starting and cancelling timers (#32616)
This commit is contained in:
parent
f4561891ae
commit
f3c07a5653
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user