From dc8c085872c9578cdd3af470aa0141995db35801 Mon Sep 17 00:00:00 2001 From: ochlocracy <5885236+ochlocracy@users.noreply.github.com> Date: Mon, 25 Nov 2019 17:50:43 -0500 Subject: [PATCH] Support default display category based one switch device_class. (#28221) --- homeassistant/components/alexa/entities.py | 4 ++++ tests/components/alexa/test_smart_home.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py index 6d2f9aef56a..d3bfe1c5d8d 100644 --- a/homeassistant/components/alexa/entities.py +++ b/homeassistant/components/alexa/entities.py @@ -270,6 +270,10 @@ class SwitchCapabilities(AlexaEntity): def default_display_categories(self): """Return the display categories for this entity.""" + device_class = self.entity.attributes.get(ATTR_DEVICE_CLASS) + if device_class == switch.DEVICE_CLASS_OUTLET: + return [DisplayCategory.SMARTPLUG] + return [DisplayCategory.SWITCH] def interfaces(self): diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 9b901288f26..20cae0e10e4 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -168,6 +168,23 @@ async def test_switch(hass, events): properties.assert_equal("Alexa.PowerController", "powerState", "ON") +async def test_outlet(hass, events): + """Test switch with device class outlet discovery.""" + device = ( + "switch.test", + "on", + {"friendly_name": "Test switch", "device_class": "outlet"}, + ) + appliance = await discovery_test(device, hass) + + assert appliance["endpointId"] == "switch#test" + assert appliance["displayCategories"][0] == "SMARTPLUG" + assert appliance["friendlyName"] == "Test switch" + assert_endpoint_capabilities( + appliance, "Alexa.PowerController", "Alexa.EndpointHealth" + ) + + async def test_light(hass): """Test light discovery.""" device = ("light.test_1", "on", {"friendly_name": "Test light 1"})