Skip to content

Commit

Permalink
all changes for npm distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
thkl committed Mar 7, 2017
1 parent 8a76e18 commit 3ad8714
Show file tree
Hide file tree
Showing 49 changed files with 1,068 additions and 162 deletions.
1 change: 1 addition & 0 deletions install_raspberrymatic.sh
Expand Up @@ -88,6 +88,7 @@ cat > /usr/local/etc/config/hvl/config.json <<EOF
"local_ip": "127.0.0.1",
"local_rpc_port": 8301,
"web_http_port":8300,
"restart_command":"/etc/init.d/S51hvl restart",
"plugins": []
}
EOF
Expand Down
35 changes: 32 additions & 3 deletions lib/HomematicLogicLayer.js
Expand Up @@ -130,7 +130,7 @@ var HomematicLogicalLayer = function (config) {
this.rpcClients = {} ;
this.rpcEventServer = undefined ;
this.CCUEventcache = {};

this.ccuInterfaceName = "HMVirtual";
this.ccuIP = this.config.getValue("ccu_ip");
if (this.ccuIP == undefined) {
logger.error("please setup your ccu ip in config.json");
Expand All @@ -144,7 +144,7 @@ util.inherits(HomematicLogicalLayer, EventEmitter);

HomematicLogicalLayer.prototype.init = function() {
var that = this;
var localPort = 7000;
var localPort = this.config.getValue("local_rpc_port") || 7000;
var localip = this.config.getValue("local_ip");


Expand Down Expand Up @@ -482,6 +482,8 @@ HomematicLogicalLayer.prototype.init = function() {
this.rpc_server.close = function() {
logger.info("RPC Server was removed.");
};

this.getmyInterfaceNameOnCCU(localip,localPort);
}

HomematicLogicalLayer.prototype.getLocalIpAdress = function() {
Expand Down Expand Up @@ -795,7 +797,7 @@ HomematicLogicalLayer.prototype.sendRPCMessage = function(consumerID, method,pay

HomematicLogicalLayer.prototype.addDevice = function(device,save,hidden) {
logger.debug("Add new Device to HomematicLogicLayer " + device.adress);
device.hidden = hidden || false;
device.hidden = hidden || false;
this.devices.push(device);
logger.debug("Pushed to list %s",device.hidden);
var that = this;
Expand Down Expand Up @@ -1029,7 +1031,34 @@ HomematicLogicalLayer.prototype.loadCCUDevices = function(interfaces, callback)
});
}

HomematicLogicalLayer.prototype.getCcuInterfaceName = function() {
return this.ccuInterfaceName;
}

HomematicLogicalLayer.prototype.getmyInterfaceNameOnCCU = function(host,port) {
var rega = "string stdout;string stderr;string cmd;cmd = 'cat /usr/local/etc/config/InterfacesList.xml';system.Exec(cmd, &stdout, &stderr);WriteLine(stdout);"
var xml2js = require('xml2js'),parser = new xml2js.Parser()
var that = this;
new regaRequest(this,rega,function(result){
parser.parseString(result, function (err, xmlresult) {
if (xmlresult) {
var ipc = xmlresult['interfaces']['ipc'];
if (ipc) {
ipc.some(function (ipcelement){
if (ipcelement.url[0].toLowerCase().indexOf("xmlrpc://"+host+":"+port)>-1) {
logger.info("My Interface Name at your CCU is %s",ipcelement.name[0])
that.ccuInterfaceName = ipcelement.name[0];
}
})

} else {
logger.error("Cannot fetch my Name from CCU .. %s",JSON.stringify(xmlresult[0]))
}
}
});
});

}

HomematicLogicalLayer.prototype.getIPAddress = function() {
var interfaces = require("os").networkInterfaces();
Expand Down
7 changes: 7 additions & 0 deletions lib/HomematicVirtualPlatform.js
Expand Up @@ -38,4 +38,11 @@ HomematicVirtualPlatform.prototype.restart = function() {

}


HomematicVirtualPlatform.prototype.getPluginVersion = function() {
var pjPath = path.join(__dirname, './package.json');
var pj = JSON.parse(fs.readFileSync(pjPath));
return pj.version;
}

module.exports = HomematicVirtualPlatform;
11 changes: 11 additions & 0 deletions lib/Installer.js
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var Installer = function(rootpath,main) {
var pjson = null;
this.rootPath = rootpath;
this.isNPM = false
var pjsonPath = path.join(rootpath, "package.json");
if (fs.existsSync(pjsonPath)) {
try {
Expand All @@ -12,6 +13,14 @@ var Installer = function(rootpath,main) {
} catch (e) {
throw new Error("Path " + rootpath + " contains an invalid package.json. Error: " + err);
}
// check if we run as npm module

if (pjson._npmVersion) {
this.isNPM = true
this.needsInstall = []
this.dependencies = {}
return
}

if (!main) {
if (pjson != null) {
Expand Down Expand Up @@ -49,6 +58,7 @@ var Installer = function(rootpath,main) {

Installer.prototype.checkVersions = function() {
var that = this
if (this.dependencies) {
Object.keys(this.dependencies).forEach(function (dependency) {
try {
var buffer = fs.readFileSync(path.join(that.rootPath , "node_modules" , dependency ,"package.json"));
Expand All @@ -61,6 +71,7 @@ Installer.prototype.checkVersions = function() {
console.error(e)
}
});
}
}

Installer.prototype.installDependencies = function() {
Expand Down
14 changes: 14 additions & 0 deletions lib/Localization.js
Expand Up @@ -32,6 +32,20 @@ module.exports = function (strings) {
this.language = dispatched_request.language;
}


module.getLanguage = function () {
return this.language;
}

module.getLocalizedStringFromModuleJSON = function (element) {
if (element[this.language]) {
return element[this.language]
} else {
return element['en-en']
}
}


module.localize = function (input) {
var result = input;
if (module.string_obj) {
Expand Down

0 comments on commit 3ad8714

Please sign in to comment.