homebridge-syntex-magichome
Advanced tools
Comparing version 1.2.4-b2 to 1.2.4-b20
@@ -44,3 +44,3 @@ let DeviceManager = require('./src/device-manager'); | ||
DeviceManager = new DeviceManager(this.logger); | ||
DeviceManager = new DeviceManager(this); | ||
@@ -47,0 +47,0 @@ this.loadAccessories(); |
{ | ||
"name": "homebridge-syntex-magichome", | ||
"version": "1.2.4-b2", | ||
"version": "1.2.4-b20", | ||
"description": "Homebridge Plugin for MagicHome LED Strips with preset scenes", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"color-convert": "^1.5.0", | ||
"homebridge-syntex-dynamic-platform": "1.0.8-b12" | ||
"homebridge-syntex-dynamic-platform": "1.0.8-b35" | ||
}, | ||
@@ -18,0 +18,0 @@ "keywords": [ |
@@ -178,3 +178,3 @@ # Homebridge SynTex MagicHome | ||
- `function` is always `light` | ||
- `ip` use a normal ip or a mac address. | ||
- `ip` use a normal IP or a MAC address. | ||
@@ -181,0 +181,0 @@ ### Preset Switch Config |
@@ -5,3 +5,3 @@ const { ColoredBulbService } = require('homebridge-syntex-dynamic-platform'); | ||
module.exports = class LightBulb extends ColoredBulbService | ||
module.exports = class SynTexColoredBulbService extends ColoredBulbService | ||
{ | ||
@@ -16,9 +16,2 @@ constructor(homebridgeAccessory, deviceConfig, serviceConfig, manager) | ||
this.tempState = { | ||
value : this.value, | ||
hue : this.hue, | ||
saturation : this.saturation, | ||
brightness : this.brightness | ||
}; | ||
this.DeviceManager = manager.DeviceManager; | ||
@@ -32,4 +25,2 @@ this.EventManager = manager.platform.EventManager; | ||
this.running = false; | ||
setInterval(() => { | ||
@@ -74,9 +65,4 @@ | ||
if(state.value != null && !isNaN(state.value)) | ||
if(state.value != null && !isNaN(state.value) && (!super.hasState('value') || this.value != state.value)) | ||
{ | ||
if(!super.hasState('value') || this.value != state.value) | ||
{ | ||
changed = true; | ||
} | ||
this.value = this.tempState.value = state.value; | ||
@@ -86,11 +72,8 @@ | ||
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value)); | ||
changed = true; | ||
} | ||
if(state.hue != null && !isNaN(state.hue)) | ||
if(state.hue != null && !isNaN(state.hue) && (!super.hasState('hue') || this.hue != state.hue)) | ||
{ | ||
if(!super.hasState('hue') || this.hue != state.hue) | ||
{ | ||
changed = true; | ||
} | ||
this.hue = this.tempState.hue = state.hue; | ||
@@ -100,11 +83,8 @@ | ||
() => this.service.getCharacteristic(this.Characteristic.Hue).updateValue(state.hue)); | ||
changed = true; | ||
} | ||
if(state.saturation != null && !isNaN(state.saturation)) | ||
if(state.saturation != null && !isNaN(state.saturation) && (!super.hasState('saturation') || this.saturation != state.saturation)) | ||
{ | ||
if(!super.hasState('saturation') || this.saturation != state.saturation) | ||
{ | ||
changed = true; | ||
} | ||
this.saturation = this.tempState.saturation = state.saturation; | ||
@@ -114,11 +94,8 @@ | ||
() => this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(state.saturation)); | ||
changed = true; | ||
} | ||
if(state.brightness != null && !isNaN(state.brightness)) | ||
if(state.brightness != null && !isNaN(state.brightness) && (!super.hasState('brightness') || this.brightness != state.brightness)) | ||
{ | ||
if(!super.hasState('brightness') || this.brightness != state.brightness) | ||
{ | ||
changed = true; | ||
} | ||
this.brightness = this.tempState.brightness = state.brightness; | ||
@@ -128,2 +105,4 @@ | ||
() => this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness)); | ||
changed = true; | ||
} | ||
@@ -158,3 +137,3 @@ | ||
{ | ||
this.DeviceManager.getDevice(this, (state) => { | ||
this.DeviceManager.getState(this, (state) => { | ||
@@ -202,3 +181,3 @@ if(state.value != null && !isNaN(state.value)) | ||
{ | ||
this.DeviceManager.getDevice(this, (state) => { | ||
this.DeviceManager.getState(this, (state) => { | ||
@@ -245,3 +224,3 @@ if(state.hue != null && !isNaN(state.hue)) | ||
{ | ||
this.DeviceManager.getDevice(this, (state) => { | ||
this.DeviceManager.getState(this, (state) => { | ||
@@ -288,3 +267,3 @@ if(state.saturation != null && !isNaN(state.saturation)) | ||
{ | ||
this.DeviceManager.getDevice(this, (state) => { | ||
this.DeviceManager.getState(this, (state) => { | ||
@@ -343,3 +322,3 @@ if(state.brightness != null && !isNaN(state.brightness)) | ||
if(callback) | ||
if(callback != null) | ||
{ | ||
@@ -396,3 +375,3 @@ callback(failed); | ||
if(callback) | ||
if(callback != null) | ||
{ | ||
@@ -428,3 +407,3 @@ callback(failed); | ||
}, (resolve) => { | ||
if(callback != null) | ||
@@ -431,0 +410,0 @@ { |
@@ -5,3 +5,3 @@ const { SwitchService } = require('homebridge-syntex-dynamic-platform'); | ||
module.exports = class PresetSwitch extends SwitchService | ||
module.exports = class SynTexPresetSwitchService extends SwitchService | ||
{ | ||
@@ -8,0 +8,0 @@ constructor(homebridgeAccessory, deviceConfig, serviceConfig, manager) |
const { SwitchService } = require('homebridge-syntex-dynamic-platform'); | ||
module.exports = class SceneSwitch extends SwitchService | ||
module.exports = class SynTexSceneSwitchService extends SwitchService | ||
{ | ||
@@ -5,0 +5,0 @@ constructor(homebridgeAccessory, deviceConfig, serviceConfig, manager) |
@@ -5,8 +5,10 @@ const cp = require('child_process'), path = require('path'), convert = require('color-convert'); | ||
{ | ||
constructor(logger) | ||
constructor(platform) | ||
{ | ||
this.logger = logger; | ||
this.logger = platform.logger; | ||
this.TypeManager = platform.TypeManager; | ||
} | ||
getDevice(service, callback) | ||
getState(service, callback) | ||
{ | ||
@@ -17,20 +19,23 @@ this.executeCommand(service.ip, '-i', (offline, output) => { | ||
var power = output.match(/\] ON /g), | ||
colors = output.match(/\(.*,.*,.*\)/g); | ||
if(!offline) | ||
{ | ||
var power = output.match(/\] ON /g), | ||
colors = output.match(/\(.*,.*,.*\)/g); | ||
state.value = (Array.isArray(power) && power.length > 0); | ||
state.value = (Array.isArray(power) && power.length > 0); | ||
if(Array.isArray(colors) && colors.length > 0) | ||
{ | ||
var converted = colors[0].slice(1).slice(0, -1).split(',').map((item) => item.trim()); | ||
if(Array.isArray(colors) && colors.length > 0) | ||
{ | ||
var converted = colors[0].slice(1).slice(0, -1).split(',').map((item) => item.trim()); | ||
converted = service.setChannels(converted); | ||
converted = convert.rgb.hsv(converted); | ||
converted = service.setChannels(converted); | ||
converted = convert.rgb.hsv(converted); | ||
if(converted != null) | ||
{ | ||
state.hue = converted[0]; | ||
state.saturation = converted[1]; | ||
state.brightness = converted[2]; | ||
if(converted != null) | ||
{ | ||
state.hue = converted[0]; | ||
state.saturation = converted[1]; | ||
state.brightness = converted[2]; | ||
} | ||
} | ||
@@ -45,4 +50,54 @@ } | ||
getStates(ips, callback) | ||
{ | ||
this.executeCommand(ips, '-i', (error, output) => { | ||
var data = output.split('\n'), states = {}; | ||
data.pop(); | ||
this.logger.debug(data); | ||
for(const i in data) | ||
{ | ||
var ip = data[i].match(/([0-9]*\.){3}[0-9]*|([A-F]|[0-9]){12}|(([0-9]|[a-f])*:){7}([0-9]|[a-f])*/g); | ||
if(Array.isArray(ip) && ip.length > 0) | ||
{ | ||
var offline = data[i].includes('Unable to connect to bulb'), state = {}; | ||
ip = ip[0]; | ||
if(!offline) | ||
{ | ||
var power = data[i].match(/\] ON /g), | ||
colors = data[i].match(/\(.*,.*,.*\)/g); | ||
state.value = (Array.isArray(power) && power.length > 0); | ||
if(Array.isArray(colors) && colors.length > 0) | ||
{ | ||
var converted = colors[0].slice(1).slice(0, -1).split(',').map((item) => item.trim()); | ||
state.red = converted[0]; | ||
state.green = converted[1]; | ||
state.blue = converted[2]; | ||
} | ||
} | ||
state.connection = !offline; | ||
states[ip] = state; | ||
} | ||
} | ||
callback(states); | ||
}, false); | ||
} | ||
refreshAccessories(accessories) | ||
{ | ||
var ips = []; | ||
this.logger.debug('%device_refresh% ..'); | ||
@@ -52,31 +107,49 @@ | ||
{ | ||
if(Array.isArray(accessory[1].services)) | ||
for(const service of accessory[1].service) | ||
{ | ||
for(const i in accessory[1].services) | ||
if(this.TypeManager.letterToType(service.letters) == 'rgb' && service.ip != null && !ips.includes(service.ip)) | ||
{ | ||
if(accessory[1].services[i].type == 'rgb' || accessory[1].services[i].type == 'rgbw') | ||
{ | ||
this.getDevice(accessory[1].service[parseInt(i) + 1], (state) => { | ||
accessory[1].service[parseInt(i) + 1].setConnectionState(state.connection, | ||
() => accessory[1].service[parseInt(i) + 1].updateState(state), true); | ||
}); | ||
} | ||
ips.push(service.ip); | ||
} | ||
} | ||
else if(accessory[1].services instanceof Object) | ||
} | ||
this.getStates(ips.join(' '), (states) => { | ||
for(const ip in states) | ||
{ | ||
if(accessory[1].services.type == 'rgb' || accessory[1].services.type == 'rgbw') | ||
for(const accessory of accessories) | ||
{ | ||
this.getDevice(accessory[1].service[1], (state) => { | ||
accessory[1].service[1].setConnectionState(state.connection, | ||
() => accessory[1].service[1].updateState(state), true); | ||
}); | ||
for(const service of accessory[1].service) | ||
{ | ||
if(this.TypeManager.letterToType(service.letters) == 'rgb' && service.ip == ip) | ||
{ | ||
if(service.setConnectionState != null && service.updateState != null) | ||
{ | ||
var converted = service.setChannels([states[ip].red, states[ip].green, states[ip].blue]); | ||
converted = convert.rgb.hsv(converted); | ||
if(converted != null) | ||
{ | ||
delete states[ip].red; | ||
delete states[ip].green; | ||
delete states[ip].blue; | ||
states[ip].hue = converted[0]; | ||
states[ip].saturation = converted[1]; | ||
states[ip].brightness = converted[2]; | ||
} | ||
service.setConnectionState(states[ip].connection, | ||
() => service.updateState(states[ip]), true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
executeCommand(address, command, callback) | ||
executeCommand(address, command, callback, verbose = true) | ||
{ | ||
@@ -88,3 +161,6 @@ const exec = cp.exec; | ||
this.logger.debug(stdOut); | ||
if(verbose) | ||
{ | ||
this.logger.debug(stdOut); | ||
} | ||
@@ -96,3 +172,3 @@ if(err) | ||
if(callback) | ||
if(callback != null) | ||
{ | ||
@@ -99,0 +175,0 @@ callback(err != null || (stdOut != null && (stdOut.includes('Errno 113') || stdOut.includes('Unable to connect to bulb'))), stdOut); |
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
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
121603
926
+ Addedcharenc@0.0.2(transitive)
+ Addedcrypt@0.0.2(transitive)
+ Addedhomebridge-syntex-dynamic-platform@1.0.8-b35(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedmd5@2.3.0(transitive)
+ Addedsyntex-automation@1.2.1-b11(transitive)
+ Addedsyntex-basic@1.0.0-b16(transitive)
+ Addedsyntex-filesystem@1.0.3-b8(transitive)
+ Addedsyntex-logger@1.0.9-b2(transitive)
+ Addedsyntex-webserver@1.1.1-b4(transitive)
- Removedaxios@0.21.4(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedhomebridge-syntex-dynamic-platform@1.0.8-b12(transitive)
- Removedsyntex-automation@1.2.1-b1(transitive)
- Removedsyntex-filesystem@1.0.2-b11.0.3-b1(transitive)
- Removedsyntex-logger@1.0.9-b1(transitive)
- Removedsyntex-webserver@1.1.1-b2(transitive)