Socket
Socket
Sign inDemoInstall

homebridge-syntex-dynamic-platform

Package Overview
Dependencies
Maintainers
1
Versions
345
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-syntex-dynamic-platform - npm Package Compare versions

Comparing version 1.0.8-b6 to 1.0.8-b60

src/accessories/debug.js

147

main.js

@@ -1,2 +0,2 @@

const axios = require('axios'), fs = require('fs'), path = require('path');
const fs = require('fs'), path = require('path');

@@ -22,6 +22,10 @@ const ContextManager = require('./src/context');

const BlindService = require('./src/accessories/blind');
const ThermostatService = require('./src/accessories/thermostat');
const FanService = require('./src/accessories/fan');
const DebugService = require('./src/accessories/debug');
const ConnectionCharacteristic = require('./src/characteristics/connection');
let logger = require('syntex-logger'), AutomationSystem = require('syntex-automation'), FileSystem = require('syntex-filesystem'), WebServer = require('syntex-webserver'), EventManager = require('./src/event-manager'), TypeManager = require('./src/type-manager');
let logger = require('syntex-logger'), AutomationSystem = require('syntex-automation'), Basic = require('syntex-basic'), FileManager = require('syntex-filesystem'), WebServer = require('syntex-webserver'), TypeManager = require('./src/type-manager');

@@ -41,4 +45,2 @@ let DynamicPlatform = class SynTexDynamicPlatform

this.options = {};
this.api = api;

@@ -53,12 +55,7 @@ this.config = config;

if(config['options'] != null)
{
this.options = config['options'];
}
this.options = config['options'] || {};
this.port = this.options['port'];
this.debug = this.options['debug'] || false;
this.language = this.options['language'] || 'en';
this.logger = new logger(this);
this.logger = new logger(this, { language : this.options['language'] || 'en', levels : this.config['log'] });

@@ -80,7 +77,10 @@ if(config['baseDirectory'] != null)

}
else
{
this.logger.log('error', 'bridge', 'Bridge', '%no_base_path%!');
}
this.files = new FileSystem(this, { initDirectories : ['activity', 'automation', 'log'] });
this.files = new FileManager(this, { initDirectories : ['activity', 'automation', 'log'] });
this.TypeManager = new TypeManager(this.logger);
this.EventManager = new EventManager(this);
this.ContextManager = new ContextManager(this);

@@ -95,2 +95,7 @@

this.Basic = new Basic({ ...this, loggerSpecial : this.logger });
this.EventManager = this.Basic.getEventManager();
this.RequestManager = this.Basic.getRequestManager();
this.AutomationSystem = new AutomationSystem(this);

@@ -141,36 +146,29 @@

