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.0 to 1.0.1-b1

10

accessories/base.js

@@ -20,5 +20,5 @@ module.exports = class BaseService

var service = homebridgeAccessory.getServiceById(serviceType, serviceConfig.subtype);
var service = homebridgeAccessory.getServiceById(serviceType, serviceConfig.subtype);
if(service)
if(service)
{

@@ -33,4 +33,4 @@ this.logger.debug('Existierenden Service gefunden! ' + serviceConfig.name + ' ' + serviceConfig.type + ' ' + serviceConfig.subtype + ' ( ' + this.id + ' )');

homebridgeAccessory.addService(serviceType, serviceConfig.name, serviceConfig.subtype)
}
homebridgeAccessory.addService(serviceType, serviceConfig.name, serviceConfig.subtype)
}
}

@@ -42,4 +42,2 @@

console.log(key, this.homebridgeAccessory.context);
if(this.homebridgeAccessory != null

@@ -46,0 +44,0 @@ && this.homebridgeAccessory.context != null

10

accessories/coloredBulb.js

@@ -16,3 +16,3 @@ const DimmedBulbService = require('./dimmedBulb');

}
super(homebridgeAccessory, deviceConfig, serviceConfig, manager);

@@ -24,3 +24,3 @@

this.changeHandler = (state) =>
{
{
if(state instanceof Object)

@@ -51,3 +51,3 @@ {

}
};
};
}

@@ -62,3 +62,3 @@

{
super.setValue('hue', level, verbose);
super.setValue('hue', level, verbose);

@@ -75,3 +75,3 @@ callback();

{
super.setValue('saturation', level, verbose);
super.setValue('saturation', level, verbose);

@@ -78,0 +78,0 @@ callback();

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

Service = manager.platform.api.hap.Service;
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.ContactSensor, manager);
homebridgeAccessory.getServiceById(Service.ContactSensor, serviceConfig.subtype).getCharacteristic(Characteristic.ContactSensorState).on('get', this.getState.bind(this));
this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.ContactSensor, serviceConfig.subtype).getCharacteristic(Characteristic.ContactSensorState).updateValue(state);
this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.ContactSensor, serviceConfig.subtype).getCharacteristic(Characteristic.ContactSensorState).updateValue(state);
super.setValue('state', state);
};
}
super.setValue('state', state);
};
}
getState(callback, verbose)
{
callback(super.getValue('state', verbose));
callback(super.getValue('state', verbose));
}
}

@@ -16,3 +16,3 @@ const LightBulbService = require('./lightBulb');

}
super(homebridgeAccessory, deviceConfig, serviceConfig, manager);

@@ -23,3 +23,3 @@

this.changeHandler = (state) =>
{
{
if(state instanceof Object)

@@ -48,3 +48,3 @@ {

}
};
};
}

@@ -59,3 +59,3 @@

{
super.setValue('brightness', level, verbose);
super.setValue('brightness', level, verbose);

@@ -62,0 +62,0 @@ callback();

@@ -5,10 +5,10 @@ let Service, Characteristic;

{
constructor(homebridgeAccessory, deviceConfig, serviceConfig, manager)
{
Service = manager.platform.api.hap.Service;
Characteristic = manager.platform.api.hap.Characteristic;
constructor(homebridgeAccessory, deviceConfig, serviceConfig, manager)
{
Service = manager.platform.api.hap.Service;
Characteristic = manager.platform.api.hap.Characteristic;
var service = homebridgeAccessory.getService(Service.AccessoryInformation);
var service = homebridgeAccessory.getService(Service.AccessoryInformation);
if(service)
if(service)
{

@@ -21,10 +21,10 @@ manager.logger.debug('Existierenden Informations-Service gefunden! ' + deviceConfig.name + ' ( ' + deviceConfig.id + ' )');

service = homebridgeAccessory.addService(Service.AccessoryInformation, deviceConfig.name);
}
service = homebridgeAccessory.addService(Service.AccessoryInformation, deviceConfig.name);
}
service.setCharacteristic(Characteristic.Manufacturer, serviceConfig.manufacturer)
.setCharacteristic(Characteristic.SerialNumber, deviceConfig.id)
.setCharacteristic(Characteristic.Model, serviceConfig.model)
.setCharacteristic(Characteristic.FirmwareRevision, serviceConfig.version);
}
service.setCharacteristic(Characteristic.Manufacturer, serviceConfig.manufacturer)
.setCharacteristic(Characteristic.SerialNumber, deviceConfig.id)
.setCharacteristic(Characteristic.Model, serviceConfig.model)
.setCharacteristic(Characteristic.FirmwareRevision, serviceConfig.version);
}
}

