homebridge-syntex-magichome
Advanced tools
Comparing version 1.0.0-b2 to 1.0.0-b20
{ | ||
"platforms": [ | ||
{ | ||
"platform": "SynTexMagicHome", | ||
"platform": "MagicHome-Platform", | ||
"debug": true, | ||
@@ -6,0 +6,0 @@ "disableDiscovery": false, |
26
index.js
@@ -0,15 +1,15 @@ | ||
// MagicHome Platform | ||
const MagicHome = require('./src/magichome') | ||
module.exports = function(homebridge) | ||
{ | ||
var homebridgeGlobals = { | ||
Service: homebridge.hap.Service, | ||
Characteristic: homebridge.hap.Characteristic, | ||
Accessory: homebridge.platformAccessory, | ||
UUIDGen: homebridge.hap.uuid, | ||
PersistPath: homebridge.user.storagePath() | ||
}; | ||
MagicHome.globals.setHomebridge(homebridgeGlobals); | ||
homebridge.registerPlatform(MagicHome.pluginName, MagicHome.platformName, MagicHome.platform, true); | ||
} | ||
module.exports = (homebridge) => { | ||
var homebridgeGlobals = { | ||
Service: homebridge.hap.Service, | ||
Characteristic: homebridge.hap.Characteristic, | ||
Accessory: homebridge.platformAccessory, | ||
UUIDGen: homebridge.hap.uuid, | ||
PersistPath: homebridge.user.storagePath(), | ||
} | ||
MagicHome.globals.setHomebridge(homebridgeGlobals) | ||
homebridge.registerPlatform(MagicHome.pluginName, MagicHome.platformName, MagicHome.platform, true) | ||
} |
{ | ||
"name": "homebridge-syntex-magichome", | ||
"version": "1.0.0-b2", | ||
"version": "1.0.0-b20", | ||
"description": "Homebridge Plugin for MagicHome LED Strips with preset scenes", | ||
"main": "index.js", | ||
"author": { | ||
"name": "SynTexDZN" | ||
"preferGlobal": true, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint": "./node_modules/.bin/eslint .", | ||
"ci": "npm install && npm run lint" | ||
}, | ||
"engines": { | ||
"homebridge": ">=0.4.30", | ||
"node": ">=9.11.2" | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/SynTexDZN/homebridge-syntex-magichome.git" | ||
}, | ||
"dependencies": { | ||
"babel-eslint": "^8.2.6", | ||
"color-convert": "^1.5.0", | ||
"node-persist": "^3.0.1" | ||
}, | ||
"keywords": [ | ||
"syntex", | ||
"homebridge", | ||
"homebridge-plugin", | ||
"plugin", | ||
"http", | ||
"homekit", | ||
"smarthome", | ||
"siri", | ||
"Flux", | ||
@@ -45,11 +37,21 @@ "magic", | ||
], | ||
"homepage": "https://github.com/SynTexDZN/homebridge-syntex-webhooks#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/SynTexDZN/homebridge-syntex-magichome.git" | ||
"engines": { | ||
"homebridge": ">=0.4.30" | ||
}, | ||
"author": "SynTexDZN", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/SynTexDZN/homebridge-syntex-magichome/issues" | ||
"url": "https://github.com/sahilchaddha/homebridge-syntex-magichome/issues" | ||
}, | ||
"license": "ISC" | ||
"homepage": "https://github.com/sahilchaddha/homebridge-syntex-magichome#readme", | ||
"devDependencies": { | ||
"eslint": "^5.3.0", | ||
"eslint-config-airbnb-base": "^13.0.0", | ||
"eslint-plugin-import": "^2.13.0" | ||
}, | ||
"dependencies": { | ||
"babel-eslint": "^8.2.6", | ||
"color-convert": "^1.5.0", | ||
"node-persist": "^3.0.1" | ||
} | ||
} |
@@ -1,79 +0,70 @@ | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const lightAgent = require('../lib/lightAgent'); | ||
// | ||
// base.js | ||
// Sahil Chaddha | ||
// | ||
// Created by Sahil Chaddha on 13/08/2018. | ||
// Copyright © 2018 sahilchaddha.com. All rights reserved. | ||
// | ||
const Accessory = class | ||
{ | ||
constructor(config, log, homebridge) | ||
{ | ||
this.homebridge = homebridge; | ||
this.log = log; | ||
this.config = config; | ||
this.name = config.name; | ||
this.services = this.getAccessoryServices(); | ||
const cp = require('child_process') | ||
const path = require('path') | ||
const lightAgent = require('../lib/lightAgent') | ||
this.services.push(this.getInformationService()); | ||
} | ||
const Accessory = class { | ||
constructor(config, log, homebridge) { | ||
this.homebridge = homebridge | ||
this.log = log | ||
this.config = config | ||
this.name = config.name | ||
this.services = this.getAccessoryServices() | ||
this.services.push(this.getInformationService()) | ||
} | ||
identify(callback) | ||
{ | ||
callback(); | ||
} | ||
identify(callback) { | ||
callback() | ||
} | ||
getInformationService() | ||
{ | ||
var informationService = new this.homebridge.Service.AccessoryInformation(); | ||
getInformationService() { | ||
var informationService = new this.homebridge.Service.AccessoryInformation() | ||
informationService | ||
.setCharacteristic(this.homebridge.Characteristic.Manufacturer, 'SynTex MagicHome') | ||
.setCharacteristic(this.homebridge.Characteristic.Model, this.getModelName()) | ||
.setCharacteristic(this.homebridge.Characteristic.SerialNumber, this.getSerialNumber()) | ||
return informationService | ||
} | ||
informationService.setCharacteristic(this.homebridge.Characteristic.Manufacturer, 'MagicHome') | ||
.setCharacteristic(this.homebridge.Characteristic.Model, this.getModelName()) | ||
.setCharacteristic(this.homebridge.Characteristic.SerialNumber, this.getSerialNumber()); | ||
executeCommand(address, command, callback) { | ||
const exec = cp.exec | ||
const self = this | ||
const cmd = path.join(__dirname, '../flux_led.py ' + lightAgent.getAddress(address) + command) | ||
if (self.homebridge.debug) { | ||
self.log(cmd) | ||
} | ||
exec(cmd, (err, stdOut) => { | ||
if (self.homebridge.debug) { | ||
self.log(stdOut) | ||
} | ||
if (callback) { | ||
callback(err, stdOut) | ||
} | ||
}) | ||
} | ||
return informationService; | ||
} | ||
getAccessoryServices() { | ||
throw new Error('The getSystemServices method must be overridden.') | ||
} | ||
executeCommand(address, command, callback) | ||
{ | ||
const exec = cp.exec; | ||
const self = this; | ||
const cmd = path.join(__dirname, '../flux_led.py ' + lightAgent.getAddress(address) + command); | ||
getModelName() { | ||
throw new Error('The getModelName method must be overridden.') | ||
} | ||
if(self.homebridge.debug) | ||
{ | ||
self.log(cmd); | ||
} | ||
getSerialNumber() { | ||
throw new Error('The getSerialNumber method must be overridden.') | ||
} | ||
exec(cmd, function(err, stdOut) | ||
{ | ||
if(self.homebridge.debug) | ||
{ | ||
self.log(stdOut); | ||
} | ||
if(callback) | ||
{ | ||
callback(err, stdOut); | ||
} | ||
}); | ||
} | ||
getAccessoryServices() | ||
{ | ||
throw new Error('The getSystemServices method must be overridden.'); | ||
} | ||
getModelName() | ||
{ | ||
throw new Error('The getModelName method must be overridden.'); | ||
} | ||
getSerialNumber() | ||
{ | ||
throw new Error('The getSerialNumber method must be overridden.'); | ||
} | ||
getServices() | ||
{ | ||
return this.services; | ||
} | ||
getServices() { | ||
return this.services | ||
} | ||
} | ||
module.exports = Accessory; | ||
module.exports = Accessory |
@@ -1,225 +0,192 @@ | ||
const convert = require('color-convert'); | ||
const Accessory = require('./base'); | ||
// | ||
// clearDirSwitch.js | ||
// Sahil Chaddha | ||
// | ||
// Created by Sahil Chaddha on 26/08/2018. | ||
// Copyright © 2018 sahilchaddha.com. All rights reserved. | ||
// | ||
const LightBulb = class extends Accessory | ||
{ | ||
constructor(config, log, homebridge) | ||
{ | ||
super(config, log, homebridge); | ||
const convert = require('color-convert') | ||
const Accessory = require('./base') | ||
this.name = config.name || 'LED Controller'; | ||
this.ip = config.ip; | ||
this.setup = config.setup || 'RGBW'; | ||
this.color = { H: 0, S: 0, L: 100 }; | ||
this.purewhite = config.purewhite || false; | ||
this.timeout = config.timeout != null ? config.timeout : 60000; | ||
const LightBulb = class extends Accessory { | ||
constructor(config, log, homebridge) { | ||
super(config, log, homebridge) | ||
this.name = config.name || 'LED Controller' | ||
this.ip = config.ip | ||
this.setup = config.setup || 'RGBW' | ||
this.color = { H: 0, S: 0, L: 100 } | ||
this.purewhite = config.purewhite || false | ||
this.timeout = config.timeout != null ? config.timeout : 60000 | ||
setTimeout(() => { | ||
this.updateState() | ||
}, 3000) | ||
} | ||
setTimeout(function() | ||
{ | ||
this.updateState(); | ||
}, 3000); | ||
} | ||
getAccessoryServices() { | ||
var lightbulbService = new this.homebridge.Service.Lightbulb(this.name) | ||
getAccessoryServices() | ||
{ | ||
var lightbulbService = new this.homebridge.Service.Lightbulb(this.name); | ||
lightbulbService | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getPowerState.bind(this)) | ||
.on('set', this.setPowerState.bind(this)) | ||
lightbulbService.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getPowerState.bind(this)) | ||
.on('set', this.setPowerState.bind(this)); | ||
lightbulbService | ||
.addCharacteristic(new this.homebridge.Characteristic.Hue()) | ||
.on('get', this.getHue.bind(this)) | ||
.on('set', this.setHue.bind(this)) | ||
lightbulbService.addCharacteristic(new this.homebridge.Characteristic.Hue()) | ||
.on('get', this.getHue.bind(this)) | ||
.on('set', this.setHue.bind(this)); | ||
lightbulbService | ||
.addCharacteristic(new this.homebridge.Characteristic.Saturation()) | ||
.on('get', this.getSaturation.bind(this)) | ||
.on('set', this.setSaturation.bind(this)) | ||
lightbulbService.addCharacteristic(new this.homebridge.Characteristic.Saturation()) | ||
.on('get', this.getSaturation.bind(this)) | ||
.on('set', this.setSaturation.bind(this)); | ||
lightbulbService | ||
.addCharacteristic(new this.homebridge.Characteristic.Brightness()) | ||
.on('get', this.getBrightness.bind(this)) | ||
.on('set', this.setBrightness.bind(this)) | ||
lightbulbService.addCharacteristic(new this.homebridge.Characteristic.Brightness()) | ||
.on('get', this.getBrightness.bind(this)) | ||
.on('set', this.setBrightness.bind(this)); | ||
return [lightbulbService] | ||
} | ||
return [lightbulbService]; | ||
} | ||
sendCommand(command, callback) { | ||
this.executeCommand(this.ip, command, callback) | ||
} | ||
sendCommand(command, callback) | ||
{ | ||
this.executeCommand(this.ip, command, callback); | ||
} | ||
getModelName() { | ||
return 'Light Bulb' | ||
} | ||
getModelName() | ||
{ | ||
return 'Light Bulb'; | ||
} | ||
getSerialNumber() { | ||
return '00-001-LightBulb' | ||
} | ||
getSerialNumber() | ||
{ | ||
return '00-001-LightBulb'; | ||
} | ||
logMessage(...args) { | ||
if (this.config.debug) { | ||
this.log(args) | ||
} | ||
} | ||
logMessage(...args) | ||
{ | ||
if(this.config.debug) | ||
{ | ||
this.log(args); | ||
} | ||
} | ||
startTimer() { | ||
if (this.timeout === 0) return | ||
setTimeout(() => { | ||
this.updateState() | ||
}, this.timeout) | ||
} | ||
startTimer() | ||
{ | ||
if(this.timeout === 0) return; | ||
updateState() { | ||
const self = this | ||
this.logMessage('Polling Light', this.ip) | ||
self.getState((settings) => { | ||
self.isOn = settings.on | ||
self.color = settings.color | ||
self.logMessage('Updating Device', self.ip, self.color, self.isOn) | ||
self.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.updateValue(self.isOn) | ||
self.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.Hue) | ||
.updateValue(self.color.H) | ||
self.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.Saturation) | ||
.updateValue(self.color.S) | ||
self.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.Brightness) | ||
.updateValue(self.color.L) | ||
this.startTimer() | ||
}) | ||
} | ||
setTimeout(function() | ||
{ | ||
this.updateState(); | ||
}, this.timeout); | ||
} | ||
getState(callback) { | ||
this.sendCommand('-i', (error, stdout) => { | ||
var settings = { | ||
on: false, | ||
color: { H: 255, S: 100, L: 50 }, | ||
} | ||
updateState() | ||
{ | ||
const self = this; | ||
var colors = stdout.match(/\(.*,.*,.*\)/g) | ||
var isOn = stdout.match(/\] ON /g) | ||
if (isOn && isOn.length > 0) { | ||
settings.on = true | ||
} | ||
if (colors && colors.length > 0) { | ||
// Remove last char ) | ||
var str = colors.toString().substring(0, colors.toString().length - 1) | ||
// Remove First Char ( | ||
str = str.substring(1, str.length) | ||
const rgbColors = str.split(',').map((item) => { | ||
return item.trim() | ||
}) | ||
var converted = convert.rgb.hsv(rgbColors) | ||
settings.color = { | ||
H: converted[0], | ||
S: converted[1], | ||
L: converted[2], | ||
} | ||
} | ||
this.logMessage('Polling Light', this.ip); | ||
callback(settings) | ||
}) | ||
} | ||
self.getState(function(settings) | ||
{ | ||
self.isOn = settings.on; | ||
self.color = settings.color; | ||
getPowerState(callback) { | ||
callback(null, this.isOn) | ||
} | ||
self.logMessage('Updating Device', self.ip, self.color, self.isOn); | ||
setPowerState(value, callback) { | ||
const self = this | ||
this.sendCommand(value ? '--on' : '--off', () => { | ||
self.isOn = value | ||
callback() | ||
}) | ||
} | ||
self.services[0].getCharacteristic(this.homebridge.Characteristic.On) | ||
.updateValue(self.isOn); | ||
getHue(callback) { | ||
callback(null, this.color.H) | ||
} | ||
self.services[0].getCharacteristic(this.homebridge.Characteristic.Hue) | ||
.updateValue(self.color.H); | ||
setHue(value, callback) { | ||
this.color.H = value | ||
this.setToCurrentColor() | ||
callback() | ||
} | ||
self.services[0].getCharacteristic(this.homebridge.Characteristic.Saturation) | ||
.updateValue(self.color.S); | ||
getBrightness(callback) { | ||
callback(null, this.color.L) | ||
} | ||
self.services[0].getCharacteristic(this.homebridge.Characteristic.Brightness) | ||
.updateValue(self.color.L); | ||
setBrightness(value, callback) { | ||
this.color.L = value | ||
this.setToCurrentColor() | ||
callback() | ||
} | ||
this.startTimer(); | ||
}) | ||
} | ||
getSaturation(callback) { | ||
callback(null, this.color.S) | ||
} | ||
getState(callback) | ||
{ | ||
this.sendCommand('-i', function(error, stdout) | ||
{ | ||
var settings = { | ||
on: false, | ||
color: { H: 255, S: 100, L: 50 } | ||
}; | ||
setSaturation(value, callback) { | ||
this.color.S = value | ||
this.setToCurrentColor() | ||
callback() | ||
} | ||
var colors = stdout.match(/\(.*,.*,.*\)/g); | ||
var isOn = stdout.match(/\] ON /g); | ||
setToWarmWhite() { | ||
this.sendCommand('-w ' + this.color.L) | ||
} | ||
if(isOn && isOn.length > 0) | ||
{ | ||
settings.on = true; | ||
} | ||
setToCurrentColor() { | ||
var color = this.color | ||
if (color.S === 0 && color.H === 0 && this.purewhite) { | ||
this.setToWarmWhite() | ||
return | ||
} | ||
if(colors && colors.length > 0) | ||
{ | ||
// Remove last char ) | ||
var str = colors.toString().substring(0, colors.toString().length - 1); | ||
// Remove First Char ( | ||
str = str.substring(1, str.length); | ||
const rgbColors = str.split(',').map(function(item) | ||
{ | ||
return item.trim(); | ||
}); | ||
var converted = convert.rgb.hsv(rgbColors); | ||
settings.color = { | ||
H: converted[0], | ||
S: converted[1], | ||
L: converted[2] | ||
}; | ||
} | ||
callback(settings) | ||
}); | ||
} | ||
getPowerState(callback) | ||
{ | ||
callback(null, this.isOn); | ||
} | ||
setPowerState(value, callback) | ||
{ | ||
const self = this; | ||
this.sendCommand(value ? '--on' : '--off', function() | ||
{ | ||
self.isOn = value; | ||
callback(); | ||
}); | ||
} | ||
getHue(callback) | ||
{ | ||
callback(null, this.color.H); | ||
} | ||
setHue(value, callback) | ||
{ | ||
this.color.H = value; | ||
this.setToCurrentColor(); | ||
callback(); | ||
} | ||
getBrightness(callback) | ||
{ | ||
callback(null, this.color.L); | ||
} | ||
setBrightness(value, callback) | ||
{ | ||
this.color.L = value; | ||
this.setToCurrentColor(); | ||
callback(); | ||
} | ||
getSaturation(callback) | ||
{ | ||
callback(null, this.color.S); | ||
} | ||
setSaturation(value, callback) | ||
{ | ||
this.color.S = value; | ||
this.setToCurrentColor(); | ||
callback(); | ||
} | ||
setToWarmWhite() | ||
{ | ||
this.sendCommand('-w ' + this.color.L); | ||
} | ||
setToCurrentColor() | ||
{ | ||
var color = this.color; | ||
if(color.S === 0 && color.H === 0 && this.purewhite) | ||
{ | ||
this.setToWarmWhite(); | ||
return; | ||
} | ||
var converted = convert.hsv.rgb([color.H, color.S, color.L]); | ||
var base = '-x ' + this.setup + ' -c '; | ||
this.logMessage('Setting New Color From ', this.ip, color, converted); | ||
this.sendCommand(base + converted[0] + ',' + converted[1] + ',' + converted[2]); | ||
} | ||
var converted = convert.hsv.rgb([color.H, color.S, color.L]) | ||
this.logMessage('Setting New Color From ', this.ip, color, converted) | ||
var base = '-x ' + this.setup + ' -c ' | ||
this.sendCommand(base + converted[0] + ',' + converted[1] + ',' + converted[2]) | ||
} | ||
} | ||
module.exports = LightBulb; | ||
module.exports = LightBulb |
@@ -0,1 +1,9 @@ | ||
// | ||
// presetSwitch.js | ||
// Sahil Chaddha | ||
// | ||
// Created by Sahil Chaddha on 13/10/2018. | ||
// Copyright © 2018 sahilchaddha.com. All rights reserved. | ||
// | ||
const Accessory = require('./base') | ||
@@ -5,137 +13,102 @@ const preset = require('../presets') | ||
const PresetSwitch = class extends Accessory | ||
{ | ||
constructor(config, log, homebridge) | ||
{ | ||
super(config, log, homebridge); | ||
const PresetSwitch = class extends Accessory { | ||
constructor(config, log, homebridge) { | ||
super(config, log, homebridge) | ||
this.isOn = false | ||
this.name = config.name || 'LED Controller Presets' | ||
this.ips = Object.keys(config.ips) | ||
this.preset = config.preset || 'seven_color_cross_fade' | ||
this.sceneValue = preset[this.preset] | ||
if (this.sceneValue == null) { | ||
log('Present Not Found... Try Different Preset') | ||
this.sceneValue = 37 | ||
} | ||
this.speed = config.speed || 40 | ||
// Should Turn Off Light When Turn Off Preset | ||
this.shouldTurnOff = config.shouldTurnOff || true | ||
this.bindEmitter() | ||
} | ||
this.isOn = false; | ||
this.name = config.name || 'LED Controller Presets'; | ||
this.ips = Object.keys(config.ips); | ||
this.preset = config.preset || 'seven_color_cross_fade'; | ||
this.sceneValue = preset[this.preset]; | ||
bindEmitter() { | ||
const self = this | ||
emitter.on('MagicHomeSynTexPresetTurnedOn', (presetName) => { | ||
if (presetName !== self.name) { | ||
self.updateState(false) | ||
} | ||
}) | ||
} | ||
if(this.sceneValue == null) | ||
{ | ||
log('Present Not Found... Try Different Preset'); | ||
this.sceneValue = 37; | ||
} | ||
getAccessoryServices() { | ||
const switchService = new this.homebridge.Service.Switch(this.name) | ||
switchService | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getState.bind(this)) | ||
.on('set', this.switchStateChanged.bind(this)) | ||
return [switchService] | ||
} | ||
this.speed = config.speed || 40; | ||
// Should Turn Off Light When Turn Off Preset | ||
this.shouldTurnOff = config.shouldTurnOff || true; | ||
this.bindEmitter(); | ||
} | ||
sendCommand(command, callback) { | ||
this.executeCommand(this.ips, command, callback) | ||
} | ||
bindEmitter() | ||
{ | ||
const self = this; | ||
switchStateChanged(newState, callback) { | ||
this.isOn = newState | ||
const self = this | ||
if (newState === true) { | ||
// Turn Off Other Running Scenes | ||
emitter.emit('MagicHomeSynTexPresetTurnedOn', self.name) | ||
self.sendCommand('--on', () => { | ||
setTimeout(() => { | ||
self.sendCommand('-p ' + self.sceneValue + ' ' + self.speed, () => { | ||
callback() | ||
}) | ||
}, 3000) | ||
}) | ||
} else { | ||
// Turning OFF | ||
var promiseArray = [] | ||
Object.keys(self.config.ips).forEach((ip) => { | ||
const newPromise = new Promise((resolve) => { | ||
self.executeCommand(ip, ' -c ' + self.config.ips[ip], () => { | ||
resolve() | ||
}) | ||
}) | ||
promiseArray.push(newPromise) | ||
}) | ||
emitter.on('MagicHomePresetTurnedOn', function(presetName) | ||
{ | ||
if(presetName !== self.name) | ||
{ | ||
self.updateState(false); | ||
} | ||
}); | ||
} | ||
Promise.all(promiseArray) | ||
.then(() => { | ||
if (self.shouldTurnOff) { | ||
setTimeout(() => { | ||
self.sendCommand('--off', () => { | ||
callback() | ||
}) | ||
}, 3000) | ||
} else { | ||
callback() | ||
} | ||
}) | ||
} | ||
} | ||
getAccessoryServices() | ||
{ | ||
const switchService = new this.homebridge.Service.Switch(this.name); | ||
updateState(newValue) { | ||
this.isOn = newValue | ||
this.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.updateValue(this.isOn) | ||
} | ||
switchService.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getState.bind(this)) | ||
.on('set', this.switchStateChanged.bind(this)); | ||
getState(callback) { | ||
callback(null, this.isOn) | ||
} | ||
return [switchService]; | ||
} | ||
getModelName() { | ||
return 'Preset Switch' | ||
} | ||
sendCommand(command, callback) | ||
{ | ||
this.executeCommand(this.ips, command, callback); | ||
} | ||
switchStateChanged(newState, callback) | ||
{ | ||
this.isOn = newState; | ||
const self = this; | ||
if(newState === true) | ||
{ | ||
// Turn Off Other Running Scenes | ||
emitter.emit('MagicHomePresetTurnedOn', self.name); | ||
self.sendCommand('--on', function() | ||
{ | ||
setTimeout(function() | ||
{ | ||
self.sendCommand('-p ' + self.sceneValue + ' ' + self.speed, function() | ||
{ | ||
callback(); | ||
}); | ||
}, 3000); | ||
}); | ||
} | ||
else | ||
{ | ||
// Turning OFF | ||
var promiseArray = []; | ||
Object.keys(self.config.ips).forEach(function(ip) | ||
{ | ||
const newPromise = new Promise(function(resolve) | ||
{ | ||
self.executeCommand(ip, ' -c ' + self.config.ips[ip], function() | ||
{ | ||
resolve(); | ||
}); | ||
}); | ||
promiseArray.push(newPromise); | ||
}); | ||
Promise.all(promiseArray).then(function() | ||
{ | ||
if(self.shouldTurnOff) | ||
{ | ||
setTimeout(function() | ||
{ | ||
self.sendCommand('--off', function() | ||
{ | ||
callback(); | ||
}); | ||
}, 3000); | ||
} | ||
else | ||
{ | ||
callback(); | ||
} | ||
}) | ||
} | ||
} | ||
updateState(newValue) | ||
{ | ||
this.isOn = newValue; | ||
this.services[0].getCharacteristic(this.homebridge.Characteristic.On) | ||
.updateValue(this.isOn); | ||
} | ||
getState(callback) | ||
{ | ||
callback(null, this.isOn); | ||
} | ||
getModelName() | ||
{ | ||
return 'Preset Switch'; | ||
} | ||
getSerialNumber() | ||
{ | ||
return '00-001-PresetSwitch'; | ||
} | ||
getSerialNumber() { | ||
return '00-001-PresetSwitch' | ||
} | ||
} | ||
module.exports = PresetSwitch; | ||
module.exports = PresetSwitch |
@@ -0,90 +1,79 @@ | ||
// | ||
// clearDirSwitch.js | ||
// Sahil Chaddha | ||
// | ||
// Created by Sahil Chaddha on 13/10/2018. | ||
// Copyright © 2018 sahilchaddha.com. All rights reserved. | ||
// | ||
const Accessory = require('./base') | ||
const emitter = require('../lib/emitter') | ||
const ResetSwitch = class extends Accessory | ||
{ | ||
constructor(config, log, homebridge) | ||
{ | ||
super(config, log, homebridge); | ||
const ResetSwitch = class extends Accessory { | ||
constructor(config, log, homebridge) { | ||
super(config, log, homebridge) | ||
this.name = config.name || 'Reset LED Controller Presets' | ||
this.ips = Object.keys(config.ips) | ||
} | ||
this.name = config.name || 'Reset LED Controller Presets'; | ||
this.ips = Object.keys(config.ips); | ||
} | ||
getAccessoryServices() { | ||
const switchService = new this.homebridge.Service.Switch(this.name) | ||
switchService | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getState.bind(this)) | ||
.on('set', this.switchStateChanged.bind(this)) | ||
return [switchService] | ||
} | ||
getAccessoryServices() | ||
{ | ||
const switchService = new this.homebridge.Service.Switch(this.name); | ||
sendCommand(command, callback) { | ||
this.executeCommand(this.ips, command, callback) | ||
} | ||
switchService.getCharacteristic(this.homebridge.Characteristic.On) | ||
.on('get', this.getState.bind(this)) | ||
.on('set', this.switchStateChanged.bind(this)); | ||
switchStateChanged(newState, callback) { | ||
const self = this | ||
emitter.emit('MagicHomeSynTexPresetTurnedOn', self.name) | ||
var promiseArray = [] | ||
Object.keys(self.config.ips).forEach((ip) => { | ||
const newPromise = new Promise((resolve) => { | ||
self.executeCommand(ip, ' -c ' + self.config.ips[ip], () => { | ||
resolve() | ||
}) | ||
}) | ||
promiseArray.push(newPromise) | ||
}) | ||
return [switchService]; | ||
} | ||
Promise.all(promiseArray) | ||
.then(() => { | ||
setTimeout(() => { | ||
self.sendCommand('--off', () => { | ||
callback() | ||
}) | ||
}, 3000) | ||
}) | ||
.then(() => { | ||
setTimeout(() => { | ||
self.updateState() | ||
}, 2000) | ||
}) | ||
} | ||
sendCommand(command, callback) | ||
{ | ||
this.executeCommand(this.ips, command, callback); | ||
} | ||
updateState() { | ||
this.services[0] | ||
.getCharacteristic(this.homebridge.Characteristic.On) | ||
.updateValue(false) | ||
} | ||
switchStateChanged(newState, callback) | ||
{ | ||
const self = this; | ||
getState(callback) { | ||
callback(null, false) | ||
} | ||
emitter.emit('MagicHomePresetTurnedOn', self.name); | ||
getModelName() { | ||
return 'Reset Switch' | ||
} | ||
var promiseArray = []; | ||
Object.keys(self.config.ips).forEach(function(ip) | ||
{ | ||
const newPromise = new Promise(function(resolve) | ||
{ | ||
self.executeCommand(ip, ' -c ' + self.config.ips[ip], function() | ||
{ | ||
resolve(); | ||
}); | ||
}); | ||
promiseArray.push(newPromise); | ||
}) | ||
Promise.all(promiseArray).then(function() | ||
{ | ||
setTimeout(function() | ||
{ | ||
self.sendCommand('--off', function() | ||
{ | ||
callback(); | ||
}); | ||
}, 3000); | ||
}).then(function() | ||
{ | ||
setTimeout(function() | ||
{ | ||
self.updateState(); | ||
}, 2000); | ||
}); | ||
} | ||
updateState() | ||
{ | ||
this.services[0].getCharacteristic(this.homebridge.Characteristic.On).updateValue(false); | ||
} | ||
getState(callback) | ||
{ | ||
callback(null, false); | ||
} | ||
getModelName() | ||
{ | ||
return 'Reset Switch'; | ||
} | ||
getSerialNumber() | ||
{ | ||
return '00-001-ResetSwitch'; | ||
} | ||
getSerialNumber() { | ||
return '00-001-ResetSwitch' | ||
} | ||
} | ||
module.exports = ResetSwitch; | ||
module.exports = ResetSwitch |
@@ -1,7 +0,5 @@ | ||
const EventEmitter = require('events'); | ||
const EventEmitter = require('events') | ||
class MyEmitter extends EventEmitter {} | ||
const emitter = new MyEmitter(); | ||
module.exports = emitter; | ||
class MyEmitter extends EventEmitter { } | ||
const emitter = new MyEmitter() | ||
module.exports = emitter |
@@ -0,5 +1,13 @@ | ||
// | ||
// lightAgent.js | ||
// Sahil Chaddha | ||
// | ||
// Created by Sahil Chaddha on 22/10/2018. | ||
// Copyright © 2018 sahilchaddha.com. All rights reserved. | ||
// | ||
const cp = require('child_process') | ||
const path = require('path') | ||
const cacheKey = 'magicHome_cache' | ||
const cacheKey = 'magicHomeSynTex_cache' | ||
const spawn = cp.spawn | ||
@@ -76,3 +84,3 @@ | ||
const self = this | ||
this.storage.init({ dir: path.join(persistPath, 'magichome-platform'), forgiveParseErrors: true, ttl: false, logging: false }) | ||
this.storage.init({ dir: path.join(persistPath, 'syntex-magichome'), forgiveParseErrors: true, ttl: false, logging: false }) | ||
.then(() => { | ||
@@ -79,0 +87,0 @@ return self.getCachedAddress() |
@@ -1,93 +0,76 @@ | ||
const LightBulb = require('./accessories/lightBulb'); | ||
const PresetSwitch = require('./accessories/presetSwitch'); | ||
const ResetSwitch = require('./accessories/resetSwitch'); | ||
const lightAgent = require('./lib/lightAgent'); | ||
const pluginName = 'homebridge-syntex-magichome'; | ||
const platformName = 'SynTexMagicHome'; | ||
const LightBulb = require('./accessories/lightBulb') | ||
const PresetSwitch = require('./accessories/presetSwitch') | ||
const ResetSwitch = require('./accessories/resetSwitch') | ||
const lightAgent = require('./lib/lightAgent') | ||
var homebridge; | ||
const pluginName = 'homebridge-syntex-magichome' | ||
const platformName = 'SynTexMagicHome' | ||
function MagicHome(log, config = {}) | ||
{ | ||
this.log = log; | ||
this.config = config; | ||
this.lights = []; | ||
this.presetSwitches = []; | ||
this.resetSwitches = []; | ||
lightAgent.setLogger(log); | ||
// Available Accessories | ||
var homebridge | ||
// Set Cache Storage Path | ||
if(homebridge) | ||
{ | ||
lightAgent.setPersistPath(homebridge.PersistPath); | ||
} | ||
function MagicHome(log, config = {}) { | ||
this.log = log | ||
this.config = config | ||
this.lights = [] | ||
this.presetSwitches = [] | ||
this.resetSwitches = [] | ||
lightAgent.setLogger(log) | ||
// Configure LightAgent | ||
if(config) | ||
{ | ||
if(config.debug) | ||
{ | ||
lightAgent.setVerbose(); | ||
} | ||
if(config.disableDiscovery) | ||
{ | ||
log('** DISABLED DISCOVERY **'); | ||
lightAgent.disableDiscovery(); | ||
} | ||
} | ||
// Set Cache Storage Path | ||
if (homebridge) { | ||
lightAgent.setPersistPath(homebridge.PersistPath) | ||
} | ||
lightAgent.startDiscovery(); | ||
// Configure LightAgent | ||
if (config) { | ||
if (config.debug) { | ||
lightAgent.setVerbose() | ||
} | ||
if (config.disableDiscovery) { | ||
log('** DISABLED DISCOVERY **') | ||
lightAgent.disableDiscovery() | ||
} | ||
} | ||
lightAgent.startDiscovery() | ||
} | ||
MagicHome.prototype = { | ||
accessories: function (callback) { | ||
homebridge.debug = this.config.debug || false | ||
if (this.config.lights != null && this.config.lights.length > 0) { | ||
this.config.lights.forEach((lightConfig) => { | ||
var newLightConfig = lightConfig | ||
newLightConfig.debug = this.config.debug || false | ||
this.lights.push(new LightBulb(newLightConfig, this.log, homebridge)) | ||
}) | ||
} | ||
accessories: function(callback) | ||
{ | ||
homebridge.debug = this.config.debug || false; | ||
if (this.config.presetSwitches != null && this.config.presetSwitches.length > 0) { | ||
this.config.presetSwitches.forEach((switchConfig) => { | ||
this.presetSwitches.push(new PresetSwitch(switchConfig, this.log, homebridge)) | ||
}) | ||
} | ||
if(this.config.lights != null && this.config.lights.length > 0) | ||
{ | ||
this.config.lights.forEach(function(lightConfig) | ||
{ | ||
var newLightConfig = lightConfig; | ||
newLightConfig.debug = /*this.config.debug || */false; | ||
this.lights.push(new LightBulb(newLightConfig, this.log, homebridge)); | ||
}) | ||
} | ||
if(this.config.presetSwitches != null && this.config.presetSwitches.length > 0) | ||
{ | ||
this.config.presetSwitches.forEach(function(switchConfig) | ||
{ | ||
this.presetSwitches.push(new PresetSwitch(switchConfig, this.log, homebridge)); | ||
}); | ||
} | ||
if(this.config.resetSwitch != null) | ||
{ | ||
this.resetSwitches.push(new ResetSwitch(this.config.resetSwitch, this.log, homebridge)); | ||
} | ||
const lightsSwitches = this.lights.concat(this.presetSwitches); | ||
const allSwitches = lightsSwitches.concat(this.resetSwitches); | ||
callback(allSwitches); | ||
} | ||
if (this.config.resetSwitch != null) { | ||
this.resetSwitches.push(new ResetSwitch(this.config.resetSwitch, this.log, homebridge)) | ||
} | ||
const lightsSwitches = this.lights.concat(this.presetSwitches) | ||
const allSwitches = lightsSwitches.concat(this.resetSwitches) | ||
callback(allSwitches) | ||
}, | ||
} | ||
function MagicHomeGlobals() {} | ||
MagicHomeGlobals.setHomebridge = (homebridgeRef) => { | ||
homebridge = homebridgeRef | ||
} | ||
MagicHomeGlobals.setHomebridge = function(homebridgeRef) | ||
{ | ||
homebridge = homebridgeRef; | ||
}; | ||
module.exports = { | ||
platform: MagicHome, | ||
globals: MagicHomeGlobals, | ||
pluginName: pluginName, | ||
platformName: platformName | ||
}; | ||
platform: MagicHome, | ||
globals: MagicHomeGlobals, | ||
pluginName: pluginName, | ||
platformName: platformName, | ||
} |
module.exports = { | ||
seven_color_cross_fade: 37, | ||
red_gradual_change: 38, | ||
green_gradual_change: 39, | ||
blue_gradual_change: 40, | ||
yellow_gradual_change: 41, | ||
cyan_gradual_change: 42, | ||
purple_gradual_change: 43, | ||
white_gradual_change: 44, | ||
red_green_cross_fade: 45, | ||
red_blue_cross_fade: 46, | ||
green_blue_cross_fade: 47, | ||
seven_color_strobe_flash: 48, | ||
red_strobe_flash: 49, | ||
green_strobe_flash: 50, | ||
blue_stobe_flash: 51, | ||
yellow_strobe_flash: 52, | ||
cyan_strobe_flash: 53, | ||
purple_strobe_flash: 54, | ||
white_strobe_flash: 55, | ||
seven_color_jumping: 56 | ||
}; | ||
seven_color_cross_fade: 37, | ||
red_gradual_change: 38, | ||
green_gradual_change: 39, | ||
blue_gradual_change: 40, | ||
yellow_gradual_change: 41, | ||
cyan_gradual_change: 42, | ||
purple_gradual_change: 43, | ||
white_gradual_change: 44, | ||
red_green_cross_fade: 45, | ||
red_blue_cross_fade: 46, | ||
green_blue_cross_fade: 47, | ||
seven_color_strobe_flash: 48, | ||
red_strobe_flash: 49, | ||
green_strobe_flash: 50, | ||
blue_stobe_flash: 51, | ||
yellow_strobe_flash: 52, | ||
cyan_strobe_flash: 53, | ||
purple_strobe_flash: 54, | ||
white_strobe_flash: 55, | ||
seven_color_jumping: 56, | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
100307
3
16
704
1
3
3