if(urlParams.remove != null)
if(service != null)
{
if(urlParams.type != null)
if(urlParams.remove != null)
{
response.end(urlParams.remove == 'CONFIRM' && await accessory.removeService(accessory, service) ? 'Success' : 'Error');
if(urlParams.type != null)
{
response.end(urlParams.remove == 'CONFIRM' && await accessory.removeService(accessory, service) ? 'Success' : 'Error');
}
else
{
response.end(urlParams.remove == 'CONFIRM' && await this.removeAccessory(accessory.homebridgeAccessory || accessory, urlParams.id) ? 'Success' : 'Error');
}
}
else
{
response.end(urlParams.remove == 'CONFIRM' && await this.removeAccessory(accessory.homebridgeAccessory || accessory, urlParams.id) ? 'Success' : 'Error');
}
}
else
{
if(service != null)
{
if(urlParams.value != null)
if(service != null)
{
let state = { value : urlParams.value };
if(urlParams.hue != null)
var characteristics = this.TypeManager.getCharacteristics({ letters : service.letters }), state = {};
for(const type in characteristics)
{
state.hue = urlParams.hue;
if(urlParams[type] != null)
{
state[type] = urlParams[type];
}
}
if(urlParams.saturation != null)
{
state.saturation = urlParams.saturation;
}
if(urlParams.brightness != null)
{
state.brightness = urlParams.brightness;
}
if(urlParams.event != null)

@@ -181,34 +179,39 @@ {

state = this.updateAccessoryService(service, state);
response.end(state != null ? 'Success' : 'Error');
}
else
{
let state = null;
if(accessory.homebridgeAccessory != null
&& accessory.homebridgeAccessory.context != null
&& accessory.homebridgeAccessory.context.data != null)
if(Object.keys(state).length > 0)
{
if(urlParams.type == null && urlParams.counter == null)
response.end(this.updateAccessoryService(service, state) != null ? 'Success' : 'Error');
}
else
{
if(accessory.homebridgeAccessory != null
&& accessory.homebridgeAccessory.context != null
&& accessory.homebridgeAccessory.context.data != null)
{
state = accessory.homebridgeAccessory.context.data;
if(urlParams.type == null && urlParams.counter == null)
{
state = accessory.homebridgeAccessory.context.data;
}
else if(service != null && service.letters != null && accessory.homebridgeAccessory.context.data[service.letters] != null)
{
state = accessory.homebridgeAccessory.context.data[service.letters];
}
}
else if(service != null && service.letters != null)
{
state = accessory.homebridgeAccessory.context.data[service.letters];
}
response.end(Object.keys(state).length > 0 ? JSON.stringify(state) : 'Error');
}
response.end(state != null ? JSON.stringify(state) : 'Error');
}
}
else
{
response.end('Error');
else
{
response.end('Error');
this.logger.log('error', urlParams.id, (urlParams.type != null ? (this.TypeManager.typeToLetter(urlParams.type) || urlParams.type) : 'X') + (urlParams.counter || '0'), '%accessory_not_found[3]% ( ' + (urlParams.type != null ? (this.TypeManager.typeToLetter(urlParams.type) || urlParams.type) : 'X') + (urlParams.counter || '0') + ' )');
this.logger.log('error', urlParams.id, (urlParams.type != null ? (this.TypeManager.typeToLetter(urlParams.type) || urlParams.type) : 'X') + (urlParams.counter || '0'), '%accessory_not_found[3]% ( ' + (urlParams.type != null ? (this.TypeManager.typeToLetter(urlParams.type) || urlParams.type) : 'X') + (urlParams.counter || '0') + ' )');
}
}
}
else
{
response.end('Error');
this.logger.log('error', urlParams.id, '', '%accessory_not_found[2]%! ( ' + urlParams.id + ' )');
}
}

@@ -474,3 +477,3 @@ else

