UNPKG

homey-api

Version:
58 lines (44 loc) 1.3 kB
'use strict'; const Manager = require('./Manager'); class ManagerUsers extends Manager { __userMe = null; async getUserMe(...args) { const options = args[0] ?? {}; if (this.__userMe != null && options.$cache !== false) { return await this.__userMe; } // TODO // // - remove on disconnect manager users this.__userMe = this.__super__getUserMe(...args) .then((result) => { const ItemClass = this.itemClasses.User; const props = ItemClass.transformGet(result); if (this.isConnected()) { if (this.__cache[ItemClass.ID][props.id] != null) { this.__cache[ItemClass.ID][props.id].__update(props); } else { this.__cache[ItemClass.ID][props.id] = new ItemClass({ id: props.id, homey: this.homey, manager: this, properties: props, }); } return this.__cache[ItemClass.ID][props.id]; } return new ItemClass({ id: props.id, homey: this.homey, manager: this, properties: props, }); }) .catch(err => { this.__userMe = null; throw err; }); return await this.__userMe; } } module.exports = ManagerUsers;