homebridge-boschcontrolpanel_bgseries
Version:
Homebridge plugin for Bosch Control Panel.
232 lines • 11.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HKSecurityPanel = void 0;
const BGConst_1 = require("./BGConst");
const HKAccessory_1 = require("./HKAccessory");
class HKSecurityPanel extends HKAccessory_1.HKAccessory {
constructor(platform, AreaMonitored, AreaInScope, PasscodeFollowScope) {
super(platform, 'BGArea' + platform.Panel.PanelType + AreaMonitored, // UUID, do not change
platform.Panel.Areas[AreaMonitored].AreaText, 'BGPanel' + AreaMonitored);
this.platform = platform;
this.AreaMonitored = AreaMonitored;
this.AreaInScope = AreaInScope;
this.PasscodeFollowScope = PasscodeFollowScope;
this.service = this.Accessory.getService(this.platform.Service.SecuritySystem)
|| this.Accessory.addService(this.platform.Service.SecuritySystem);
if (AreaInScope.indexOf(AreaMonitored) === -1) {
this.AreaInScope.push(this.AreaMonitored);
}
this.AreaInScope.sort((a, b) => a - b);
this.platform.log.info('Security System: Area' + AreaMonitored + ' - ' + this.Accessory.displayName);
this.platform.log.debug(' Area(s) in Scope: ' + this.GetAreaInScopeString());
this.platform.log.debug(' Passcode Follows Scope: ' + this.PasscodeFollowScope);
this.service.getCharacteristic(this.platform.Characteristic.SecuritySystemTargetState)
.onSet(this.handleSecuritySystemTargetStateSet.bind(this));
this.platform.Panel.on('AreaOnOffStateChange', (Area) => {
if (this.AreaMonitored === Area.AreaNumber) {
this.UpdateStateFromPanel(Area.AreaStatus);
}
});
this.platform.Panel.on('AreaAlarmStateChange', (Area) => {
if (this.AreaInScope.indexOf(Area.AreaNumber) === -1) {
return;
}
let AlarmDetected = false;
for (let i = 0; i < this.AreaInScope.length; i++) {
if (this.platform.Panel.Areas[this.AreaInScope[i]].GetAlarmDetected()) {
AlarmDetected = true;
break;
}
}
this.SetAlarmTriggered(AlarmDetected);
});
}
UpdateStateFromPanel(AreaStatus) {
const HKCurrentStatus = this.BoschAreaStatusToCurrentHomekitSecurityStatus(AreaStatus);
const HKTargetStatus = this.BoschAreaStatusToTargetHomekitSecurityStatus(AreaStatus);
this.service.getCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState).updateValue(HKCurrentStatus);
this.service.getCharacteristic(this.platform.Characteristic.SecuritySystemTargetState).updateValue(HKTargetStatus);
}
SetAlarmTriggered(AlarmTrigerred) {
if (AlarmTrigerred) {
this.service.updateCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState, this.platform.Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED);
}
else {
const Area = this.platform.Panel.Areas[this.AreaMonitored];
if (Area) {
const HKCurrentStatus = this.BoschAreaStatusToCurrentHomekitSecurityStatus(Area.AreaStatus);
this.service.getCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState).updateValue(HKCurrentStatus);
}
else {
this.platform.log.error('Security System: Error reading Area Status');
}
}
}
SetFaulted() {
// Not Working
// this.service.updateCharacteristic(this.platform.Characteristic.SecuritySystemCurrentState,new Error(''));
}
handleSecuritySystemTargetStateSet(value) {
let AreaToArm = [this.AreaMonitored];
if (this.PasscodeFollowScope) {
AreaToArm = this.AreaInScope;
}
const Panel = this.platform.Panel;
switch (value) {
case this.platform.Characteristic.SecuritySystemTargetState.DISARM: {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.Disarm);
break;
}
case this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM: {
if (Panel.PanelType === BGConst_1.BGPanelType.Solution2000 ||
Panel.PanelType === BGConst_1.BGPanelType.Solution3000 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX2100 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX3000 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX4000) {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.AwayArm);
}
else {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.MasterDelayArm);
}
break;
}
case this.platform.Characteristic.SecuritySystemTargetState.NIGHT_ARM: {
if (Panel.PanelType === BGConst_1.BGPanelType.AMAX2100 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX3000 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX4000) {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.StayArm1);
break;
}
if (Panel.PanelType === BGConst_1.BGPanelType.Solution2000 ||
Panel.PanelType === BGConst_1.BGPanelType.Solution3000) {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.StayArm2);
break;
}
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.PerimeterInstantArm);
break;
}
case this.platform.Characteristic.SecuritySystemTargetState.STAY_ARM: {
if (Panel.PanelType === BGConst_1.BGPanelType.Solution2000 ||
Panel.PanelType === BGConst_1.BGPanelType.Solution3000 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX2100 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX3000 ||
Panel.PanelType === BGConst_1.BGPanelType.AMAX4000) {
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.StayArm1);
break;
}
this.platform.Panel.ArmArea(AreaToArm, BGConst_1.BGArmingType.PerimeterDelayArm);
break;
}
}
}
BoschAreaStatusToCurrentHomekitSecurityStatus(AreaStatus) {
switch (AreaStatus) {
case BGConst_1.BGAreaStatus.AllOn: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
break;
}
case BGConst_1.BGAreaStatus.AllOnEntryDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AllOnExitDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AllOnInstantArmed: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.Disarmed: {
return this.platform.Characteristic.SecuritySystemCurrentState.DISARMED;
}
case BGConst_1.BGAreaStatus.PartOnDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnEntryDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnExitDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnInstant: {
return this.platform.Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
}
case BGConst_1.BGAreaStatus.StayArm1On: {
return this.platform.Characteristic.SecuritySystemCurrentState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.StayArm2On: {
return this.platform.Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
}
case BGConst_1.BGAreaStatus.AwayOn: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AwayExitDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AwayEntryDelay: {
return this.platform.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.Unknown: {
return this.platform.Characteristic.SecuritySystemCurrentState.DISARMED;
}
}
}
BoschAreaStatusToTargetHomekitSecurityStatus(AreaStatus) {
switch (AreaStatus) {
case BGConst_1.BGAreaStatus.AllOn: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
break;
}
case BGConst_1.BGAreaStatus.AllOnEntryDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AllOnExitDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AllOnInstantArmed: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.Disarmed: {
return this.platform.Characteristic.SecuritySystemTargetState.DISARM;
}
case BGConst_1.BGAreaStatus.PartOnDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnEntryDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnExitDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.PartOnInstant: {
return this.platform.Characteristic.SecuritySystemTargetState.NIGHT_ARM;
}
case BGConst_1.BGAreaStatus.StayArm1On: {
return this.platform.Characteristic.SecuritySystemTargetState.STAY_ARM;
}
case BGConst_1.BGAreaStatus.StayArm2On: {
return this.platform.Characteristic.SecuritySystemTargetState.NIGHT_ARM;
}
case BGConst_1.BGAreaStatus.AwayOn: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AwayEntryDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.AwayExitDelay: {
return this.platform.Characteristic.SecuritySystemTargetState.AWAY_ARM;
}
case BGConst_1.BGAreaStatus.Unknown: {
// throw error
return this.platform.Characteristic.SecuritySystemTargetState.DISARM;
}
}
}
GetAreaInScopeString() {
let AreaInScopeString = '';
for (let i = 0; i < this.AreaInScope.length; i++) {
AreaInScopeString += this.AreaInScope[i] + ',';
}
return AreaInScopeString.slice(0, AreaInScopeString.length - 1);
}
}
exports.HKSecurityPanel = HKSecurityPanel;
//# sourceMappingURL=HKSecurityPanel.js.map