{
var url = 'http://syntex.sytes.net:8800/init-bridge?id=' + bridgeID + '&plugin=' + this.pluginName + '&version=' + this.pluginVersion + '&name=' + this.bridgeName;
var url = 'http://syntex-cloud.com:8888/init-bridge?id=' + bridgeID + '&plugin=' + this.pluginName + '&version=' + this.pluginVersion + '&name=' + this.bridgeName;

@@ -482,9 +485,9 @@ if(initBridge)

axios.get(url).then((data) => {
this.RequestManager.fetch(url).then((response) => {
if(data != null && data.data != null)
if(response.data != null)
{
if(data.data != bridgeID)
if(response.data != bridgeID)
{
setTimeout(() => this.setBridgeID(data.data), 10000);
setTimeout(() => this.setBridgeID(response.data), 10000);
}

@@ -496,8 +499,2 @@ }

}
}).catch((e) => {
this.logger.err(e);
setTimeout(() => this.connectBridge(bridgeID, initBridge), 30000);
});

@@ -572,2 +569,2 @@ }

module.exports = { DynamicPlatform, UniversalAccessory, AccessoryInformationService, OutletService, SwitchService, LightBulbService, DimmedBulbService, ColoredBulbService, ContactService, LightService, MotionService, TemperatureService, HumidityService, LeakService, OccupancyService, StatelessSwitchService, SmokeService, AirQualityService, BlindService };
module.exports = { DynamicPlatform, UniversalAccessory, AccessoryInformationService, DebugService, OutletService, SwitchService, LightBulbService, DimmedBulbService, ColoredBulbService, ContactService, LightService, MotionService, TemperatureService, HumidityService, LeakService, OccupancyService, StatelessSwitchService, SmokeService, AirQualityService, BlindService, ThermostatService, FanService };
{
"name": "homebridge-syntex-dynamic-platform",
"version": "1.0.8-b6",
"version": "1.0.8-b60",
"description": "A Dynamic Platform Accessory",

@@ -12,7 +12,7 @@ "main": "main.js",

"dependencies": {
"axios": "^0.21.1",
"syntex-automation": "1.2.0",
"syntex-filesystem": "1.0.2",
"syntex-logger": "1.0.8",
"syntex-webserver": "1.1.0"
"syntex-automation": "1.2.1-b16",
"syntex-basic": "1.0.0-b18",
"syntex-filesystem": "1.0.3-b9",
"syntex-logger": "1.0.9-b2",
"syntex-webserver": "1.1.1-b14"
},

@@ -43,4 +43,5 @@ "keywords": [

"devDependencies": {
"eslint": "^8.7.0"
"eslint": "^8.7.0",
"eslint-plugin-react": "^7.31.11"
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.AirQualitySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.AirQuality).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.AirQuality).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.AirQualitySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.AirQuality).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.AirQuality).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.AirQualitySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.AirQuality).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.AirQuality).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,70 +9,103 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.position = super.getValue('position');
this.value = super.getValue('value');
this.target = super.getValue('target', false);
this.state = super.getValue('state', false);
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.TargetPosition).on('get', this.getTargetPosition.bind(this)).on('set', this.setTargetPosition.bind(this));
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentPosition).on('get', this.getCurrentPosition.bind(this));
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.PositionState).on('get', this.getPositionState.bind(this));
this.service.getCharacteristic(this.Characteristic.CurrentPosition).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.TargetPosition).on('get', this.getTargetPosition.bind(this)).on('set', this.setTargetPosition.bind(this));
this.service.getCharacteristic(this.Characteristic.PositionState).on('get', this.getPositionState.bind(this));
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.TargetPosition).updateValue(this.value);
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentPosition).updateValue(this.value);
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.PositionState).updateValue(this.position);
this.service.getCharacteristic(this.Characteristic.CurrentPosition).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.TargetPosition).updateValue(this.target);
this.service.getCharacteristic(this.Characteristic.PositionState).updateValue(this.state);
this.changeHandler = (state) => {
if(state instanceof Object)
var changed = false;
if(state.value != null)
{
var v = [
{ type : 'value', Characteristic : this.Characteristic.TargetPosition },
{ type : 'value', Characteristic : this.Characteristic.CurrentPosition }
];
if(!super.hasState('value') || this.value != state.value)
{
changed = true;
}
for(const c of v)
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.CurrentPosition).updateValue(state.value), false);
}
if(state.target != null)
{
if(!super.hasState('target') || this.target != state.target)
{
if(state[c.type] != null)
{
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(c.Characteristic).updateValue(state[c.type]);
super.setValue('value', state[c.type]);
}
changed = true;
}
this.setTargetPosition(state.target,
() => this.service.getCharacteristic(this.Characteristic.TargetPosition).updateValue(state.target), false);
}
else
if(state.state != null)
{
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.TargetPosition).updateValue(state);
homebridgeAccessory.getServiceById(this.Service.WindowCovering, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentPosition).updateValue(state);
super.setValue('value', state);
if(!super.hasState('state') || this.state != state.state)
{
changed = true;
}
this.setPositionState(state.state,
() => this.service.getCharacteristic(this.Characteristic.PositionState).updateValue(state.state), false);
}
if(changed)
{
this.logger.log('update', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
}
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.value, target : this.target, state : this.state });
};
}
getTargetPosition(callback, verbose)
getTargetPosition(callback, verbose = false)
{
callback(super.getValue('value', verbose));
this.target = this.getValue('target', verbose);
if(callback != null)
{
callback(null, this.target);
}
}
setTargetPosition(level, callback, verbose)
setTargetPosition(target, callback, verbose = false)
{
super.setValue('value', level, verbose);
this.target = target;
callback();
}
this.setValue('target', target, verbose);
getCurrentPosition(callback, verbose)
{
callback(super.getValue('value', verbose));
if(callback != null)
{
callback();
}
}
getPositionState(callback, verbose)
getPositionState(callback, verbose = false)
{
callback(super.getValue('position', verbose));
this.state = this.getValue('state', verbose);
if(callback != null)
{
callback(null, this.state);
}
}
setPositionState(level, callback, verbose)
setPositionState(state, callback, verbose = false)
{
super.setValue('position', level, verbose);
this.state = state;
callback();
this.setValue('state', state, verbose);
if(callback != null)
{
callback();
}
}
}

