homebridge-plugin-command-dev
Advanced tools
Comparing version 1.0.12 to 1.0.13
26
index.js
@@ -1,5 +0,3 @@ | ||
const { exit } = require('process'); | ||
const { execSync } = require('child_process'); | ||
var exec = require('child_process').execSync; | ||
module.exports = function (api) { | ||
@@ -21,2 +19,3 @@ api.registerAccessory("homebridge-plugin-command", "commandAccessory", CommandAccessoryPlugin); | ||
.setCharacteristic(this.api.hap.Characteristic.Manufacturer, "adyanth") | ||
.setCharacteristic(this.api.hap.Characteristic.SerialNumber, "#007") | ||
.setCharacteristic(this.api.hap.Characteristic.Model, config["name"]); | ||
@@ -44,13 +43,18 @@ | ||
if (!this.config.check_status) { | ||
this.log.debug(`No check_status, returning static state: ${this.currentState}`) | ||
return this.currentState; | ||
} | ||
this.log.info(`Running check_status`); | ||
this.log.debug(`Running: ${this.config.check_status}`); | ||
let state = null; | ||
try { | ||
exec(this.config.check_status); | ||
return !this.config.invert_status; | ||
} catch (error) { } | ||
execSync(this.config.check_status); | ||
state = !this.config.invert_status; | ||
} catch (error) { | ||
state = false; | ||
} | ||
return false; | ||
this.log.debug(`Returning: ${state}`); | ||
return state; | ||
} | ||
@@ -61,6 +65,7 @@ | ||
let cmd = value ? this.config.turn_on : this.config.turn_off; | ||
let exitCode = 1; | ||
this.log.info(`Running ${value ? "turn_on" : "turn_off"}`); | ||
this.log.debug(`Running: ${cmd}`); | ||
try { | ||
exec(value ? this.config.turn_on : this.config.turn_off); | ||
execSync(cmd); | ||
exitCode = 0; | ||
@@ -73,4 +78,5 @@ } catch (error) { | ||
this.currentState = value ^ (exitCode != 0); | ||
this.log.debug(`Returning: ${this.currentState}}`); | ||
return this.currentState; | ||
} | ||
} |
{ | ||
"name": "homebridge-plugin-command-dev", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "This Homebridge plugin enables you to create virtual switches that can run any custom command when it is turned on or off.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
15624
68