Skip to content

Commit

Permalink
fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
t4qjXH8N committed Jun 27, 2021
1 parent 60b160d commit a8782ab
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ function openSocket() {

// get the ip of the wiffi
let ip;
if (Object.prototype.hasOwnProperty.call(jsonContent, 'vars') && Array.isArray(jsonContent.vars) && jsonContent.vars.length > 0) {
if (Object.hasOwnProperty.call(jsonContent, 'vars') && Array.isArray(jsonContent.vars) && jsonContent.vars.length > 0) {
// datagram seems to be fine, look for an ip in homematic name
ip = _.find(jsonContent.vars, function (cvar) {
return cvar.homematic_name.search(/_ip/i);
});

ip = Object.prototype.hasOwnProperty.call(ip, 'value') ? ip.value : null;
ip = Object.hasOwnProperty.call(ip, 'value') ? ip.value : null;
}

if (!ip) {
Expand Down Expand Up @@ -354,11 +354,11 @@ function syncStates(ip, jsonContent, callback) {
'role': 'state' // default if there is no other information on the roles
};

if (Object.prototype.hasOwnProperty.call(cstate, 'homematic_name') && cstate.homematic_name) {
if (Object.hasOwnProperty.call(cstate, 'homematic_name') && cstate.homematic_name) {
state['id'] = cleanid(cstate.homematic_name);
} else {
// if id not present use name if set
if (Object.prototype.hasOwnProperty.call(cstate, 'name') && cstate.name) {
if (Object.hasOwnProperty.call(cstate, 'name') && cstate.name) {
state['id'] = cleanid(cstate.name);
} else {
// sorry, I have no idea how to deal with this datapoint
Expand All @@ -370,19 +370,19 @@ function syncStates(ip, jsonContent, callback) {
}
}

if (Object.prototype.hasOwnProperty.call(cstate, 'name') && cstate.name) {
if (Object.hasOwnProperty.call(cstate, 'name') && cstate.name) {
state['name'] = cstate.name.toString();
}

if (Object.prototype.hasOwnProperty.call(cstate, 'desc') && cstate.desc) {
if (Object.hasOwnProperty.call(cstate, 'desc') && cstate.desc) {
state['desc'] = cstate.desc;
}

if (Object.prototype.hasOwnProperty.call(cstate, 'unit') && cstate.unit) {
if (Object.hasOwnProperty.call(cstate, 'unit') && cstate.unit) {
state['unit'] = cstate.unit.replace(/grad/ig, '°');
}

if (Object.prototype.hasOwnProperty.call(cstate, 'type') && cstate.type) {
if (Object.hasOwnProperty.call(cstate, 'type') && cstate.type) {
switch (cstate.type) {
case 'string':
state['type'] = 'string';
Expand Down Expand Up @@ -413,7 +413,7 @@ function syncStates(ip, jsonContent, callback) {

// load state extensions if there are any
for (let j = 0; j < state_extensions.length; j++) {
if ((state['id'].search(RegExp(state_extensions[j].expression, 'i')) !== -1) && Object.prototype.hasOwnProperty.call(state_extensions[j], 'extensions')) {
if ((state['id'].search(RegExp(state_extensions[j].expression, 'i')) !== -1) && Object.hasOwnProperty.call(state_extensions[j], 'extensions')) {
// we found some extensions
const cext = state_extensions[j].extensions;
Object.assign(state, cext);
Expand Down Expand Up @@ -477,7 +477,7 @@ function syncStates(ip, jsonContent, callback) {
const sys_states_in_db = [];

for (const cstate in states) {
if (!Object.prototype.hasOwnProperty.call(states, cstate)) {
if (!Object.hasOwnProperty.call(states, cstate)) {
continue;
}

Expand All @@ -490,7 +490,7 @@ function syncStates(ip, jsonContent, callback) {

// sync native systemconfig states
for (const csysstate in jsonContent.Systeminfo) {
if (!Object.prototype.hasOwnProperty.call(jsonContent.Systeminfo, csysstate)) {
if (!Object.hasOwnProperty.call(jsonContent.Systeminfo, csysstate)) {
continue;
}

Expand Down Expand Up @@ -525,9 +525,9 @@ function syncStates(ip, jsonContent, callback) {
// set states from the received JSON
function updateStates(ip, jsonContents, callback) {
// update systeminfo states
if (Object.prototype.hasOwnProperty.call(jsonContents, 'Systeminfo')) {
if (Object.hasOwnProperty.call(jsonContents, 'Systeminfo')) {
for (const citem in jsonContents.Systeminfo) {
if (!Object.prototype.hasOwnProperty.call(jsonContents.Systeminfo, citem)) {
if (!Object.hasOwnProperty.call(jsonContents.Systeminfo, citem)) {
continue;
}

Expand All @@ -546,9 +546,9 @@ function updateStates(ip, jsonContents, callback) {
for (let i = 0; i < jsonContents.vars.length; i++) {
const cstate = jsonContents.vars[i];

if (!(Object.prototype.hasOwnProperty.call(cstate, 'homematic_name') && cstate.homematic_name)) {
if (!(Object.hasOwnProperty.call(cstate, 'homematic_name') && cstate.homematic_name)) {
// use name if id is missing
if (Object.prototype.hasOwnProperty.call(cstate, 'name') && cstate.name) {
if (Object.hasOwnProperty.call(cstate, 'name') && cstate.name) {
cstate['homematic_name'] = cstate.name;
} else {
if (!cstate.desc) {
Expand Down Expand Up @@ -593,7 +593,7 @@ function cleanid(id) {
}

function checkAndSubscribe(ip, state, callback) {
if (Object.prototype.hasOwnProperty.call(state, 'write') && state['write']) {
if (Object.hasOwnProperty.call(state, 'write') && state['write']) {
adapter.subscribeStates('root.' + ip_to_id(ip) + '.' + cleanid(state['id']));
subscribed_states.push(adapter_db_prefix + ip_to_id(ip) + '.' + cleanid(state['id']));
}
Expand Down

0 comments on commit a8782ab

Please sign in to comment.