This commit is contained in:
Evgenii Abramov
2021-03-30 21:39:23 +03:00
parent cc3b0779a0
commit 736529aa4a
2 changed files with 6 additions and 5 deletions

View File

@@ -34,13 +34,15 @@ class Device {
room: options.room || '', room: options.room || '',
type: options.type || 'devices.types.light', type: options.type || 'devices.types.light',
custom_data: { custom_data: {
allowedUsers: options.allowedUsers || [1],
mqtt: options.mqtt || [], mqtt: options.mqtt || [],
valueMapping: options.valueMapping || [], valueMapping: options.valueMapping || [],
}, },
capabilities: (options.capabilities || []).map(c => Object.assign({}, c, {state: (c.state == undefined) ? this.initState(c) : c.state})), capabilities: (options.capabilities || []).map(c => Object.assign({}, c, {state: (c.state == undefined) ? this.initState(c) : c.state})),
properties: (options.properties || []).map(p => Object.assign({}, p, {state: (p.state == undefined) ? this.initState(p) : p.state})) properties: (options.properties || []).map(p => Object.assign({}, p, {state: (p.state == undefined) ? this.initState(p) : p.state})),
} };
this.meta = {
allowedUsers: options.allowedUsers || [1],
};
} }
/* Create init state (for capabilities and properties) on device object create */ /* Create init state (for capabilities and properties) on device object create */

View File

@@ -35,8 +35,7 @@ module.exports.devices = [
}; };
for (const d of global.devices) { for (const d of global.devices) {
console.log(d); const {allowedUsers} = d.meta;
const {allowedUsers} = d.custom_data;
if (Array.isArray(allowedUsers) && allowedUsers.indexOf(userId)) { if (Array.isArray(allowedUsers) && allowedUsers.indexOf(userId)) {
console.log(d.getInfo()); console.log(d.getInfo());
r.payload.devices.push(d.getInfo()); r.payload.devices.push(d.getInfo());