mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Alexa: Support vacuums without turn_on/turn_off feature (#32570)
* Alexa: Support vacuums without turn_on/turn_off feature
This commit is contained in:
parent
e1d6964589
commit
22b5690607
@ -364,6 +364,8 @@ class AlexaPowerController(AlexaCapability):
|
||||
|
||||
if self.entity.domain == climate.DOMAIN:
|
||||
is_on = self.entity.state != climate.HVAC_MODE_OFF
|
||||
elif self.entity.domain == vacuum.DOMAIN:
|
||||
is_on = self.entity.state == vacuum.STATE_CLEANING
|
||||
|
||||
else:
|
||||
is_on = self.entity.state != STATE_OFF
|
||||
|
@ -741,8 +741,11 @@ class VacuumCapabilities(AlexaEntity):
|
||||
def interfaces(self):
|
||||
"""Yield the supported interfaces."""
|
||||
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
if (supported & vacuum.SUPPORT_TURN_ON) and (
|
||||
supported & vacuum.SUPPORT_TURN_OFF
|
||||
if (
|
||||
(supported & vacuum.SUPPORT_TURN_ON) or (supported & vacuum.SUPPORT_START)
|
||||
) and (
|
||||
(supported & vacuum.SUPPORT_TURN_OFF)
|
||||
or (supported & vacuum.SUPPORT_RETURN_HOME)
|
||||
):
|
||||
yield AlexaPowerController(self.entity)
|
||||
|
||||
|
@ -121,6 +121,10 @@ async def async_api_turn_on(hass, config, directive, context):
|
||||
service = SERVICE_TURN_ON
|
||||
if domain == cover.DOMAIN:
|
||||
service = cover.SERVICE_OPEN_COVER
|
||||
elif domain == vacuum.DOMAIN:
|
||||
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 == media_player.DOMAIN:
|
||||
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
|
||||
@ -149,6 +153,13 @@ async def async_api_turn_off(hass, config, directive, context):
|
||||
service = SERVICE_TURN_OFF
|
||||
if entity.domain == cover.DOMAIN:
|
||||
service = cover.SERVICE_CLOSE_COVER
|
||||
elif domain == vacuum.DOMAIN:
|
||||
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
if (
|
||||
not supported & vacuum.SUPPORT_TURN_OFF
|
||||
and supported & vacuum.SUPPORT_RETURN_HOME
|
||||
):
|
||||
service = vacuum.SERVICE_RETURN_TO_BASE
|
||||
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
|
||||
|
@ -3386,6 +3386,7 @@ async def test_vacuum_discovery(hass):
|
||||
| vacuum.SUPPORT_TURN_OFF
|
||||
| vacuum.SUPPORT_START
|
||||
| vacuum.SUPPORT_STOP
|
||||
| vacuum.SUPPORT_RETURN_HOME
|
||||
| vacuum.SUPPORT_PAUSE,
|
||||
},
|
||||
)
|
||||
@ -3403,6 +3404,17 @@ async def test_vacuum_discovery(hass):
|
||||
"Alexa",
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "vacuum#test_1")
|
||||
properties.assert_equal("Alexa.PowerController", "powerState", "OFF")
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOn", "vacuum#test_1", "vacuum.turn_on", hass,
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOff", "vacuum#test_1", "vacuum.turn_off", hass,
|
||||
)
|
||||
|
||||
|
||||
async def test_vacuum_fan_speed(hass):
|
||||
"""Test vacuum fan speed with rangeController."""
|
||||
@ -3597,3 +3609,93 @@ async def test_vacuum_resume(hass):
|
||||
"vacuum.start_pause",
|
||||
hass,
|
||||
)
|
||||
|
||||
|
||||
async def test_vacuum_discovery_no_turn_on(hass):
|
||||
"""Test vacuum discovery for vacuums without turn_on."""
|
||||
device = (
|
||||
"vacuum.test_5",
|
||||
"cleaning",
|
||||
{
|
||||
"friendly_name": "Test vacuum 5",
|
||||
"supported_features": vacuum.SUPPORT_TURN_OFF
|
||||
| vacuum.SUPPORT_START
|
||||
| vacuum.SUPPORT_RETURN_HOME,
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert_endpoint_capabilities(
|
||||
appliance, "Alexa.PowerController", "Alexa.EndpointHealth", "Alexa",
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "vacuum#test_5")
|
||||
properties.assert_equal("Alexa.PowerController", "powerState", "ON")
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOn", "vacuum#test_5", "vacuum.start", hass,
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOff", "vacuum#test_5", "vacuum.turn_off", hass,
|
||||
)
|
||||
|
||||
|
||||
async def test_vacuum_discovery_no_turn_off(hass):
|
||||
"""Test vacuum discovery for vacuums without turn_off."""
|
||||
device = (
|
||||
"vacuum.test_6",
|
||||
"cleaning",
|
||||
{
|
||||
"friendly_name": "Test vacuum 6",
|
||||
"supported_features": vacuum.SUPPORT_TURN_ON
|
||||
| vacuum.SUPPORT_START
|
||||
| vacuum.SUPPORT_RETURN_HOME,
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert_endpoint_capabilities(
|
||||
appliance, "Alexa.PowerController", "Alexa.EndpointHealth", "Alexa",
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOn", "vacuum#test_6", "vacuum.turn_on", hass,
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController",
|
||||
"TurnOff",
|
||||
"vacuum#test_6",
|
||||
"vacuum.return_to_base",
|
||||
hass,
|
||||
)
|
||||
|
||||
|
||||
async def test_vacuum_discovery_no_turn_on_or_off(hass):
|
||||
"""Test vacuum discovery vacuums without on or off."""
|
||||
device = (
|
||||
"vacuum.test_7",
|
||||
"cleaning",
|
||||
{
|
||||
"friendly_name": "Test vacuum 7",
|
||||
"supported_features": vacuum.SUPPORT_START | vacuum.SUPPORT_RETURN_HOME,
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert_endpoint_capabilities(
|
||||
appliance, "Alexa.PowerController", "Alexa.EndpointHealth", "Alexa",
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOn", "vacuum#test_7", "vacuum.start", hass,
|
||||
)
|
||||
|
||||
await assert_request_calls_service(
|
||||
"Alexa.PowerController",
|
||||
"TurnOff",
|
||||
"vacuum#test_7",
|
||||
"vacuum.return_to_base",
|
||||
hass,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user