@@ -22,7 +22,7 @@ const BaseService = require('./base');

this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Lightbulb, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
{
homebridgeAccessory.getServiceById(Service.Lightbulb, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
super.setValue('state', state);
};
super.setValue('state', state);
};
}

@@ -32,3 +32,3 @@

{
callback(super.getValue('state', verbose));
callback(super.getValue('state', verbose));
}

@@ -35,0 +35,0 @@

@@ -11,3 +11,3 @@ const BaseService = require('./base');

Service = manager.platform.api.hap.Service;
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.Outlet, manager);

@@ -18,7 +18,7 @@

this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Outlet, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
{
homebridgeAccessory.getServiceById(Service.Outlet, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
super.setValue('state', state);
};
super.setValue('state', state);
};
}

@@ -28,3 +28,3 @@

{
callback(super.getValue('state', verbose));
callback(super.getValue('state', verbose));
}

@@ -31,0 +31,0 @@

@@ -11,3 +11,3 @@ const BaseService = require('./base');

Service = manager.platform.api.hap.Service;
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.Switch, manager);

@@ -18,7 +18,7 @@

this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Switch, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
{
homebridgeAccessory.getServiceById(Service.Switch, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
super.setValue('state', state);
};
super.setValue('state', state);
};
}

@@ -28,3 +28,3 @@

{
callback(super.getValue('state', verbose));
callback(super.getValue('state', verbose));
}

@@ -31,0 +31,0 @@

@@ -22,8 +22,8 @@ const AccessoryInformationService = require('./info');

this.service = [];
this.id = deviceConfig['id'];
this.name = deviceConfig['name'];
this.services = deviceConfig['services'];
this.id = deviceConfig['id'];
this.name = deviceConfig['name'];
this.services = deviceConfig['services'];
this.manufacturer = deviceConfig['manufacturer'] || 'SynTex';
this.model = deviceConfig['model'] || 'Virtual Accessory';
this.model = deviceConfig['model'] || 'Virtual Accessory';
this.version = deviceConfig['version'] || '1.0.0';

@@ -159,20 +159,20 @@

getID()
{
return this.id;
}
{
return this.id;
}
getManufacturer()
{
return this.manufacturer
}
getManufacturer()
{
return this.manufacturer
}
getModel()
{
return this.model;
}
getModel()
{
return this.model;
}
getVersion()
{
return this.version;
}
getVersion()
{
return this.version;
}
}

@@ -6,122 +6,122 @@ const store = require('json-fs-store');

