Skip to content

Commit

Permalink
Release 2.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jghaanstra committed Jan 16, 2019
1 parent 8228d90 commit 607742d
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 150 deletions.
7 changes: 2 additions & 5 deletions APPSTORE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ For Homey to be able to communicate with devices over the miIO protocol a unique
Xiaomi has recently released an update for its v1 vacuum that enabled it for the zoned cleaning and goto function that was previously only available to the v2 vacuum. Using the action cards that utilize these functions are a bit challenging. If you want to use these cards please read the instructions [here](https://github.com/jghaanstra/com.xiaomi-miio/blob/master/docs/mirobot_zonecleanup.md).

## Changelog
### 2018-11-28 - v2.9.3
* FIX: fix for Xiaomi Philips Zhirui Downlights

### 2018-11-28 - v2.9.2
* NEW: added support for Xiaomi Philips Zhirui Candle Lights (PR from rdvanbuuren) and Xiaomi Philips Zhirui Downlights
### 2019-01-16 - v2.9.4
* FIX: better error handling to avoid app crashes
120 changes: 86 additions & 34 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,44 @@ class XiaomiMiioApp extends Homey.App {
new Homey.FlowCardAction('findVacuum')
.register()
.registerRunListener((args, state) => {
return args.device.miio.find();
if (args.device.miio) {
return args.device.miio.find();
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('fanPowerVacuum')
.register()
.registerRunListener((args, state) => {
return args.device.miio.changeFanSpeed(Number(args.fanspeed)).then(result => {
return args.device.setStoreValue('fanspeed', args.fanspeed);
});
if (args.device.miio) {
return args.device.miio.changeFanSpeed(Number(args.fanspeed)).then(result => {
return args.device.setStoreValue('fanspeed', args.fanspeed);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('goToTargetVacuum')
.register()
.registerRunListener((args, state) => {
return args.device.miio.goToTarget([args.xcoordinate, args.ycoordinate]);
if (args.device.miio) {
return args.device.miio.goToTarget([args.xcoordinate, args.ycoordinate]);
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('cleanZoneVacuum')
.register()
.registerRunListener((args, state) => {
const zones = JSON.parse("[" + args.zones + "]");
return args.device.miio.activateZoneClean(zones);
if (args.device.miio) {
const zones = JSON.parse("[" + args.zones + "]");
return args.device.miio.activateZoneClean(zones);
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

// MI AIR PURIFIER: CONDITION AND ACTION FLOW CARDS
Expand All @@ -92,31 +108,47 @@ class XiaomiMiioApp extends Homey.App {
new Homey.FlowCardAction('modeAirpurifier')
.register()
.registerRunListener((args, state) => {
return args.device.miio.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
if (args.device.miio) {
return args.device.miio.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('airpurifierSetFavorite')
.register()
.registerRunListener((args, state) => {
return args.device.miio.favoriteLevel(args.favorite);
if (args.device.miio) {
return args.device.miio.favoriteLevel(args.favorite);
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('airpurifierOn')
.register()
.registerRunListener((args, state) => {
return args.device.miio.setPower(true).then(result => {
return args.device.setCapabilityValue('onoff', true);
});
if (args.device.miio) {
return args.device.miio.setPower(true).then(result => {
return args.device.setCapabilityValue('onoff', true);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('airpurifierOff')
.register()
.registerRunListener((args, state) => {
return args.device.miio.setPower(false).then(result => {
return args.device.setCapabilityValue('onoff', false);
});
if (args.device.miio) {
return args.device.miio.setPower(false).then(result => {
return args.device.setCapabilityValue('onoff', false);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

// MI HUMDIFIER: CONDITION AND ACTION FLOW CARDS
Expand All @@ -129,9 +161,13 @@ class XiaomiMiioApp extends Homey.App {
new Homey.FlowCardAction('modeHumidifier')
.register()
.registerRunListener((args, state) => {
return args.device.miio.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
if (args.device.miio) {
return args.device.miio.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('humidifierOn')
Expand All @@ -145,37 +181,53 @@ class XiaomiMiioApp extends Homey.App {
new Homey.FlowCardAction('humidifierOff')
.register()
.registerRunListener((args, state) => {
return args.device.miio.setPower(false).then(result => {
return args.device.setCapabilityValue('onoff', false);
});
if (args.device.miio) {
return args.device.miio.setPower(false).then(result => {
return args.device.setCapabilityValue('onoff', false);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

// PHILIPS EYECARE LAMP: CONDITION AND ACTION FLOW CARDS
new Homey.FlowCardAction('enableEyecare')
.register()
.registerRunListener((args, state) => {
const eyecare = args.eyecare == 'on' ? true : false;
return args.device.setEyeCare(eyecare).then(result => {
return args.device.setStoreValue('eyecare', eyecare);
});
if (args.device.miio) {
const eyecare = args.eyecare == 'on' ? true : false;
return args.device.setEyeCare(eyecare).then(result => {
return args.device.setStoreValue('eyecare', eyecare);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

new Homey.FlowCardAction('modeEyecare')
.register()
.registerRunListener((args, state) => {
return args.device.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
if (args.device.miio) {
return args.device.mode(args.mode).then(result => {
return args.device.setStoreValue('mode', args.mode);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})

// GATEWAY: CONDITION AND ACTION FLOW CARDS
new Homey.FlowCardAction('armGateway')
.register()
.registerRunListener((args, state) => {
const alarm = args.alarm == 'armed' ? true : false;
return args.device.miio.setArming(alarm).then(result => {
return args.device.setCapabilityValue('homealarm_state', args.alarm);
});
if (args.device.miio) {
const alarm = args.alarm == 'armed' ? true : false;
return args.device.miio.setArming(alarm).then(result => {
return args.device.setCapabilityValue('homealarm_state', args.alarm);
});
} else {
return Promise.reject(new Error('Device unreachable, please try again ...'));
}
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"en": [ "Xiaomi", "Mi", "Mi Home", "miio", "vacuumcleaner", "robot", "yeelight", "yeelights", "purifier", "humidifier", "philips", "eyecare", "powerplug", "gateway" ],
"nl": [ "Xiaomi", "Mi", "Mi home", "miio", "stofzuiger", "robot", "yeelight", "yeelights", "luchtreiniger", "luchtbevochtiger", "philips", "eyecare", "powerplug", "gateway" ]
},
"version": "2.9.3",
"version": "2.9.4",
"compatibility": ">=1.5.12",
"author": {
"name": "Jelger Haanstra",
Expand Down
15 changes: 11 additions & 4 deletions drivers/air-monitor/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ class MiAirMonitorDevice extends Homey.Device {

onInit() {
this.createDevice();
this.setUnavailable(Homey.__('unreachable'));

this.registerCapabilityListener('onoff', this.onCapabilityOnoff.bind(this));
}

onDeleted() {
clearInterval(this.pollingInterval);
if (typeof this.miio !== "undefined") {
if (this.miio) {
this.miio.destroy();
}
}

// LISTENERS FOR UPDATING CAPABILITIES
onCapabilityOnoff(value, opts, callback) {
this.miio.setPower(value)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
if (this.miio) {
this.miio.setPower(value)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

// HELPER FUNCTIONS
Expand Down
67 changes: 46 additions & 21 deletions drivers/gateway/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GatewayDevice extends Homey.Device {
this.gatewayLuminanceTrigger = new Homey.FlowCardTriggerDevice('gatewayLuminance').register();

this.createDevice();
this.setUnavailable(Homey.__('unreachable'));

this.registerCapabilityListener('onoff', this.onCapabilityOnoff.bind(this));
this.registerCapabilityListener('dim', this.onCapabilityDim.bind(this));
Expand All @@ -20,45 +21,69 @@ class GatewayDevice extends Homey.Device {

onDeleted() {
clearInterval(this.pollingInterval);
if (typeof this.miio !== "undefined") {
if (this.miio) {
this.miio.destroy();
}
}

// LISTENERS FOR UPDATING CAPABILITIES
onCapabilityOnoff(value, opts) {
return this.miio.light.setPower(value)
if (this.miio) {
return this.miio.light.setPower(value)
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

onCapabilityDim(value, opts) {
const brightness = value * 100;
return this.miio.light.setBrightness(brightness)
if (this.miio) {
const brightness = value * 100;
return this.miio.light.setBrightness(brightness);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

onCapabilityHueSaturation(valueObj, optsObj) {
if (valueObj.hasOwnProperty('light_hue')) {
var hue_value = valueObj.light_hue;
} else {
var hue_value = this.getCapabilityValue('light_hue');
}
if (this.miio) {
if (valueObj.hasOwnProperty('light_hue')) {
var hue_value = valueObj.light_hue;
} else {
var hue_value = this.getCapabilityValue('light_hue');
}

if (valueObj.hasOwnProperty('light_saturation')) {
var saturation_value = valueObj.light_saturation;
} else {
var saturation_value = this.getCapabilityValue('light_saturation');
}
if (valueObj.hasOwnProperty('light_saturation')) {
var saturation_value = valueObj.light_saturation;
} else {
var saturation_value = this.getCapabilityValue('light_saturation');
}

const hue = hue_value * 359;
const saturation = saturation_value * 100;
const dim = this.getCapabilityValue('dim') * 100
const colorUpdate = tinycolor({ h: Math.round(hue), s: Math.round(saturation), v: dim });
const hue = hue_value * 359;
const saturation = saturation_value * 100;
const dim = this.getCapabilityValue('dim') * 100
const colorUpdate = tinycolor({ h: Math.round(hue), s: Math.round(saturation), v: dim });

return this.miio.light.color(colorUpdate.toRgbString());
return this.miio.light.color(colorUpdate.toRgbString());
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

onCapabilityAlarm(value, opts) {
const state = value == 'armed' ? true : false;
return this.miio.setArming(state)
if (this.miio) {
const state = value == 'armed' ? true : false;
return this.miio.setArming(state);
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

// HELPER FUNCTIONS
Expand Down
15 changes: 11 additions & 4 deletions drivers/mi-airpurifier/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ class MiAirPurifierDevice extends Homey.Device {

onInit() {
this.createDevice();
this.setUnavailable(Homey.__('unreachable'));

this.registerCapabilityListener('onoff', this.onCapabilityOnoff.bind(this));
}

onDeleted() {
clearInterval(this.pollingInterval);
if (typeof this.miio !== "undefined") {
if (this.miio) {
this.miio.destroy();
}
}

// LISTENERS FOR UPDATING CAPABILITIES
onCapabilityOnoff(value, opts, callback) {
this.miio.setPower(value)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
if (this.miio) {
this.miio.setPower(value)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
} else {
this.setUnavailable(Homey.__('unreachable'));
this.createDevice();
callback('Device unreachable, please try again ...', false)
}
}

// HELPER FUNCTIONS
Expand Down
Loading

0 comments on commit 607742d

Please sign in to comment.