Skip to content

Commit

Permalink
v3.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jemu75 committed Apr 5, 2021
1 parent b9cc23b commit 863eaf6
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 109 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
header: ''
}
},
version: 'v3.5.3',
version: 'v3.5.4',
status: {
color: 'secondary',
icon: 'mdi-circle',
Expand Down
4 changes: 2 additions & 2 deletions src/components/TemplChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
if(this.vals.maxSize) {
this.$router.go(-1);
} else {
this.$router.push('/devices/' + this.item.Name + '&size=max');
this.$router.push('/devices/device=' + this.item.Name + '&size=max');
}
},
Expand All @@ -196,7 +196,7 @@
let def = { deviceName: this.item.Name, from: this.vals.from, to: this.vals.to, defs: this.item.Options.chartDef };
this.$fhem.readLogFile(def)
this.$fhem.readLogData(def)
.then((res) => {
if(res.defs.length > 0) {
let idx = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/TemplHmLan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
},
goTo() {
this.$router.push('/devices/' + this.vals.devOffline);
this.$router.push('/devices/device=' + this.vals.devOffline);
}
},
Expand Down
184 changes: 100 additions & 84 deletions src/plugins/fhem.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default class Fhem extends EventEmitter {
}

// mainfunction { deviceName: '', from: timestamp, to: timestamp, defs: [def1, def2] }
async readLogFile(obj) {
async readLogData(obj) {
let promise = new Promise((resolve, reject) => {
if(obj.defs && obj.defs.length > 0) {
let data = [];
Expand Down Expand Up @@ -273,24 +273,19 @@ export default class Fhem extends EventEmitter {
let list = [];
this.app.data.[listName].splice(0);

this.request({ param: 'cmd', value: 'jsonList2 appOptions!= appOptions ' + attr }, 'json')
this.request({ param: 'cmd', value: 'jsonList2 appOptions!= appOptions room group' }, 'json')
.then(async (res) => {
let idx = 1;

for (const item of res.Results) {
let options = await this.createOptions(item, true);
let options = await this.createOptions(item);
let defs = options[attr];
let ignoreAttr = false;
if(this.app.options.ignoreFhemRoom && attr === 'room') ignoreAttr = true;
if(this.app.options.ignoreFhemGroup && attr === 'group') ignoreAttr = true;
if(!defs && !ignoreAttr) defs = item.Attributes[attr];

if(defs && options.template) {
let vals = defs.split(',');
for (let val of vals) {
let route = '/devices/' + attr + '=' + val.replace(/\s/g,'\\s').replace(/&/g,'.');

if(options[attr]) route += '&appOptions=' + attr;
//let route = '/devices/' + attr + '=' + val.replace(/\s/g,'\\s').replace(/&/g,'.');
let route = '/devices/' + attr + '=' + val;

if(list.map((e) => e.title).indexOf(val) == -1) {
list.push({ title: val, route: route });
Expand Down Expand Up @@ -424,36 +419,33 @@ export default class Fhem extends EventEmitter {
return vals;
}

// subfunction for getDevices(), create Connected Object
async createConnected(device) {
let promise = new Promise((resolve, reject) => {
if('connected' in device.Options) {
let list = Object.keys(device.Options.connected);
let result = {};
let idx = 1;
let result = {};

for (const item of list) {
this.request({ param: 'cmd', value: 'jsonlist2 ' + device.Options.connected[item] }, 'json')
.then(async (res) => {
result[item] = res.Results[0];
if('PossibleSets' in result[item]) delete result[item].PossibleSets;
if('PossibleAttrs' in result[item]) delete result[item].PossibleAttrs;

let options = await this.createOptions(result[item]);
if(options) result[item].Options = options;
if(idx === list.length) resolve(result);
idx ++;
})
.catch((err) => reject(err));
}
} else {
resolve({});
if('connected' in device.Options) {
let deviceList = Object.keys(device.Options.connected);

for (const item of deviceList) {
result[item] = await this.request({ param: 'cmd', value: 'jsonlist2 ' + device.Options.connected[item] }, 'json')
.then(async (res) => {
if('PossibleSets' in res.Results[0]) delete res.Results[0].PossibleSets;
if('PossibleAttrs' in res.Results[0]) delete res.Results[0].PossibleAttrs;

let options = await this.createOptions(res.Results[0]);
if(options) res.Results[0].Options = options;

return res.Results[0];
})
.catch((err) => {
this.log = { type: 'error', message: 'Request to FHEM failed.', meta: err };
})
}
})
return promise;
}

return result;
}

// subfunction for getDevices(), create the
// subfunction for getDevices(), create the setup
async getSetup(template) {
let result = null;

Expand Down Expand Up @@ -506,83 +498,107 @@ export default class Fhem extends EventEmitter {
return result;
}

// subfunction for getDevices(), create Options Object
async createOptions(device, onlyOpts) {
let result = null;
// core function for validation json strings
createJson(string) {
let result = {};

if('appOptions' in device.Attributes) {
if(string) {
try {
result = JSON.parse(device.Attributes.appOptions);
if(!onlyOpts && result.template) {
let component = this.getComponent(result.template);
Object.assign(result, component);
}
if(!onlyOpts && result.template && result.component === 'templ_default') {
let setup = await this.getSetup(result.template);
if(result.setup) Object.assign(setup, result.setup);
result.setup = setup;
}
result = JSON.parse(string);
} catch(err) {
this.log = { type: 'error', message: 'Read appOptions from ' + device.Name + ' failed.', meta: err.message };
this.log = { type: 'error', message: 'Json Data is no valid. ' + string, meta: err.message };
}
}
return result;
}

// subfunction for getDevices(), create the Options Object for device
async createOptions(device) {
let result = null;

if('appOptions' in device.Attributes) {
result = this.createJson(device.Attributes.appOptions);
if(result) {
result.device = device.Name;
if(!result.name) result.name = this.getEl(device, 'Attributes', 'alias') || device.Name;
if(!result.sortby && !this.app.options.ignoreFhemSortby) result.sortby = this.getEl(device, 'Attributes', 'sortby') || 'zzz';
if(!result.room && !this.app.options.ignoreFhemRoom) result.room = this.getEl(device, 'Attributes', 'room') || '';
if(!result.group && !this.app.options.ignoreFhemGroup) result.group = this.getEl(device, 'Attributes', 'group') || '';
if(result.room === 'hidden') result.room = '';
if(result.group === 'hidden') result.group = '';
}
}

return await result;
}

// mainfunction fill array with devices
// subfunction for getDevices(), checking filter in jsonlist2 result
checkFilter(fltr, options) {
let result = false;

if(fltr === 'app=home' && options.home) result = true;
if(fltr === 'app=dashboard' && options.dashboard) result = true;
if(fltr === 'app=system' && options.system) result = true;
if(fltr.match('room=') || fltr.match('group=')) {
let fltrPart = fltr.split('=');
if(options[fltrPart[0]]) {
let defs = options[fltrPart[0]].split(',');
let search = fltrPart[1].replace('%20',' ');
if(defs.indexOf(search) != -1) result = true;
}
}
if(fltr.match('device=')) {
let defs = fltr.split('=')[1].split('&')[0].split(',');
if(defs.indexOf(options.device) != -1) result = true;
}

return(result);
}

// mainfunction fill array with Devices
getDevices(fltr) {
this.app.options.loading = true;
this.app.data.deviceList.splice(0);

this.request({ param: 'cmd', value: 'jsonlist2 ' + fltr }, 'json')
this.request({ param: 'cmd', value: 'jsonlist2 appOptions!=' }, 'json')
.then(async (res) => {
let idx = 1;
let target = [];
let idx = 1;

for(const item of res.Results) {
let options = await this.createOptions(item);

if(res.Results.length > 0) {
for(const item of res.Results) {
if(this.checkFilter(fltr, options) && options.template) {
if('PossibleSets' in item) delete item.PossibleSets;
if('PossibleAttrs' in item) delete item.PossibleAttrs;
let blockItem = false;
let options = await this.createOptions(item);

if(options) {
item.Options = options;
if(!item.Options.sortby && !this.app.options.ignoreFhemSortby) item.Options.sortby = item.Attributes.sortby;
if(!item.Options.sortby) item.Options.sortby = 'zzz';
let component = this.getComponent(options.template);
Object.assign(options, component);

if(fltr.match('FILTER=group') && item.Options.group) blockItem = true;
if(fltr.match('FILTER=room') && item.Options.room) blockItem =true;
if(options.component === 'templ_default') {
let setup = await this.getSetup(options.template);
if(options.setup) Object.assign(setup, options.setup);
options.setup = setup;
}

this.createConnected(item)
.then((connected) => {
item.Connected = connected;
if(!blockItem) target.push(item);
item.Options = options;
if(item.Options.connected) item.Connected = await this.createConnected(item);
target.push(item);
}

if(idx === res.Results.length) {
target.sort((a,b) => (a.Options.sortby > b.Options.sortby) ? 1 : ((b.Options.sortby > a.Options.sortby) ? -1 : 0));
this.app.data.deviceList = Object.assign([], target);
this.app.options.loading = false
}
idx ++;
})
.catch((err) => {
this.log = { type: 'error', message: 'Add Connected Element failed.', meta: err };
this.app.options.loading = false;
});
} else {
this.app.options.loading = false;
}
if(idx === res.Results.length) {
target.sort((a,b) => (a.Options.sortby > b.Options.sortby) ? 1 : ((b.Options.sortby > a.Options.sortby) ? -1 : 0));
this.app.data.deviceList = Object.assign([], target);
this.app.options.loading = false
}
} else {
this.app.options.loading = false
idx ++;

}
})
.catch((err) => {
this.log = { type: 'error', message: 'Request to FHEM failed.', meta: err };
this.app.options.loading = false;
});
})
}

// subfunction for doUpdate(), return Data from update as Object
Expand Down
27 changes: 11 additions & 16 deletions src/views/Devices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export default {
setHeader() {
if(this.app.options.mobileHeader) {
if(this.$route.name === 'Devices') {
let part = this.$route.params.filter.split('&')[0].split('=')[1];
this.app.data.header = part.replace(/\\s.\\s/g,' & ');
if(this.$route.params.filter.match('device=')) {
this.app.data.header = ''
} else {
this.app.data.header = this.$route.params.filter.split('=')[1];
}
} else {
this.app.data.header = this.$route.name;
}
Expand All @@ -55,25 +58,17 @@ export default {
subscribe() {
if(!this.app.session.connect) return;
let fltr = 'appOptions!=:FILTER=';
let fltr = '';
if(this.$route.params.filter) {
let parts = this.$route.params.filter.split('&');
if(this.$route.params.filter) fltr = this.$route.params.filter;
if(parts.indexOf('appOptions=room') != -1 || parts.indexOf('appOptions=group') != -1) {
fltr = 'appOptions=.*' + parts[0].replace('=', '.*') + '.*';
} else {
fltr += parts[0];
}
}
if(this.$route.name == 'Dashboard') fltr = 'appOptions=.*dashboard.:..true.*';
if(this.$route.name == 'System') fltr = 'appOptions=.*system.:..true.*';
if(this.$route.name == 'Home') fltr = 'appOptions=.*home.:..true.*';
if(this.$route.name == 'Dashboard') fltr = 'app=dashboard';
if(this.$route.name == 'System') fltr = 'app=system';
if(this.$route.name == 'Home') fltr = 'app=home';
this.setHeader();
this.$fhem.getDevices(fltr);
}
},
},
mounted() {
Expand Down
2 changes: 1 addition & 1 deletion www/fhemapp/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="icon" href="favicon.png"><link rel="apple-touch-icon" href="apple-touch-icon.png"><title>fhemapp</title><link href="css/chunk-03454508.55c011d2.css" rel="prefetch"><link href="css/chunk-0458398b.c4749bc4.css" rel="prefetch"><link href="css/chunk-098d33d4.61e1e199.css" rel="prefetch"><link href="css/chunk-15fa718e.55c011d2.css" rel="prefetch"><link href="css/chunk-27250ed3.55c011d2.css" rel="prefetch"><link href="css/chunk-2c05d556.cb4d0868.css" rel="prefetch"><link href="css/chunk-57a6c555.611711b5.css" rel="prefetch"><link href="css/chunk-58038582.55c011d2.css" rel="prefetch"><link href="css/chunk-62d9ca09.792facbe.css" rel="prefetch"><link href="css/chunk-72c6e8d8.8d89ed40.css" rel="prefetch"><link href="css/chunk-83618c9a.3058ccc5.css" rel="prefetch"><link href="css/chunk-d584b056.4c33e4ab.css" rel="prefetch"><link href="css/chunk-f90907bc.01cf6fd8.css" rel="prefetch"><link href="js/chunk-03454508.432c8b15.js" rel="prefetch"><link href="js/chunk-0458398b.ff29fd68.js" rel="prefetch"><link href="js/chunk-098d33d4.bbdd65ab.js" rel="prefetch"><link href="js/chunk-15fa718e.820d5967.js" rel="prefetch"><link href="js/chunk-27250ed3.00eafedc.js" rel="prefetch"><link href="js/chunk-2c05d556.1084b9d2.js" rel="prefetch"><link href="js/chunk-2d212bf1.61adf40b.js" rel="prefetch"><link href="js/chunk-57a6c555.7c0a36f4.js" rel="prefetch"><link href="js/chunk-58038582.a600d1fb.js" rel="prefetch"><link href="js/chunk-62d9ca09.da27c615.js" rel="prefetch"><link href="js/chunk-72c6e8d8.c00175b8.js" rel="prefetch"><link href="js/chunk-83618c9a.f88bebf6.js" rel="prefetch"><link href="js/chunk-d584b056.b951ef6d.js" rel="prefetch"><link href="js/chunk-f90907bc.3ec9d165.js" rel="prefetch"><link href="css/chunk-vendors.95431e8e.css" rel="preload" as="style"><link href="js/app.a68de743.js" rel="preload" as="script"><link href="js/chunk-vendors.aacf57ae.js" rel="preload" as="script"><link href="css/chunk-vendors.95431e8e.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but fhemapp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.aacf57ae.js"></script><script src="js/app.a68de743.js"></script></body></html>
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="icon" href="favicon.png"><link rel="apple-touch-icon" href="apple-touch-icon.png"><title>fhemapp</title><link href="css/chunk-03454508.55c011d2.css" rel="prefetch"><link href="css/chunk-0458398b.c4749bc4.css" rel="prefetch"><link href="css/chunk-098d33d4.61e1e199.css" rel="prefetch"><link href="css/chunk-15fa718e.55c011d2.css" rel="prefetch"><link href="css/chunk-27250ed3.55c011d2.css" rel="prefetch"><link href="css/chunk-2c05d556.cb4d0868.css" rel="prefetch"><link href="css/chunk-57a6c555.611711b5.css" rel="prefetch"><link href="css/chunk-58038582.55c011d2.css" rel="prefetch"><link href="css/chunk-62d9ca09.792facbe.css" rel="prefetch"><link href="css/chunk-72c6e8d8.8d89ed40.css" rel="prefetch"><link href="css/chunk-83618c9a.3058ccc5.css" rel="prefetch"><link href="css/chunk-d584b056.4c33e4ab.css" rel="prefetch"><link href="css/chunk-f90907bc.01cf6fd8.css" rel="prefetch"><link href="js/chunk-03454508.432c8b15.js" rel="prefetch"><link href="js/chunk-0458398b.ff29fd68.js" rel="prefetch"><link href="js/chunk-098d33d4.bbdd65ab.js" rel="prefetch"><link href="js/chunk-15fa718e.b8680e39.js" rel="prefetch"><link href="js/chunk-27250ed3.00eafedc.js" rel="prefetch"><link href="js/chunk-2c05d556.1084b9d2.js" rel="prefetch"><link href="js/chunk-2d212bf1.1ddb5d0a.js" rel="prefetch"><link href="js/chunk-57a6c555.7c0a36f4.js" rel="prefetch"><link href="js/chunk-58038582.a600d1fb.js" rel="prefetch"><link href="js/chunk-62d9ca09.da27c615.js" rel="prefetch"><link href="js/chunk-72c6e8d8.c00175b8.js" rel="prefetch"><link href="js/chunk-83618c9a.f88bebf6.js" rel="prefetch"><link href="js/chunk-d584b056.618304a4.js" rel="prefetch"><link href="js/chunk-f90907bc.3ec9d165.js" rel="prefetch"><link href="css/chunk-vendors.95431e8e.css" rel="preload" as="style"><link href="js/app.588b3867.js" rel="preload" as="script"><link href="js/chunk-vendors.aacf57ae.js" rel="preload" as="script"><link href="css/chunk-vendors.95431e8e.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but fhemapp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.aacf57ae.js"></script><script src="js/app.588b3867.js"></script></body></html>

Large diffs are not rendered by default.

Loading

0 comments on commit 863eaf6

Please sign in to comment.