(bluefox) remove unused code
This commit is contained in:
@@ -177,342 +177,6 @@ function syncRoom(room, members, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
function syncRooms(rooms, cb) {
|
||||
for (var r in rooms) {
|
||||
if (!rooms.hasOwnProperty(r)) continue;
|
||||
if (rooms[r]) {
|
||||
syncRoom(r, rooms[r], function () {
|
||||
setTimeout(syncRooms, 0, rooms, cb);
|
||||
});
|
||||
rooms[r] = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cb) cb();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------<<<
|
||||
function parseObjects(objs, cb) {
|
||||
var rooms = {};
|
||||
var objects = [];
|
||||
var states = [];
|
||||
var id;
|
||||
var obj;
|
||||
var name;
|
||||
var ignoreStates = ['getConfig', 'getRegRaw', 'regBulk', 'regSet', 'deviceMsg', 'CommandAccepted'];
|
||||
|
||||
for (var i = 0; i < objs.length; i++) {
|
||||
try {
|
||||
name = objs[i].Name.replace(/\./g, '_');
|
||||
|
||||
if (objs[i].Attributes && objs[i].Attributes.room === 'hidden') continue;
|
||||
|
||||
id = adapter.namespace + '.' + name;
|
||||
|
||||
objects.push({
|
||||
_id: id,
|
||||
type: 'channel',
|
||||
common: {
|
||||
name: objs[i].Name
|
||||
},
|
||||
native: objs[i]
|
||||
});
|
||||
|
||||
if (objs[i].Attributes && objs[i].Attributes.room) {
|
||||
var rrr = objs[i].Attributes.room.split(',');
|
||||
for (var r = 0; r < rrr.length; r++) {
|
||||
rrr[r] = rrr[r].trim();
|
||||
rooms[rrr[r]] = rooms[rrr[r]] || [];
|
||||
rooms[rrr[r]].push(adapter.namespace + '.' + name);
|
||||
}
|
||||
}
|
||||
|
||||
var isOn = false;
|
||||
var isOff = false;
|
||||
var setStates = {};
|
||||
|
||||
if (objs[i].PossibleSets) {
|
||||
var attrs = objs[i].PossibleSets.split(' ');
|
||||
for (var a = 0; a < attrs.length; a++) {
|
||||
if (!attrs[a]) continue;
|
||||
var parts = attrs[a].split(':');
|
||||
|
||||
// ignore some useless "sets"
|
||||
if (ignoreStates.indexOf(parts[0]) !== -1) continue;
|
||||
|
||||
var stateName = parts[0].replace(/\./g, '_');
|
||||
id = adapter.namespace + '.' + name + '.' + stateName;
|
||||
|
||||
|
||||
if (parts[0] === 'off') isOff = true;
|
||||
if (parts[0] === 'on') isOn = true;
|
||||
|
||||
obj = {
|
||||
_id: id,
|
||||
type: 'state',
|
||||
common: {
|
||||
name: objs[i].Name + ' ' + parts[0],
|
||||
read: false,
|
||||
write: true
|
||||
},
|
||||
native: {
|
||||
Name: objs[i].Name,
|
||||
Attribute: parts[0]
|
||||
}
|
||||
};
|
||||
if (parts[1]) {
|
||||
var _states = parts[1].split(',');
|
||||
// adapter.log.info('LausiD "' + obj._id + ' : ' + _states + '"');
|
||||
// obj.common.states = JSON.stringify(_states);
|
||||
obj.common.states = '';
|
||||
|
||||
if (parseFloat(_states[0]) == _states[0]) {
|
||||
obj.common.type = 'number';
|
||||
}
|
||||
}
|
||||
|
||||
obj.common.type = obj.common.type || 'string';
|
||||
obj.common.role = 'command';
|
||||
// edit 08.03.17 LausiD
|
||||
// detect pct,Volume,GroupVolume,brightness
|
||||
if (parts[0] === 'pct' || parts[0] === 'Volume' || parts[0] === 'GroupVolume' || parts[0] === 'brightness') {
|
||||
// obj.common.write = true;
|
||||
// obj.common.unit= '%';
|
||||
obj.common.type = 'number';
|
||||
obj.common.min = '0';
|
||||
obj.common.max = '100';
|
||||
obj.common.role = 'command.dim.100';
|
||||
}
|
||||
// detect bri,sat
|
||||
if (parts[0] === 'bri' || parts[0] === 'sat') {
|
||||
// obj.common.write = true;
|
||||
// obj.common.unit = '%';
|
||||
obj.common.type = 'number';
|
||||
obj.common.min = '0';
|
||||
obj.common.max = '254';
|
||||
obj.common.role = 'command.dim.254';
|
||||
}
|
||||
|
||||
|
||||
if (parts[0].indexOf('RGB') !== -1) {
|
||||
obj.common.role = 'light.color.rgb';
|
||||
obj.native.rgb = true;
|
||||
}
|
||||
if (parts[0].indexOf('HSV') !== -1) {
|
||||
obj.common.role = 'light.color.hsv';
|
||||
obj.native.hsv = true;
|
||||
}
|
||||
objects.push(obj);
|
||||
setStates[stateName] = obj;
|
||||
//console.log(' ' + obj._id + ': ' + (parts[1] || ''));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (objs[i].Attributes[attr]) {
|
||||
// for (var attr in objs[i].Attributes) {
|
||||
adapter.log.info('LausiD '+ attr);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* if (!objs[i].Readings.hasOwnProperty(attr)) continue;
|
||||
// ignore some useless states
|
||||
if (ignoreStates.indexOf(attr) !== -1) continue;
|
||||
|
||||
var stateName = attr.replace(/\./g, '_');
|
||||
id = adapter.namespace + '.' + name + '.' + stateName;
|
||||
//adapter.log.info('LausiD '+ id);
|
||||
var combined = false;
|
||||
if (setStates[stateName]) {
|
||||
combined = true;
|
||||
obj = setStates[stateName];
|
||||
obj.common.read = true;
|
||||
obj.common.unit = getUnit(attr);
|
||||
} else {
|
||||
obj = {
|
||||
_id: id,
|
||||
type: 'state',
|
||||
common: {
|
||||
name: objs[i].Name + ' ' + attr,
|
||||
read: true,
|
||||
write: false,
|
||||
unit: getUnit(attr)
|
||||
},
|
||||
native: {
|
||||
Name: objs[i].Name,
|
||||
Attribute: attr
|
||||
}
|
||||
};
|
||||
} */
|
||||
|
||||
|
||||
if (objs[i].Readings) {
|
||||
for (var attr in objs[i].Readings) {
|
||||
if (!objs[i].Readings.hasOwnProperty(attr)) continue;
|
||||
// ignore some useless states
|
||||
if (ignoreStates.indexOf(attr) !== -1) continue;
|
||||
|
||||
var stateName = attr.replace(/\./g, '_');
|
||||
id = adapter.namespace + '.' + name + '.' + stateName;
|
||||
var combined = false;
|
||||
if (setStates[stateName]) {
|
||||
combined = true;
|
||||
obj = setStates[stateName];
|
||||
obj.common.read = true;
|
||||
obj.common.unit = getUnit(attr);
|
||||
} else {
|
||||
obj = {
|
||||
_id: id,
|
||||
type: 'state',
|
||||
common: {
|
||||
name: objs[i].Name + ' ' + attr,
|
||||
read: true,
|
||||
write: false,
|
||||
unit: getUnit(attr)
|
||||
},
|
||||
native: {
|
||||
Name: objs[i].Name,
|
||||
Attribute: attr
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (objs[i].Readings[attr]) {
|
||||
var val = convertFhemValue(objs[i].Readings[attr].Value);
|
||||
obj.common.type = obj.common.type || typeof val;
|
||||
obj.common.role = obj.common.role || 'value';
|
||||
|
||||
states.push({
|
||||
id: obj._id,
|
||||
val: val,
|
||||
ts: objs[i].Readings[attr].Time ? new Date(objs[i].Readings[attr].Time).getTime() : new Date().getTime(),
|
||||
ack: true
|
||||
});
|
||||
|
||||
// detect pct
|
||||
if (attr === 'pct' || attr === 'Volume' || attr === 'GroupVolume' || attr === 'brightness') {
|
||||
obj.common.unit = '%';
|
||||
}
|
||||
// detect bri,sat
|
||||
if (attr === 'bri' || attr === 'sat') {
|
||||
obj.common.unit = '%';
|
||||
}
|
||||
|
||||
// detect state
|
||||
if (attr === 'state') {
|
||||
obj.common.write = true;
|
||||
obj.native.onoff = true;
|
||||
obj.common.role = 'switch';
|
||||
}
|
||||
// detect on/off state
|
||||
if (isOff && isOn && attr === 'state') {
|
||||
obj.common.write = true;
|
||||
obj.native.onoff = true;
|
||||
obj.common.role = 'switch';
|
||||
}
|
||||
|
||||
if (!combined) objects.push(obj);
|
||||
}
|
||||
}
|
||||
delete objs[i].Readings;
|
||||
}
|
||||
setStates = null;
|
||||
|
||||
/*id = adapter.namespace + '.' + name + '.lastError';
|
||||
obj = {
|
||||
_id: id,
|
||||
type: 'state',
|
||||
common: {
|
||||
name: objs[i].Name + ' lastError',
|
||||
read: true,
|
||||
write: false,
|
||||
def: '',
|
||||
type: 'string',
|
||||
role: 'error'
|
||||
},
|
||||
native: objs[i]
|
||||
};
|
||||
objects.push(obj);*/
|
||||
|
||||
/*id = adapter.namespace + '.' + objs[i].Name + '.validity';
|
||||
obj = {
|
||||
_id: id,
|
||||
type: 'state',
|
||||
common: {
|
||||
name: objs[i].Name + ' validity',
|
||||
read: true,
|
||||
write: false,
|
||||
def: '',
|
||||
type: 'string',
|
||||
role: 'state.quality'
|
||||
},
|
||||
native: objs[i]
|
||||
};
|
||||
objects.push(obj);*/
|
||||
|
||||
} catch (err) {
|
||||
adapter.log.error('Cannot process object: ' + JSON.stringify(objs[i]));
|
||||
adapter.log.error('Cannot process object: ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
syncObjects(objects, function () {
|
||||
syncRooms(rooms, function () {
|
||||
syncStates(states, cb);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function readValue(id, cb) {
|
||||
telnetOut.send('get ' + hassObjects[id].native.Name + ' ' + hassObjects[id].native.Attribute, function (err, result) {
|
||||
if (err) adapter.log.error('readValue: ' + err);
|
||||
// MeinWetter city => Berlin
|
||||
if (result) {
|
||||
result = convertFhemValue(result.substring(hassObjects[id].native.Name.length + hassObjects[id].native.Attribute + 5));
|
||||
if (result !== '') {
|
||||
adapter.setForeignState(id, result, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (cb) cb();
|
||||
});
|
||||
}
|
||||
|
||||
function writeValue(id, val, cb) {
|
||||
var cmd;
|
||||
var val_org = val;
|
||||
if (val === undefined || val === null) val = '';
|
||||
// edit LausiD 05.03.17
|
||||
// May be RGB
|
||||
if (hassObjects[id].native.Attribute === 'rgb') val = val.substring(1);
|
||||
|
||||
// if (typeof val === 'string' && val[0] === '#' && val.length > 3) val = val.substring(1);
|
||||
// if (hassObjects[id].native.rgb) {
|
||||
// }
|
||||
|
||||
if (hassObjects[id].native.Attribute === 'state') {
|
||||
if (val === '1' || val === 1 || val === 'on' || val === 'true' || val === true) val = 'on';
|
||||
if (val === '0' || val === 0 || val === 'off' || val === 'false' || val === false) val = 'off';
|
||||
cmd = 'set ' + hassObjects[id].native.Name + ' ' + val;
|
||||
// adapter.log.info(adapter.namespace + '.' + hassObjects[id].native.Name + '.' + hassObjects[id].native.Attribute + '.' + val_org + ' ==> ' + cmd);
|
||||
}
|
||||
else {
|
||||
cmd = 'set ' + hassObjects[id].native.Name + ' ' + hassObjects[id].native.Attribute + ' ' + val;
|
||||
}
|
||||
adapter.log.info(adapter.namespace + '.' + hassObjects[id].native.Name + '.' + hassObjects[id].native.Attribute + '.' + val_org + ' ==> writeFHEM: ' + cmd);
|
||||
// edit end LausiD 05.03.17
|
||||
|
||||
telnetOut.send(cmd, function (err, result) {
|
||||
if (err) adapter.log.error('writeValue: ' + err);
|
||||
if (cb) cb();
|
||||
});
|
||||
}
|
||||
|
||||
var knownAttributes = {
|
||||
azimuth: {write: false, read: true, unit: '°'},
|
||||
elevation: {write: false, read: true, unit: '°'}
|
||||
|
||||
Reference in New Issue
Block a user