{
constructor(pluginName, logDirectory, debug)
{
prefix = pluginName;
logs = store(logDirectory);
constructor(pluginName, logDirectory, debug)
{
prefix = pluginName;
logs = store(logDirectory);
logger = this;
logger = this;
if(debug)
{
debugLevel = 'debug';
}
}
if(debug)
{
debugLevel = 'debug';
}
}
log(level, id, letters, message)
{
var levels = ['debug', 'success', 'update', 'read', 'info', 'warn', 'error'];
log(level, id, letters, message)
{
var levels = ['debug', 'success', 'update', 'read', 'info', 'warn', 'error'];
if(levels.indexOf(level) >= levels.indexOf(debugLevel))
{
if(typeof message !== 'string')
{
message = JSON.stringify(message);
};
if(levels.indexOf(level) >= levels.indexOf(debugLevel))
{
if(typeof message !== 'string')
{
message = JSON.stringify(message);
};
var color = '';
var color = '';
if(level == 'success')
{
color = '\x1b[92m';
}
else if(level == 'update')
{
color = '\x1b[96m';
}
else if(level == 'read')
{
color = '\x1b[36m';
}
else if(level == 'info')
{
color = '\x1b[93m';
}
else if(level == 'warn')
{
color = '\x1b[93m';
}
else if(level == 'debug')
{
color = '\x1b[35m';
}
else
{
color = '\x1b[31m';
}
if(level == 'success')
{
color = '\x1b[92m';
}
else if(level == 'update')
{
color = '\x1b[96m';
}
else if(level == 'read')
{
color = '\x1b[36m';
}
else if(level == 'info')
{
color = '\x1b[93m';
}
else if(level == 'warn')
{
color = '\x1b[93m';
}
else if(level == 'debug')
{
color = '\x1b[35m';
}
else
{
color = '\x1b[31m';
}
console.log('[' + prefix + '] ' + color + '[' + level.toUpperCase() + '] \x1b[0m' + message);
console.log('[' + prefix + '] ' + color + '[' + level.toUpperCase() + '] \x1b[0m' + message);
saveLog(level[0].toUpperCase() + level.substring(1), id, letters, Math.round(new Date().getTime() / 1000), message);
}
}
saveLog(level[0].toUpperCase() + level.substring(1), id, letters, Math.round(new Date().getTime() / 1000), message);
}
}
err(error)
{
var s = (error.stack.split('\n')[1].split('\n')[0].match(/\//g) || []).length;
this.log('error', 'bridge', 'Bridge', 'Code Fehler: ' + error.message + ' ( [' + error.stack.split('\n')[1].split('\n')[0].split('/')[s].split(':')[0] + '] bei Zeile [' + error.stack.split('\n')[1].split('\n')[0].split('/')[s].split(':')[1] + '] )');
console.log(error);
}
err(error)
{
var s = (error.stack.split('\n')[1].split('\n')[0].match(/\//g) || []).length;
this.log('error', 'bridge', 'Bridge', 'Code Fehler: ' + error.message + ' ( [' + error.stack.split('\n')[1].split('\n')[0].split('/')[s].split(':')[0] + '] bei Zeile [' + error.stack.split('\n')[1].split('\n')[0].split('/')[s].split(':')[1] + '] )');
console.log(error);
}
debug(message)
{
this.log('debug', 'bridge', 'Bridge', message);
}
debug(message)
{
this.log('debug', 'bridge', 'Bridge', message);
}
load(pluginName, group)
{
return new Promise((resolve) => {
logs.load(pluginName, (err, obj) => {
load(pluginName, group)
{
return new Promise((resolve) => {
logs.load(pluginName, (err, obj) => {
if(obj && !err)
{
var logs = [];
if(obj && !err)
{
var logs = [];
for(const i in obj)
{
if(i != 'id' && (group == null || group == i))
{
logs.push(obj[i]);
}
}
for(const i in obj)
{
if(i != 'id' && (group == null || group == i))
{
logs.push(obj[i]);
}
}
resolve(logs);
}
else
{
resolve(null);
}
});
});
}
resolve(logs);
}
else
{
resolve(null);
}
});
});
}
list()
{
return new Promise((resolve) => {
list()
{
return new Promise((resolve) => {
logs.list((err, objects) => {
logs.list((err, objects) => {
if(!objects || err)
{
resolve([]);
}
else
{
resolve(objects);
}
});
});
}
if(!objects || err)
{
resolve([]);
}
else
{
resolve(objects);
}
});
});
}
}

@@ -131,78 +131,78 @@

{
var queOBJ = { id : id, letters : letters, time : time, level : level, message : message };
var queOBJ = { id : id, letters : letters, time : time, level : level, message : message };
if(inWork)
{
if(!que.some(element => element.time == time && element.message == message))
{
que.push(queOBJ);
}
}
else
{
inWork = true;
if(inWork)
{
if(!que.some(element => element.time == time && element.message == message))
{
que.push(queOBJ);
}
}
else
{
inWork = true;
if(que.some(element => element.time == time && element.message == message))
{
que.shift();
}
if(que.some(element => element.time == time && element.message == message))
{
que.shift();
}
logs.load(prefix, (err, device) => {
logs.load(prefix, (err, device) => {
if(device && !err)
{
device = removeExpired(device);
if(device && !err)
{
device = removeExpired(device);
if(!device[id])
{
device[id] = {};
}
if(!device[id])
{
device[id] = {};
}
if(!device[id][letters])
{
device[id][letters] = [];
}
if(!device[id][letters])
{
device[id][letters] = [];
}
device[id][letters][device[id][letters].length] = { t : time, l : level, m : message };
device[id][letters][device[id][letters].length] = { t : time, l : level, m : message };
logs.add(device, (err) => {
logs.add(device, (err) => {
inWork = false;
inWork = false;
if(err)
{
logger.log('error', 'bridge', 'Bridge', prefix + '.json konnte nicht aktualisiert werden! ' + err);
}
if(err)
{
logger.log('error', 'bridge', 'Bridge', prefix + '.json konnte nicht aktualisiert werden! ' + err);
}
if(que.length != 0)
{
saveLog(que[0].level, que[0].id, que[0].letters, que[0].time, que[0].message);
}
});
}
else
{
var entry = { id : prefix };
if(que.length != 0)
{
saveLog(que[0].level, que[0].id, que[0].letters, que[0].time, que[0].message);
}
});
}
else
{
var entry = { id : prefix };
entry[id] = {};
entry[id] = {};
entry[id][letters] = [ { t : time, l : level, m : message } ];
entry[id][letters] = [ { t : time, l : level, m : message } ];
logs.add(entry, (err) => {
logs.add(entry, (err) => {
inWork = false;
inWork = false;
if(err)
{
logger.log('error', 'bridge', 'Bridge', prefix + '.json konnte nicht aktualisiert werden! ' + err);
}
if(err)
{
logger.log('error', 'bridge', 'Bridge', prefix + '.json konnte nicht aktualisiert werden! ' + err);
}
if(que.length != 0)
{
saveLog(que[0].level, que[0].id, que[0].letters, que[0].time, que[0].message);
}
});
}
});
}
if(que.length != 0)
{
saveLog(que[0].level, que[0].id, que[0].letters, que[0].time, que[0].message);
}
});
}
});
}
}

@@ -212,22 +212,22 @@

{
for(const i in obj)
{
if(i != 'id')
{
for(const j in obj[i])
{
for(var k = 1; k < obj[i][j].length + 1; k++)
{
var time = obj[i][j][obj[i][j].length - k].t;
for(const i in obj)
{
if(i != 'id')
{
for(const j in obj[i])
{
for(var k = 1; k < obj[i][j].length + 1; k++)
{
var time = obj[i][j][obj[i][j].length - k].t;
if(new Date() - new Date(time * 1000) > 86400000)
{
obj[i][j].splice(obj[i][j].length - k, 1);
}
}
}
}
}
return obj;
if(new Date() - new Date(time * 1000) > 86400000)
{
obj[i][j].splice(obj[i][j].length - k, 1);
}
}
}
}
}
return obj;
}

@@ -17,224 +17,120 @@ const UniversalAccessory = require('./accessories/universal');

{
constructor(config, api, pID, pName)
{
if(!config)
{
this.logger.debug('Keine Config gefunden, das Plugin wird deaktiviert!');
constructor(config, api, pID, pName)
{
if(!config)
{
this.logger.debug('Keine Config gefunden, das Plugin wird deaktiviert!');
return;
}
return;
}
this.config = config;
this.debug = config['debug'] || false;
this.port = config['port'];
this.config = config;
this.debug = config['debug'] || false;
this.port = config['port'];
pluginID = pID;
pluginName = pName;
pluginID = pID;
pluginName = pName;
this.logger = new logger(pluginName, config.log_directory, this.debug);
this.accessories = new Map();
if(this.port != null)
{
this.WebServer = new WebServer(pluginName, this.logger, this.port, config.fileserver);
/*
WebServer.addPage('/serverside/version', (response) => {
if(api)
{
this.api = api;
}
response.write(require('./package.json').version);
response.end();
});
WebServer.addPage('/serverside/check-restart', (response) => {
response.write(restart.toString());
response.end();
});
WebServer.addPage('/serverside/update', (response, urlParams) => {
var version = urlParams.version != null ? urlParams.version : 'latest';
const { exec } = require('child_process');
exec('sudo npm install ' + pluginID + '@' + version + ' -g', (error, stdout, stderr) => {
try
{
if(error || stderr.includes('ERR!'))
{
logger.log('warn', 'bridge', 'Bridge', 'Das Plugin ' + pluginName + ' konnte nicht aktualisiert werden! ' + (error || stderr));
}
else
{
logger.log('success', 'bridge', 'Bridge', 'Das Plugin ' + pluginName + ' wurde auf die Version [' + version + '] aktualisiert!');
restart = true;
logger.log('warn', 'bridge', 'Bridge', 'Die Homebridge wird neu gestartet ..');
exec('sudo systemctl restart homebridge');
}
response.write(error || stderr.includes('ERR!') ? 'Error' : 'Success');
response.end();
}
catch(e)
{
logger.err(e);
}
});
});
*/
}
if(config.log_directory != null)
{
this.logger = new logger(pluginName, config.log_directory, this.debug);
this.accessories = new Map();
if(api)
{
this.api = api;
/*
this.api.on('didFinishLaunching', () => {
if(this.port != null)
{
this.WebServer = new WebServer(pluginName, this.logger, this.port, config.fileserver);
}
}
}
// Demo Stuff
registerPlatformAccessory(platformAccessory)
{
this.logger.debug('Registriere Platform Accessory [' + platformAccessory.displayName + ']');
this.logger.debug('Initialisiere ' + pluginName + ' ...');
this.api.registerPlatformAccessories(pluginID, pluginName, [platformAccessory]);
}
var devices = ['acc1', 'acc2', 'acc3', 'acc4', 'acc5'];
getPlatformAccessory()
{
return this;
}
addAccessory(accessory)
{
this.logger.log('info', 'bridge', 'Bridge', 'Hinzufügen: ' + accessory.name + ' ( ' + accessory.id + ' )');
for(const id of devices)
{
if(this.accessories.get(this.api.hap.uuid.generate(id)) != null)
{
//this.removeAccessory(this.accessories.get(this.api.hap.uuid.generate(id)));
}
}
const uuid = this.api.hap.uuid.generate(accessory.id);
var devices = [{id : 'acc1', name : 'Accessory 1', services : [{ type : 'outlet', name : 'Outlet 1' }, { type : 'outlet', name : 'Outlet 2' }, { type : 'outlet', name : 'Outlet 3' }, { type : 'outlet', name : 'Outlet 4' }, { type : 'outlet', name : 'Outlet 5' }]},
{id : 'acc2', name : 'Accessory 2', services : ['led', 'dimmer', 'rgb', 'switch']},
{id : 'acc3', name : 'Accessory 3', services : ['dimmer']},
{id : 'acc4', name : 'Accessory 4', services : 'led'},
{id : 'acc5', name : 'Accessory 5', services : 'contact'}];
this.accessories.set(uuid, accessory);
}
for(const device of devices)
{
this.addAccessory(device);
}
getAccessory(id)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
for(const accessory of this.accessories)
{
for(const x in accessory[1].service)
{
if(accessory[1].service[x].letters)
{
console.log(accessory[1].id, accessory[1].service[x].letters);
return homebridgeAccessory;
}
console.log(this.readAccessoryService(accessory[1].id, accessory[1].service[x].letters));
}
}
}
configureAccessory(accessory)
{
this.logger.debug('Konfiguriere Accessory aus dem Cache Speicher [' + accessory.displayName + '] ( ' + accessory.UUID + ' )');
setTimeout(() => {
this.accessories.set(accessory.UUID, accessory);
}
this.updateAccessoryService('acc5', 'A0', false);
}, 10000);
removeAccessory(accessory)
{
this.logger.log('info', 'bridge', 'Bridge', 'Entferne Accessory [' + accessory.displayName + '] ( ' + accessory.UUID + ' )');
setTimeout(() => {
this.api.unregisterPlatformAccessories(pluginID, pluginName, [accessory]);
this.updateAccessoryService('acc5', 'A0', true);
}, 20000);
this.accessories.delete(accessory.uuid);
}
/*
updateAccessoryReachability(accessory, state)
{
this.log("Update Reachability [%s]", accessory.displayName, state);
accessory.updateReachability(state);
}
*/
updateAccessoryService(id, letters, value)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
setTimeout(() => {
for(var i = 0; i < homebridgeAccessory.service.length; i++)
{
if(homebridgeAccessory.service[i].letters == letters)
{
homebridgeAccessory.service[i].changeHandler(value);
}
}
}
this.updateAccessoryService('acc3', '90', { power : true, brightness : 75 });
}, 30000);
});
*/
}
}
readAccessoryService(id, letters)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
registerPlatformAccessory(platformAccessory)
{
this.logger.debug('Registriere Platform Accessory [' + platformAccessory.displayName + ']');
this.api.registerPlatformAccessories(pluginID, pluginName, [platformAccessory]);
}
var state = null;
getPlatformAccessory()
{
return this;
}
addAccessory(accessory)
{
this.logger.log('info', 'bridge', 'Bridge', 'Hinzufügen: ' + accessory.name + ' ( ' + accessory.id + ' )');
for(var i = 0; i < homebridgeAccessory.service.length; i++)
{
if(homebridgeAccessory.service[i].letters == letters)
{
state = homebridgeAccessory.service[i].getValues();
}
}
const uuid = this.api.hap.uuid.generate(accessory.id);
this.accessories.set(uuid, accessory);
}
getAccessory(id)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
return homebridgeAccessory;
}
configureAccessory(accessory)
{
this.logger.debug('Konfiguriere Accessory aus dem Cache Speicher [' + accessory.displayName + '] ( ' + accessory.UUID + ' )');
this.accessories.set(accessory.UUID, accessory);
}
removeAccessory(accessory)
{
this.logger.log('info', 'bridge', 'Bridge', 'Entferne Accessory [' + accessory.displayName + '] ( ' + accessory.UUID + ' )');
this.api.unregisterPlatformAccessories(pluginID, pluginName, [accessory]);
this.accessories.delete(accessory.uuid);
}
/*
updateAccessoryReachability(accessory, state)
{
this.log("Update Reachability [%s]", accessory.displayName, state);
accessory.updateReachability(state);
}
*/
updateAccessoryService(id, letters, value)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
for(var i = 0; i < homebridgeAccessory.service.length; i++)
{
if(homebridgeAccessory.service[i].letters == letters)
{
homebridgeAccessory.service[i].changeHandler(value);
}
}
}
readAccessoryService(id, letters)
{
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
var state = null;
for(var i = 0; i < homebridgeAccessory.service.length; i++)
{
if(homebridgeAccessory.service[i].letters == letters)
{
state = homebridgeAccessory.service[i].getValues();
}
}
return state;
}
return state;
}
}
module.exports = { DynamicPlatform, UniversalAccessory, AccessoryInformationService, OutletService, SwitchService, LightBulbService, DimmedBulbService, ColoredBulbService, ContactService };
{
"name": "homebridge-syntex-dynamic-platform",
"version": "1.0.0",
"description": "A Dynamic Platform Accessory",
"main": "main.js",
"author": "SynTexDZN",
"engines": {
"homebridge": ">=0.3.0",
"node": ">=9.11.2"
},
"dependencies": {
"json-fs-store": "^1.0.1",
"request": "^2.88.0"
},
"keywords": [
"syntex",
"syntex-platform",
"homebridge-plugin",
"homebridge",
"plugin",
"http",
"tuya",
"homekit",
"smarthome",
"siri"
],
"homepage": "https://github.com/SynTexDZN/homebridge-syntex-dynamic-platform#readme",
"repository": {
"type": "git",
"url": "git://github.com/SynTexDZN/homebridge-syntex-dynamic-platform.git"
},
"bugs": {
"url": "https://github.com/SynTexDZN/homebridge-syntex-dynamic-platform/issues"
},
"license": "ISC",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
"name": "homebridge-syntex-dynamic-platform",
"version": "1.0.1-b1",
"description": "A Dynamic Platform Accessory",
"main": "main.js",
"author": "SynTexDZN",
"engines": {
"homebridge": ">=0.3.0",
"node": ">=9.11.2"
},
"dependencies": {
"json-fs-store": "^1.0.1",
"request": "^2.88.0"
},
"keywords": [
"syntex",
"syntex-platform",
"homebridge-plugin",
"homebridge",
"plugin",
"http",
"tuya",
"homekit",
"smarthome",
"siri"
],
"homepage": "https://github.com/SynTexDZN/homebridge-syntex-dynamic-platform#readme",
"repository": {
"type": "git",
"url": "git://github.com/SynTexDZN/homebridge-syntex-dynamic-platform.git"
},
"bugs": {
"url": "https://github.com/SynTexDZN/homebridge-syntex-dynamic-platform/issues"
},
"license": "ISC",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}

