Skip to content

Commit

Permalink
SecurityPanelController
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio Chimera authored and Claudio Chimera committed Oct 8, 2021
1 parent a55b33c commit 6631416
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions alexa/alexa-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,33 @@ module.exports = function (RED) {

// SecurityPanelController
// https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-securitypanelcontroller.html
if (node.config.i_security_panel_controller) {
if (node.isVerbose()) node._debug("Alexa.SecurityPanelController");
const arm_state = node.config.arm_state || [];
const alarms = node.config.alarms || [];
const pin_code = node.config.pin_code || '';
let configuration = {};
if (arm_state.length > 0 || pin_code.trim().length === 4) {
let properties_value = {};
if (arm_state.length > 0) {
properties_value['armState'] = arm_state[0];
configuration['supportedArmStates'] = arm_state.map(state => ({ "value": state }));
}
alarms.forEach(alarm => {
properties_value[alarm] = {
value: "OK"
};
});
if (pin_code.trim().length === 4) {
configuration['supportedAuthorizationTypes'] = ['FOUR_DIGIT_PIN'];
}
node.addCapability("Alexa.SecurityPanelController", properties_value,
{
configuration: configuration
}
);
}
}

// Speaker
// https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-speaker.html
Expand Down Expand Up @@ -624,17 +651,17 @@ module.exports = function (RED) {
//
//
//
getCapability(iface, obj_val) {
getCapability(iface, properties_val) {
var node = this;
let capability = {
type: "AlexaInterface",
interface: iface,
version: "3",
};
if (obj_val) {
if (properties_val) {
let supported = [];
Object.keys(obj_val).forEach(key => {
node.state[key] = obj_val[key];
Object.keys(properties_val).forEach(key => {
node.state[key] = properties_val[key];
supported.push({
name: key
});
Expand All @@ -652,9 +679,9 @@ module.exports = function (RED) {
//
//
//
addCapability(iface, obj_val, attributes) {
addCapability(iface, properties_val, attributes) {
var node = this;
let capability = node.getCapability(iface, obj_val);
let capability = node.getCapability(iface, properties_val);
if (attributes !== undefined) {
Object.assign(capability, attributes);
}
Expand Down Expand Up @@ -867,6 +894,20 @@ module.exports = function (RED) {
}
break;

case "Alexa.SecurityPanelController": // SecurityPanelController
if (name === 'Arm') {
modified = node.setValues({ armState: payload['armState'] }, node.state);
// TODO ?? "bypassType": "BYPASS_ALL"
// exitDelayInSeconds
// bypassedEndpoints
}
else if (name === 'Disarm') {
if (payload.authorization && payload.authorization.type === 'FOUR_DIGIT_PIN' && payload.authorization.value === node.config.pin_code) {
modified = node.setValues({ armState: 'DISARMED' }, node.state);
}
}
break;

case "Alexa.Speaker": // Speaker
if (name === 'SetVolume') {
modified = node.setValues(payload, node.state);
Expand Down Expand Up @@ -1069,6 +1110,27 @@ module.exports = function (RED) {
uncertaintyInMilliseconds: uncertainty,
});
}
// SecurityPanelController
if (node.config.i_security_panel_controller) {
if (node.state['armState']) {
properties.push({
namespace: "Alexa.SecurityPanelController",
name: "armState",
value: node.state['armState'],
timeOfSample: time_of_sample,
uncertaintyInMilliseconds: uncertainty,
});
}
node.config.alarms.forEach(alarm => {
properties.push({
namespace: "Alexa.SecurityPanelController",
name: alarm,
value: node.state[alarm],
timeOfSample: time_of_sample,
uncertaintyInMilliseconds: uncertainty,
});
});
}
// PowerController
if (node.config.i_power_controller) {
properties.push({
Expand Down

0 comments on commit 6631416

Please sign in to comment.