Rebase Implement Alexa.DoorbellEventSource Interface Controller (#27726)

This commit is contained in:
ochlocracy authored and Paulus Schoutsen committed 2019-10-23 11:41:26 -07:00
1 parent 0771dc3a37
commit 65d8c70377
6 files changed
+161 -10

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ TEST_TOKEN_URL = "https://api.amazon.com/auth/o2/token"
class MockConfig(config.AbstractConfig):
"""Mock Alexa config."""
entity_config = {}
entity_config = {"binary_sensor.test_doorbell": {"display_categories": "DOORBELL"}}
@property
def supports_auth(self):
+22
View File
@@ -1196,6 +1196,28 @@ async def test_motion_sensor(hass):
properties.assert_equal("Alexa.MotionSensor", "detectionState", "DETECTED")
async def test_doorbell_sensor(hass):
"""Test doorbell sensor discovery."""
device = (
"binary_sensor.test_doorbell",
"off",
{"friendly_name": "Test Doorbell Sensor", "device_class": "occupancy"},
)
appliance = await discovery_test(device, hass)
assert appliance["endpointId"] == "binary_sensor#test_doorbell"
assert appliance["displayCategories"][0] == "DOORBELL"
assert appliance["friendlyName"] == "Test Doorbell Sensor"
capabilities = assert_endpoint_capabilities(
appliance, "Alexa.DoorbellEventSource", "Alexa.EndpointHealth"
)
doorbell_capability = get_capability(capabilities, "Alexa.DoorbellEventSource")
assert doorbell_capability is not None
assert doorbell_capability["proactivelyReported"] is True
async def test_unknown_sensor(hass):
"""Test sensors of unknown quantities are not discovered."""
device = (
@@ -137,3 +137,34 @@ async def test_send_delete_message(hass, aioclient_mock):
call_json["event"]["payload"]["endpoints"][0]["endpointId"]
== "binary_sensor#test_contact"
)
async def test_doorbell_event(hass, aioclient_mock):
"""Test doorbell press reports."""
aioclient_mock.post(TEST_URL, text="", status=202)
hass.states.async_set(
"binary_sensor.test_doorbell",
"off",
{"friendly_name": "Test Doorbell Sensor", "device_class": "occupancy"},
)
await state_report.async_enable_proactive_mode(hass, DEFAULT_CONFIG)
hass.states.async_set(
"binary_sensor.test_doorbell",
"on",
{"friendly_name": "Test Doorbell Sensor", "device_class": "occupancy"},
)
# To trigger event listener
await hass.async_block_till_done()
assert len(aioclient_mock.mock_calls) == 1
call = aioclient_mock.mock_calls
call_json = call[0][2]
assert call_json["event"]["header"]["namespace"] == "Alexa.DoorbellEventSource"
assert call_json["event"]["header"]["name"] == "DoorbellPress"
assert call_json["event"]["payload"]["cause"]["type"] == "PHYSICAL_INTERACTION"
assert call_json["event"]["endpoint"]["endpointId"] == "binary_sensor#test_doorbell"