@@ -17,5 +17,5 @@ # Homebridge SynTex Dynamic Platform

{
"platform": "SynTexDynamicPlatform",
"log_directory": "./SynTex/log"
"platform": "SynTexDynamicPlatform",
"log_directory": "./SynTex/log"
}
```

@@ -6,134 +6,134 @@ const http = require('http'), url = require('url'), fs = require('fs'), path = require('path');

{
constructor(prefix, log, port, filesystem)
{
logger = log;
constructor(prefix, log, port, filesystem)
{
logger = log;
var createServerCallback = async (request, response) => {
var createServerCallback = async (request, response) => {
var urlParts = url.parse(request.url, true);
var urlParams = urlParts.query;
var urlPath = urlParts.pathname;
var body = [];
body = Buffer.concat(body).toString();
var urlParts = url.parse(request.url, true);
var urlParams = urlParts.query;
var urlPath = urlParts.pathname;
var body = [];
body = Buffer.concat(body).toString();
response.statusCode = 200;
response.setHeader('Access-Control-Allow-Origin', '*');
response.statusCode = 200;
response.setHeader('Access-Control-Allow-Origin', '*');
var content = '', data = '', found = false;
var content = '', data = '', found = false;
if(filesystem)
{
var relPath = await exists(urlPath.substring(1));
if(relPath)
{
data = await read(relPath);
if(filesystem)
{
var relPath = await exists(urlPath.substring(1));
if(relPath)
{
data = await read(relPath);
if(path.parse(relPath).ext == '.html')
{
response.setHeader('Content-Type', 'text/html; charset=utf-8');
content = head + data;
}
}
}
else
{
response.setHeader('Content-Type', 'application/json');
}
if(path.parse(relPath).ext == '.html')
{
response.setHeader('Content-Type', 'text/html; charset=utf-8');
content = head + data;
}
}
}
else
{
response.setHeader('Content-Type', 'application/json');
}
if(urlPath.includes('.'))
{
urlPath = urlPath.split('.')[0];
}
if(urlPath.includes('.'))
{
urlPath = urlPath.split('.')[0];
}
for(var i = 0; i < pages.length; i++)
{
if(urlPath == pages[i].path || (Array.isArray(pages[i].path) && pages[i].path.includes(urlPath))) // TODO : Array .html Abfrage
{
found = true;
for(var i = 0; i < pages.length; i++)
{
if(urlPath == pages[i].path || (Array.isArray(pages[i].path) && pages[i].path.includes(urlPath))) // TODO : Array .html Abfrage
{
found = true;
if(request.method == 'POST')
{
var post = '', page = pages[i];
if(request.method == 'POST')
{
var post = '', page = pages[i];
request.on('data', (data) => {
request.on('data', (data) => {
post += data;
});
post += data;
});
request.on('end', () => {
var json = null;
request.on('end', () => {
var json = null;
if(post != '')
{
try
{
json = JSON.parse(post);
}
catch(error)
{
logger.log('error', 'bridge', 'Bridge', 'JSON String konnte nicht verarbeitet werden! ( ' + post + ')');
}
}
page.callback(response, urlParams, content, json);
});
}
else
{
pages[i].callback(response, urlParams, content, null);
}
}
}
if(post != '')
{
try
{
json = JSON.parse(post);
}
catch(error)
{
logger.log('error', 'bridge', 'Bridge', 'JSON String konnte nicht verarbeitet werden! ( ' + post + ')');
}
}
page.callback(response, urlParams, content, json);
});
}
else
{
pages[i].callback(response, urlParams, content, null);
}
}
}
if(!found)
{
if(data == '')
{
response.statusCode = 404;
//response.setHeader('Content-Type', 'text/html; charset=utf-8');
//response.write(head + await read(__dirname + '/includes/not-found.html'));
}
else if(relPath)
{
var mimeType = {
".html": "text/html; charset=utf-8",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
".png": "image/png",
".js": "text/javascript",
".css": "text/css",
".ttf": "font/ttf",
".ico": "image/x-icon"
};
if(!found)
{
if(data == '')
{
response.statusCode = 404;
//response.setHeader('Content-Type', 'text/html; charset=utf-8');
//response.write(head + await read(__dirname + '/includes/not-found.html'));
}
else if(relPath)
{
var mimeType = {
".html": "text/html; charset=utf-8",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
".png": "image/png",
".js": "text/javascript",
".css": "text/css",
".ttf": "font/ttf",
".ico": "image/x-icon"
};
response.setHeader('Content-Type', mimeType[path.parse(relPath).ext] || 'text/html; charset=utf-8');
response.write(path.parse(relPath).ext == '.html' ? content : data);
}
response.end();
}
response.setHeader('Content-Type', mimeType[path.parse(relPath).ext] || 'text/html; charset=utf-8');
response.write(path.parse(relPath).ext == '.html' ? content : data);
}
response.end();
}
};
};
http.createServer(createServerCallback).listen(port, '0.0.0.0');
logger.log('info', 'bridge', 'Bridge', prefix + ' Web-Server läuft auf Port [' + port + ']');
}
http.createServer(createServerCallback).listen(port, '0.0.0.0');
logger.log('info', 'bridge', 'Bridge', prefix + ' Web-Server läuft auf Port [' + port + ']');
}
addPage(path, callback)
{
pages.push({ path : path, callback : callback });
}
addPage(path, callback)
{
pages.push({ path : path, callback : callback });
}
setHead(relPath)
{
read(relPath).then((H) => {
setHead(relPath)
{
read(relPath).then((H) => {
head = H;
});
}
head = H;
});
}
}

@@ -143,33 +143,33 @@

{
return new Promise(resolve => {
var pathname = path.join(__dirname, '../' + reqPath);
return new Promise(resolve => {
var pathname = path.join(__dirname, '../' + reqPath);
var noext = false;
var noext = false;
if(path.parse(pathname).ext == '')
{
noext = true;
}
if(path.parse(pathname).ext == '')
{
noext = true;
}
fs.exists(pathname, (exist) => {
fs.exists(pathname, (exist) => {
if(exist && fs.statSync(pathname).isDirectory())
{
resolve(exists(reqPath + 'index.html'));
}
else if(exist)
{
resolve(pathname);
}
else if(noext)
{
resolve(exists(reqPath + '.html'));
}
else
{
resolve(false);
}
});
});
if(exist && fs.statSync(pathname).isDirectory())
{
resolve(exists(reqPath + 'index.html'));
}
else if(exist)
{
resolve(pathname);
}
else if(noext)
{
resolve(exists(reqPath + '.html'));
}
else
{
resolve(false);
}
});
});
}

@@ -179,14 +179,14 @@

{
return new Promise(resolve => {
fs.readFile(reqPath, (err, res) => {
return new Promise(resolve => {
fs.readFile(reqPath, (err, res) => {
if(!res || err)
{
res = "";
}
if(!res || err)
{
res = "";
}
resolve(res);
});
});
resolve(res);
});
});
}
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