Add PowerController to covers in Alexa (#31265)

* Add PowerController to covers.

* Comment Fix.

* Update test device_class.

* Update Comment.
This commit is contained in:
ochlocracy 2020-01-29 12:03:20 -05:00 committed by GitHub
parent 85dbf1ffad
commit 7116c7404a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 7 deletions

View File

@ -400,6 +400,7 @@ class CoverCapabilities(AlexaEntity):
def interfaces(self):
"""Yield the supported interfaces."""
yield AlexaPowerController(self.entity)
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
if supported & cover.SUPPORT_SET_POSITION:
yield AlexaRangeController(

View File

@ -119,7 +119,9 @@ async def async_api_turn_on(hass, config, directive, context):
domain = ha.DOMAIN
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)
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
if not supported & power_features:
@ -145,7 +147,9 @@ async def async_api_turn_off(hass, config, directive, context):
domain = ha.DOMAIN
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)
power_features = media_player.SUPPORT_TURN_ON | media_player.SUPPORT_TURN_OFF
if not supported & power_features:

View File

@ -131,7 +131,7 @@ async def discovery_test(device, hass, expected_endpoints=1):
def get_capability(capabilities, capability_name, instance=None):
"""Search a set of capabilities for a specific one."""
for capability in capabilities:
if instance and capability["instance"] == instance:
if instance and capability.get("instance") == instance:
return capability
if not instance and capability["interface"] == capability_name:
return capability
@ -1452,7 +1452,11 @@ async def test_cover_position_range(hass):
assert appliance["friendlyName"] == "Test cover range"
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")
@ -2515,6 +2519,36 @@ async def test_mode_unsupported_domain(hass):
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):
"""Test cover discovery and position using modeController."""
device = (
@ -2533,7 +2567,11 @@ async def test_cover_position_mode(hass):
assert appliance["friendlyName"] == "Test cover mode"
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")
@ -2752,7 +2790,11 @@ async def test_cover_tilt_position_range(hass):
assert appliance["friendlyName"] == "Test cover tilt range"
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")
@ -2868,7 +2910,11 @@ async def test_cover_semantics_position_and_tilt(hass):
assert appliance["friendlyName"] == "Test cover semantics"
capabilities = assert_endpoint_capabilities(
appliance, "Alexa.RangeController", "Alexa.EndpointHealth", "Alexa"
appliance,
"Alexa.PowerController",
"Alexa.RangeController",
"Alexa.EndpointHealth",
"Alexa",
)
# Assert for Position Semantics