Socket
Socket
Sign inDemoInstall

homebridge-syntex-magichome

Package Overview
Dependencies
Maintainers
1
Versions
420
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-syntex-magichome - npm Package Compare versions

Comparing version 1.0.0-b5 to 1.0.0-b50

logger.js

106

package.json
{
"name": "homebridge-syntex-magichome",
"version": "1.0.0-b5",
"description": "Homebridge Plugin for MagicHome LED Strips with preset scenes",
"main": "index.js",
"author": {
"name": "SynTexDZN"
},
"engines": {
"homebridge": ">=0.4.30",
"node": ">=9.11.2"
},
"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",
"magic",
"home",
"wifi",
"zengge",
"led",
"strips",
"lighbulb",
"blub",
"preset",
"magichome",
"scene",
"automation",
"fade",
"strobe",
"party",
"color-cycle"
],
"homepage": "https://github.com/SynTexDZN/homebridge-syntex-webhooks#readme",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/SynTexDZN/homebridge-syntex-magichome.git"
},
"bugs": {
"url": "https://github.com/SynTexDZN/homebridge-syntex-magichome/issues"
},
"license": "ISC"
"name": "homebridge-syntex-magichome",
"version": "1.0.0-b50",
"description": "Homebridge Plugin for MagicHome LED Strips with preset scenes",
"main": "index.js",
"author": {
"name": "SynTexDZN"
},
"engines": {
"homebridge": ">=0.4.30",
"node": ">=9.11.2"
},
"dependencies": {
"json-fs-store": "^1.0.1",
"request": "^2.88.0",
"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",
"magic",
"home",
"wifi",
"zengge",
"led",
"strips",
"lighbulb",
"blub",
"preset",
"magichome",
"scene",
"automation",
"fade",
"strobe",
"party",
"color-cycle"
],
"homepage": "https://github.com/SynTexDZN/homebridge-syntex-webhooks#readme",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/SynTexDZN/homebridge-syntex-magichome.git"
},
"bugs": {
"url": "https://github.com/SynTexDZN/homebridge-syntex-magichome/issues"
},
"license": "ISC"
}
# homebridge-magichome-platform
[![NPM](https://nodei.co/npm/homebridge-magichome-platform.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/homebridge-magichome-platform/)
[![npm](https://img.shields.io/npm/dm/homebridge-magichome-platform.svg)](https://www.npmjs.com/package/homebridge-magichome-platform)
[![npm](https://img.shields.io/npm/v/homebridge-magichome-platform.svg)](https://www.npmjs.com/package/homebridge-magichome-platform)
[![CircleCI](https://circleci.com/gh/sahilchaddha/homebridge-magichome-platform.svg?style=svg)](https://circleci.com/gh/sahilchaddha/homebridge-magichome-platform)
**A Homebridge plugin for devices running fade/strobe effects on the Magic Home Wi-Fi system.**

@@ -56,6 +49,2 @@

### Demo
![Demo](https://raw.githubusercontent.com/sahilchaddha/homebridge-magichome-platform/master/demo.gif)
## Compatible Devices

@@ -145,22 +134,2 @@

Setting Device `timeout` to 0, will disable polling device for status update.
## Lint
```shell
$ npm run lint
```
## Need Help ?
Get Slack Invite => `https://slackin-znyruquwmv.now.sh/`
Slack Channel => `https://homebridgeteam.slack.com/messages/homebridge-magichome`
Slack User => `@sahilchaddha`
### Author
Sahil Chaddha
mail@sahilchaddha.com
Setting Device `timeout` to 0, will disable polling device for status update.

@@ -45,4 +45,4 @@ const cp = require('child_process');

exec(cmd, function(err, stdOut)
{
exec(cmd, (err, stdOut) => {
if(self.homebridge.debug)

@@ -49,0 +49,0 @@ {

@@ -16,7 +16,8 @@ const convert = require('color-convert');

this.timeout = config.timeout != null ? config.timeout : 60000;
setTimeout(() => {
setTimeout(function()
{
this.updateState();
}.bind(this), 3000);
}, 3000)
}

@@ -45,3 +46,3 @@

return [lightbulbService];
}
}

@@ -73,7 +74,8 @@ sendCommand(command, callback)

{
if(this.timeout === 0) return;
if (this.timeout === 0) return;
setTimeout(function()
{
setTimeout(() => {
this.updateState();
}, this.timeout);

@@ -88,4 +90,4 @@ }

self.getState(function(settings)
{
self.getState((settings) => {
self.isOn = settings.on;

@@ -96,16 +98,9 @@ self.color = settings.color;

self.services[0].getCharacteristic(this.homebridge.Characteristic.On)
.updateValue(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);
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();
})
});
}

@@ -115,4 +110,4 @@

{
this.sendCommand('-i', function(error, stdout)
{
this.sendCommand('-i', (error, stdout) => {
var settings = {

@@ -138,5 +133,5 @@ on: false,

const rgbColors = str.split(',').map(function(item)
{
return item.trim();
const rgbColors = str.split(',').map((item) => {
return item.trim()
});

@@ -153,4 +148,4 @@

callback(settings)
});
callback(settings);
})
}

@@ -167,4 +162,4 @@

this.sendCommand(value ? '--on' : '--off', function()
{
this.sendCommand(value ? '--on' : '--off', () => {
self.isOn = value;

@@ -227,5 +222,5 @@ callback();

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.logMessage('Setting New Color From ', this.ip, color, converted);
this.sendCommand(base + converted[0] + ',' + converted[1] + ',' + converted[2]);

@@ -232,0 +227,0 @@ }

@@ -1,4 +0,4 @@

const Accessory = require('./base')
const preset = require('../presets')
const emitter = require('../lib/emitter')
const Accessory = require('./base');
const preset = require('../presets');
const emitter = require('../lib/emitter');

@@ -33,4 +33,4 @@ const PresetSwitch = class extends Accessory

emitter.on('MagicHomePresetTurnedOn', function(presetName)
{
emitter.on('MagicHomeSynTexPresetTurnedOn', (presetName) => {
if(presetName !== self.name)

@@ -40,3 +40,3 @@ {

}
});
})
}

@@ -63,2 +63,3 @@

this.isOn = newState;
const self = this;

@@ -69,10 +70,10 @@

// Turn Off Other Running Scenes
emitter.emit('MagicHomePresetTurnedOn', self.name);
emitter.emit('MagicHomeSynTexPresetTurnedOn', self.name);
self.sendCommand('--on', function()
{
setTimeout(function()
{
self.sendCommand('-p ' + self.sceneValue + ' ' + self.speed, function()
{
self.sendCommand('--on', () => {
setTimeout(() => {
self.sendCommand('-p ' + self.sceneValue + ' ' + self.speed, () => {
callback();

@@ -88,8 +89,8 @@ });

Object.keys(self.config.ips).forEach(function(ip)
{
const newPromise = new Promise(function(resolve)
{
self.executeCommand(ip, ' -c ' + self.config.ips[ip], function()
{
Object.keys(self.config.ips).forEach((ip) => {
const newPromise = new Promise((resolve) => {
self.executeCommand(ip, ' -c ' + self.config.ips[ip], () => {
resolve();

@@ -102,10 +103,10 @@ });

Promise.all(promiseArray).then(function()
{
Promise.all(promiseArray).then(() => {
if(self.shouldTurnOff)
{
setTimeout(function()
{
self.sendCommand('--off', function()
{
setTimeout(() => {
self.sendCommand('--off', () => {
callback();

@@ -119,3 +120,3 @@ });

}
})
});
}

@@ -127,4 +128,3 @@ }

this.isOn = newValue;
this.services[0].getCharacteristic(this.homebridge.Characteristic.On)
.updateValue(this.isOn);
this.services[0].getCharacteristic(this.homebridge.Characteristic.On).updateValue(this.isOn);
}

@@ -131,0 +131,0 @@

@@ -1,3 +0,3 @@

const Accessory = require('./base')
const emitter = require('../lib/emitter')
const Accessory = require('./base');
const emitter = require('../lib/emitter');

@@ -34,12 +34,12 @@ const ResetSwitch = class extends Accessory

emitter.emit('MagicHomePresetTurnedOn', self.name);
emitter.emit('MagicHomeSynTexPresetTurnedOn', self.name);
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()
{
Object.keys(self.config.ips).forEach((ip) => {
const newPromise = new Promise((resolve) => {
self.executeCommand(ip, ' -c ' + self.config.ips[ip], () => {
resolve();

@@ -50,17 +50,17 @@ });

promiseArray.push(newPromise);
})
});
Promise.all(promiseArray).then(function()
{
setTimeout(function()
{
self.sendCommand('--off', function()
{
Promise.all(promiseArray).then(() => {
setTimeout(() => {
self.sendCommand('--off', () => {
callback();
});
}, 3000);
}).then(function()
{
setTimeout(function()
{
}).then(() => {
setTimeout(() => {
self.updateState();

@@ -67,0 +67,0 @@ }, 2000);

const cp = require('child_process')
const path = require('path')
const cacheKey = 'magicHome_cache'
const cacheKey = 'magicHomeSynTex_cache'
const spawn = cp.spawn

@@ -9,166 +9,232 @@

constructor() {
this.cachedAddress = {}
this.pollingInterval = 300 * 1000 // 5 Minutes
this.logger = null
this.storage = null
this.hasDiscoveryStarted = false
this.isVerbose = false
this.shouldDiscover = true
}
constructor()
{
this.cachedAddress = {};
this.pollingInterval = 300 * 1000;
this.logger = null;
this.storage = null;
this.hasDiscoveryStarted = false;
this.isVerbose = false;
this.shouldDiscover = true;
}
getCachedAddress() {
if (!this.storage) {
return {}
}
this.log('Getting Bulbs from Cache')
return this.storage.getItem(cacheKey)
.then((data) => {
var devices = {}
if (data) {
try {
devices = JSON.parse(data)
} catch (error) {
devices = {}
}
}
this.log(' ** Fetched Lights from Cache **')
this.log(devices)
return devices
})
}
getCachedAddress()
{
if(!this.storage)
{
return {};
}
saveAddress(res) {
if (this.storage) {
const data = JSON.stringify(res)
this.log('Saving Lights')
this.log(data)
this.log('Getting Bulbs from Cache');
this.storage.setItem(cacheKey, data)
.then(() => {
this.log('Lights Saved.')
})
}
}
return this.storage.getItem(cacheKey).then((data) => {
disableDiscovery() {
this.shouldDiscover = false
}
var devices = {};
startDiscovery() {
if (!this.hasDiscoveryStarted && this.shouldDiscover) {
this.hasDiscoveryStarted = true
this.getDevices()
}
}
if(data)
{
try
{
devices = JSON.parse(data);
}
catch(error)
{
devices = {};
}
}
setLogger(logger) {
this.logger = logger
}
this.log(' ** Fetched Lights from Cache **');
this.logger.debug(devices);
return devices;
});
}
setVerbose() {
this.isVerbose = true
}
saveAddress(res)
{
if(this.storage)
{
const data = JSON.stringify(res);
setPersistPath(persistPath) {
if (!this.storage) {
this.storage = require('node-persist')
const self = this
this.storage.init({ dir: path.join(persistPath, 'magichome-platform'), forgiveParseErrors: true, ttl: false, logging: false })
.then(() => {
return self.getCachedAddress()
})
.then((devices) => {
self.cachedAddress = devices
})
}
}
this.log('Saving Lights');
this.logger.debug(data);
log(message) {
if (this.logger && this.isVerbose) {
this.logger(message)
}
}
this.storage.setItem(cacheKey, data).then(() => {
parseDevices(res) {
if (!res) {
return this.cachedAddress
}
if (res.length > 0) {
const lines = res.split('\n')
if (lines.length < 3) {
return this.cachedAddress
}
// Format Response
var devices = {}
lines.splice(0, 1)
lines.splice(-1, 1)
lines.forEach((element) => {
const mappedAddr = element.split('=')
devices[mappedAddr[0]] = mappedAddr[1]
devices[mappedAddr[1]] = mappedAddr[1]
})
var newDevices = this.cachedAddress
Object.keys(devices).forEach((element) => {
newDevices[element] = devices[element]
})
// Cache IPS
this.saveAddress(newDevices)
return newDevices
}
return this.cachedAddress
}
this.log('Lights Saved.');
});
}
}
getCachedDevice(addr) {
var address = ''
if (this.cachedAddress[addr] && this.shouldDiscover) {
address = this.cachedAddress[addr]
} else {
address = addr
}
return address + ' '
}
disableDiscovery()
{
this.shouldDiscover = false;
}
getDevices() {
const self = this
const cmd = path.join(__dirname, '../flux_led.py')
self.log('Discovering Devices')
this.proc = spawn(cmd, ['-s'])
this.proc.stdout.on('data', (data) => {
const newData = '' + data
self.log(newData)
self.cachedAddress = self.parseDevices(newData)
})
startDiscovery()
{
if(!this.hasDiscoveryStarted && this.shouldDiscover)
{
this.hasDiscoveryStarted = true;
this.getDevices();
}
}
this.proc.stderr.on('data', (data) => {
self.log('Error : ' + data)
})
setLogger(logger)
{
this.logger = logger;
}
this.proc.on('close', () => {
self.log('Discovery Finished');
self.rediscoverLights()
})
}
setVerbose()
{
this.isVerbose = true;
}
rediscoverLights() {
this.proc = null
this.log(this.cachedAddress)
setTimeout(this.getDevices.bind(this), this.pollingInterval)
}
setPersistPath(persistPath)
{
if(!this.storage)
{
this.storage = require('node-persist');
getAddress(address) {
var ips = ''
if (typeof address === 'string') {
ips = this.getCachedDevice(address)
} else if (address.length > 0) {
address.forEach((addr) => {
ips += this.getCachedDevice(addr)
})
}
return ips
}
const self = this;
this.storage.init({ dir: path.join(persistPath, 'syntex-magichome'), forgiveParseErrors: true, ttl: false, logging: false }).then(() => {
return self.getCachedAddress();
}).then((devices) => {
self.cachedAddress = devices;
});
}
}
log(message)
{
if(this.logger && this.isVerbose)
{
//this.logger(message);
this.logger.log('info', 'bridge', 'Bridge', message);
}
}
parseDevices(res)
{
if(!res)
{
return this.cachedAddress;
}
if(res.length > 0)
{
const lines = res.split('\n');
if(lines.length < 3)
{
return this.cachedAddress;
}
// Format Response
var devices = {};
lines.splice(0, 1);
lines.splice(-1, 1);
lines.forEach((element) => {
const mappedAddr = element.split('=');
devices[mappedAddr[0]] = mappedAddr[1];
devices[mappedAddr[1]] = mappedAddr[1];
});
var newDevices = this.cachedAddress;
Object.keys(devices).forEach((element) => {
newDevices[element] = devices[element];
});
// Cache IPS
this.saveAddress(newDevices);
return newDevices;
}
return this.cachedAddress;
}
getCachedDevice(addr)
{
var address = '';
if(this.cachedAddress[addr] && this.shouldDiscover)
{
address = this.cachedAddress[addr];
}
else
{
address = addr;
}
return address + ' ';
}
getDevices()
{
const self = this;
const cmd = path.join(__dirname, '../flux_led.py');
self.log('Discovering Devices');
this.proc = spawn(cmd, ['-s']);
this.proc.stdout.on('data', (data) => {
const newData = '' + data;
self.logger.debug(newData);
self.cachedAddress = self.parseDevices(newData);
});
this.proc.stderr.on('data', (data) => {
self.logger.log('error', 'bridge', 'Bridge', 'Error : ' + data)
});
this.proc.on('close', () => {
self.log('Discovery Finished');
self.rediscoverLights();
});
}
rediscoverLights()
{
this.proc = null;
this.logger.debug(this.cachedAddress);
setTimeout(this.getDevices.bind(this), this.pollingInterval);
}
getAddress(address)
{
var ips = '';
if(typeof address === 'string')
{
ips = this.getCachedDevice(address);
}
else if (address.length > 0)
{
address.forEach((addr) => {
ips += this.getCachedDevice(addr);
});
}
return ips;
}
}
const agent = new LightAgent()
const agent = new LightAgent();
module.exports = agent
module.exports = agent;

@@ -9,5 +9,8 @@ const LightBulb = require('./accessories/lightBulb');

var logger = require('../logger');
var server = require('../webserver');
var homebridge;
function MagicHome(log, config = {})
function MagicHome(log, config = {}, api)
{

@@ -19,4 +22,104 @@ this.log = log;

this.resetSwitches = [];
lightAgent.setLogger(log);
this.devices = config['accessories'] || [];
this.cacheDirectory = config['cache_directory'] || './SynTex';
this.logDirectory = config['log_directory'] || './SynTex/log';
this.port = config['port'] || 1712;
logger.create('SynTexMagicHome', this.logDirectory, api.user.storagePath());
server.SETUP('SynTexMagicHome', logger, this.port);
server.addPage('/test', (response, params) => {
if(params.id)
{
if(Array.isArray(params.id))
{
response.write('Mehrere IDs!');
}
else
{
response.write('Deine ID lautet: ' + params.id);
}
}
else
{
response.write('Keine ID!');
}
response.end();
});
server.addPage('/set-device', (response, params) => {
if(params.ip)
{
var found = false;
for(var i = 0; i < this.lights.length; i++)
{
if(this.lights[i].ip == params.ip)
{
found = true;
if(params.power)
{
this.lights[i].setPowerState(params.power == 'true' ? true : false, () => {});
}
if(params.hue)
{
this.lights[i].setHue(params.hue, () => {});
}
if(params.saturation)
{
this.lights[i].setSaturation(params.saturation, () => {});
}
if(params.brightness)
{
this.lights[i].setBrightness(params.brightness, () => {});
}
}
}
response.write(found ? 'Success' : 'Error');
}
else
{
response.write('Keine IP angegeben!');
}
response.end();
});
server.addPage('/get-device', (response, params) => {
if(params.ip)
{
var found = null;
for(var i = 0; i < this.lights.length; i++)
{
if(this.lights[i].ip == params.ip)
{
found = this.lights[i].isOn + ':' + this.lights[i].color.H + ':' + this.lights[i].color.S + ':' + this.lights[i].color.L;
}
}
response.write(found != null ? found : 'Error');
}
else
{
response.write('Keine IP angegeben!');
}
response.end();
});
lightAgent.setLogger(logger);
// Set Cache Storage Path

@@ -37,3 +140,3 @@ if(homebridge)

{
log('** DISABLED DISCOVERY **');
logger.log('info', 'bridge', 'Bridge', '** DISABLED DISCOVERY **');
lightAgent.disableDiscovery();

@@ -44,2 +147,9 @@ }

lightAgent.startDiscovery();
/*
DeviceManager.SETUP(logger, this.cacheDirectory);
Automations.SETUP(logger, this.cacheDirectory, DeviceManager).then(function () {
restart = false;
});
*/
}

@@ -55,12 +165,10 @@

{
this.config.lights.forEach(function(lightConfig)
{
this.config.lights.forEach((lightConfig) => {
var newLightConfig = lightConfig;
console.log(this);
newLightConfig.debug = this.config.debug || false;
this.lights.push(new LightBulb(newLightConfig, this.log, homebridge));
}.bind(this));
});
}

@@ -70,4 +178,4 @@

{
this.config.presetSwitches.forEach(function(switchConfig)
{
this.config.presetSwitches.forEach((switchConfig) => {
this.presetSwitches.push(new PresetSwitch(switchConfig, this.log, homebridge));

@@ -74,0 +182,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc