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-b5 to 1.0.0-b6

accessories/coloredBulb.js

100

accessories/base.js

@@ -0,1 +1,3 @@

let logger;
module.exports = class BaseService

@@ -5,10 +7,17 @@ {

{
this.id = deviceConfig.id;
this.name = serviceConfig.name;
this.letters = typeToLetter(serviceConfig.type) + serviceConfig.subtype;
this.id = deviceConfig['id'];
this.name = serviceConfig['name'];
this.serviceType = serviceType;
var subtype = serviceConfig.subtype;
homebridgeAccessory.context = {}; // To Store Variables in Homebridge
if(subtype.includes('-'))
{
subtype = subtype.split('-')[1];
}
this.letters = typeToLetter(serviceConfig.type) + subtype;
this.homebridgeAccessory = homebridgeAccessory;
logger = manager.logger;
var service = homebridgeAccessory.getServiceById(serviceType, serviceConfig.subtype);

@@ -18,3 +27,3 @@

{
manager.logger.debug('Existierenden Service gefunden! ' + serviceConfig.name + ' ' + serviceConfig.type + ' ' + serviceConfig.subtype + ' ( ' + this.id + ' )');
logger.debug('Existierenden Service gefunden! ' + serviceConfig.name + ' ' + serviceConfig.type + ' ' + serviceConfig.subtype + ' ( ' + this.id + ' )');

@@ -25,17 +34,82 @@ service.setCharacteristic(manager.platform.api.hap.Characteristic.Name, serviceConfig.name);

{
manager.logger.debug('Erstelle neuen Service! ' + serviceConfig.name + ' ' + serviceConfig.type + ' ' + serviceConfig.subtype + ' ( ' + this.id + ' )');
logger.debug('Erstelle neuen Service! ' + serviceConfig.name + ' ' + serviceConfig.type + ' ' + serviceConfig.subtype + ' ( ' + this.id + ' )');
homebridgeAccessory.addService(serviceType, serviceConfig.name, serviceConfig.subtype)
//homebridgeAccessory.service.push();
}
}
getService()
getValue(key)
{
return homebridgeAccessory.getServiceById(this.serviceType, this.letters[1]);
var value = null;
console.log(key, this.homebridgeAccessory.context);
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][key] != null)
{
value = this.homebridgeAccessory.context.data[this.letters][key];
logger.log('read', this.id, this.letters, 'HomeKit Status für [' + this.name + '] ist [' + JSON.stringify(value) + '] ( ' + this.id + ' )');
}
else
{
logger.log('warn', this.id, this.letters, '[' + this.name + '] wurde nicht im Cache gefunden! ( ' + this.id + ' )');
}
return value;
}
setValue(key, value)
{
if(this.homebridgeAccessory && this.homebridgeAccessory.context)
{
if(!this.homebridgeAccessory.context.data)
{
this.homebridgeAccessory.context.data = {};
}
if(!this.homebridgeAccessory.context.data[this.letters])
{
this.homebridgeAccessory.context.data[this.letters] = {};
}
this.homebridgeAccessory.context.data[this.letters][key] = value;
logger.log('update', this.id, this.letters, 'HomeKit Status für [' + this.name + '] geändert zu [' + JSON.stringify(value) + '] ( ' + this.id + ' )');
return true;
}
else
{
logger.log('error', this.id, this.letters, '[' + this.name + '] konnte nicht im Cache gespeichert werden! ( ' + this.id + ' )');
return false;
}
}
getValues()
{
var values = null;
if(this.homebridgeAccessory != null
&& this.homebridgeAccessory.context != null
&& this.homebridgeAccessory.context.data != null
&& this.homebridgeAccessory.context.data[this.letters] != null)
{
values = this.homebridgeAccessory.context.data[this.letters];
}
else
{
logger.log('warn', this.id, this.letters, '[' + this.name + '] wurde nicht im Cache gefunden! ( ' + this.id + ' )');
}
return values;
}
}
var types = ['contact', 'motion', 'temperature', 'humidity', 'rain', 'light', 'occupancy', 'smoke', 'airquality', 'rgb', 'switch', 'relais', 'statelessswitch', 'outlet'];
var letters = ['A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7'];
var types = ['contact', 'motion', 'temperature', 'humidity', 'rain', 'light', 'occupancy', 'smoke', 'airquality', 'rgb', 'switch', 'relais', 'statelessswitch', 'outlet', 'led', 'dimmer'];
var letters = ['A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

@@ -42,0 +116,0 @@ function letterToType(letter)

29

accessories/lightbulb.js
const BaseService = require('./base');
let Characteristic;
let Service, Characteristic;

@@ -9,7 +9,20 @@ module.exports = class LightBulbService extends BaseService

{
Characteristic = manager.platform.api.hap.Characteristic;
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.Lightbulb, manager);
Characteristic = manager.platform.api.hap.Characteristic;
Service = manager.platform.api.hap.Service;
homebridgeAccessory.getServiceById(this.serviceType, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
if(!serviceConfig.subtype.includes('-'))
{
serviceConfig.subtype = 'led-' + serviceConfig.subtype;
}
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.Lightbulb, manager);
homebridgeAccessory.getServiceById(Service.Lightbulb, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Lightbulb, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
super.setValue('state', state);
};
}

