diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py index f9cf0cdf353..f9463949b58 100644 --- a/homeassistant/components/alexa/entities.py +++ b/homeassistant/components/alexa/entities.py @@ -543,6 +543,10 @@ class BinarySensorCapabilities(AlexaEntity): if CONF_DISPLAY_CATEGORIES in entity_conf: if entity_conf[CONF_DISPLAY_CATEGORIES] == DisplayCategory.DOORBELL: yield AlexaDoorbellEventSource(self.entity) + elif entity_conf[CONF_DISPLAY_CATEGORIES] == DisplayCategory.CONTACT_SENSOR: + yield AlexaContactSensor(self.hass, self.entity) + elif entity_conf[CONF_DISPLAY_CATEGORIES] == DisplayCategory.MOTION_SENSOR: + yield AlexaMotionSensor(self.hass, self.entity) yield AlexaEndpointHealth(self.hass, self.entity) yield Alexa(self.hass) diff --git a/tests/components/alexa/__init__.py b/tests/components/alexa/__init__.py index 0fa1961ad61..3752ad7d48f 100644 --- a/tests/components/alexa/__init__.py +++ b/tests/components/alexa/__init__.py @@ -13,7 +13,11 @@ TEST_TOKEN_URL = "https://api.amazon.com/auth/o2/token" class MockConfig(config.AbstractConfig): """Mock Alexa config.""" - entity_config = {"binary_sensor.test_doorbell": {"display_categories": "DOORBELL"}} + entity_config = { + "binary_sensor.test_doorbell": {"display_categories": "DOORBELL"}, + "binary_sensor.test_contact_forced": {"display_categories": "CONTACT_SENSOR"}, + "binary_sensor.test_motion_forced": {"display_categories": "MOTION_SENSOR"}, + } @property def supports_auth(self): diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 7cc1638bf25..b720182e4d2 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -1473,6 +1473,35 @@ async def test_contact_sensor(hass): properties.assert_equal("Alexa.EndpointHealth", "connectivity", {"value": "OK"}) +async def test_forced_contact_sensor(hass): + """Test contact sensor discovery with specified display_category.""" + device = ( + "binary_sensor.test_contact_forced", + "on", + {"friendly_name": "Test Contact Sensor With DisplayCategory"}, + ) + appliance = await discovery_test(device, hass) + + assert appliance["endpointId"] == "binary_sensor#test_contact_forced" + assert appliance["displayCategories"][0] == "CONTACT_SENSOR" + assert appliance["friendlyName"] == "Test Contact Sensor With DisplayCategory" + + capabilities = assert_endpoint_capabilities( + appliance, "Alexa.ContactSensor", "Alexa.EndpointHealth", "Alexa" + ) + + contact_sensor_capability = get_capability(capabilities, "Alexa.ContactSensor") + assert contact_sensor_capability is not None + properties = contact_sensor_capability["properties"] + assert properties["retrievable"] is True + assert {"name": "detectionState"} in properties["supported"] + + properties = await reported_properties(hass, "binary_sensor#test_contact_forced") + properties.assert_equal("Alexa.ContactSensor", "detectionState", "DETECTED") + + properties.assert_equal("Alexa.EndpointHealth", "connectivity", {"value": "OK"}) + + async def test_motion_sensor(hass): """Test motion sensor discovery.""" device = ( @@ -1500,6 +1529,35 @@ async def test_motion_sensor(hass): properties.assert_equal("Alexa.MotionSensor", "detectionState", "DETECTED") +async def test_forced_motion_sensor(hass): + """Test motion sensor discovery with specified display_category.""" + device = ( + "binary_sensor.test_motion_forced", + "on", + {"friendly_name": "Test Motion Sensor With DisplayCategory"}, + ) + appliance = await discovery_test(device, hass) + + assert appliance["endpointId"] == "binary_sensor#test_motion_forced" + assert appliance["displayCategories"][0] == "MOTION_SENSOR" + assert appliance["friendlyName"] == "Test Motion Sensor With DisplayCategory" + + capabilities = assert_endpoint_capabilities( + appliance, "Alexa.MotionSensor", "Alexa.EndpointHealth", "Alexa" + ) + + motion_sensor_capability = get_capability(capabilities, "Alexa.MotionSensor") + assert motion_sensor_capability is not None + properties = motion_sensor_capability["properties"] + assert properties["retrievable"] is True + assert {"name": "detectionState"} in properties["supported"] + + properties = await reported_properties(hass, "binary_sensor#test_motion_forced") + properties.assert_equal("Alexa.MotionSensor", "detectionState", "DETECTED") + + properties.assert_equal("Alexa.EndpointHealth", "connectivity", {"value": "OK"}) + + async def test_doorbell_sensor(hass): """Test doorbell sensor discovery.""" device = (