@@ -14,64 +14,179 @@ const DimmedBulbService = require('./dimmedBulb');

this.hue = super.getValue('hue');
this.saturation = super.getValue('saturation');
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Hue).on('get', this.getHue.bind(this)).on('set', this.setHue.bind(this));
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Saturation).on('get', this.getSaturation.bind(this)).on('set', this.setSaturation.bind(this));
this.running = false;
this.hue = super.getValue('hue', false);
this.saturation = super.getValue('saturation', false);
this.tempState = {
value : this.value,
hue : this.hue,
saturation : this.saturation,
brightness : this.brightness
};
this.service.getCharacteristic(this.Characteristic.Hue).on('get', this.getHue.bind(this)).on('set', this.setHue.bind(this));
this.service.getCharacteristic(this.Characteristic.Saturation).on('get', this.getSaturation.bind(this)).on('set', this.setSaturation.bind(this));
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Hue).updateValue(this.hue);
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Saturation).updateValue(this.saturation);
this.service.getCharacteristic(this.Characteristic.Hue).updateValue(this.hue);
this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(this.saturation);
this.changeHandler = (state) => {
if(state instanceof Object)
{
var v = [
{ type : 'value', Characteristic : this.Characteristic.On },
{ type : 'hue', Characteristic : this.Characteristic.Hue },
{ type : 'saturation', Characteristic : this.Characteristic.Saturation },
{ type : 'brightness', Characteristic : this.Characteristic.Brightness }
];
const setState = () => {
for(const c of v)
if(this.changedValue)
{
if(state[c.type] != null)
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(c.Characteristic).updateValue(state[c.type]);
super.setValue('value', state[c.type]);
}
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value), false);
}
}
else
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
super.setValue('value', state);
}
if(this.changedColor)
{
this.setHue(state.hue,
() => this.service.getCharacteristic(this.Characteristic.Hue).updateValue(state.hue), false);
this.setSaturation(state.saturation,
() => this.service.getCharacteristic(this.Characteristic.Saturation).updateValue(state.saturation), false);
this.setBrightness(state.brightness,
() => this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness), false);
}
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
};
this.setToCurrentColor(state, (resolve) => {
setState();
resolve();
}, (resolve) => {
setState();
resolve();
}, (resolve) => {
resolve();
});
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.value, hue : this.hue, saturation : this.saturation, brightness : this.brightness });
};
}
getHue(callback, verbose)
getHue(callback, verbose = false)
{
callback(super.getValue('hue', verbose));
this.hue = this.getValue('hue', verbose);
if(callback != null)
{
callback(null, this.hue);
}
}
setHue(level, callback, verbose)
setHue(hue, callback, verbose = false)
{
super.setValue('hue', level, verbose);
this.hue = this.tempState.hue = hue;
callback();
this.setValue('hue', hue, verbose);
if(callback != null)
{
callback();
}
}
getSaturation(callback, verbose)
getSaturation(callback, verbose = false)
{
callback(super.getValue('saturation', verbose));
this.saturation = this.getValue('saturation', verbose);
if(callback != null)
{
callback(null, this.saturation);
}
}
setSaturation(level, callback, verbose)
setSaturation(saturation, callback, verbose = false)
{
super.setValue('saturation', level, verbose);
this.saturation = this.tempState.saturation = saturation;
callback();
this.setValue('saturation', saturation, verbose);
if(callback != null)
{
callback();
}
}
setToCurrentColor(state, powerCallback, colorCallback, unchangedCallback)
{
if(state.value != null && (!super.hasState('value') || this.tempState.value != state.value))
{
this.tempState.value = state.value;
this.changedValue = true;
}
if(state.hue != null && (!super.hasState('hue') || this.tempState.hue != state.hue))
{
this.tempState.hue = state.hue;
this.changedColor = true;
}
if(state.saturation != null && (!super.hasState('saturation') || this.tempState.saturation != state.saturation))
{
this.tempState.saturation = state.saturation;
this.changedColor = true;
}
if(state.brightness != null && (!super.hasState('brightness') || this.tempState.brightness != state.brightness))
{
this.tempState.brightness = state.brightness;
this.changedColor = true;
}
if(!this.running)
{
this.running = true;
setTimeout(() => {
if(this.changedValue)
{
powerCallback(() => {
this.changedValue = false;
this.running = false;
});
}
else if(this.changedColor)
{
colorCallback(() => {
this.changedColor = false;
this.running = false;
});
}
else
{
unchangedCallback(() => {
this.running = false;
});
}
}, 10);
}
else
{
unchangedCallback(() => {});
}
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.ContactSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.ContactSensorState).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.ContactSensorState).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.ContactSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.ContactSensorState).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.ContactSensorState).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.ContactSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.ContactSensorState).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.ContactSensorState).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -14,47 +14,139 @@ const LightBulbService = require('./lightBulb');

