homebridge-syntex-magichome
Advanced tools
Comparing version 1.2.3-b9 to 1.2.3
@@ -21,2 +21,3 @@ { | ||
"type": "rgb", | ||
"pins": "rgb", | ||
"function": "light", | ||
@@ -33,2 +34,3 @@ "ip": "DC4F22C5D4E1" | ||
"type": "rgbw", | ||
"pins": "grb", | ||
"function": "light", | ||
@@ -35,0 +37,0 @@ "ip": "192.168.1.112" |
{ | ||
"name": "homebridge-syntex-magichome", | ||
"version": "1.2.3-b9", | ||
"version": "1.2.3", | ||
"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.7-b67" | ||
"homebridge-syntex-dynamic-platform": "1.0.8-b6" | ||
}, | ||
@@ -18,0 +18,0 @@ "keywords": [ |
172
README.md
@@ -41,4 +41,4 @@ # Homebridge SynTex MagicHome | ||
- `sudo mkdir -p /var/homebridge/SynTex/` *( create the directory )* | ||
- `sudo chmod -R 777 /var/homebridge/SynTex/` *( permissions for many processes )* | ||
- `sudo chown -R homebridge /var/homebridge/SynTex/` *( permissions only for homebridge )* | ||
- `sudo chmod 777 -R homebridge /var/homebridge/SynTex/` *( permissions for many processes )* | ||
@@ -65,2 +65,3 @@ ```json | ||
"type": "rgb", | ||
"pins": "rgb", | ||
"function": "light", | ||
@@ -77,2 +78,3 @@ "ip": "DC4F22C5D4E1" | ||
"type": "rgbw", | ||
"pins": "grb", | ||
"function": "light", | ||
@@ -169,4 +171,4 @@ "ip": "192.168.1.100" | ||
### Accessory Config | ||
- Every device needs these parameters: `id`, `name` and `services` *( required )* | ||
- `id` has to be a `random unique text` *( no duplicates! )* | ||
- Every accessory needs these parameters: `id`, `name` and `services` *( required )* | ||
- `id` has to be either a `real mac address` or another `random unique text` *( no duplicates! )* | ||
- `name` could be anything. | ||
@@ -176,11 +178,12 @@ - `services` choose a device config from below. | ||
### Light Config | ||
- `name` could be anything. | ||
- `type` must be either `rgb` / `rgbw` *( based on your device: look below )* | ||
- `pins` can change the order of your pin setup `rgb` / `grb` / `brg` *( every possible combination )* | ||
- `function` is always `light` | ||
- `name` could be anything. | ||
- `ip` use a normal ip or a mac address. | ||
### Preset Switch Config | ||
- `name` could be anything. | ||
- `type` must be a `switch` *( for preset and reset switches )* | ||
- `function` is always `preset-switch` | ||
- `name` could be anything. | ||
- `ips` must be a key-value object where `key` is MagicHome LED IP Address `192.168.1.100` or `DC4F22C5XXXX` MAC Address and `value` is the default rgb color of the light `"255,255,255" ( white )` | ||
@@ -191,5 +194,5 @@ - `preset` is the name of the preset you want to use for the effect *( see `Available Presets Scenes` below )* | ||
### Scene Switch Config | ||
- `name` could be anything. | ||
- `type` must be a `switch` *( for preset and reset switches )* | ||
- `function` is always `scene-switch` | ||
- `name` could be anything. | ||
- `ips` must be a key-value object where `key` is MagicHome LED IP Address `192.168.1.100` or `DC4F22C5XXXX` MAC Address and `value` is the default rgb color of the light `"255,255,255" ( white )` | ||
@@ -211,7 +214,7 @@ | ||
## Update MagicHome Devices | ||
## Update MagicHome Device | ||
1. Open `http://` **Bridge IP** `/devices?id=` **Device ID** `&value=` **New Value** | ||
2. Insert the `Bridge IP` and `Device ID` | ||
3. For the `New Value` you can type this pattern: | ||
- For all devices: `true` / `false` *( colored light, preset switch, reset switch )* | ||
- For boolean devices: `true` / `false` *( colored light, preset switch, reset switch )* | ||
- For colored lights add `&hue=` **New Hue** or `&saturation=` **New Saturation** or `&brightness=` **New Brightness** *( have to be numbers )* | ||
@@ -222,7 +225,7 @@ - For accessories with multiple service types add `&type=` **SERVICETYPE** | ||
**Example:** `http://homebridge.local:1712/devices?id=ABCDEF1234567890&value=true&hue=4&saturation=100&brightness=100`\ | ||
*( Updates the value and hue, saturation and brightness of `ABCDEF1234567890` to `turned on, orange color, 100% saturation, 100% brightness` for example )* | ||
**Example:** `http://homebridge.local:1712/devices?id=ABCDEF1234567890&type=rgb&counter=0&value=true&hue=4&saturation=100&brightness=100`\ | ||
*( Updates the value, hue, saturation and brightness of `ABCDEF1234567890` to `turned on, orange color, 100% saturation, 100% brightness` for example )* | ||
## Read MagicHome Device Values | ||
## Read MagicHome Device | ||
1. Open `http://` **Bridge IP** `/devices?id=` **Device ID** | ||
@@ -235,3 +238,3 @@ 2. Insert the `Bridge IP` and `Device ID` | ||
**Example:** `http://homebridge.local:1712/devices?id=ABCDEF1234567890`\ | ||
*( Reads the value of `ABCDEF1234567890` for example )* | ||
*( Reads the state of `ABCDEF1234567890` for example )* | ||
@@ -264,22 +267,57 @@ | ||
"active": true, | ||
"trigger": [ | ||
{ | ||
"id": "multi2", | ||
"name": "Multi Device", | ||
"letters": "F0", | ||
"plugin": "SynTexWebHooks", | ||
"operation": "<", | ||
"value": "1000" | ||
} | ||
], | ||
"condition": [ | ||
{ | ||
"id": "multi1", | ||
"name": "Multi Switch", | ||
"letters": "41", | ||
"plugin": "SynTexWebHooks", | ||
"operation": "=", | ||
"value": "false" | ||
} | ||
], | ||
"trigger": { | ||
"logic": "AND", | ||
"groups": [ | ||
{ | ||
"logic": "OR", | ||
"blocks": [ | ||
{ | ||
"id": "multi2", | ||
"name": "Multi Device", | ||
"letters": "F0", | ||
"plugin": "SynTexWebHooks", | ||
"operation": "<", | ||
"state": { | ||
"value": 1000 | ||
} | ||
}, | ||
{ | ||
"operation": "=", | ||
"time": "16:00", | ||
"options": { | ||
"stateLock": true | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"logic": "AND", | ||
"blocks": [ | ||
{ | ||
"id": "multi1", | ||
"name": "Multi Switch", | ||
"letters": "41", | ||
"plugin": "SynTexWebHooks", | ||
"operation": "=", | ||
"state": { | ||
"value": false | ||
}, | ||
"options": { | ||
"stateLock": true | ||
} | ||
}, | ||
{ | ||
"operation": "=", | ||
"days": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"result": [ | ||
@@ -292,9 +330,29 @@ { | ||
"operation": "=", | ||
"value": "true", | ||
"hue": "4", | ||
"saturation": "100", | ||
"brightness": "100" | ||
"state": { | ||
"value": true, | ||
"hue": 4, | ||
"saturation": 100, | ||
"brightness": 100 | ||
} | ||
}, | ||
{ | ||
"url": "http://192.168.1.100:1712/devices?id=58747407d8cfc108d0dc&value=true&brightness=100" | ||
"id": "extern1", | ||
"name": "Extern Accessory", | ||
"letters": "40", | ||
"bridge": "192.168.1.100", | ||
"plugin": "SynTexWebHooks", | ||
"operation": "=", | ||
"state": { | ||
"value": false | ||
}, | ||
"options": { | ||
"stateLock": false | ||
} | ||
}, | ||
{ | ||
"operation": "=", | ||
"delay": 1000 | ||
}, | ||
{ | ||
"url": "http://192.168.1.100:1712/devices?id=ABCDEF1234567890&value=true&brightness=100" | ||
} | ||
@@ -308,14 +366,42 @@ ] | ||
### Required Parameters | ||
- `id` A unique ID of your automation. | ||
- `name` The name of the automation. | ||
- `active` Enable / disable a single automation. | ||
- `trigger` What triggers the automation?<br><br> | ||
- `logic` Define a logical operation for your groups *( `AND`, `OR` )* | ||
- `groups` Logical layer one<br><br> | ||
- `logic` Define a logical operation for your blocks *( `AND`, `OR` )* | ||
- `blocks` Logical layer two<br><br> | ||
- `result` What happens when running an automation? | ||
- `options` General automation options<br><br> | ||
- `timeLock` Set a timeout to prevent to many executions *( in milliseconds )* | ||
### Block Configuration | ||
#### Service Block ( Trigger, Result ) | ||
- `id` is the same like in your config file *( or in your log )* | ||
- `name` The name of the accessory. | ||
- `letters` See letter configuration below. | ||
- `bridge` IP of your other bridge *( optional )* | ||
- `plugin` Use the platform name of the plugin *( optional, see supported plugins below )* | ||
- `operation` Use the logical operands *( `>`, `<`, `=` )* | ||
- `value` The state value of your accessory. | ||
- `state` The state of your accessory.<br><br> | ||
- `value` is used for the main characteristic. | ||
- `brightness` can be used for dimmable / RGB lights. | ||
- `hue` can be used for RGB lights. | ||
- `saturation` can be used for RGB lights. | ||
### Optional Parameters | ||
- `plugin` Use the platform name of the plugin *( see supported plugins below )* | ||
- `brightness` can be used for dimmable / RGB lights. | ||
- `hue` can be used for RGB lights. | ||
- `saturation` can be used for RGB lights. | ||
#### Time Block ( Trigger ) | ||
- `operation` Use the logical operands *( `>`, `<`, `=` )* | ||
- `time` Define a time point *( e.g. `16:00` )* | ||
#### Weekday Block ( Trigger ) | ||
- `operation` Use the logical operands *( `=` )* | ||
- `days` Set the weekdays *( from `0` to `6` )* | ||
#### Delay Block ( Result ) | ||
- `delay` Set a timeout *( in milliseconds )* | ||
#### URL Block ( Result ) | ||
- `url` Fetch an URL. | ||
### Letter Configuration | ||
@@ -322,0 +408,0 @@ The letters are split into two parts *( characters )* |
const { ColoredBulbService } = require('homebridge-syntex-dynamic-platform'); | ||
const convert = require('color-convert'), emitter = require('../emitter'); | ||
const convert = require('color-convert'); | ||
@@ -9,3 +9,3 @@ module.exports = class LightBulb extends ColoredBulbService | ||
{ | ||
var specialConfig = serviceConfig; | ||
var specialConfig = { ...serviceConfig }; | ||
@@ -24,5 +24,7 @@ specialConfig.type = 'rgb'; | ||
this.DeviceManager = manager.DeviceManager; | ||
this.EventManager = manager.platform.EventManager; | ||
this.ip = serviceConfig.ip; | ||
this.setup = serviceConfig.type == 'rgb' ? 'RGBW' : serviceConfig.type == 'rgbw' ? 'RGBWW' : 'RGBW'; | ||
this.setup = serviceConfig.type == 'rgbw' ? 'RGBWW' : 'RGBW'; | ||
this.pins = serviceConfig.pins || 'rgb'; | ||
//this.purewhite = serviceConfig.purewhite || false; | ||
@@ -40,8 +42,11 @@ | ||
{ | ||
this.setPower(this.tempState.value).then(() => { | ||
this.setPower(this.tempState.value).then((failed) => { | ||
if(!failed) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.On).updateValue(this.value); | ||
} | ||
this.running = false; | ||
}); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.tempState.value }); | ||
} | ||
@@ -54,8 +59,15 @@ else if(this.hue != this.tempState.hue || this.saturation != this.tempState.saturation || this.brightness != this.tempState.brightness) | ||
{ | ||
this.setColor(converted[0], converted[1], converted[2]).then(() => { | ||
converted = this.setChannels(converted); | ||
this.setColor(converted[0], converted[1], converted[2]).then((failed) => { | ||
if(!failed) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.Hue).updateValue(this.hue); | ||
this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(this.saturation); | ||
this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(this.brightness); | ||
} | ||
this.running = false; | ||
}); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.tempState.value, hue : converted[0], saturation : converted[1], brightness : converted[2] }); | ||
} | ||
@@ -77,26 +89,25 @@ else | ||
this.setToCurrentColor(state, () => { | ||
this.setToCurrentColor(state, (failed) => { | ||
if(state.value != null) | ||
if(!failed) | ||
{ | ||
super.setState(state.value, | ||
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value)); | ||
} | ||
if(state.value != null) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value); | ||
} | ||
if(state.hue != null) | ||
{ | ||
super.setHue(state.hue, | ||
() => this.service.getCharacteristic(this.Characteristic.Hue).updateValue(state.hue)); | ||
} | ||
if(state.hue != null) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.Hue).updateValue(state.hue); | ||
} | ||
if(state.saturation != null) | ||
{ | ||
super.setSaturation(state.saturation, | ||
() => this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(state.saturation)); | ||
} | ||
if(state.saturation != null) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(state.saturation); | ||
} | ||
if(state.brightness != null) | ||
{ | ||
super.setBrightness(state.brightness, | ||
() => this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness)); | ||
if(state.brightness != null) | ||
{ | ||
this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness); | ||
} | ||
} | ||
@@ -120,3 +131,3 @@ }); | ||
this.tempState.value = this.value = state.value; | ||
this.value = this.tempState.value = state.value; | ||
@@ -134,3 +145,3 @@ super.setState(state.value, | ||
this.tempState.hue = this.hue = state.hue; | ||
this.hue = this.tempState.hue = state.hue; | ||
@@ -148,3 +159,3 @@ super.setHue(state.hue, | ||
this.tempState.saturation = this.saturation = state.saturation; | ||
this.saturation = this.tempState.saturation = state.saturation; | ||
@@ -162,3 +173,3 @@ super.setSaturation(state.saturation, | ||
this.tempState.brightness = this.brightness = state.brightness; | ||
this.brightness = this.tempState.brightness = state.brightness; | ||
@@ -175,3 +186,3 @@ super.setBrightness(state.brightness, | ||
{ | ||
this.logger.log('debug', this.id, this.letters, '%update_state[0]% [' + this.name + '] was not changed! ( ' + this.id + ' )'); | ||
this.logger.log('debug', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[2]%! ( ' + this.id + ' )'); | ||
} | ||
@@ -197,3 +208,3 @@ | ||
{ | ||
this.DeviceManager.getDevice(this.id, (state) => { | ||
this.DeviceManager.getDevice(this, (state) => { | ||
@@ -216,7 +227,7 @@ if(state.value != null && !isNaN(state.value)) | ||
{ | ||
this.setToCurrentColor({ value }, (offline) => { | ||
this.setToCurrentColor({ value }, (failed) => { | ||
if(!offline) | ||
if(!failed) | ||
{ | ||
super.setState(value, () => callback()); | ||
callback(); | ||
} | ||
@@ -242,3 +253,3 @@ else | ||
{ | ||
this.DeviceManager.getDevice(this.id, (state) => { | ||
this.DeviceManager.getDevice(this, (state) => { | ||
@@ -260,7 +271,7 @@ if(state.hue != null && !isNaN(state.hue)) | ||
{ | ||
this.setToCurrentColor({ hue }, (offline) => { | ||
this.setToCurrentColor({ hue }, (failed) => { | ||
if(!offline) | ||
if(!failed) | ||
{ | ||
super.setHue(hue, () => callback()); | ||
callback(); | ||
} | ||
@@ -286,3 +297,3 @@ else | ||
{ | ||
this.DeviceManager.getDevice(this.id, (state) => { | ||
this.DeviceManager.getDevice(this, (state) => { | ||
@@ -304,7 +315,7 @@ if(state.saturation != null && !isNaN(state.saturation)) | ||
{ | ||
this.setToCurrentColor({ saturation }, (offline) => { | ||
this.setToCurrentColor({ saturation }, (failed) => { | ||
if(!offline) | ||
if(!failed) | ||
{ | ||
super.setSaturation(saturation, () => callback()); | ||
callback(); | ||
} | ||
@@ -330,3 +341,3 @@ else | ||
{ | ||
this.DeviceManager.getDevice(this.id, (state) => { | ||
this.DeviceManager.getDevice(this, (state) => { | ||
@@ -348,7 +359,7 @@ if(state.brightness != null && !isNaN(state.brightness)) | ||
{ | ||
this.setToCurrentColor({ brightness }, (offline) => { | ||
this.setToCurrentColor({ brightness }, (failed) => { | ||
if(!offline) | ||
if(!failed) | ||
{ | ||
super.setBrightness(brightness, () => callback()); | ||
callback(); | ||
} | ||
@@ -417,3 +428,3 @@ else | ||
{ | ||
this.setPower(this.tempState.value).then((offline) => { | ||
this.setPower(this.tempState.value).then((failed) => { | ||
@@ -426,3 +437,3 @@ this.running = false; | ||
{ | ||
callback(offline); | ||
callback(failed); | ||
} | ||
@@ -437,3 +448,5 @@ }); | ||
{ | ||
this.setColor(converted[0], converted[1], converted[2]).then((offline) => { | ||
converted = this.setChannels(converted); | ||
this.setColor(converted[0], converted[1], converted[2]).then((failed) => { | ||
@@ -446,4 +459,6 @@ this.running = false; | ||
{ | ||
callback(offline); | ||
callback(failed); | ||
} | ||
this.EventManager.setOutputStream('resetSwitch', { sender : this }, [ this.ip ]); | ||
}); | ||
@@ -472,6 +487,2 @@ } | ||
} | ||
emitter.emit('SynTexMagicHomePresetTurnedOn', this.name, [ this.ip ]); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.tempState.value, hue : this.tempState.hue, saturation : this.tempState.saturation, brightness : this.tempState.brightness }); | ||
} | ||
@@ -497,15 +508,19 @@ else if(callback != null) | ||
this.DeviceManager.executeCommand(this.ip, value ? '--on' : '--off', (error, output) => { | ||
this.DeviceManager.executeCommand(this.ip, value ? '--on' : '--off', (offline, output) => { | ||
this.offline = error || output.includes('Unable to connect to bulb'); | ||
var failed = offline || (value && !output.includes('Turning on')) || (!value && !output.includes('Turning off')); | ||
if(!this.offline) | ||
this.offline = offline; | ||
if(!failed) | ||
{ | ||
this.value = output.includes('Turning on') ? true : output.includes('Turning off') ? false : value; | ||
this.value = value; | ||
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [value: ' + this.value + ', hue: ' + this.hue + ', saturation: ' + this.saturation + ', brightness: ' + this.brightness + '] ( ' + this.id + ' )'); | ||
super.setState(this.value, () => {}, true); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.value, hue : this.hue, saturation : this.saturation, brightness : this.brightness }); | ||
} | ||
this.setConnectionState(!output.includes('Unable to connect to bulb'), | ||
() => resolve(this.offline), true); | ||
this.setConnectionState(!this.offline, | ||
() => resolve(failed), true); | ||
}); | ||
@@ -519,35 +534,62 @@ }); | ||
this.DeviceManager.executeCommand(this.ip, '-x ' + this.setup + ' -c ' + red + ',' + green + ',' + blue, (error, output) => { | ||
this.DeviceManager.executeCommand(this.ip, '-x ' + this.setup + ' -c ' + red + ',' + green + ',' + blue, (offline, output) => { | ||
this.offline = error || output.includes('Unable to connect to bulb'); | ||
var failed = offline || !output.includes('Setting color'); | ||
if(!this.offline) | ||
this.offline = offline; | ||
if(!failed) | ||
{ | ||
var rgb = null, hsl = null; | ||
var color = output.match(/\[\(.*,.*,.*\)\]/g); | ||
if(output.includes('(') && output.includes(')') && output.includes(', ')) | ||
if(Array.isArray(color) && color.length > 0) | ||
{ | ||
rgb = output.split('(')[1].split(')')[0].split(', '); | ||
} | ||
var rgb = this.setChannels(color[0].slice(2).slice(0, -2).split(',').map((item) => item.trim())), | ||
hsl = convert.rgb.hsv([rgb[0], rgb[1], rgb[2]]); | ||
if(rgb != null && Array.isArray(rgb) && rgb.length == 3) | ||
{ | ||
hsl = convert.rgb.hsv([rgb[0], rgb[1], rgb[2]]); | ||
if(hsl != null) | ||
{ | ||
this.hue = hsl[0]; | ||
this.saturation = hsl[1]; | ||
this.brightness = hsl[2]; | ||
super.setHue(this.hue, () => {}); | ||
super.setSaturation(this.saturation, () => {}); | ||
super.setBrightness(this.brightness, () => {}); | ||
} | ||
} | ||
if(hsl != null) | ||
{ | ||
this.hue = hsl[0]; | ||
this.saturation = hsl[1]; | ||
this.brightness = hsl[2]; | ||
} | ||
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [value: ' + this.value + ', hue: ' + this.hue + ', saturation: ' + this.saturation + ', brightness: ' + this.brightness + '] ( ' + this.id + ' )'); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.value, hue : this.hue, saturation : this.saturation, brightness : this.brightness }); | ||
} | ||
this.setConnectionState(!output.includes('Unable to connect to bulb'), | ||
() => resolve(this.offline), true); | ||
this.setConnectionState(!this.offline, | ||
() => resolve(failed), true); | ||
}); | ||
}); | ||
} | ||
setChannels(color) | ||
{ | ||
var converted = [ ...color ]; | ||
for(const x in this.pins) | ||
{ | ||
if(this.pins[x] == 'r') | ||
{ | ||
converted[x] = color[0]; | ||
} | ||
else if(this.pins[x] == 'g') | ||
{ | ||
converted[x] = color[1]; | ||
} | ||
else if(this.pins[x] == 'b') | ||
{ | ||
converted[x] = color[2]; | ||
} | ||
} | ||
return converted; | ||
} | ||
} |
const { SwitchService } = require('homebridge-syntex-dynamic-platform'); | ||
const preset = require('../presets'), custom = require('../custom'), emitter = require('../emitter'); | ||
const preset = require('../presets'), custom = require('../custom'); | ||
@@ -12,14 +12,12 @@ module.exports = class PresetSwitch extends SwitchService | ||
this.DeviceManager = manager.DeviceManager; | ||
this.EventManager = manager.platform.EventManager; | ||
this.ips = serviceConfig.ips; | ||
this.preset = serviceConfig.preset || 'seven_color_cross_fade'; | ||
this.speed = serviceConfig.speed || 100; | ||
this.shouldTurnOff = serviceConfig.shouldTurnOff || false; | ||
this.preset = serviceConfig.preset || 'seven_color_cross_fade'; | ||
this.speed = serviceConfig.speed || 40; | ||
this.sceneValue = preset[this.preset] || custom[this.preset]; | ||
if(this.sceneValue == null) | ||
if(preset[this.preset] == null && custom[this.preset] == null) | ||
{ | ||
this.sceneValue = 37; | ||
this.logger.log('warn', this.id, this.letters, '%preset_not_found[0]% [' + this.preset + '] %preset_not_found[1]% [seven_color_cross_fade] %preset_not_found[2]%!'); | ||
this.logger.log('warn', this.id, this.letters, '%preset_not_found[0]% [' + this.preset + '] %preset_not_found[1]%!'); | ||
} | ||
@@ -56,60 +54,85 @@ | ||
if(value == true) | ||
{ | ||
Object.keys(this.ips).forEach((ip) => { | ||
Object.keys(this.ips).forEach((ip) => { | ||
promiseArray.push(new Promise((resolve) => { | ||
if(value == true) | ||
{ | ||
// OPTIMIZE: Remove Timeout When LED is Already On | ||
promiseArray.push(new Promise((resolve) => { | ||
this.DeviceManager.executeCommand(ip, '--on', () => resolve()); | ||
})); | ||
this.DeviceManager.executeCommand(ip, '--on', (offline, output) => { | ||
var failed = offline || !output.includes('Turning on'); | ||
// OPTIMIZE: Remove Timeout When LED is Already On | ||
if(!failed && preset[this.preset] != null) | ||
{ | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '-p ' + preset[this.preset] + ' ' + this.speed, (offline, output) => { | ||
var failed = offline || !output.includes('Setting preset pattern'); | ||
if(preset[this.preset] != null) | ||
{ | ||
promiseArray.push(new Promise((resolve) => { | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '-p ' + this.sceneValue + ' ' + this.speed, () => resolve()), 1500); | ||
})); | ||
resolve(!failed); | ||
}), 1500); | ||
} | ||
else if(!failed && custom[this.preset] != null) | ||
{ | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '-C ' + custom[this.preset].transition + ' ' + this.speed + ' "' + custom[this.preset].preset + '"', (offline, output) => { | ||
var failed = offline || !output.includes('Setting custom pattern'); | ||
resolve(!failed); | ||
}), 1500); | ||
} | ||
else | ||
{ | ||
if(!failed) | ||
{ | ||
this.logger.log('error', this.id, this.letters, '%preset_not_found[0]% [' + this.preset + '] %preset_not_found[1]%!'); | ||
} | ||
resolve(false); | ||
} | ||
}); | ||
} | ||
else if(custom[this.preset] != null) | ||
else | ||
{ | ||
promiseArray.push(new Promise((resolve) => { | ||
this.DeviceManager.executeCommand(ip, ' -c ' + this.ips[ip], (offline, output) => { | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '-C ' + custom[this.preset].transition + ' ' + this.speed + ' "' + custom[this.preset].preset + '"', () => resolve()), 1500); | ||
})); | ||
} | ||
}); | ||
var failed = offline || !output.includes('Setting color'); | ||
Promise.all(promiseArray).then(() => super.setState(true, () => callback(), true)); | ||
} | ||
else | ||
{ | ||
Object.keys(this.ips).forEach((ip) => { | ||
if(!failed && this.shouldTurnOff) | ||
{ | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '--off', (offline, output) => { | ||
promiseArray.push(new Promise((resolve) => { | ||
this.DeviceManager.executeCommand(ip, ' -c ' + this.ips[ip], () => resolve()); | ||
})); | ||
}); | ||
var failed = offline || !output.includes('Turning off'); | ||
Promise.all(promiseArray).then(() => { | ||
resolve(!failed); | ||
callback(); | ||
if(this.shouldTurnOff) | ||
{ | ||
Object.keys(this.ips).forEach((ip) => { | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '--off', () => {}), 1500); | ||
}), 1500); | ||
} | ||
else | ||
{ | ||
resolve(!failed); | ||
} | ||
}); | ||
} | ||
})); | ||
}); | ||
super.setState(false, () => {}, true); | ||
}); | ||
} | ||
Promise.all(promiseArray).then((result) => { | ||
if(result.includes(true)) | ||
{ | ||
super.setState(value, () => callback(), true); | ||
emitter.emit('SynTexMagicHomePresetTurnedOn', this.name, Object.keys(this.ips)); | ||
this.EventManager.setOutputStream('resetSwitch', { sender : this }, Object.keys(this.ips)); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value }); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value }); | ||
} | ||
else | ||
{ | ||
callback(new Error('Offline')); | ||
} | ||
}); | ||
} | ||
@@ -132,20 +155,17 @@ | ||
{ | ||
emitter.on('SynTexMagicHomePresetTurnedOn', (presetName, ips) => { | ||
this.EventManager.setInputStream('resetSwitch', { source : this, destination : this.id }, (ips) => { | ||
if(presetName != this.name) | ||
var changed = false; | ||
for(const ip of ips) | ||
{ | ||
var updateState = false; | ||
for(const ip of ips) | ||
if(Object.keys(this.ips).includes(ip)) | ||
{ | ||
if(Object.keys(this.ips).includes(ip)) | ||
{ | ||
updateState = true; | ||
} | ||
changed = true; | ||
} | ||
} | ||
if(updateState) | ||
{ | ||
this.updateState({ value : false }); | ||
} | ||
if(changed) | ||
{ | ||
this.updateState({ value : false }); | ||
} | ||
@@ -152,0 +172,0 @@ }); |
const { SwitchService } = require('homebridge-syntex-dynamic-platform'); | ||
const emitter = require('../emitter'); | ||
module.exports = class SceneSwitch extends SwitchService | ||
@@ -12,2 +10,3 @@ { | ||
this.DeviceManager = manager.DeviceManager; | ||
this.EventManager = manager.platform.EventManager; | ||
@@ -40,26 +39,58 @@ this.ips = serviceConfig.ips; | ||
this.DeviceManager.executeCommand(ip, ' -c ' + this.ips[ip], () => resolve()); | ||
// OPTIMIZE: Remove Timeout When LED is Already On | ||
this.DeviceManager.executeCommand(ip, '--on', (offline, output) => { | ||
var failed = offline || !output.includes('Turning on'); | ||
if(!failed) | ||
{ | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, ' -c ' + this.ips[ip], (offline, output) => { | ||
var failed = offline || !output.includes('Setting color'); | ||
if(!failed && this.shouldTurnOff) | ||
{ | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '--off', (offline, output) => { | ||
var failed = offline || !output.includes('Turning off'); | ||
resolve(!failed); | ||
}), 1500); | ||
} | ||
else | ||
{ | ||
resolve(!failed); | ||
} | ||
}), 1500); | ||
} | ||
else | ||
{ | ||
resolve(!failed); | ||
} | ||
}); | ||
})); | ||
}); | ||
Promise.all(promiseArray).then(() => { | ||
Promise.all(promiseArray).then((result) => { | ||
callback(); | ||
if(result.includes(true)) | ||
{ | ||
callback(); | ||
if(this.shouldTurnOff) | ||
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [triggered] ( ' + this.id + ' )'); | ||
this.EventManager.setOutputStream('resetSwitch', { sender : this }, Object.keys(this.ips)); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value }); | ||
} | ||
else | ||
{ | ||
Object.keys(this.ips).forEach((ip) => { | ||
setTimeout(() => this.DeviceManager.executeCommand(ip, '--off', () => {}), 1500); | ||
}); | ||
callback(new Error('Offline')); | ||
} | ||
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [triggered] ( ' + this.id + ' )'); | ||
}).then(() => setTimeout(() => this.service.getCharacteristic(this.Characteristic.On).updateValue(false), 2000)); | ||
emitter.emit('SynTexMagicHomePresetTurnedOn', this.name, Object.keys(this.ips)); | ||
this.AutomationSystem.LogikEngine.runAutomation(this, { value }); | ||
}).then(() => setTimeout(() => this.service.getCharacteristic(this.Characteristic.On).updateValue(false), 3000)); | ||
} | ||
} |
@@ -10,28 +10,30 @@ const cp = require('child_process'), path = require('path'), convert = require('color-convert'); | ||
getDevice(ip, callback) | ||
getDevice(service, callback) | ||
{ | ||
this.executeCommand(ip, '-i', (error, stdout) => { | ||
this.executeCommand(service.ip, '-i', (offline, output) => { | ||
var state = {}; | ||
var colors = stdout.match(/\(.*,.*,.*\)/g); | ||
var power = stdout.match(/\] ON /g); | ||
var power = output.match(/\] ON /g), | ||
colors = output.match(/\(.*,.*,.*\)/g); | ||
state.value = (power != null && power.length > 0); | ||
state.value = (Array.isArray(power) && power.length > 0); | ||
if(colors && colors.length > 0) | ||
if(Array.isArray(colors) && colors.length > 0) | ||
{ | ||
var str = colors.toString().substring(0, colors.toString().length - 1); | ||
str = str.substring(1, str.length); | ||
var converted = colors[0].slice(1).slice(0, -1).split(',').map((item) => item.trim()); | ||
const rgbColors = str.split(',').map((item) => { return item.trim() }); | ||
converted = service.setChannels(converted); | ||
converted = convert.rgb.hsv(converted); | ||
var converted = convert.rgb.hsv(rgbColors); | ||
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]; | ||
} | ||
} | ||
state.connection = !stdout.includes('Unable to connect to bulb'); | ||
state.connection = !offline; | ||
@@ -54,3 +56,3 @@ callback(state); | ||
{ | ||
this.getDevice(accessory[1].services[i].ip, (state) => { | ||
this.getDevice(accessory[1].service[parseInt(i) + 1], (state) => { | ||
@@ -67,3 +69,3 @@ accessory[1].service[parseInt(i) + 1].setConnectionState(state.connection, | ||
{ | ||
this.getDevice(accessory[1].services.ip, (state) => { | ||
this.getDevice(accessory[1].service[1], (state) => { | ||
@@ -87,3 +89,3 @@ accessory[1].service[1].setConnectionState(state.connection, | ||
{ | ||
callback(err != null || (stdOut != null && stdOut.includes('Errno 113')), stdOut); | ||
callback(err != null || (stdOut != null && (stdOut.includes('Errno 113') || stdOut.includes('Unable to connect to bulb'))), stdOut); | ||
} | ||
@@ -90,0 +92,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
121881
988
0
474
14
+ Addedhomebridge-syntex-dynamic-platform@1.0.8-b6(transitive)
+ Addedsyntex-automation@1.2.0(transitive)
+ Addedsyntex-filesystem@1.0.2(transitive)
+ Addedsyntex-logger@1.0.8(transitive)
+ Addedsyntex-webserver@1.1.0(transitive)
- Removedhomebridge-syntex-dynamic-platform@1.0.7-b67(transitive)
- Removedsyntex-automation@1.2.0-b2(transitive)
- Removedsyntex-filesystem@1.0.2-b7(transitive)
- Removedsyntex-logger@1.0.8-b21(transitive)
- Removedsyntex-webserver@1.1.0-b13(transitive)