MCPcopy
hub / github.com/aholstenson/miio / update

Method update

lib/tokens.js:87–126  ·  view source on GitHub ↗
(deviceId, token)

Source from the content-addressed store, hash-verified

85 }
86
87 update(deviceId, token) {
88 return this._load()
89 .then(() => {
90 this._data[deviceId] = token;
91
92 if(this._saving) {
93 this._dirty = true;
94 return this._saving;
95 }
96
97 return this._saving = new Promise((resolve, reject) => {
98 const save = () => {
99 debug('About to save tokens');
100 fs.writeFile(this._file, JSON.stringify(this._data, null, 2), (err) => {
101 if(err) {
102 reject(err);
103 } else {
104 if(this._dirty) {
105 debug('Redoing save due to multiple updates');
106 this._dirty = false;
107 save();
108 } else {
109 delete this._saving;
110 resolve();
111 }
112 }
113 });
114 };
115
116 mkdirp(dirs.userData(), (err) => {
117 if(err) {
118 reject(err);
119 return;
120 }
121
122 save();
123 });
124 });
125 });
126 }
127}
128
129module.exports = new Tokens();

Callers 6

rawMethod · 0.80
tokenMethod · 0.80
updateTokenMethod · 0.80
_updateDeviceListMethod · 0.80
configure.jsFile · 0.80
discover.jsFile · 0.80

Calls 1

_loadMethod · 0.95

Tested by

no test coverage detected