Support default display category based one switch device_class. (#28221)

This commit is contained in:
ochlocracy 2019-11-25 17:50:43 -05:00 committed by Paulus Schoutsen
parent f971e16749
commit dc8c085872
2 changed files with 21 additions and 0 deletions

View File

@ -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):

View File

@ -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"})