Skip to content

Commit

Permalink
Added Mi Robot driver again
Browse files Browse the repository at this point in the history
  • Loading branch information
jghaanstra committed Nov 4, 2017
1 parent dde009d commit b9b32a9
Show file tree
Hide file tree
Showing 17 changed files with 771 additions and 53 deletions.
27 changes: 9 additions & 18 deletions drivers/mi-robot/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class MiRobotDevice extends Homey.Device {
if (error) {
callback(error, false);
} else {
this._device.state.onoff = value;
this.setCapabilityValue('onoff', value);
callback(null, value);
}
Expand All @@ -39,20 +38,16 @@ class MiRobotDevice extends Homey.Device {
switch (value) {
case "cleaning":
var vacuum_state = 'start';
this._device.state.state = 'cleaning';
break;
case "spot_cleaning":
var vacuum_state = 'spotclean';
this._device.state.state = 'spot_cleaning';
break;
case "stopped":
var vacuum_state = 'stop';
this._device.state.state = 'stopped';
break;
case "docked":
case "charging":
var vacuum_state = 'charge';
this._device.state.state = 'charging';
break;
default:
this.log("Not a valid vacuumcleaner_state");
Expand All @@ -77,43 +72,39 @@ class MiRobotDevice extends Homey.Device {
this.pollingInterval = setInterval(() => {
util.getVacuumCleaner(this.getSetting('address'), this.getSetting('token'))
.then(result => {
if (this._device.state.onoff != result.onoff) {
this._device.state.onoff = result.onoff;
if (this.getCapabilityValue('onoff') != result.onoff) {
this.setCapabilityValue('onoff', result.onoff);
}
if (this._device.state.battery != result.battery) {
this._device.state.battery = result.battery;
if (this.getCapabilityValue('measure_battery') != result.battery) {
this.setCapabilityValue('measure_battery', result.battery);
}

var vacuumcleanerState = this.getCapabilityValue('vacuumcleaner_state');

switch (result.state) {
case 'cleaning':
case 'returning':
if (this._device.state.state != 'cleaning') {
this._device.state.state = 'cleaning';
if (vacuumcleanerState != 'cleaning') {
this.setCapabilityValue('vacuumcleaner_state', 'cleaning');
}
break;
case 'spot-cleaning':
if (this._device.state.state != 'spot_cleaning') {
this._device.state.state = 'spot_cleaning';
if (vacuumcleanerState != 'spot_cleaning') {
this.setCapabilityValue('vacuumcleaner_state', 'spot_cleaning');
}
break;
case 'charging':
if (this._device.state.state != 'charging') {
this._device.state.state = 'charging';
if (vacuumcleanerState != 'charging') {
this.setCapabilityValue('vacuumcleaner_state', 'charging');
}
break;
case 'paused':
if (this._device.state.state != 'stopped') {
this._device.state.state = 'stopped';
if (vacuumcleanerState != 'stopped') {
this.setCapabilityValue('vacuumcleaner_state', 'stopped');
}
break;
default:
this._device.state.state = 'stopped';
vacuumcleanerState = 'stopped';
this.setCapabilityValue('vacuumcleaner_state', 'stopped');
}

Expand Down
3 changes: 3 additions & 0 deletions node_modules/appdirectory/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/appdirectory/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions node_modules/appdirectory/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions node_modules/appdirectory/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions node_modules/appdirectory/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

200 changes: 200 additions & 0 deletions node_modules/appdirectory/lib/appdirectory.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b9b32a9

Please sign in to comment.