this.brightness = super.getValue('brightness');
this.running = false;
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Brightness).on('get', this.getBrightness.bind(this)).on('set', this.setBrightness.bind(this));
this.brightness = super.getValue('brightness', false);
this.tempState = {
value : this.value,
brightness : this.brightness
};
this.service.getCharacteristic(this.Characteristic.Brightness).on('get', this.getBrightness.bind(this)).on('set', this.setBrightness.bind(this));
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Brightness).updateValue(this.brightness);
this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(this.brightness);
this.changeHandler = (state) => {
if(state instanceof Object)
{
var v = [
{ type : 'value', Characteristic : this.Characteristic.On },
{ type : 'brightness', Characteristic : this.Characteristic.Brightness }
];
const setState = () => {
for(const c of v)
if(this.changedValue)
{
if(state[c.type] != null)
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(c.Characteristic).updateValue(state[c.type]);
super.setValue('value', state[c.type]);
}
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value), false);
}
}
else
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
super.setValue('value', state);
}
if(this.changedBrightness)
{
this.setBrightness(state.brightness,
() => this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness), false);
}
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
};
this.setToCurrentBrightness(state, (resolve) => {
setState();
resolve();
}, (resolve) => {
setState();
resolve();
}, (resolve) => {
resolve();
});
this.AutomationSystem.LogikEngine.runAutomation(this, { value : this.value, brightness : this.brightness });
};
}
getBrightness(callback, verbose)
setState(value, callback, verbose)
{
callback(super.getValue('brightness', verbose));
this.tempState.value = value;
super.setState(value, callback, verbose);
}
setBrightness(level, callback, verbose)
getBrightness(callback, verbose = false)
{
super.setValue('brightness', level, verbose);
this.brightness = this.getValue('brightness', verbose);
if(callback != null)
{
callback(null, this.brightness);
}
}
callback();
setBrightness(brightness, callback, verbose = false)
{
this.brightness = this.tempState.brightness = brightness;
this.setValue('brightness', brightness, verbose);
if(callback != null)
{
callback();
}
}
setToCurrentBrightness(state, powerCallback, brightnessCallback, unchangedCallback)
{
if(state.value != null && (!super.hasState('value') || this.tempState.value != state.value))
{
this.tempState.value = state.value;
this.changedValue = true;
}
if(state.brightness != null && (!super.hasState('brightness') || this.tempState.brightness != state.brightness))
{
this.tempState.brightness = state.brightness;
this.changedBrightness = true;
}
if(!this.running)
{
this.running = true;
setTimeout(() => {
if(this.changedValue)
{
powerCallback(() => {
this.changedValue = false;
this.running = false;
});
}
else if(this.changedBrightness)
{
brightnessCallback(() => {
this.changedBrightness = false;
this.running = false;
});
}
else
{
unchangedCallback(() => {
this.running = false;
});
}
}, 10);
}
else
{
unchangedCallback(() => {});
}
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.HumiditySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentRelativeHumidity).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.CurrentRelativeHumidity).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.HumiditySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentRelativeHumidity).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.CurrentRelativeHumidity).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.HumiditySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentRelativeHumidity).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.CurrentRelativeHumidity).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.LeakSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.LeakDetected).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.LeakDetected).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.LeakSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.LeakDetected).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.LeakDetected).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.LeakSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.LeakDetected).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.LeakDetected).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.LightSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.LightSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.LightSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.CurrentAmbientLightLevel).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -14,15 +14,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.service.getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.MotionSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.MotionDetected).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.MotionDetected).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.MotionSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.MotionDetected).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.MotionDetected).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.MotionSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.MotionDetected).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.MotionDetected).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.OccupancySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.OccupancyDetected).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.OccupancyDetected).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.OccupancySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.OccupancyDetected).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.OccupancyDetected).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.OccupancySensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.OccupancyDetected).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.OccupancyDetected).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.Outlet, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.service.getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
homebridgeAccessory.getServiceById(this.Service.Outlet, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.Outlet, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.SmokeSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.SmokeDetected).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.SmokeDetected).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.SmokeSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.SmokeDetected).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.SmokeDetected).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.SmokeSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.SmokeDetected).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.SmokeDetected).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,15 +9,19 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.Switch, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.service.getCharacteristic(this.Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
homebridgeAccessory.getServiceById(this.Service.Switch, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.On).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.Switch, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,16 +9,20 @@ const BaseService = require('../base');

this.value = super.getValue('value', true);
this.value = super.getValue('value');
homebridgeAccessory.getServiceById(this.Service.TemperatureSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentTemperature).on('get', this.getState.bind(this));
homebridgeAccessory.getServiceById(this.Service.TemperatureSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentTemperature).setProps({ minValue : -100, maxValue : 140 });
this.service.getCharacteristic(this.Characteristic.CurrentTemperature).on('get', this.getState.bind(this));
this.service.getCharacteristic(this.Characteristic.CurrentTemperature).setProps({ minValue : -100, maxValue : 140 });
homebridgeAccessory.getServiceById(this.Service.TemperatureSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentTemperature).updateValue(this.value);
this.service.getCharacteristic(this.Characteristic.CurrentTemperature).updateValue(this.value);
this.changeHandler = (state) => {
homebridgeAccessory.getServiceById(this.Service.TemperatureSensor, serviceConfig.subtype).getCharacteristic(this.Characteristic.CurrentTemperature).updateValue(state);
if(state.value != null)
{
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.CurrentTemperature).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -132,3 +132,3 @@ module.exports = class BaseService

getValue(key, verbose)
getValue(key, verbose = true)
{

@@ -152,30 +152,3 @@ var state = {}, characteristic = this.TypeManager.getCharacteristic(key, { letters : this.letters });

{
var stateText = JSON.stringify(state[key]), characteristics = Object.keys(this.homebridgeAccessory.context.data[this.letters]);
if(characteristics.length > 1)
{
stateText = 'value: ' + stateText;
}
if(characteristics.hue != null)
{
stateText += ', hue: ' + characteristics.hue;
}
if(characteristics.saturation != null)
{
stateText += ', saturation: ' + characteristics.saturation;
}
if(characteristics.brightness != null)
{
stateText += ', brightness: ' + characteristics.brightness;
}
if(characteristics.position != null)
{
stateText += ', position: ' + characteristics.position;
}
this.logger.log('read', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + stateText + '] ( ' + this.id + ' )');
this.logger.log('read', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
}

@@ -193,3 +166,3 @@ }

setValue(key, value, verbose)
setValue(key, value, verbose = true)
{

@@ -214,30 +187,3 @@ if(key != null && value != null && !isNaN(value))

{
var stateText = JSON.stringify(value), characteristics = Object.keys(this.homebridgeAccessory.context.data[this.letters]);
if(characteristics.length > 1)
{
stateText = 'value: ' + stateText;
}
if(characteristics.hue != null)
{
stateText += ', hue: ' + characteristics.hue;
}
if(characteristics.saturation != null)
{
stateText += ', saturation: ' + characteristics.saturation;
}
if(characteristics.brightness != null)
{
stateText += ', brightness: ' + characteristics.brightness;
}
if(characteristics.position != null)
{
stateText += ', position: ' + characteristics.position;
}
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [' + stateText + '] ( ' + this.id + ' )');
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
}

@@ -284,30 +230,3 @@

{
var stateText = JSON.stringify(state.value), characteristics = Object.keys(state);
if(characteristics.length > 1)
{
stateText = 'value: ' + stateText;
}
if(characteristics.hue != null)
{
stateText += ', hue: ' + characteristics.hue;
}
if(characteristics.saturation != null)
{
stateText += ', saturation: ' + characteristics.saturation;
}
if(characteristics.brightness != null)
{
stateText += ', brightness: ' + characteristics.brightness;
}
if(characteristics.position != null)
{
stateText += ', position: ' + characteristics.position;
}
this.logger.log('read', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + stateText + '] ( ' + this.id + ' )');
this.logger.log('read', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )');
}

@@ -323,12 +242,22 @@ }

getState(callback, verbose)
getState(callback, verbose = true)
{
callback(this.getValue('value', verbose));
this.value = this.getValue('value', verbose);
if(callback != null)
{
callback(null, this.value);
}
}
setState(level, callback, verbose)
setState(value, callback, verbose = true)
{
this.setValue('value', level, verbose);
this.value = value;
callback();
this.setValue('value', value, verbose);
if(callback != null)
{
callback();
}
}

@@ -396,2 +325,32 @@

}
getStateText()
{
var characteristics = this.TypeManager.getCharacteristics({ letters : this.letters }), array = [];
for(const type in characteristics)
{
var value = characteristics[type].default;
if(this.homebridgeAccessory != null
&& this.homebridgeAccessory.context != null
&& this.homebridgeAccessory.context.data != null
&& this.homebridgeAccessory.context.data[this.letters] != null
&& this.homebridgeAccessory.context.data[this.letters][type] != null)
{
value = this.homebridgeAccessory.context.data[this.letters][type];
}
if(Object.keys(characteristics).length > 1)
{
array.push(type + ': ' + value);
}
else
{
array.push(value);
}
}
return array.join(', ');
}
}

@@ -69,3 +69,3 @@ module.exports = class TypeManager

value : { format : 'boolean', default : false },
brightness : { format : 'number', default : 0, min : 0, max : 100 }
brightness : { format : 'number', default : 100, min : 0, max : 100 }
}

