homebridge-syntex-dynamic-platform
Advanced tools
Comparing version 1.0.8-b8 to 1.0.8-b80
@@ -0,0 +0,0 @@ { |
149
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.TypeManager = new TypeManager(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-b8", | ||
"version": "1.0.8-b80", | ||
"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-b26", | ||
"syntex-basic": "1.0.0-b18", | ||
"syntex-filesystem": "1.0.3-b10", | ||
"syntex-logger": "1.0.9-b3", | ||
"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" | ||
} | ||
} |
@@ -8,16 +8,16 @@ const BaseService = require('../base'); | ||
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.AirQualitySensor, manager); | ||
this.value = super.getValue('value', true); | ||
homebridgeAccessory.getServiceById(this.Service.AirQualitySensor, serviceConfig.subtype).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).on('get', this.getState.bind(this)); | ||
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,95 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
this.position = super.getValue('position'); | ||
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).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)); | ||
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.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,72 +14,111 @@ 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.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.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 = 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 = saturation; | ||
callback(); | ||
this.setValue('saturation', saturation, verbose); | ||
if(callback != null) | ||
{ | ||
callback(); | ||
} | ||
} | ||
setToCurrentColor(state, powerCallback, brightnessCallback, unchangedCallback) | ||
setToCurrentColor(state, powerCallback, colorCallback, unchangedCallback) | ||
{ | ||
if(state.value != null && (!super.hasState('value') || this.value != state.value)) | ||
{ | ||
this.value = state.value; | ||
this.tempState.value = state.value; | ||
this.changedPower = true; | ||
this.changedValue = true; | ||
} | ||
@@ -89,3 +128,3 @@ | ||
{ | ||
this.hue = state.hue; | ||
this.tempState.hue = state.hue; | ||
@@ -97,3 +136,3 @@ this.changedColor = true; | ||
{ | ||
this.saturation = state.saturation; | ||
this.tempState.saturation = state.saturation; | ||
@@ -105,3 +144,3 @@ this.changedColor = true; | ||
{ | ||
this.brightness = state.brightness; | ||
this.tempState.brightness = state.brightness; | ||
@@ -111,13 +150,13 @@ this.changedColor = true; | ||
setTimeout(() => { | ||
if(!this.running) | ||
{ | ||
this.running = true; | ||
if(!this.running) | ||
{ | ||
this.running = true; | ||
setTimeout(() => { | ||
if(this.changedPower) | ||
if(this.changedValue) | ||
{ | ||
powerCallback(() => { | ||
this.changedPower = false; | ||
this.changedValue = false; | ||
@@ -143,10 +182,10 @@ this.running = false; | ||
} | ||
} | ||
else | ||
{ | ||
unchangedCallback(() => {}); | ||
} | ||
}, 10); | ||
}, 10); | ||
} | ||
else | ||
{ | ||
unchangedCallback(() => {}); | ||
} | ||
} | ||
} |
@@ -9,15 +9,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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,46 +14,71 @@ 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)); | ||
homebridgeAccessory.getServiceById(this.Service.Lightbulb, serviceConfig.subtype).getCharacteristic(this.Characteristic.Brightness).updateValue(this.brightness); | ||
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)); | ||
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) | ||
getBrightness(callback, verbose = false) | ||
{ | ||
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 = false) | ||
{ | ||
super.setValue('brightness', level, verbose); | ||
this.brightness = brightness; | ||
callback(); | ||
this.setValue('brightness', brightness, verbose); | ||
if(callback != null) | ||
{ | ||
callback(); | ||
} | ||
} | ||
@@ -65,5 +90,5 @@ | ||
{ | ||
this.value = state.value; | ||
this.tempState.value = state.value; | ||
this.changedPower = true; | ||
this.changedValue = true; | ||
} | ||
@@ -73,3 +98,3 @@ | ||
{ | ||
this.brightness = state.brightness; | ||
this.tempState.brightness = state.brightness; | ||
@@ -79,13 +104,13 @@ this.changedBrightness = true; | ||
setTimeout(() => { | ||
if(!this.running) | ||
{ | ||
this.running = true; | ||
if(!this.running) | ||
{ | ||
this.running = true; | ||
setTimeout(() => { | ||
if(this.changedPower) | ||
if(this.changedValue) | ||
{ | ||
powerCallback(() => { | ||
this.changedPower = false; | ||
this.changedValue = false; | ||
@@ -111,10 +136,10 @@ this.running = false; | ||
} | ||
} | ||
else | ||
{ | ||
unchangedCallback(() => {}); | ||
} | ||
}, 10); | ||
}, 10); | ||
} | ||
else | ||
{ | ||
unchangedCallback(() => {}); | ||
} | ||
} | ||
} |
@@ -9,15 +9,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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); | ||
}; | ||
} | ||
} |
@@ -8,16 +8,16 @@ const BaseService = require('../base'); | ||
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.LeakSensor, manager); | ||
this.value = super.getValue('value', true); | ||
homebridgeAccessory.getServiceById(this.Service.LeakSensor, serviceConfig.subtype).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).on('get', this.getState.bind(this)); | ||
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); | ||
}; | ||
} | ||
} |
@@ -8,16 +8,16 @@ const BaseService = require('../base'); | ||
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.LightSensor, manager); | ||
this.value = super.getValue('value', true); | ||
homebridgeAccessory.getServiceById(this.Service.LightSensor, serviceConfig.subtype).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).on('get', this.getState.bind(this)); | ||
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,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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); | ||
}; | ||
} | ||
} |
@@ -8,16 +8,16 @@ const BaseService = require('../base'); | ||
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.MotionSensor, manager); | ||
this.value = super.getValue('value', true); | ||
homebridgeAccessory.getServiceById(this.Service.MotionSensor, serviceConfig.subtype).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).on('get', this.getState.bind(this)); | ||
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,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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); | ||
}; | ||
} | ||
} |
@@ -8,16 +8,16 @@ const BaseService = require('../base'); | ||
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.SmokeSensor, manager); | ||
this.value = super.getValue('value', true); | ||
homebridgeAccessory.getServiceById(this.Service.SmokeSensor, serviceConfig.subtype).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).on('get', this.getState.bind(this)); | ||
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,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
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.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,15 @@ const BaseService = require('../base'); | ||
this.value = super.getValue('value', true); | ||
this.service.getCharacteristic(this.Characteristic.CurrentTemperature).on('get', this.getState.bind(this)); | ||
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 }); | ||
homebridgeAccessory.getServiceById(this.Service.TemperatureSensor, serviceConfig.subtype).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); | ||
}; | ||
} | ||
} |
203
src/base.js
@@ -35,7 +35,11 @@ module.exports = class BaseService | ||
this.options.virtual = serviceConfig.virtual || false; | ||
this.options.requests = serviceConfig.requests || []; | ||
this.options.characteristics = serviceConfig.characteristics || {}; | ||
this.virtual = deviceConfig.virtual || false; | ||
this.service = this.createService(serviceType, serviceConfig.type, serviceConfig.subtype); | ||
this.createCharacteristics(); | ||
this.connection = this.service.getCharacteristic(this.Characteristic.Connection) || this.service.addCharacteristic(this.Characteristic.Connection); | ||
@@ -133,3 +137,3 @@ | ||
getValue(key, verbose) | ||
getValue(key, verbose = true) | ||
{ | ||
@@ -153,30 +157,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 + ' )'); | ||
} | ||
@@ -189,2 +166,4 @@ } | ||
this.EventManager.setOutputStream('stateUpdate', { sender : this }, { type : 'READ', service : { id : this.id, letters : this.letters }, state }); | ||
this.ContextManager.updateContext(this.id, this.letters, state, true); | ||
@@ -195,3 +174,3 @@ | ||
setValue(key, value, verbose) | ||
setValue(key, value, verbose = true) | ||
{ | ||
@@ -202,2 +181,6 @@ if(key != null && value != null && !isNaN(value)) | ||
{ | ||
var state = {}; | ||
state[key] = value; | ||
if(!this.homebridgeAccessory.context.data) | ||
@@ -217,32 +200,7 @@ { | ||
{ | ||
var stateText = JSON.stringify(value), characteristics = Object.keys(this.homebridgeAccessory.context.data[this.letters]); | ||
this.logger.log('update', this.id, this.letters, '%update_state[0]% [' + this.name + '] %update_state[1]% [' + this.getStateText() + '] ( ' + this.id + ' )'); | ||
} | ||
if(characteristics.length > 1) | ||
{ | ||
stateText = 'value: ' + stateText; | ||
} | ||
this.EventManager.setOutputStream('stateUpdate', { sender : this }, { type : 'WRITE', service : { id : this.id, letters : this.letters }, state }); | ||
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.ContextManager.updateContext(this.id, this.letters, this.getValues()); | ||
@@ -287,30 +245,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 + ' )'); | ||
} | ||
@@ -326,12 +257,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(); | ||
} | ||
} | ||
@@ -399,2 +340,80 @@ | ||
} | ||
getStateText() | ||
{ | ||
var characteristics = this.TypeManager.getCharacteristics({ letters : this.letters }), array = []; | ||
for(const type in characteristics) | ||
{ | ||
if(characteristics[type].characteristic != null) | ||
{ | ||
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(', '); | ||
} | ||
createCharacteristics() | ||
{ | ||
var characteristics = this.TypeManager.getCharacteristics({ letters : this.letters }); | ||
if(characteristics != null) | ||
{ | ||
for(const type in characteristics) | ||
{ | ||
this[type] = this.getValue(type, type == 'value'); | ||
if(characteristics[type].characteristic != null) | ||
{ | ||
var characteristic = this.service.getCharacteristic(characteristics[type].characteristic); | ||
characteristic.updateValue(this[type]); | ||
if(this.options.characteristics[type] != null) | ||
{ | ||
characteristic.setProps(this.options.characteristics[type]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
updateProperties(type, properties) | ||
{ | ||
var characteristics = this.TypeManager.getCharacteristics({ letters : this.letters }); | ||
if(characteristics != null && characteristics[type] != null && characteristics[type].characteristic != null) | ||
{ | ||
var options = this.options.characteristics[type] || {}, characteristic = this.service.getCharacteristic(characteristics[type].characteristic); | ||
for(const x in properties) | ||
{ | ||
if(options[x] == null) | ||
{ | ||
options[x] = properties[x]; | ||
} | ||
} | ||
characteristic.setProps(options); | ||
} | ||
} | ||
} |
@@ -19,4 +19,6 @@ const fs = require('fs'), path = require('path'); | ||
{ | ||
this.path = path.join(platform.baseDirectory, 'activity', platform.pluginName + '.txt'); | ||
this.baseDirectory = platform.baseDirectory; | ||
this.path = path.join(this.baseDirectory, 'activity', platform.pluginName + '.txt'); | ||
this.files.readFile(this.path).then((data) => { | ||
@@ -23,0 +25,0 @@ |
module.exports = class TypeManager | ||
{ | ||
constructor(logger) | ||
constructor(platform) | ||
{ | ||
this.logger = logger; | ||
this.services = []; | ||
this.data = { | ||
0 : { | ||
type : 'occupancy', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
1 : { | ||
type : 'smoke', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
2 : { | ||
type : 'airquality', | ||
characteristics : { | ||
value : { format : 'number', default : 0, min : 0, max : 5 } | ||
} | ||
}, | ||
3 : { | ||
type : 'rgb', | ||
characteristics : { | ||
value : { format : 'boolean', default : false }, | ||
brightness : { format : 'number', default : 100, min : 0, max : 100 }, | ||
saturation : { format : 'number', default : 100, min : 0, max : 100 }, | ||
hue : { format : 'number', default : 0, min : 0, max : 360 } | ||
} | ||
}, | ||
4 : { | ||
type : 'switch', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
5 : { | ||
type : 'relais', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
6 : { | ||
type : 'statelessswitch', | ||
characteristics : { | ||
value : { format : 'number' } | ||
} | ||
}, | ||
7 : { | ||
type : 'outlet', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
8 : { | ||
type : 'led', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
9 : { | ||
type : 'dimmer', | ||
characteristics : { | ||
value : { format : 'boolean', default : false }, | ||
brightness : { format : 'number', default : 0, min : 0, max : 100 } | ||
} | ||
}, | ||
A : { | ||
type : 'contact', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
B : { | ||
type : 'motion', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
C : { | ||
type : 'temperature', | ||
characteristics : { | ||
value : { format : 'number', default : 0, min : -270, max : 100 } | ||
} | ||
}, | ||
D : { | ||
type : 'humidity', | ||
characteristics : { | ||
value : { format : 'number', default : 0, min : 0, max : 100 } | ||
} | ||
}, | ||
E : { | ||
type : 'rain', | ||
characteristics : { | ||
value : { format : 'boolean', default : false } | ||
} | ||
}, | ||
F : { | ||
type : 'light', | ||
characteristics : { | ||
value : { format : 'number', default : 0.0001, min : 0.0001, max : 100000 } | ||
} | ||
}, | ||
G : { | ||
type : 'blind', | ||
characteristics : { | ||
value : { format : 'number', default : 0, min : 0, max : 100 }, | ||
position : { format : 'number', default : 0, min : 0, max : 2 } | ||
} | ||
} | ||
}; | ||
this.logger = platform.logger; | ||
this.Characteristic = platform.api.hap.Characteristic; | ||
this.addServices([ AirQuality, Blind, ColoredBulb, Contact, DimmedBulb, Fan, Humidity, Leak, Light, LightBulb, Motion, Occupancy, Outlet, Relais, Smoke, StatelessSwitch, Switch, Temperature, Thermostat ]); | ||
} | ||
@@ -120,16 +16,7 @@ | ||
{ | ||
if(typeof type == 'string') | ||
var service = this.getService({ type : type.startsWith('rgb') ? 'rgb' : type }); | ||
if(service != null) | ||
{ | ||
if(type.startsWith('rgb')) | ||
{ | ||
type = 'rgb'; | ||
} | ||
for(const letter in this.data) | ||
{ | ||
if(this.data[letter].type == type.toLowerCase()) | ||
{ | ||
return letter; | ||
} | ||
} | ||
return service.letter; | ||
} | ||
@@ -140,7 +27,9 @@ | ||
letterToType(letter) | ||
letterToType(letters) | ||
{ | ||
if(typeof letter == 'string' && this.data[letter.toUpperCase()] != null) | ||
var service = this.getService({ letters }); | ||
if(service != null) | ||
{ | ||
return this.data[letter.toUpperCase()].type; | ||
return service.type; | ||
} | ||
@@ -151,19 +40,46 @@ | ||
getCharacteristic(type, options) | ||
getCharacteristic(type, options = {}) | ||
{ | ||
var letter = null; | ||
var service = this.getService(options); | ||
if(service != null) | ||
{ | ||
if(service.characteristics[type] != null) | ||
{ | ||
return service.characteristics[type]; | ||
} | ||
} | ||
return null; | ||
} | ||
getCharacteristics(options = {}) | ||
{ | ||
var service = this.getService(options); | ||
if(options.letters != null) | ||
if(service != null) | ||
{ | ||
letter = options.letters[0].toUpperCase(); | ||
return service.characteristics; | ||
} | ||
if(options.type != null) | ||
return null; | ||
} | ||
addServices(services) | ||
{ | ||
for(const Service of services) | ||
{ | ||
letter = this.typeToLetter(options.type); | ||
this.services.push(new Service(this.Characteristic)); | ||
} | ||
} | ||
if(letter != null && type != null && this.data[letter] != null && this.data[letter].characteristics[type] != null) | ||
getService(options = {}) | ||
{ | ||
for(const service of this.services) | ||
{ | ||
return this.data[letter].characteristics[type]; | ||
if((typeof options.type == 'string' && options.type.toLowerCase() == service.type) | ||
|| (typeof options.letters == 'string' && options.letters[0].toUpperCase() == service.letter)) | ||
{ | ||
return service; | ||
} | ||
} | ||
@@ -173,6 +89,6 @@ | ||
} | ||
validateUpdate(id, letters, state) | ||
{ | ||
if(id != null && letters != null && state != null && state instanceof Object) | ||
if(id != null && letters != null && state instanceof Object) | ||
{ | ||
@@ -223,2 +139,235 @@ for(const x in state) | ||
} | ||
}; | ||
} | ||
class ServiceType | ||
{ | ||
constructor(type, letter) | ||
{ | ||
this.characteristics = {}; | ||
this.type = type; | ||
this.letter = letter; | ||
} | ||
addCharacteristic(type, format, characteristic, options = {}) | ||
{ | ||
this.characteristics[type] = { format, characteristic }; | ||
if(format == 'boolean') | ||
{ | ||
this.characteristics[type].default = false; | ||
} | ||
else if(format == 'number') | ||
{ | ||
this.characteristics[type].default = 0; | ||
} | ||
for(const x in options) | ||
{ | ||
this.characteristics[type][x] = options[x]; | ||
} | ||
} | ||
} | ||
class Occupancy extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('occupancy', '0'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.OccupancyDetected); | ||
} | ||
} | ||
class Smoke extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('smoke', '1'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.SmokeDetected); | ||
} | ||
} | ||
class AirQuality extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('airquality', '2'); | ||
this.addCharacteristic('value', 'number', Characteristic.AirQuality, { min : 0, max : 5 }); | ||
} | ||
} | ||
class ColoredBulb extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('rgb', '3'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
this.addCharacteristic('hue', 'number', Characteristic.Hue, { min : 0, max : 360 }); | ||
this.addCharacteristic('saturation', 'number', Characteristic.Saturation, { min : 0, max : 100, default : 100 }); | ||
this.addCharacteristic('brightness', 'number', Characteristic.Brightness, { min : 0, max : 100, default : 100 }); | ||
} | ||
} | ||
class Switch extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('switch', '4'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
} | ||
} | ||
class Relais extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('relais', '5'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
} | ||
} | ||
class StatelessSwitch extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('statelessswitch', '6'); | ||
this.addCharacteristic('value', 'number', Characteristic.ProgrammableSwitchEvent); | ||
} | ||
} | ||
class Outlet extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('outlet', '7'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
} | ||
} | ||
class LightBulb extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('led', '8'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
} | ||
} | ||
class DimmedBulb extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('dimmer', '9'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
this.addCharacteristic('brightness', 'number', Characteristic.Brightness, { min : 0, max : 100, default : 100 }); | ||
} | ||
} | ||
class Contact extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('contact', 'A'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.ContactSensorState); | ||
} | ||
} | ||
class Motion extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('motion', 'B'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.MotionDetected); | ||
} | ||
} | ||
class Temperature extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('temperature', 'C'); | ||
this.addCharacteristic('value', 'number', Characteristic.CurrentTemperature, { min : -270, max : 100 }); | ||
} | ||
} | ||
class Humidity extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('humidity', 'D'); | ||
this.addCharacteristic('value', 'number', Characteristic.CurrentRelativeHumidity, { min : 0, max : 100 }); | ||
} | ||
} | ||
class Leak extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('rain', 'E'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.LeakDetected); | ||
} | ||
} | ||
class Light extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('light', 'F'); | ||
this.addCharacteristic('value', 'number', Characteristic.CurrentAmbientLightLevel, { min : 0.0001, max : 100000 , default : 0.0001}); | ||
} | ||
} | ||
class Blind extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('blind', 'G'); | ||
this.addCharacteristic('value', 'number', Characteristic.CurrentPosition, { min : 0, max : 100 }); | ||
this.addCharacteristic('target', 'number', Characteristic.TargetPosition, { min : 0, max : 100 }); | ||
this.addCharacteristic('state', 'number', Characteristic.PositionState, { min : 0, max : 2, default : 2 }); | ||
} | ||
} | ||
class Thermostat extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('thermostat', 'H'); | ||
this.addCharacteristic('value', 'number', Characteristic.CurrentTemperature, { min : -270, max : 100 }); | ||
this.addCharacteristic('target', 'number', Characteristic.TargetTemperature, { min : 4, max : 36, default : 4 }); | ||
this.addCharacteristic('state', 'number', Characteristic.CurrentHeatingCoolingState, { min : 0, max : 2 }); | ||
this.addCharacteristic('mode', 'number', Characteristic.TargetHeatingCoolingState, { min : 1, max : 3, default : 3 }); | ||
this.addCharacteristic('base', 'number', null, { min : 4, max : 36, default : 4 }); | ||
this.addCharacteristic('offset', 'number', null, { min : -127, max : 128 }); | ||
} | ||
} | ||
class Fan extends ServiceType | ||
{ | ||
constructor(Characteristic) | ||
{ | ||
super('fan', 'I'); | ||
this.addCharacteristic('value', 'boolean', Characteristic.On); | ||
this.addCharacteristic('speed', 'number', Characteristic.RotationSpeed, { min : 0, max : 100, default : 100 }); | ||
this.addCharacteristic('direction', 'number', Characteristic.RotationDirection, { min : 0, max : 1 }); | ||
} | ||
} |
@@ -20,2 +20,4 @@ let PlatformAccessory, Service, UUIDGen; | ||
const BlindService = require('./accessories/blind'); | ||
const ThermostatService = require('./accessories/thermostat'); | ||
const FanService = require('./accessories/fan'); | ||
@@ -47,3 +49,3 @@ module.exports = class UniversalAccessory | ||
({ Service, uuid: UUIDGen } = manager.platform.api.hap); | ||
({ Service, uuid : UUIDGen } = manager.platform.api.hap); | ||
@@ -204,2 +206,10 @@ this.homebridgeAccessory = homebridgeAccessory; | ||
} | ||
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); | ||
} | ||
@@ -238,3 +248,3 @@ if(service != null) | ||
{ | ||
if(service.letters[1] == counter) | ||
if(service.letters.slice(1) == counter) | ||
{ | ||
@@ -241,0 +251,0 @@ platform.accessories[i].services.splice(j, 1); |
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
102927
34
3014
2
+ Addedsyntex-basic@1.0.0-b18
+ Addedcharenc@0.0.2(transitive)
+ Addedcrypt@0.0.2(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedmd5@2.3.0(transitive)
+ Addedsyntex-automation@1.2.1-b26(transitive)
+ Addedsyntex-basic@1.0.0-b18(transitive)
+ Addedsyntex-filesystem@1.0.3-b10(transitive)
+ Addedsyntex-logger@1.0.9-b3(transitive)
+ Addedsyntex-webserver@1.1.1-b14(transitive)
- Removedaxios@^0.21.1
- Removedaxios@0.21.4(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedsyntex-automation@1.2.0(transitive)
- Removedsyntex-filesystem@1.0.2(transitive)
- Removedsyntex-logger@1.0.8(transitive)
- Removedsyntex-webserver@1.1.0(transitive)
Updatedsyntex-automation@1.2.1-b26
Updatedsyntex-filesystem@1.0.3-b10
Updatedsyntex-logger@1.0.9-b3
Updatedsyntex-webserver@1.1.1-b14