Skip to content

Commit

Permalink
Logging durch checkbox reduzieren
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-vaNu committed Jun 6, 2021
1 parent 51df587 commit d337ee0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
10 changes: 8 additions & 2 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
<img src="blebox.png" class="logo">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input class="value filled-in" id="extLog" type="checkbox">
<span class="translate">Erweitertes Logging</span>
</div>
</div>
<div class="row tab-smart-devices-toolbar " id="values">
<div class="col s2 m1 l1 center">
<button title="Add device"
Expand All @@ -285,8 +291,8 @@
<th data-name="ip" class="translate">ip adress</th>
<th data-name="port" class="translate">port</th>
<th data-name="smart_name" class="translate">smartname</th>
<th data-name="type" class="translate" data-options="shutterbox;switchbox;tempsensor;saunabox"
data-type="select">type</th>
<th data-name="type" class="translate"
data-options="shutterbox;switchbox;tempsensor;saunabox" data-type="select">type</th>
<th data-buttons="delete" style="width: 40px"></th>
</tr>
</thead>
Expand Down
6 changes: 5 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "blebox",
"version": "0.0.13",
"version": "0.0.15",
"news": {
"0.0.15": {
"en": "",
"de": "Logging durch Checkbox einstellbar"
},
"0.0.14": {
"en": "",
"de": "Bugfixing, Automatische Updates von Werten nach shutterbox- und switchbox-Befehlen, Refactoring Tools und Business-Logik, Konfigurierbarkeit verbessert"
Expand Down
30 changes: 15 additions & 15 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ async function simpleObjectUrlGetter(device, url) {
let response = {};
//const iob = this;
const res = "http://" + device.ip + ":" + device.port + url;
iob.log.info("URL = " + res);
if (iob.extLog) iob.log.info("URL = " + res);
try {
response = await axios.default.get(res);
iob.log.info("body:" + JSON.stringify(response.data));
if (iob.extLog) iob.log.info("body:" + JSON.stringify(response.data));
//const state_response = JSON.parse(response.data);
states = dot.dot(response.data);
iob.log.info("data:" + JSON.stringify(states));
if (iob.extLog) iob.log.info("data:" + JSON.stringify(states));
} catch (error) {
iob.log.error("simpleObjectUrlGetter: " + error);
}
Expand All @@ -63,13 +63,13 @@ async function simpleObjectUrlGetter(device, url) {
* @param {object} states object of dotted styled keys with values e.g. device.ip = 192.168.1.2
*/
async function initIobStates(name, datapoints) {
iob.log.info("initIobStates start: " + JSON.stringify(name) + " = " + JSON.stringify(datapoints));
if (iob.extLog) iob.log.info("initIobStates start: " + JSON.stringify(name) + " = " + JSON.stringify(datapoints));
for (const key in datapoints) {
iob.log.info("initIobStates key: " + JSON.stringify(key));
if (iob.extLog) iob.log.info("initIobStates key: " + JSON.stringify(key));
if (Object.prototype.hasOwnProperty.call(datapoints, key)) {
const path = name + "." + datapoints[key].path;
const iobObject = datapoints[key];
iob.log.info("initIobStates: " + JSON.stringify(path) + " = " + JSON.stringify(iobObject));
if (iob.extLog) iob.log.info("initIobStates: " + JSON.stringify(path) + " = " + JSON.stringify(iobObject));
iob.setObject(path, {
type: iobObject.type,
common: iobObject.common,
Expand All @@ -84,18 +84,18 @@ async function initIobStates(name, datapoints) {
* @param {object} states object of dotted styled keys with values e.g. device.ip = 192.168.1.2
*/
async function setIobStates(device, values) {
iob.log.info("setIobStates device: " + JSON.stringify(device));
iob.log.info("setIobStates values: " + JSON.stringify(values));
if (iob.extLog) iob.log.info("setIobStates device: " + JSON.stringify(device));
if (iob.extLog) iob.log.info("setIobStates values: " + JSON.stringify(values));
for (const key in values) {
const search = device.type + "#" + key;
iob.log.info("setIobStates search: " + search);
iob.log.info("setIobStates datapoints: " + JSON.stringify(iob.datapoints[device.name]));
if (iob.extLog) iob.log.info("setIobStates search: " + search);
if (iob.extLog) iob.log.info("setIobStates datapoints: " + JSON.stringify(iob.datapoints[device.name]));
if (Object.prototype.hasOwnProperty.call(iob.datapoints[device.name], search)) {
const deviceDatapoints = iob.datapoints[device.name];
const path = deviceDatapoints[search].path;
iob.log.info("setIobStates path: " + path);
if (iob.extLog) iob.log.info("setIobStates path: " + path);
const value = values[key];
iob.log.info("setIobStates: " + JSON.stringify(device.name + "." + path) + " = " + JSON.stringify(value));
if (iob.extLog) iob.log.info("setIobStates: " + JSON.stringify(device.name + "." + path) + " = " + JSON.stringify(value));
if (path) {
if (Object.prototype.hasOwnProperty.call(deviceDatapoints[search], "factor")) {
iob.setState(device.name + "." + path, value * deviceDatapoints[search].factor);
Expand All @@ -112,16 +112,16 @@ async function setIobStates(device, values) {
*/
async function getBleboxData(device, type) {
let values = {};
iob.log.info("getBleboxData : device : " + JSON.stringify(device) + " type: " + type);
if (iob.extLog) iob.log.info("getBleboxData : device : " + JSON.stringify(device) + " type: " + type);
values = await iob.getSimpleObject(device, type, null);
await this.setIobStates(device, values);
return true;
}

async function initCommon(name, type) {
iob.log.info("initCommon: name: " + name + " type: " + type);
if (iob.extLog) iob.log.info("initCommon: name: " + name + " type: " + type);
iob.datapoints[name] = iob.getDatapoints(type);
iob.log.info("initCommon: datapoints: " + JSON.stringify(iob.datapoints[name]));
if (iob.extLog) iob.log.info("initCommon: datapoints: " + JSON.stringify(iob.datapoints[name]));
await this.initIobStates(name, iob.datapoints[name]);
}

Expand Down
28 changes: 15 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ class Blebox extends utils.Adapter {
this.on("unload", this.onUnload.bind(this));
tools.setIob(this);
this.datapoints = {};
this.extLog = {};
}

/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
this.log.info("Full config: " + JSON.stringify(this.config));
if (this.extLog) this.log.info("Full config: " + JSON.stringify(this.config));
let result = await this.checkPasswordAsync("admin", "iobroker");
this.log.info("check user admin pw ioboker: " + result);
if (this.extLog) this.log.info("check user admin pw ioboker: " + result);
result = await this.checkGroupAsync("admin", "admin");
this.log.info("check group user admin group admin: " + result);
if (this.extLog) this.log.info("check group user admin group admin: " + result);
if (Object.prototype.hasOwnProperty.call(this.config, "devices")) {
this.extLog = this.config.extLog;
this.config.devices.forEach(device => {
this.log.info("device name: " + device.name);
this.log.info("device smart_name: " + device.smart_name);
Expand Down Expand Up @@ -118,10 +120,10 @@ class Blebox extends utils.Adapter {
onObjectChange(id, obj) {
if (obj) {
// The object was changed
this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
if (this.extLog) this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
} else {
// The object was deleted
this.log.info(`object ${id} deleted`);
if (this.extLog) this.log.info(`object ${id} deleted`);
}
}

Expand All @@ -131,11 +133,11 @@ class Blebox extends utils.Adapter {
*/
getDeviceByName(name) {
let ret = {};
this.log.info("getDeviceByName # name : " + JSON.stringify(name));
if (this.extLog) this.log.info("getDeviceByName # name : " + JSON.stringify(name));
this.config.devices.forEach(device => {
this.log.info("getDeviceByName # device : " + JSON.stringify(device));
if (this.extLog) this.log.info("getDeviceByName # device : " + JSON.stringify(device));
if (device.name == name) {
this.log.info("getDeviceByName # return device : " + JSON.stringify(device));
if (this.extLog) this.log.info("getDeviceByName # return device : " + JSON.stringify(device));
ret = device;
}
});
Expand All @@ -151,9 +153,9 @@ class Blebox extends utils.Adapter {
const name = id.split(".")[2];
const device = this.getDeviceByName(name);
const l_datapoint = this.datapoints[device.type + "#" + name];
this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack}) name: ${name}`);
this.log.info("datapoint : " + JSON.stringify(l_datapoint));
this.log.info("device : " + JSON.stringify(device));
if (this.extLog) this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack}) name: ${name}`);
if (this.extLog) this.log.info("datapoint : " + JSON.stringify(l_datapoint));
if (this.extLog) this.log.info("device : " + JSON.stringify(device));
if (state) {
let response = {};
// The state was changed
Expand Down Expand Up @@ -247,7 +249,7 @@ class Blebox extends utils.Adapter {
response["command.relay"] = "";
await tools.setIobStates(response);
tools.getBleboxData(device, "switchState");
break;
break;
case this.namespace + "." + name + ".command.setRelayForTime":
this.log.info("set relayForTime to " + state.val);
response = await this.getSimpleObject(device, "switchSetRelayForTime", state.val);
Expand Down Expand Up @@ -318,7 +320,7 @@ class Blebox extends utils.Adapter {
break;
}

this.log.info("getSimpleObject : " + type + " URL: " + locationUrl + " device: " + JSON.stringify(device));
if (this.extLog) this.log.info("getSimpleObject : " + type + " URL: " + locationUrl + " device: " + JSON.stringify(device));
values = await tools.simpleObjectUrlGetter(device, locationUrl);
return values;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.blebox",
"version": "0.0.14",
"version": "0.0.15",
"description": "Adapter für Bleboxsysteme",
"author": {
"name": "Kai van Nuis",
Expand Down

0 comments on commit d337ee0

Please sign in to comment.