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:
parent
f169e84d21
commit
9a5c1fbaed
8 changed files with 337 additions and 2 deletions
|
@ -9,6 +9,11 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_TEMPERATURE,
|
||||
STATE_ALARM_DISARMED,
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
SERVICE_ALARM_DISARM,
|
||||
SERVICE_LOCK,
|
||||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
SERVICE_MEDIA_PAUSE,
|
||||
|
@ -35,6 +40,8 @@ from .const import API_TEMP_UNITS, API_THERMOSTAT_MODES, API_THERMOSTAT_PRESETS,
|
|||
from .entities import async_get_entities
|
||||
from .errors import (
|
||||
AlexaInvalidValueError,
|
||||
AlexaSecurityPanelAuthorizationRequired,
|
||||
AlexaSecurityPanelUnauthorizedError,
|
||||
AlexaTempRangeError,
|
||||
AlexaUnsupportedThermostatModeError,
|
||||
)
|
||||
|
@ -849,3 +856,71 @@ async def async_api_adjust_power_level(hass, config, directive, context):
|
|||
)
|
||||
|
||||
return directive.response()
|
||||
|
||||
|
||||
@HANDLERS.register(("Alexa.SecurityPanelController", "Arm"))
|
||||
async def async_api_arm(hass, config, directive, context):
|
||||
"""Process a Security Panel Arm request."""
|
||||
entity = directive.entity
|
||||
service = None
|
||||
arm_state = directive.payload["armState"]
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
|
||||
if entity.state != STATE_ALARM_DISARMED:
|
||||
msg = "You must disarm the system before you can set the requested arm state."
|
||||
raise AlexaSecurityPanelAuthorizationRequired(msg)
|
||||
|
||||
if arm_state == "ARMED_AWAY":
|
||||
service = SERVICE_ALARM_ARM_AWAY
|
||||
if arm_state == "ARMED_STAY":
|
||||
service = SERVICE_ALARM_ARM_HOME
|
||||
if arm_state == "ARMED_NIGHT":
|
||||
service = SERVICE_ALARM_ARM_NIGHT
|
||||
|
||||
await hass.services.async_call(
|
||||
entity.domain, service, data, blocking=False, context=context
|
||||
)
|
||||
|
||||
response = directive.response(
|
||||
name="Arm.Response", namespace="Alexa.SecurityPanelController"
|
||||
)
|
||||
|
||||
response.add_context_property(
|
||||
{
|
||||
"name": "armState",
|
||||
"namespace": "Alexa.SecurityPanelController",
|
||||
"value": arm_state,
|
||||
}
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@HANDLERS.register(("Alexa.SecurityPanelController", "Disarm"))
|
||||
async def async_api_disarm(hass, config, directive, context):
|
||||
"""Process a Security Panel Disarm request."""
|
||||
entity = directive.entity
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
|
||||
payload = directive.payload
|
||||
if "authorization" in payload:
|
||||
value = payload["authorization"]["value"]
|
||||
if payload["authorization"]["type"] == "FOUR_DIGIT_PIN":
|
||||
data["code"] = value
|
||||
|
||||
if not await hass.services.async_call(
|
||||
entity.domain, SERVICE_ALARM_DISARM, data, blocking=True, context=context
|
||||
):
|
||||
msg = "Invalid Code"
|
||||
raise AlexaSecurityPanelUnauthorizedError(msg)
|
||||
|
||||
response = directive.response()
|
||||
response.add_context_property(
|
||||
{
|
||||
"name": "armState",
|
||||
"namespace": "Alexa.SecurityPanelController",
|
||||
"value": "DISARMED",
|
||||
}
|
||||
)
|
||||
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue