Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homebridge-syntex-dynamic-platform

Package Overview
Dependencies
Maintainers
1
Versions
348
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-b5 to 1.0.8-b50

src/accessories/thermostat.js

163

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,7 @@ const ContextManager = require('./src/context');

const BlindService = require('./src/accessories/blind');
const ThermostatService = require('./src/accessories/thermostat');
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 +42,2 @@ let DynamicPlatform = class SynTexDynamicPlatform

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

@@ -53,12 +52,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 +74,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 +92,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,72 +143,81 @@

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)
if(urlParams.value != null)
{
state.hue = urlParams.hue;
let state = { value : urlParams.value };
if(urlParams.hue != null)
{
state.hue = urlParams.hue;
}
if(urlParams.saturation != null)
{
state.saturation = urlParams.saturation;
}
if(urlParams.brightness != null)
{
state.brightness = urlParams.brightness;
}
if(urlParams.event != null)
{
state.event = urlParams.event;
}
state = this.updateAccessoryService(service, state);
response.end(state != null ? 'Success' : 'Error');
}
if(urlParams.saturation != null)
else
{
state.saturation = urlParams.saturation;
let state = null;
if(accessory.homebridgeAccessory != null
&& accessory.homebridgeAccessory.context != null
&& accessory.homebridgeAccessory.context.data != null)
{
if(urlParams.type == null && urlParams.counter == null)
{
state = accessory.homebridgeAccessory.context.data;
}
else if(service != null && service.letters != null)
{
state = accessory.homebridgeAccessory.context.data[service.letters];
}
}
response.end(state != null ? JSON.stringify(state) : 'Error');
}
if(urlParams.brightness != null)
{
state.brightness = urlParams.brightness;
}
if(urlParams.event != null)
{
state.event = urlParams.event;
}
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(urlParams.type == null && urlParams.counter == null)
{
state = accessory.homebridgeAccessory.context.data;
}
else if(service != null && service.letters != null)
{
state = accessory.homebridgeAccessory.context.data[service.letters];
}
}
response.end(state != null ? JSON.stringify(state) : 'Error');
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') + ' )');
}
}
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, '', '%accessory_not_found[2]%! ( ' + urlParams.id + ' )');
}

@@ -473,3 +484,3 @@ }

{
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;

@@ -481,9 +492,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);
}

@@ -495,8 +506,2 @@ }

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

@@ -571,2 +576,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, OutletService, SwitchService, LightBulbService, DimmedBulbService, ColoredBulbService, ContactService, LightService, MotionService, TemperatureService, HumidityService, LeakService, OccupancyService, StatelessSwitchService, SmokeService, AirQualityService, BlindService, ThermostatService };
{
"name": "homebridge-syntex-dynamic-platform",
"version": "1.0.8-b5",
"version": "1.0.8-b50",
"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)
{
super.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.AirQuality).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -9,39 +9,59 @@ 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)
{
var stateText = this.getStateText(this.letters);
this.logger.log('update', this.id, this.letters, '%read_state[0]% [' + this.name + '] %read_state[1]% [' + stateText + '] ( ' + this.id + ' )');
}
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};

@@ -52,15 +72,20 @@ }

{
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)
{
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();
}
}

@@ -70,11 +95,21 @@

{
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)
{
super.setValue('position', level, verbose);
this.state = state;
callback();
this.setValue('state', state, verbose);
if(callback != null)
{
callback();
}
}
}

@@ -14,38 +14,48 @@ 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 }
];
this.setToCurrentColor(state, (resolve) => {
for(const c of v)
{
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]);
}
}
}
else
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
super.setValue('value', state);
}
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value));
resolve();
}, (resolve) => {
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));
resolve();
}, (resolve) => {
resolve();
});
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};

@@ -56,10 +66,20 @@ }

{
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)
{
super.setValue('hue', level, verbose);
this.hue = hue;
callback();
this.setValue('hue', hue, verbose);
if(callback != null)
{
callback();
}
}

@@ -69,11 +89,91 @@

{
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)
{
super.setValue('saturation', level, verbose);
this.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.changedPower = 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.changedPower)
{
powerCallback(() => {
this.changedPower = 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)
{
super.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.ContactSensorState).updateValue(state.value));
}
super.setValue('value', state);
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};
}
}

@@ -14,33 +14,37 @@ 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 }
];
this.setToCurrentBrightness(state, (resolve) => {
for(const c of v)
{
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]);
}
}
}
else
{
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.On).updateValue(state);
super.setValue('value', state);
}
this.setState(state.value,
() => this.service.getCharacteristic(this.Characteristic.On).updateValue(state.value));
resolve();
}, (resolve) => {
this.setBrightness(state.brightness,
() => this.service.getCharacteristic(this.Characteristic.Brightness).updateValue(state.brightness));
resolve();
}, (resolve) => {
resolve();
});
this.AutomationSystem.LogikEngine.runAutomation(this, state);
};

@@ -51,11 +55,77 @@ }

{
callback(super.getValue('brightness', verbose));
this.brightness = this.getValue('brightness', verbose);
if(callback != null)
{
callback(null, this.brightness);
}
}
setBrightness(level, callback, verbose)
setBrightness(brightness, callback, verbose)
{
super.setValue('brightness', level, verbose);
this.brightness = brightness;
callback();
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.changedPower = 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.changedPower)
{
powerCallback(() => {
this.changedPower = 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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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)
{
super.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,29 +152,4 @@ 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]);
var stateText = this.getStateText(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 + ' )');

@@ -193,3 +168,3 @@ }

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

@@ -214,29 +189,4 @@ if(key != null && value != null && !isNaN(value))

{
var stateText = JSON.stringify(value), characteristics = Object.keys(this.homebridgeAccessory.context.data[this.letters]);
var stateText = this.getStateText(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 + ' )');

@@ -284,29 +234,4 @@ }

{
var stateText = JSON.stringify(state.value), characteristics = Object.keys(state);
var stateText = this.getStateText(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 + ' )');

@@ -323,12 +248,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 +331,32 @@

}
getStateText(letters)
{
var characteristics = this.TypeManager.getCharacteristics({ 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[letters] != null
&& this.homebridgeAccessory.context.data[letters][type] != null)
{
value = this.homebridgeAccessory.context.data[letters][type];
}
if(Object.keys(characteristics).length > 1)
{
array.push(type + ': ' + value);
}
else
{
array.push(value);
}
}
return array.join(', ');
}
}

@@ -40,6 +40,6 @@ const fs = require('fs'), path = require('path');

{
this.context[entry.id][entry.letters] = { time : entry.time * 60000, state : entry.state };
this.context[entry.id][entry.letters] = { time : entry.time * 60000, state : { ...entry.state } };
}
this.cache[entry.id][entry.letters].history.push({ time : entry.time * 60000, state : entry.state });
this.cache[entry.id][entry.letters].history.push({ time : entry.time * 60000, state : { ...entry.state } });
}

@@ -287,3 +287,3 @@ else if(entry.automation != null)

if(new Date().getTime() - time < 86400000)
if(new Date().getTime() - time < 86400000 * 2)
{

@@ -290,0 +290,0 @@ newData += JSON.stringify(entry) + '\n';

@@ -112,4 +112,15 @@ module.exports = class TypeManager

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 : 0, 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 }
}
}

@@ -140,7 +151,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;
}

@@ -165,3 +176,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)
{

@@ -173,2 +184,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;
}

@@ -175,0 +208,0 @@ validateUpdate(id, letters, state)

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

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

@@ -203,2 +204,6 @@ module.exports = class UniversalAccessory

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

@@ -205,0 +210,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