@@ -19,5 +32,3 @@

{
console.log('getState() LIGHTBULB');
callback(false);
callback(null, super.getValue('state') || false);
}

@@ -27,3 +38,3 @@

{
console.log('setState(' + level + ') LIGHTBULB');
super.setValue('state', level);

@@ -30,0 +41,0 @@ callback();

const BaseService = require('./base');
let Characteristic;
let Service, Characteristic;

@@ -9,7 +9,15 @@ module.exports = class OutletService extends BaseService

{
Characteristic = manager.platform.api.hap.Characteristic;
Characteristic = manager.platform.api.hap.Characteristic;
Service = manager.platform.api.hap.Service;
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.Outlet, manager);
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.Outlet, manager);
homebridgeAccessory.getServiceById(this.serviceType, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
homebridgeAccessory.getServiceById(Service.Outlet, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Outlet, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
super.setValue('state', state);
};
}

@@ -19,5 +27,3 @@

{
console.log('getState() OUTLET');
callback(false);
callback(null, super.getValue('state') || false);
}

@@ -27,3 +33,3 @@

{
console.log('setState(' + level + ') OUTLET');
super.setValue('state', level);

@@ -30,0 +36,0 @@ callback();

const BaseService = require('./base');
let Characteristic;
let Service, Characteristic;

@@ -9,7 +9,15 @@ module.exports = class SwitchService extends BaseService

{
Characteristic = manager.platform.api.hap.Characteristic;
Characteristic = manager.platform.api.hap.Characteristic;
Service = manager.platform.api.hap.Service;
super(homebridgeAccessory, deviceConfig, serviceConfig, manager.platform.api.hap.Service.Switch, manager);
super(homebridgeAccessory, deviceConfig, serviceConfig, Service.Switch, manager);
homebridgeAccessory.getServiceById(Service.Switch, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
this.changeHandler = (state) =>
{
homebridgeAccessory.getServiceById(Service.Switch, serviceConfig.subtype).getCharacteristic(Characteristic.On).updateValue(state);
homebridgeAccessory.getServiceById(this.serviceType, serviceConfig.subtype).getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this));
super.setValue('state', state);
};
}

@@ -19,5 +27,3 @@

{
console.log('getState() SWITCH');
callback(false);
callback(null, super.getValue('state') || false);
}

@@ -27,3 +33,3 @@

