Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onInit() {
this.createDevice();
setTimeout(() => { this.refreshDevice(); }, 600000);
this.setUnavailable(Homey.__('unreachable'));
// LISTENERS FOR UPDATING CAPABILITIES
this.registerCapabilityListener('onoff', (value, opts) => {
if (this.miio) {
return this.miio.setPower(value);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
return Promise.reject('Device unreachable, please try again ...');
}
});
}
onInit() {
this.createDevice();
setTimeout(() => { this.refreshDevice(); }, 600000);
this.setUnavailable(Homey.__('unreachable'));
// LISTENERS FOR UPDATING CAPABILITIES
this.registerCapabilityListener('onoff', (value, opts) => {
if (this.miio) {
return this.miio.setPower(value);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
return Promise.reject('Device unreachable, please try again ...');
}
});
this.registerCapabilityListener('dim', (value, opts) => {
if (this.miio) {
var brightness = value * 100;
return this.miio.setBrightness(brightness);
onInit() {
this.createDevice();
setTimeout(() => { this.refreshDevice(); }, 600000);
this.setUnavailable(Homey.__('unreachable'));
// LISTENERS FOR UPDATING CAPABILITIES
this.registerCapabilityListener('onoff', (value, opts) => {
if (this.miio) {
return this.miio.setPower(value);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
return Promise.reject('Device unreachable, please try again ...');
}
});
}
onInit() {
this.createDevice();
setTimeout(() => { this.refreshDevice(); }, 600000);
this.setUnavailable(Homey.__('unreachable'));
// LISTENERS FOR UPDATING CAPABILITIES
this.registerCapabilityListener('onoff', (value, opts) => {
if (this.miio) {
return this.miio.setPower(value);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
return Promise.reject('Device unreachable, please try again ...');
}
});
}
onInit() {
this.createDevice();
setTimeout(() => { this.refreshDevice(); }, 600000);
this.setUnavailable(Homey.__('unreachable'));
// LISTENERS FOR UPDATING CAPABILITIES
this.registerCapabilityListener('onoff', (value, opts) => {
if (this.miio) {
return this.miio.setPower(value);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
return Promise.reject('Device unreachable, please try again ...');
}
});
}
_composeCustomSaveMessage(oldSettings, newSettings, changedKeysArr) {
// Provide user with proper feedback after clicking save
let saveMessage = null;
if (this.node.battery === true && this.node.online === false) saveMessage = Homey.__(i18n.settings.offlineNodeSaveMessage);
if (typeof this.customSaveMessage === 'function') {
const message = this.customSaveMessage(oldSettings, newSettings, changedKeysArr);
if (typeof message !== 'object' && typeof message !== 'string') {
this._debug('Save message\'s return value is not an object nor a string');
} else if (typeof message === 'object' && !message.hasOwnProperty('en')) {
this._debug('A custom save message needs at least the english translation');
} else {
saveMessage = message;
}
} else if (typeof this.customSaveMessage === 'object') {
if (!this.customSaveMessage.hasOwnProperty('en')) {
this._debug('A custom save message needs at least the english translation');
} else {
saveMessage = this.customSaveMessage;
}
_composeCustomSaveMessage(oldSettings, newSettings, changedKeysArr) {
// Provide user with proper feedback after clicking save
let saveMessage = null;
if (this.node.battery === true && this.node.online === false) saveMessage = Homey.__(i18n.settings.offlineNodeSaveMessage);
if (typeof this.customSaveMessage === 'function') {
const message = this.customSaveMessage(oldSettings, newSettings, changedKeysArr);
if (typeof message !== 'object' && typeof message !== 'string') {
this._debug('Save message\'s return value is not an object nor a string');
} else if (typeof message === 'object' && !message.hasOwnProperty('en')) {
this._debug('A custom save message needs at least the english translation');
} else {
saveMessage = message;
}
} else if (typeof this.customSaveMessage === 'object') {
if (!this.customSaveMessage.hasOwnProperty('en')) {
this._debug('A custom save message needs at least the english translation');
} else {
saveMessage = this.customSaveMessage;
}
onSceneAutocomplete(query, args, callback) {
let resultArray = [];
for (let sceneID in this.sceneMap) {
resultArray.push({
id: this.sceneMap[sceneID].scene,
name: Homey.__(this.sceneMap[sceneID].scene),
})
}
// filter for query
resultArray = resultArray.filter(result => {
return result.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
});
this._debug(resultArray);
return Promise.resolve(resultArray);
}
onSceneAutocomplete(query, args, callback) {
let resultArray = [];
for (let sceneID in this.sceneMap) {
resultArray.push({
id: this.sceneMap[sceneID].scene,
name: Homey.__(this.sceneMap[sceneID].scene),
})
}
// filter for query
resultArray = resultArray.filter(result => {
return result.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
});
this._debug(resultArray);
return Promise.resolve(resultArray);
}
onSceneAutocomplete(query, args, callback) {
let resultArray = [];
for (let sceneID in this.sceneMap) {
resultArray.push({
id: this.sceneMap[sceneID].scene,
name: Homey.__(this.sceneMap[sceneID].scene),
})
}
// filter for query
resultArray = resultArray.filter(result => {
return result.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
});
this._debug(resultArray);
return Promise.resolve(resultArray);
}