diff --git a/index.js b/index.js index cf957c7..98f7dc3 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ module.exports = function(homebridge) { Utility.addSupportTo(ItemFactory.Gate, ItemFactory.AbstractItem); Utility.addSupportTo(ItemFactory.DoorBell, ItemFactory.AbstractItem); Utility.addSupportTo(ItemFactory.Jalousie, ItemFactory.AbstractItem); - Utility.addSupportTo(ItemFactory.TimedSwitch, ItemFactory.AbstractItem); + Utility.addSupportTo(ItemFactory.TimedSwitch, ItemFactory.AbstractItem); + Utility.addSupportTo(ItemFactory.Alarm, ItemFactory.AbstractItem); Utility.addSupportTo(ItemFactory.Switch, ItemFactory.AbstractItem); //Add childs of switch Utility.addSupportTo(ItemFactory.Lightbulb, ItemFactory.Switch); @@ -60,13 +61,13 @@ function LoxPlatform(log, config) { this.rooms = config["rooms"]; } else { this.rooms =[]; - } + } this.log(typeof this.rooms); if (this.config['moodSwitches']) { this.moodSwitches = config["moodSwitches"]; } else { this.moodSwitches = 'none'; - } + } //Also make a WS connection this.ws = new WSListener(platform); @@ -92,7 +93,3 @@ LoxPlatform.prototype.accessories = function(callback) { }) },8000); }; - - - - diff --git a/items/Alarm.js b/items/Alarm.js new file mode 100644 index 0000000..f0937d7 --- /dev/null +++ b/items/Alarm.js @@ -0,0 +1,52 @@ +"use strict"; + +var request = require("request"); + +var Alarm = function (widget, platform, homebridge) { + + this.platform = platform; + this.uuidAction = widget.uuidAction; + this.stateUuid = widget.states.armed; + this.currentState = undefined; + + Alarm.super_.call(this, widget, platform, homebridge); +}; + +Alarm.prototype.initListener = function () { + this.platform.ws.registerListenerForUUID(this.stateUuid, this.callBack.bind(this)); +}; + +Alarm.prototype.callBack = function (value) { + this.currentState = value; +} + +Alarm.prototype.getOtherServices = function () { + var otherService = new this.homebridge.hap.Service.Switch(); + + otherService.getCharacteristic(this.homebridge.hap.Characteristic.On) + .on('set', this.setItemState.bind(this)) + .on('get', this.getItemState.bind(this)) + .updateValue(this.currentState == '1'); + + return otherService; +}; + +Alarm.prototype.getItemState = function (callback) { + callback(undefined, this.currentState == '1'); +}; + +Alarm.prototype.onCommand = function () { + return 'On'; +}; + +Alarm.prototype.setItemState = function (value, callback) { + var self = this; + + var command = (value == '1') ? this.onCommand() : 'Off'; + this.log("[Alarm] iOS - send message to " + this.name + ": " + command); + this.platform.ws.sendCommand(this.uuidAction, command); + callback(); + +}; + +module.exports = Alarm; diff --git a/libs/ItemFactory.js b/libs/ItemFactory.js index 79bf0a2..8d2e692 100644 --- a/libs/ItemFactory.js +++ b/libs/ItemFactory.js @@ -18,6 +18,7 @@ exports.DoorBell = require('../items/DoorBellItem.js'); exports.MotionSensor = require('../items/MotionSensorItem.js'); exports.ContactSensor = require('../items/ContactSensorItem.js'); exports.LightSensor = require('../items/LightSensorItem.js'); +exports.Alarm = require('../items/Alarm.js'); exports.Factory = function(LoxPlatform, homebridge) { this.platform = LoxPlatform; @@ -70,7 +71,7 @@ exports.Factory.prototype.parseSitemap = function(jsonSitemap) { // https://github.com/nfarina/homebridge/issues/509 this.log("Platform - Accessory count limit (100) exceeded so skipping: '" + this.itemList[key].name + "' of type " + this.itemList[key].type + " was skipped."); } else { - + var keyToLookup = key; if (keyToLookup.indexOf('/') > -1) { keyToLookup = keyToLookup.split('/')[0]; @@ -79,11 +80,11 @@ exports.Factory.prototype.parseSitemap = function(jsonSitemap) { var control = this.itemList[keyToLookup]; var controlRoom = null; - + if (this.platform.rooms.length == 0) { //Show all rooms accessoryList.push(accessory); - + } else { //Filter rooms if (control.room) { @@ -279,4 +280,4 @@ exports.Factory.prototype.traverseSitemap = function(jsonSitmap, factory) { } } } -}; \ No newline at end of file +};