From a679ebcee7295adf98d5e6edb56171504c61db12 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Wed, 20 Oct 2021 13:05:11 +0200 Subject: [PATCH] Patch for Alexa percentage_step to precision (#58062) * speed_step must be an integer and a divider of 100 * use percentage_step in tests to test patch * test with not supported percentage_step * undo change in test_capabilities * Use a default precision of one not percentage_step * typo 2 * Update tests/components/alexa/test_smart_home.py Co-authored-by: Erik Montnemery * Update homeassistant/components/alexa/capabilities.py Co-authored-by: Erik Montnemery Co-authored-by: Erik Montnemery --- .../components/alexa/capabilities.py | 4 ++- tests/components/alexa/test_smart_home.py | 35 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 660ef46e478..ea8a1ed8681 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -1535,7 +1535,9 @@ class AlexaRangeController(AlexaCapability): labels=["Percentage", AlexaGlobalCatalog.SETTING_FAN_SPEED], min_value=0, max_value=100, - precision=percentage_step if percentage_step else 100, + # precision must be a divider of 100 and must be an integer; set step + # size to 1 for a consistent behavior except for on/off fans + precision=1 if percentage_step else 100, unit=AlexaGlobalCatalog.UNIT_PERCENT, ) return self._resource.serialize_capability_resources() diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 71123ca27ba..99d43816050 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -365,7 +365,7 @@ async def test_fan(hass): assert appliance["endpointId"] == "fan#test_1" assert appliance["displayCategories"][0] == "FAN" assert appliance["friendlyName"] == "Test fan 1" - # Alexa.RangeController is added to make a van controllable when no other controllers are available + # Alexa.RangeController is added to make a fan controllable when no other controllers are available capabilities = assert_endpoint_capabilities( appliance, "Alexa.RangeController", @@ -402,6 +402,39 @@ async def test_fan(hass): ) +async def test_fan2(hass): + """Test fan discovery with percentage_step.""" + + # Test fan discovery with percentage_step + device = ( + "fan.test_2", + "on", + { + "friendly_name": "Test fan 2", + "percentage": 66, + "supported_features": 1, + "percentage_step": 33.3333, + }, + ) + appliance = await discovery_test(device, hass) + + assert appliance["endpointId"] == "fan#test_2" + assert appliance["displayCategories"][0] == "FAN" + assert appliance["friendlyName"] == "Test fan 2" + # Alexa.RangeController is added to make a fan controllable when no other controllers are available + capabilities = assert_endpoint_capabilities( + appliance, + "Alexa.RangeController", + "Alexa.PowerController", + "Alexa.EndpointHealth", + "Alexa", + ) + + power_capability = get_capability(capabilities, "Alexa.PowerController") + assert "capabilityResources" not in power_capability + assert "configuration" not in power_capability + + async def test_variable_fan(hass): """Test fan discovery.