iobroker.innogy-smarthome
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"common": { | ||
"name": "innogy-smarthome", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"title": "Innogy Smarthome Adapter", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
89
main.js
/* jshint -W097 */// jshint strict:false | ||
/*jslint node: true */ | ||
"use strict"; | ||
var utils = require(__dirname + '/lib/utils'); // Get common adapter utils | ||
var helpers = require(__dirname + '/lib/helpers'); | ||
var adapter = utils.adapter('innogy-smarthome'); | ||
var SmartHome = require('innogy-smarthome-lib'); | ||
var smartHome = null; | ||
String.prototype.replaceAll = function (search, replacement) { | ||
@@ -10,10 +16,11 @@ var target = this; | ||
var utils = require(__dirname + '/lib/utils'); // Get common adapter utils | ||
var adapter = utils.adapter('innogy-smarthome'); | ||
var SmartHome = require('innogy-smarthome-lib'); | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
var smartHome = null; | ||
adapter.on('unload', function (callback) { | ||
try { | ||
if (smartHome) | ||
smartHome.finalize(); | ||
adapter.log.info('cleaned everything up...'); | ||
@@ -26,5 +33,2 @@ callback(); | ||
adapter.on('objectChange', stateChanged); | ||
adapter.on('stateChange', stateChanged); | ||
// New message arrived. obj is array with current messages | ||
@@ -57,21 +61,8 @@ adapter.on('message', function (obj) { | ||
adapter.on('objectChange', stateChanged); | ||
adapter.on('stateChange', stateChanged); | ||
adapter.on('ready', initSmartHome); | ||
function getDevicePath(aDevice) { | ||
var room = null; | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
if (aDevice.Location) | ||
room = aDevice.Location.getName(); | ||
else | ||
room = "Virtual"; | ||
var deviceName = aDevice.getName(); | ||
return cleanDeviceName((room ? room + "." : "") + deviceName); | ||
} | ||
function cleanDeviceName(aString) { | ||
return aString.replaceAll(" ", "-").replaceAll("---", "-").replaceAll("--", "-") | ||
} | ||
function initSmartHome() { | ||
@@ -96,7 +87,7 @@ adapter.subscribeStates('*'); | ||
if (aDevice) { | ||
var devicePath = getDevicePath(aDevice); | ||
var devicePath = helpers.getDevicePath(aDevice); | ||
aDevice.Capabilities.forEach(function (aCapability) { | ||
aCapability.State.forEach(function (aState) { | ||
var capabilityPath = devicePath + "." + cleanDeviceName(aState.name); | ||
var capabilityPath = devicePath + "." + helpers.cleanDeviceName(aState.name); | ||
adapter.setState(capabilityPath, {val: aState.value, ack: true}); | ||
@@ -120,8 +111,12 @@ }); | ||
smartHome.on("close", function (e) { | ||
adapter.log.error("CLOSE:" + JSON.stringify(e)); | ||
}); | ||
smartHome.init(); | ||
}; | ||
} | ||
function updateDevice(aDevice) { | ||
if (aDevice) { | ||
var devicePath = getDevicePath(aDevice); | ||
var devicePath = helpers.getDevicePath(aDevice); | ||
@@ -149,3 +144,3 @@ var hasCapStates = function (aDevice) { | ||
id: aDevice.Id, | ||
type: aDevice.type, | ||
type: aDevice.type | ||
} | ||
@@ -157,7 +152,7 @@ }); | ||
var capabilityPath = devicePath + "." + cleanDeviceName(aState.name); | ||
var capabilityPath = devicePath + "." + helpers.cleanDeviceName(aState.name); | ||
adapter.setObjectNotExists(capabilityPath, { | ||
type: "state", | ||
common: merge_options({name: aState.name}, getCommonForState(aState)), | ||
common: helpers.merge_options({name: aState.name}, getCommonForState(aState)), | ||
native: { | ||
@@ -174,3 +169,3 @@ id: aCapability.Id, | ||
} | ||
}; | ||
} | ||
@@ -186,7 +181,7 @@ function stateChanged(id, state) { | ||
if (capability && obj.common.write) { | ||
capability.setState(state.val, obj.common.name).then(function (state) { | ||
adapter.log.info("OK" + state); | ||
}, function (state) { | ||
adapter.log.info("ERR" + state); | ||
}) | ||
capability.setState(state.val, obj.common.name).then(function (data) { | ||
adapter.log.info("STATE OK " + JSON.stringify(data)); | ||
}, function (data) { | ||
adapter.log.error("STATE ERR " + JSON.stringify(data)); | ||
}); | ||
} else { | ||
@@ -198,4 +193,8 @@ updateDevice(smartHome.resolveLink(capability.Device)); | ||
}); | ||
}; | ||
} | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
function getCommonForState(aState) { | ||
@@ -317,16 +316,8 @@ var res = {}; | ||
res.role = "unknown"; | ||
res.read = true; | ||
res.write = true; | ||
break; | ||
} | ||
return res; | ||
}; | ||
function merge_options(obj1, obj2) { | ||
var obj3 = {}; | ||
for (var attrname in obj1) { | ||
obj3[attrname] = obj1[attrname]; | ||
} | ||
for (var attrname in obj2) { | ||
obj3[attrname] = obj2[attrname]; | ||
} | ||
return obj3; | ||
} |
{ | ||
"name": "iobroker.innogy-smarthome", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "ioBroker Innogy SmartHome Adapter", | ||
@@ -28,3 +28,3 @@ "author": { | ||
"dependencies": { | ||
"innogy-smarthome-lib": "^0.1.6" | ||
"innogy-smarthome-lib": "^0.1.14" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
![Logo](admin/innogy-smarthome.png) | ||
# ioBroker.innogy-smarthome | ||
# ioBroker.Innogy-SmartHome | ||
[![Build](https://travis-ci.org/PArns/ioBroker.innogy-smarthome.svg?branch=master)](https://travis-ci.org/PArns/ioBroker.innogy-smarthome) | ||
This adapter can be used to add the Innogy Smarthome client to ioBroker | ||
This adapter is used to connect the Innogy smarthome devices to ioBroker. You can read more about Innogy [here](https://www.innogy.com). | ||
@@ -12,2 +12,7 @@ ###Requires Node > 4.x | ||
### 0.0.6 | ||
Removed no longer needed log errors | ||
Added unload method | ||
Optimized session refreshing | ||
### 0.0.5 | ||
@@ -14,0 +19,0 @@ Fixed parsing errors |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
35413
9
341
37
4
Updatedinnogy-smarthome-lib@^0.1.14