{
console.log('setState(' + level + ') SWITCH');
super.setValue('state', level);

@@ -30,0 +36,0 @@ callback();

@@ -0,8 +1,11 @@

const AccessoryInformationService = require('./info');
const OutletService = require('./outlet');
const SwitchService = require('./switch');
const LightBulbService = require('./lightbulb');
const LightBulbService = require('./lightBulb');
const DimmedBulbService = require('./dimmedBulb');
const ColoredBulbService = require('./coloredBulb');
const ContactService = require('./contact');
let PlatformAccessory;
let Service;
let Characteristic;
let UUIDGen;

@@ -23,6 +26,6 @@

this.manufacturer = deviceConfig['manufacturer'] || 'SynTex';
this.model = deviceConfig['model'] || 'Virtual Accessory';
this.version = deviceConfig['version'] || '1.0.0';
this.model = deviceConfig['model'] || 'Virtual Accessory';
this.manufacturer = deviceConfig['manufacturer'] || 'SynTex';
this.manager = manager;

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

({ Service, Characteristic, uuid: UUIDGen } = manager.platform.api.hap);
({ Service, uuid: UUIDGen } = manager.platform.api.hap);

@@ -40,6 +43,15 @@ this.homebridgeAccessory = homebridgeAccessory;

for(var i = 0; i < this.services.length; i++)
this.setAccessoryInformation();
if(Array.isArray(this.services))
{
this.addService(deviceConfig.services[i]);
for(var i = 0; i < this.services.length; i++)
{
this.addService(this.services[i]);
}
}
else
{
this.addService(this.services);
}
}

@@ -61,3 +73,3 @@

this.setService(config, this.subtypes[type]);
this.setService(config, this.subtypes[type].toString());

@@ -67,2 +79,27 @@ this.subtypes[type]++;

addAccessory()
{
if(this.homebridgeAccessory)
{
this.logger.debug('Existierendes Accessory gefunden! ' + this.name + ' ( ' + this.id + ' )');
this.homebridgeAccessory.displayName = this.name;
}
else
{
this.logger.debug('Erstelle neues Accessory! ' + this.name + ' ( ' + this.id + ' )');
this.homebridgeAccessory = new PlatformAccessory(this.name, UUIDGen.generate(this.id), Service.Switch);
this.platform.registerPlatformAccessory(this.homebridgeAccessory);
}
}
setAccessoryInformation()
{
var service = new AccessoryInformationService(this.homebridgeAccessory, this.deviceConfig, { manufacturer : this.manufacturer, model : this.model, version : this.version }, this.manager);
this.service.push(service);
}
setService(config, subtype)

@@ -86,16 +123,34 @@ {

var service = null;
var serviceConfig = { name : name, type : type, subtype : subtype };
if(type == 'switch')
{
var service = new SwitchService(this.homebridgeAccessory, this.deviceConfig, { name : name, type : type, subtype : subtype }, this.manager);
service = new SwitchService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'outlet')
{
var service = new OutletService(this.homebridgeAccessory, this.deviceConfig, { name : name, type : type, subtype : subtype }, this.manager);
service = new OutletService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'led')
{
service = new LightBulbService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'dimmer')
{
service = new DimmedBulbService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'rgb')
{
var service = new LightBulbService(this.homebridgeAccessory, this.deviceConfig, { name : name, type : type, subtype : subtype }, this.manager);
service = new ColoredBulbService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
else if(type == 'contact')
{
service = new ContactService(this.homebridgeAccessory, this.deviceConfig, serviceConfig, this.manager);
}
this.service.push(service);
if(service != null)
{
this.service.push(service);
}
}

@@ -107,20 +162,2 @@

}
addAccessory()
{
if(this.homebridgeAccessory)
{
this.logger.debug('Existierendes Accessory gefunden! ' + this.name + ' ( ' + this.id + ' )');
this.homebridgeAccessory.displayName = this.name;
}
else
{
this.logger.debug('Erstelle neues Accessory! ' + this.name + ' ( ' + this.id + ' )');
this.homebridgeAccessory = new PlatformAccessory(this.name, UUIDGen.generate(this.id), Service.Switch);
this.platform.registerPlatformAccessory(this.homebridgeAccessory);
}
}
}
{
"name": "homebridge-syntex-dynamic-platform",
"version": "1.0.0-b5",
"version": "1.0.0-b6",
"description": "A Dynamic Platform Accessory",
"main": "index.js",
"main": "platform.js",
"author": "SynTexDZN",

@@ -7,0 +7,0 @@ "engines": {

@@ -6,3 +6,3 @@ const UniversalAccessory = require('./accessories/universal');

let logger = require('./logger');
let logger = require('./logger'), WebServer = require('./webserver');;

@@ -15,5 +15,60 @@ module.exports = class SynTexDynamicPlatform

this.config = config;
this.port = config.port;
console.log(this.port);
this.logger = new logger(pluginName, config.log_directory, api.user.storagePath());
if(this.port != null)
{
WebServer = new WebServer(pluginName, this.logger, this.port, false);
WebServer.addPage('/serverside/version', (response) => {
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)

@@ -34,5 +89,7 @@ {

// Demo Stuff
this.logger.debug('Initialisiere ' + pluginName + ' ...');
var devices = ['acc1', 'acc2'];
var devices = ['acc1', 'acc2', 'acc3', 'acc4', 'acc5'];

@@ -48,3 +105,6 @@ for(const id of devices)

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 : ['rgb', 'switch']}];
{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'}];

@@ -55,2 +115,33 @@ for(const device of devices)

}
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);
console.log(this.readAccessoryService(accessory[1].id, accessory[1].service[x].letters));
}
}
}
setTimeout(() => {
this.updateAccessoryService('acc5', 'A0', false);
}, 10000);
setTimeout(() => {
this.updateAccessoryService('acc5', 'A0', true);
}, 20000);
setTimeout(() => {
this.updateAccessoryService('acc3', '90', { power : true, brightness : 75 });
}, 30000);
});

