mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add PowerController to covers in Alexa (#31265)
* Add PowerController to covers. * Comment Fix. * Update test device_class. * Update Comment.
This commit is contained in:
parent
85dbf1ffad
commit
7116c7404a
@ -400,6 +400,7 @@ class CoverCapabilities(AlexaEntity):
|
|||||||
|
|
||||||
def interfaces(self):
|
def interfaces(self):
|
||||||
"""Yield the supported interfaces."""
|
"""Yield the supported interfaces."""
|
||||||
|
yield AlexaPowerController(self.entity)
|
||||||
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
if supported & cover.SUPPORT_SET_POSITION:
|
if supported & cover.SUPPORT_SET_POSITION:
|
||||||
yield AlexaRangeController(
|
yield AlexaRangeController(
|
||||||
|
@ -119,7 +119,9 @@ async def async_api_turn_on(hass, config, directive, context):
|
|||||||
domain = ha.DOMAIN
|
domain = ha.DOMAIN
|
||||||
|
|
||||||
service = SERVICE_TURN_ON
|
service = SERVICE_TURN_ON
|
||||||
if domain == media_player.DOMAIN:
|
if domain == cover.DOMAIN:
|
||||||
|
service = cover.SERVICE_OPEN_COVER
|
||||||
|
elif domain == media_player.DOMAIN:
|
||||||
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
|
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
|
||||||
if not supported & power_features:
|
if not supported & power_features:
|
||||||
@ -145,7 +147,9 @@ async def async_api_turn_off(hass, config, directive, context):
|
|||||||
domain = ha.DOMAIN
|
domain = ha.DOMAIN
|
||||||
|
|
||||||
service = SERVICE_TURN_OFF
|
service = SERVICE_TURN_OFF
|
||||||
if domain == media_player.DOMAIN:
|
if entity.domain == cover.DOMAIN:
|
||||||
|
service = cover.SERVICE_CLOSE_COVER
|
||||||
|
elif domain == media_player.DOMAIN:
|
||||||
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
supported = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
|
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
|
||||||
if not supported & power_features:
|
if not supported & power_features:
|
||||||
|
@ -131,7 +131,7 @@ async def discovery_test(device, hass, expected_endpoints=1):
|
|||||||
def get_capability(capabilities, capability_name, instance=None):
|
def get_capability(capabilities, capability_name, instance=None):
|
||||||
"""Search a set of capabilities for a specific one."""
|
"""Search a set of capabilities for a specific one."""
|
||||||
for capability in capabilities:
|
for capability in capabilities:
|
||||||
if instance and capability["instance"] == instance:
|
if instance and capability.get("instance") == instance:
|
||||||
return capability
|
return capability
|
||||||
if not instance and capability["interface"] == capability_name:
|
if not instance and capability["interface"] == capability_name:
|
||||||
return capability
|
return capability
|
||||||
@ -1452,7 +1452,11 @@ async def test_cover_position_range(hass):
|
|||||||
assert appliance["friendlyName"] == "Test cover range"
|
assert appliance["friendlyName"] == "Test cover range"
|
||||||
|
|
||||||
capabilities = assert_endpoint_capabilities(
|
capabilities = assert_endpoint_capabilities(
|
||||||
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
|
appliance,
|
||||||
|
"Alexa.PowerController",
|
||||||
|
"Alexa.RangeController",
|
||||||
|
"Alexa.EndpointHealth",
|
||||||
|
"Alexa",
|
||||||
)
|
)
|
||||||
|
|
||||||
range_capability = get_capability(capabilities, "Alexa.RangeController")
|
range_capability = get_capability(capabilities, "Alexa.RangeController")
|
||||||
@ -2515,6 +2519,36 @@ async def test_mode_unsupported_domain(hass):
|
|||||||
assert msg["payload"]["type"] == "INVALID_DIRECTIVE"
|
assert msg["payload"]["type"] == "INVALID_DIRECTIVE"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover(hass):
|
||||||
|
"""Test garage cover discovery and powerController."""
|
||||||
|
device = (
|
||||||
|
"cover.test",
|
||||||
|
"off",
|
||||||
|
{
|
||||||
|
"friendly_name": "Test cover",
|
||||||
|
"supported_features": 3,
|
||||||
|
"device_class": "garage",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
appliance = await discovery_test(device, hass)
|
||||||
|
|
||||||
|
assert appliance["endpointId"] == "cover#test"
|
||||||
|
assert appliance["displayCategories"][0] == "GARAGE_DOOR"
|
||||||
|
assert appliance["friendlyName"] == "Test cover"
|
||||||
|
|
||||||
|
assert_endpoint_capabilities(
|
||||||
|
appliance,
|
||||||
|
"Alexa.ModeController",
|
||||||
|
"Alexa.PowerController",
|
||||||
|
"Alexa.EndpointHealth",
|
||||||
|
"Alexa",
|
||||||
|
)
|
||||||
|
|
||||||
|
await assert_power_controller_works(
|
||||||
|
"cover#test", "cover.open_cover", "cover.close_cover", hass
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_cover_position_mode(hass):
|
async def test_cover_position_mode(hass):
|
||||||
"""Test cover discovery and position using modeController."""
|
"""Test cover discovery and position using modeController."""
|
||||||
device = (
|
device = (
|
||||||
@ -2533,7 +2567,11 @@ async def test_cover_position_mode(hass):
|
|||||||
assert appliance["friendlyName"] == "Test cover mode"
|
assert appliance["friendlyName"] == "Test cover mode"
|
||||||
|
|
||||||
capabilities = assert_endpoint_capabilities(
|
capabilities = assert_endpoint_capabilities(
|
||||||
appliance, "Alexa", "Alexa.ModeController", "Alexa.EndpointHealth"
|
appliance,
|
||||||
|
"Alexa.PowerController",
|
||||||
|
"Alexa.ModeController",
|
||||||
|
"Alexa.EndpointHealth",
|
||||||
|
"Alexa",
|
||||||
)
|
)
|
||||||
|
|
||||||
mode_capability = get_capability(capabilities, "Alexa.ModeController")
|
mode_capability = get_capability(capabilities, "Alexa.ModeController")
|
||||||
@ -2752,7 +2790,11 @@ async def test_cover_tilt_position_range(hass):
|
|||||||
assert appliance["friendlyName"] == "Test cover tilt range"
|
assert appliance["friendlyName"] == "Test cover tilt range"
|
||||||
|
|
||||||
capabilities = assert_endpoint_capabilities(
|
capabilities = assert_endpoint_capabilities(
|
||||||
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
|
appliance,
|
||||||
|
"Alexa.PowerController",
|
||||||
|
"Alexa.RangeController",
|
||||||
|
"Alexa.EndpointHealth",
|
||||||
|
"Alexa",
|
||||||
)
|
)
|
||||||
|
|
||||||
range_capability = get_capability(capabilities, "Alexa.RangeController")
|
range_capability = get_capability(capabilities, "Alexa.RangeController")
|
||||||
@ -2868,7 +2910,11 @@ async def test_cover_semantics_position_and_tilt(hass):
|
|||||||
assert appliance["friendlyName"] == "Test cover semantics"
|
assert appliance["friendlyName"] == "Test cover semantics"
|
||||||
|
|
||||||
capabilities = assert_endpoint_capabilities(
|
capabilities = assert_endpoint_capabilities(
|
||||||
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
|
appliance,
|
||||||
|
"Alexa.PowerController",
|
||||||
|
"Alexa.RangeController",
|
||||||
|
"Alexa.EndpointHealth",
|
||||||
|
"Alexa",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert for Position Semantics
|
# Assert for Position Semantics
|
||||||
|
Loading…
x
Reference in New Issue
Block a user