Skip to content

Commit

Permalink
Merge pull request #483 from iobroker-community-adapters/revert-456-m…
Browse files Browse the repository at this point in the history
…aster

Revert "Better handling of empty objects"
  • Loading branch information
mcm1957 authored Jul 24, 2024
2 parents fad373d + cedf9aa commit 0084b04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
26 changes: 5 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,24 +630,18 @@ function getStorageRealtimeData(id) {
adapter.log.debug('Response to ' + requestType + ip + baseurl + 'GetStorageRealtimeData.cgi?Scope=Device&DeviceId=' + id + ': ' + JSON.stringify(response.data));
if (response.status == 200) {
try {
let data = response.data;
const data = response.data;
if ('Body' in data) {
// check if object is existing and not empty
if (data.Body.Data === null || Object.entries(data.Body.Data).length === 0) {
if (data.Body.Data === null) {
adapter.log.debug('Storage object is not supported: ' + JSON.stringify(data));
return;
}
data = data.Body.Data;

if (!isObjectsCreated) {
devObjects.createStorageObjects(adapter, id, data);
}
if (Object.prototype.hasOwnProperty.call(data, 'Controller')) {
fillData(adapter, data.Controller, 'storage.' + id);
}
if (Object.prototype.hasOwnProperty.call(data, 'Modules')) {
fillData(adapter, data.Modules, 'storage.' + id + '.module');
devObjects.createStorageObjects(adapter, id, response.data.Body.Data);
}
fillData(adapter, response.data.Body.Data.Controller, 'storage.' + id);
fillData(adapter, response.data.Body.Data.Modules, 'storage.' + id + '.module');
} else {
adapter.log.warn(data.Head.Status.Reason + ' storage: ' + id);
}
Expand Down Expand Up @@ -1171,11 +1165,6 @@ function GetArchiveValue(adapter, data, prefix, id, key) {

// this function should not be called directly, better is to call through fillData function as this includes a timeout handling
function fillDataObject(adapt, apiObject, prefix = '') {
// check if the given object is existing and not empty
if (apiObject === null || Object.entries(apiObject).length === 0) {
adapter.log.debug('fillDataObject: Object is empty!');
return;
}
if (prefix != '' && prefix.endsWith('.') == false) {
// make sure the path ends with a . if set
prefix = prefix + '.';
Expand Down Expand Up @@ -1237,11 +1226,6 @@ function fillDataObject(adapt, apiObject, prefix = '') {

// function to be called to fill the data
function fillData(adapter, apiObject, prefix = '') {
// check if object is existing and not empty
if (apiObject === null || Object.entries(apiObject).length === 0) {
adapter.log.debug('fillData: Object is null or empty!');
return;
}
setTimeout(
function (adapt, data, pref) {
fillDataObject(adapt, data, pref);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0084b04

Please sign in to comment.