@@ -60,25 +151,20 @@ }

refreshDeviceStates()
registerPlatformAccessory(platformAccessory)
{
this.logger.debug('Registriere Platform Accessory [' + platformAccessory.displayName + ']');
this.api.registerPlatformAccessories(pluginID, pluginName, [platformAccessory]);
}
}
addAccessory(device)
addAccessory(accessory)
{
this.logger.log('info', 'bridge', 'Bridge', 'Hinzufügen: ' + device.name + ' ( ' + device.id + ' )');
this.logger.log('info', 'bridge', 'Bridge', 'Hinzufügen: ' + accessory.name + ' ( ' + accessory.id + ' )');
const uuid = this.api.hap.uuid.generate(device.id);
const uuid = this.api.hap.uuid.generate(accessory.id);
const homebridgeAccessory = this.accessories.get(uuid);
let deviceAccessory = new UniversalAccessory(homebridgeAccessory, device, { platform : this, logger : this.logger });
let deviceAccessory = new UniversalAccessory(homebridgeAccessory, accessory, { platform : this, logger : this.logger });
this.accessories.set(uuid, deviceAccessory.homebridgeAccessory);
this.accessories.set(uuid, deviceAccessory);
}
registerPlatformAccessory(platformAccessory)
{
this.logger.debug('Registriere Platform Accessory [' + platformAccessory.displayName + ']');
this.api.registerPlatformAccessories(pluginID, pluginName, [platformAccessory]);
}
configureAccessory(accessory)

@@ -90,2 +176,11 @@ {

}
removeAccessory(accessory)
{
this.logger.debug('Entferne Accessory [' + accessory.displayName + '] ( ' + accessory.UUID + ' )');
this.api.unregisterPlatformAccessories(pluginID, pluginName, [accessory]);
this.accessories.delete(accessory.uuid);
}
/*

@@ -98,9 +193,34 @@ updateAccessoryReachability(accessory, state)

*/
removeAccessory(accessory)
updateAccessoryService(id, letters, value)
{
this.logger.debug('Entferne Accessory [' + accessory.name + '] ( ' + accessory.UUID + ' )');
this.api.unregisterPlatformAccessories(pluginID, pluginName, [accessory]);
const uuid = this.api.hap.uuid.generate(id);
const homebridgeAccessory = this.accessories.get(uuid);
this.accessories.delete(accessory.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;
}
}
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