@@ -113,4 +113,23 @@ },

value : { format : 'number', default : 0, min : 0, max : 100 },
position : { format : 'number', default : 0, min : 0, max : 2 }
target : { format : 'number', default : 0, min : 0, max : 100 },
state : { format : 'number', default : 2, min : 0, max : 2 }
}
},
H : {
type : 'thermostat',
characteristics : {
value : { format : 'number', default : 0, min : -270, max : 100 },
target : { format : 'number', default : 4, min : 4, max : 36 },
state : { format : 'number', default : 0, min : 0, max : 2 },
mode : { format : 'number', default : 3, min : 1, max : 3 },
offset : { format : 'number', default : 0, min : -127, max : 128 }
}
},
I : {
type : 'fan',
characteristics : {
value : { format : 'boolean', default : false },
direction : { format : 'number', default : 0, min : 0, max : 1 },
speed : { format : 'number', default : 100, min : 0, max : 100 }
}
}

@@ -141,7 +160,7 @@ };

letterToType(letter)
letterToType(letters)
{
if(typeof letter == 'string' && this.data[letter.toUpperCase()] != null)
if(typeof letters == 'string' && this.data[letters[0].toUpperCase()] != null)
{
return this.data[letter.toUpperCase()].type;
return this.data[letters[0].toUpperCase()].type;
}

@@ -166,3 +185,3 @@

if(letter != null && type != null && this.data[letter] != null && this.data[letter].characteristics[type] != null)
if(letter != null && type != null && this.data[letter] != null && this.data[letter].characteristics != null && this.data[letter].characteristics[type] != null)
{

@@ -174,2 +193,24 @@ return this.data[letter].characteristics[type];

}
getCharacteristics(options)
{
var letter = null;
if(options.letters != null)
{
letter = options.letters[0].toUpperCase();
}
if(options.type != null)
{
letter = this.typeToLetter(options.type);
}
if(letter != null && this.data[letter] != null && this.data[letter].characteristics != null)
{
return this.data[letter].characteristics;
}
return null;
}

@@ -176,0 +217,0 @@ validateUpdate(id, letters, state)

@@ -20,2 +20,4 @@ let PlatformAccessory, Service, UUIDGen;

const BlindService = require('./accessories/blind');
const ThermostatService = require('./accessories/thermostat');
const FanService = require('./accessories/fan');

@@ -203,2 +205,10 @@ module.exports = class UniversalAccessory

}
else if(type == 'thermostat')
{
service = new ThermostatService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'fan')
{
service = new FanService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}

@@ -205,0 +215,0 @@ if(service != null)

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