Implement Alexa.EventDetectionSensor for Alexa (#28276)
* Implement Alexa.EventDetectionSensor Interface * Removed references to PR #28218 not yet merged into dev. * Update tests to include Alexa Interface * Guard for `unknown` and `unavailible` states. * Fixed Unnecessary "elif" after "return"
This commit is contained in:
1 parent
3c86825e25
commit
3db7e8f5e9
5 files changed
+217
-3
No files matched your search
@@ -17,6 +17,7 @@ class MockConfig(config.AbstractConfig):
|
||||
"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"},
|
||||
"binary_sensor.test_motion_camera_event": {"display_categories": "CAMERA"},
|
||||
}
|
||||
|
||||
@property
|
||||
|
||||
@@ -667,3 +667,45 @@ async def test_report_playback_state(hass):
|
||||
properties.assert_equal(
|
||||
"Alexa.PlaybackStateReporter", "playbackState", {"state": "STOPPED"}
|
||||
)
|
||||
|
||||
|
||||
async def test_report_image_processing(hass):
|
||||
"""Test EventDetectionSensor implements humanPresenceDetectionState property."""
|
||||
hass.states.async_set(
|
||||
"image_processing.test_face",
|
||||
0,
|
||||
{
|
||||
"friendly_name": "Test face",
|
||||
"device_class": "face",
|
||||
"faces": [],
|
||||
"total_faces": 0,
|
||||
},
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "image_processing#test_face")
|
||||
properties.assert_equal(
|
||||
"Alexa.EventDetectionSensor",
|
||||
"humanPresenceDetectionState",
|
||||
{"value": "NOT_DETECTED"},
|
||||
)
|
||||
|
||||
hass.states.async_set(
|
||||
"image_processing.test_classifier",
|
||||
3,
|
||||
{
|
||||
"friendly_name": "Test classifier",
|
||||
"device_class": "face",
|
||||
"faces": [
|
||||
{"confidence": 98.34, "name": "Hans", "age": 16.0, "gender": "male"},
|
||||
{"name": "Helena", "age": 28.0, "gender": "female"},
|
||||
{"confidence": 62.53, "name": "Luna"},
|
||||
],
|
||||
"total_faces": 3,
|
||||
},
|
||||
)
|
||||
properties = await reported_properties(hass, "image_processing#test_classifier")
|
||||
properties.assert_equal(
|
||||
"Alexa.EventDetectionSensor",
|
||||
"humanPresenceDetectionState",
|
||||
{"value": "DETECTED"},
|
||||
)
|
||||
@@ -2386,3 +2386,84 @@ async def test_cover_position(hass):
|
||||
assert properties["name"] == "mode"
|
||||
assert properties["namespace"] == "Alexa.ModeController"
|
||||
assert properties["value"] == "position.open"
|
||||
|
||||
|
||||
async def test_image_processing(hass):
|
||||
"""Test image_processing discovery as event detection."""
|
||||
device = (
|
||||
"image_processing.test_face",
|
||||
0,
|
||||
{
|
||||
"friendly_name": "Test face",
|
||||
"device_class": "face",
|
||||
"faces": [],
|
||||
"total_faces": 0,
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "image_processing#test_face"
|
||||
assert appliance["displayCategories"][0] == "CAMERA"
|
||||
assert appliance["friendlyName"] == "Test face"
|
||||
|
||||
assert_endpoint_capabilities(
|
||||
appliance, "Alexa.EventDetectionSensor", "Alexa.EndpointHealth"
|
||||
)
|
||||
|
||||
|
||||
async def test_motion_sensor_event_detection(hass):
|
||||
"""Test motion sensor with EventDetectionSensor discovery."""
|
||||
device = (
|
||||
"binary_sensor.test_motion_camera_event",
|
||||
"off",
|
||||
{"friendly_name": "Test motion camera event", "device_class": "motion"},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "binary_sensor#test_motion_camera_event"
|
||||
assert appliance["displayCategories"][0] == "CAMERA"
|
||||
assert appliance["friendlyName"] == "Test motion camera event"
|
||||
|
||||
capabilities = assert_endpoint_capabilities(
|
||||
appliance,
|
||||
"Alexa",
|
||||
"Alexa.MotionSensor",
|
||||
"Alexa.EventDetectionSensor",
|
||||
"Alexa.EndpointHealth",
|
||||
)
|
||||
|
||||
event_detection_capability = get_capability(
|
||||
capabilities, "Alexa.EventDetectionSensor"
|
||||
)
|
||||
assert event_detection_capability is not None
|
||||
properties = event_detection_capability["properties"]
|
||||
assert properties["proactivelyReported"] is True
|
||||
assert not properties["retrievable"]
|
||||
assert {"name": "humanPresenceDetectionState"} in properties["supported"]
|
||||
|
||||
|
||||
async def test_presence_sensor(hass):
|
||||
"""Test presence sensor."""
|
||||
device = (
|
||||
"binary_sensor.test_presence_sensor",
|
||||
"off",
|
||||
{"friendly_name": "Test presence sensor", "device_class": "presence"},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "binary_sensor#test_presence_sensor"
|
||||
assert appliance["displayCategories"][0] == "CAMERA"
|
||||
assert appliance["friendlyName"] == "Test presence sensor"
|
||||
|
||||
capabilities = assert_endpoint_capabilities(
|
||||
appliance, "Alexa", "Alexa.EventDetectionSensor", "Alexa.EndpointHealth"
|
||||
)
|
||||
|
||||
event_detection_capability = get_capability(
|
||||
capabilities, "Alexa.EventDetectionSensor"
|
||||
)
|
||||
assert event_detection_capability is not None
|
||||
properties = event_detection_capability["properties"]
|
||||
assert properties["proactivelyReported"] is True
|
||||
assert not properties["retrievable"]
|
||||
assert {"name": "humanPresenceDetectionState"} in properties["supported"]
|
||||
Reference in new issue
Block a user