Add SecurityPanelController for alarm_control_panel to alexa (#27081)
* Implemented Alexa.SecurityPanelController Interface for alarm_control_panel https://developer.amazon.com/docs/device-apis/alexa-securitypanelcontroller.html * Implemented Tests for Alexa.SecurityPanelController Interface for alarm_control_panel * Added additional AuthorizationRequired error handling * Removed optional exitDelayInSeconds * Updating elif to if to please pylint * Adding self to code owners. * Adding self to code owners. * Added AlexaEndpointHealth Interface to alarm_control_panel entities. * Added additional entity tests. * Code reformatted with Black. * Updated alexa alarm_control_panel tests for more coverage. * Updated alexa alarm_control_panel tests for more coverage. Fixed Test. * Adding self to code owners.
This commit is contained in:
1 parent
f169e84d21
commit
9a5c1fbaed
8 files changed
+337
-2
No files matched your search
@@ -8,6 +8,11 @@ from homeassistant.const import (
|
||||
STATE_UNLOCKED,
|
||||
STATE_UNKNOWN,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_ALARM_DISARMED,
|
||||
STATE_ALARM_ARMED_AWAY,
|
||||
STATE_ALARM_ARMED_CUSTOM_BYPASS,
|
||||
STATE_ALARM_ARMED_HOME,
|
||||
STATE_ALARM_ARMED_NIGHT,
|
||||
)
|
||||
from homeassistant.components.climate import const as climate
|
||||
from homeassistant.components.alexa import smart_home
|
||||
@@ -527,3 +532,33 @@ async def test_temperature_sensor_climate(hass):
|
||||
properties.assert_equal(
|
||||
"Alexa.TemperatureSensor", "temperature", {"value": 34.0, "scale": "CELSIUS"}
|
||||
)
|
||||
|
||||
|
||||
async def test_report_alarm_control_panel_state(hass):
|
||||
"""Test SecurityPanelController implements armState property."""
|
||||
hass.states.async_set("alarm_control_panel.armed_away", STATE_ALARM_ARMED_AWAY, {})
|
||||
hass.states.async_set(
|
||||
"alarm_control_panel.armed_custom_bypass", STATE_ALARM_ARMED_CUSTOM_BYPASS, {}
|
||||
)
|
||||
hass.states.async_set("alarm_control_panel.armed_home", STATE_ALARM_ARMED_HOME, {})
|
||||
hass.states.async_set(
|
||||
"alarm_control_panel.armed_night", STATE_ALARM_ARMED_NIGHT, {}
|
||||
)
|
||||
hass.states.async_set("alarm_control_panel.disarmed", STATE_ALARM_DISARMED, {})
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel.armed_away")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_AWAY")
|
||||
|
||||
properties = await reported_properties(
|
||||
hass, "alarm_control_panel.armed_custom_bypass"
|
||||
)
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_STAY")
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel.armed_home")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_STAY")
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel.armed_night")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_NIGHT")
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel.disarmed")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "DISARMED")
|
||||
@@ -1306,3 +1306,127 @@ async def test_endpoint_bad_health(hass):
|
||||
properties.assert_equal(
|
||||
"Alexa.EndpointHealth", "connectivity", {"value": "UNREACHABLE"}
|
||||
)
|
||||
|
||||
|
||||
async def test_alarm_control_panel_disarmed(hass):
|
||||
"""Test alarm_control_panel discovery."""
|
||||
device = (
|
||||
"alarm_control_panel.test_1",
|
||||
"disarmed",
|
||||
{
|
||||
"friendly_name": "Test Alarm Control Panel 1",
|
||||
"code_arm_required": False,
|
||||
"code_format": "number",
|
||||
"code": "1234",
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "alarm_control_panel#test_1"
|
||||
assert appliance["displayCategories"][0] == "SECURITY_PANEL"
|
||||
assert appliance["friendlyName"] == "Test Alarm Control Panel 1"
|
||||
capabilities = assert_endpoint_capabilities(
|
||||
appliance, "Alexa.SecurityPanelController", "Alexa.EndpointHealth"
|
||||
)
|
||||
security_panel_capability = get_capability(
|
||||
capabilities, "Alexa.SecurityPanelController"
|
||||
)
|
||||
assert security_panel_capability is not None
|
||||
configuration = security_panel_capability["configuration"]
|
||||
assert {"type": "FOUR_DIGIT_PIN"} in configuration["supportedAuthorizationTypes"]
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel#test_1")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "DISARMED")
|
||||
|
||||
call, msg = await assert_request_calls_service(
|
||||
"Alexa.SecurityPanelController",
|
||||
"Arm",
|
||||
"alarm_control_panel#test_1",
|
||||
"alarm_control_panel.alarm_arm_home",
|
||||
hass,
|
||||
response_type="Arm.Response",
|
||||
payload={"armState": "ARMED_STAY"},
|
||||
)
|
||||
properties = ReportedProperties(msg["context"]["properties"])
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_STAY")
|
||||
|
||||
call, msg = await assert_request_calls_service(
|
||||
"Alexa.SecurityPanelController",
|
||||
"Arm",
|
||||
"alarm_control_panel#test_1",
|
||||
"alarm_control_panel.alarm_arm_away",
|
||||
hass,
|
||||
response_type="Arm.Response",
|
||||
payload={"armState": "ARMED_AWAY"},
|
||||
)
|
||||
properties = ReportedProperties(msg["context"]["properties"])
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_AWAY")
|
||||
|
||||
call, msg = await assert_request_calls_service(
|
||||
"Alexa.SecurityPanelController",
|
||||
"Arm",
|
||||
"alarm_control_panel#test_1",
|
||||
"alarm_control_panel.alarm_arm_night",
|
||||
hass,
|
||||
response_type="Arm.Response",
|
||||
payload={"armState": "ARMED_NIGHT"},
|
||||
)
|
||||
properties = ReportedProperties(msg["context"]["properties"])
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_NIGHT")
|
||||
|
||||
|
||||
async def test_alarm_control_panel_armed(hass):
|
||||
"""Test alarm_control_panel discovery."""
|
||||
device = (
|
||||
"alarm_control_panel.test_2",
|
||||
"armed_away",
|
||||
{
|
||||
"friendly_name": "Test Alarm Control Panel 2",
|
||||
"code_arm_required": False,
|
||||
"code_format": "FORMAT_NUMBER",
|
||||
"code": "1234",
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
assert appliance["endpointId"] == "alarm_control_panel#test_2"
|
||||
assert appliance["displayCategories"][0] == "SECURITY_PANEL"
|
||||
assert appliance["friendlyName"] == "Test Alarm Control Panel 2"
|
||||
assert_endpoint_capabilities(
|
||||
appliance, "Alexa.SecurityPanelController", "Alexa.EndpointHealth"
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "alarm_control_panel#test_2")
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "ARMED_AWAY")
|
||||
|
||||
call, msg = await assert_request_calls_service(
|
||||
"Alexa.SecurityPanelController",
|
||||
"Disarm",
|
||||
"alarm_control_panel#test_2",
|
||||
"alarm_control_panel.alarm_disarm",
|
||||
hass,
|
||||
payload={"authorization": {"type": "FOUR_DIGIT_PIN", "value": "1234"}},
|
||||
)
|
||||
assert call.data["code"] == "1234"
|
||||
properties = ReportedProperties(msg["context"]["properties"])
|
||||
properties.assert_equal("Alexa.SecurityPanelController", "armState", "DISARMED")
|
||||
|
||||
msg = await assert_request_fails(
|
||||
"Alexa.SecurityPanelController",
|
||||
"Arm",
|
||||
"alarm_control_panel#test_2",
|
||||
"alarm_control_panel.alarm_arm_home",
|
||||
hass,
|
||||
payload={"armState": "ARMED_STAY"},
|
||||
)
|
||||
assert msg["event"]["payload"]["type"] == "AUTHORIZATION_REQUIRED"
|
||||
|
||||
|
||||
async def test_alarm_control_panel_code_arm_required(hass):
|
||||
"""Test alarm_control_panel with code_arm_required discovery."""
|
||||
device = (
|
||||
"alarm_control_panel.test_3",
|
||||
"disarmed",
|
||||
{"friendly_name": "Test Alarm Control Panel 3", "code_arm_required": True},
|
||||
)
|
||||
await discovery_test(device, hass, expected_endpoints=0)
|
||||
Reference in new issue
Block a user