4 Commits

Author SHA1 Message Date
Arne
d8ca308338 Updated changelog 2019-10-19 17:33:58 +02:00
Arne
75180b27cb Bumped version to v0.7.2 2019-10-19 17:31:38 +02:00
Arne
b8971b64a9 Updated readme 2019-10-18 10:02:55 +02:00
Arne
32e47d0a8f Fixed launch error with multiple robots 2019-10-16 22:32:53 +02:00
5 changed files with 159 additions and 150 deletions

View File

@@ -113,4 +113,7 @@
* Fixed room switches not supporting pause/resume
## 0.7.1
* Fixed robot not shown before setting up a floor plan
* Fixed robot not shown before setting up a floor plan
## 0.7.2
* Fixed homebridge crash with multiple robots per account

View File

@@ -17,9 +17,9 @@ Feel free to leave any feedback [here](https://github.com/naofireblade/homebridg
- Eco mode
- Extra care navigation
- Nogo lines
- Zone cleaning* (only D7)
- Zone cleaning <sup>[1](#d7)</sup><sup>, </sup><sup>[2](#change-room)</sup>
- Spot cleaning
- Individual spot size (only D7)
- Individual spot size <sup>[1](#d7)</sup>
- Clean twice
- Return to dock
- Find the robot
@@ -32,7 +32,9 @@ Feel free to leave any feedback [here](https://github.com/naofireblade/homebridg
- Automatic or periodic refresh of robot state
- Multiple robots
>*You can also send the robot from one room to another. He will return to the base, wait there some seconds and then starts cleaning the other room.
> <b name="d7">1</b> Only available on the Neato D7.
> <b name="change-room">2</b> You can send the robot from one room to another as well. He will return to the base, wait there some seconds and then starts cleaning the next room.
## Installation
@@ -59,11 +61,16 @@ Add the following information to your config file. Change the values for email a
### Advanced
The following config contains advanced optional settings.
Below are explanations for advanced parameters to adjust the plugin to your needs. All parameters are *optional*.
The parameter **refresh** is default set to `auto` and updates the robot state when a cleaning was started via homekit so that you can activate automations based on a successful cleaning. If you want to get robot state updates after starting the cleaning from outside of homekit as well (neato app or schedule), you have to set refresh to a static value in seconds e.g. `120`. You can disable background updates completely by setting this to `0`.
**refresh**
Timer for periodic refresh of robot state. The default is `auto`. The options are:
`auto` Updates the robot state when a cleaning was started via homekit so that you can activate automations based on a successful cleaning.
`120` Or any other time in seconds (minimum `60`) is required if you want to receive robot state updates after starting the cleaning from outside of homekit (e.g. neato app or schedule).
`0` Disables background updates completely.
The parameter **hidden** accepts a list of switches/sensors that can be hidden from homekit (e.g. `dock`, `dockstate`, `eco`, `nogolines`, `extracare`, `schedule`, `find`, `spot`).
**hidden**
List of plugin features that you don't want to use in homekit (e.g. `dock`, `dockstate`, `eco`, `nogolines`, `extracare`, `schedule`, `find`, `spot`).
```json
"platforms": [

View File

@@ -17,6 +17,9 @@ module.exports = function (_Service, _Characteristic)
{
Service = _Service;
Characteristic = _Characteristic;
SpotWidthCharacteristic = require('../characteristics/spotWidth')(Characteristic, CustomUUID);
SpotHeightCharacteristic = require('../characteristics/spotHeight')(Characteristic, CustomUUID);
SpotRepeatCharacteristic = require('../characteristics/spotRepeat')(Characteristic, CustomUUID);
return NeatoVacuumRobotAccessory;
};
@@ -32,7 +35,7 @@ function NeatoVacuumRobotAccessory(platform, robotObject)
this.robotObject = robotObject;
this.robot = robotObject.device;
this.meta = robotObject.meta;
this.availableServices = robotObject.availableServices;
this.spotPlusFeatures = ((typeof robotObject.availableServices.spotCleaning !== 'undefined') && robotObject.availableServices.spotCleaning.includes("basic"));
this.boundary = (typeof robotObject.boundary === 'undefined') ? null : robotObject.boundary;
if (this.boundary == null)
@@ -74,23 +77,12 @@ function NeatoVacuumRobotAccessory(platform, robotObject)
this.scheduleService = new Service.Switch(this.name + " Schedule", "schedule");
this.findMeService = new Service.Switch(this.name + " Find Me", "findMe");
SpotWidthCharacteristic = require('../characteristics/spotWidth')(Characteristic, CustomUUID);
SpotHeightCharacteristic = require('../characteristics/spotHeight')(Characteristic, CustomUUID);
SpotRepeatCharacteristic = require('../characteristics/spotRepeat')(Characteristic, CustomUUID);
// Spot cleaning with advanced options
if ((typeof this.availableServices.spotCleaning !== 'undefined') && this.availableServices.spotCleaning.includes("basic"))
this.spotCleanService = new Service.Switch(this.name + " Clean Spot", "cleanSpot");
this.spotCleanService.addCharacteristic(SpotRepeatCharacteristic);
if (this.spotPlusFeatures)
{
this.spotCleanAdvancedService = new Service.Switch(this.name + " Clean Spot", "cleanSpot");
this.spotCleanAdvancedService.addCharacteristic(SpotRepeatCharacteristic);
this.spotCleanAdvancedService.addCharacteristic(SpotWidthCharacteristic);
this.spotCleanAdvancedService.addCharacteristic(SpotHeightCharacteristic);
}
// Spot cleaning without advanced options
else
{
this.spotCleanSimpleService = new Service.Switch(this.name + " Clean Spot", "cleanSpot");
this.spotCleanSimpleService.addCharacteristic(SpotRepeatCharacteristic);
this.spotCleanService.addCharacteristic(SpotWidthCharacteristic);
this.spotCleanService.addCharacteristic(SpotHeightCharacteristic);
}
}
else
@@ -166,29 +158,22 @@ NeatoVacuumRobotAccessory.prototype = {
this.findMeService.getCharacteristic(Characteristic.On).on('set', this.setFindMe.bind(this));
this.findMeService.getCharacteristic(Characteristic.On).on('get', this.getFindMe.bind(this));
if (typeof this.spotCleanAdvancedService !== 'undefined')
{
this.spotCleanAdvancedService.getCharacteristic(Characteristic.On).on('set', this.setSpotClean.bind(this));
this.spotCleanAdvancedService.getCharacteristic(Characteristic.On).on('get', this.getSpotClean.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotRepeatCharacteristic).on('set', this.setSpotRepeat.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotRepeatCharacteristic).on('get', this.getSpotRepeat.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotWidthCharacteristic).on('set', this.setSpotWidth.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotWidthCharacteristic).on('get', this.getSpotWidth.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotHeightCharacteristic).on('set', this.setSpotHeight.bind(this));
this.spotCleanAdvancedService.getCharacteristic(SpotHeightCharacteristic).on('get', this.getSpotHeight.bind(this));
this.spotCleanService.getCharacteristic(Characteristic.On).on('set', this.setSpotClean.bind(this));
this.spotCleanService.getCharacteristic(Characteristic.On).on('get', this.getSpotClean.bind(this));
this.spotCleanService.getCharacteristic(SpotRepeatCharacteristic).on('set', this.setSpotRepeat.bind(this));
this.spotCleanService.getCharacteristic(SpotRepeatCharacteristic).on('get', this.getSpotRepeat.bind(this));
if (this.hiddenServices.indexOf('spot') === -1)
this.services.push(this.spotCleanAdvancedService);
if (this.spotPlusFeatures)
{
this.spotCleanService.getCharacteristic(SpotWidthCharacteristic).on('set', this.setSpotWidth.bind(this));
this.spotCleanService.getCharacteristic(SpotWidthCharacteristic).on('get', this.getSpotWidth.bind(this));
this.spotCleanService.getCharacteristic(SpotHeightCharacteristic).on('set', this.setSpotHeight.bind(this));
this.spotCleanService.getCharacteristic(SpotHeightCharacteristic).on('get', this.getSpotHeight.bind(this));
}
else
{
this.spotCleanSimpleService.getCharacteristic(Characteristic.On).on('set', this.setSpotClean.bind(this));
this.spotCleanSimpleService.getCharacteristic(Characteristic.On).on('get', this.getSpotClean.bind(this));
this.spotCleanSimpleService.getCharacteristic(SpotRepeatCharacteristic).on('set', this.setSpotRepeat.bind(this));
this.spotCleanSimpleService.getCharacteristic(SpotRepeatCharacteristic).on('get', this.getSpotRepeat.bind(this));
if (this.hiddenServices.indexOf('spot') === -1)
this.services.push(this.spotCleanSimpleService);
if (this.hiddenServices.indexOf('spot') === -1)
{
this.services.push(this.spotCleanService);
}
// Add optional services
@@ -507,12 +492,10 @@ NeatoVacuumRobotAccessory.prototype = {
setSpotClean: function (on, callback)
{
let spotCleanService = (typeof this.spotCleanAdvancedService !== 'undefined') ? this.spotCleanAdvancedService : this.spotCleanSimpleService;
let spot = {
width: spotCleanService.getCharacteristic(SpotWidthCharacteristic).value,
height: spotCleanService.getCharacteristic(SpotHeightCharacteristic).value,
repeat: spotCleanService.getCharacteristic(SpotRepeatCharacteristic).value
width: this.spotPlusFeatures ? this.spotCleanService.getCharacteristic(SpotWidthCharacteristic).value : null,
height: this.spotPlusFeatures ? this.spotCleanService.getCharacteristic(SpotHeightCharacteristic).value : null,
repeat: this.spotCleanService.getCharacteristic(SpotRepeatCharacteristic).value
};
this.platform.updateRobot(this.robot._serial, (error, result) =>
@@ -658,15 +641,12 @@ NeatoVacuumRobotAccessory.prototype = {
this.noGoLinesService.setCharacteristic(Characteristic.On, this.robot.noGoLines);
this.extraCareService.setCharacteristic(Characteristic.On, this.robot.navigationMode == 2 ? true : false);
if (typeof this.spotCleanAdvancedService !== 'undefined')
this.spotCleanService.setCharacteristic(SpotRepeatCharacteristic, this.robot.spotRepeat);
if (this.spotPlusFeatures)
{
this.spotCleanAdvancedService.setCharacteristic(SpotWidthCharacteristic, this.robot.spotWidth);
this.spotCleanAdvancedService.setCharacteristic(SpotHeightCharacteristic, this.robot.spotHeight);
this.spotCleanAdvancedService.setCharacteristic(SpotRepeatCharacteristic, this.robot.spotRepeat);
}
else
{
this.spotCleanSimpleService.setCharacteristic(SpotRepeatCharacteristic, this.robot.spotRepeat);
this.spotCleanService.setCharacteristic(SpotWidthCharacteristic, this.robot.spotWidth);
this.spotCleanService.setCharacteristic(SpotHeightCharacteristic, this.robot.spotHeight);
}
}

203
index.js
View File

@@ -4,12 +4,14 @@ let inherits = require('util').inherits,
botvac = require('node-botvac'),
Service,
Characteristic;
Characteristic,
NeatoVacuumRobotAccessory;
module.exports = function (homebridge)
{
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
NeatoVacuumRobotAccessory = require('./accessories/neatoVacuumRobot')(Service, Characteristic);
homebridge.registerPlatform("homebridge-neato", "NeatoVacuumRobot", NeatoVacuumRobotPlatform);
};
@@ -54,50 +56,70 @@ NeatoVacuumRobotPlatform.prototype = {
debug("Get robots");
let accessories = [];
this.boundaryNames = [];
this.getRobots(() =>
{
this.robots.forEach((robot, i) =>
{
this.log("Found robot #" + (i + 1) + " named \"" + robot.device.name + "\" with serial \"" + robot.device._serial.substring(0,9) + "XXXXXXXXXXXX\"");
// // MOCK MULTIPLE ROBOTS START
// let client = new botvac.Client();
// client.authorize(this.email, this.password, false, (error) =>
// {
// client.getRobots((error, robs) =>
// {
// let testRobot = robs[0];
// testRobot.getState((error, result) =>
// {
// testRobot.name = "Testrobot";
// this.robots.push({device: testRobot, meta: result.meta, availableServices: result.availableServices});
// // MOCK MULTIPLE ROBOTS END
// Start Update Intervall
this.updateRobotTimer(robot.device._serial);
let NeatoVacuumRobotAccessory = require('./accessories/neatoVacuumRobot')(Service, Characteristic);
let mainAccessory = new NeatoVacuumRobotAccessory(this, robot);
accessories.push(mainAccessory);
robot.mainAccessory = mainAccessory;
robot.roomAccessories = [];
// For testing purposes only
// robot.boundary = {name: "Testroom", id: "1"};
// let roomAccessory = new NeatoVacuumRobotAccessory(this, robot);
// accessories.push(roomAccessory);
// robot.roomAccessories.push(roomAccessory);
if (robot.device.maps)
{
robot.device.maps.forEach((map) =>
{
if (map.boundaries)
this.robots.forEach((robot, i) =>
{
map.boundaries.forEach((boundary) =>
{
if (boundary.type === "polygon")
{
robot.boundary = boundary;
let roomAccessory = new NeatoVacuumRobotAccessory(this, robot);
accessories.push(roomAccessory);
this.log("Found robot #" + (i + 1) + " named \"" + robot.device.name + "\" with serial \"" + robot.device._serial.substring(0, 9) + "XXXXXXXXXXXX\"");
robot.roomAccessories.push(roomAccessory);
}
})
}
})
}
});
callback(accessories);
let mainAccessory = new NeatoVacuumRobotAccessory(this, robot);
accessories.push(mainAccessory);
robot.mainAccessory = mainAccessory;
robot.roomAccessories = [];
// Start Update Intervall
this.updateRobotTimer(robot.device._serial);
// // MOCK ZONE CLEANING START
// robot.boundary = {name: "Testroom", id: "1"};
// let roomAccessory = new NeatoVacuumRobotAccessory(this, robot);
// accessories.push(roomAccessory);
// robot.roomAccessories.push(roomAccessory);
// // MOCK ZONE CLEANING END
if (robot.device.maps)
{
robot.device.maps.forEach((map) =>
{
if (map.boundaries)
{
map.boundaries.forEach((boundary) =>
{
if (boundary.type === "polygon")
{
robot.boundary = boundary;
let roomAccessory = new NeatoVacuumRobotAccessory(this, robot);
accessories.push(roomAccessory);
robot.roomAccessories.push(roomAccessory);
}
})
}
})
}
});
callback(accessories);
// // MOCK MULTIPLE ROBOTS START
// });
// });
// });
// // MOCK MULTIPLE ROBOTS END
});
},
@@ -137,46 +159,68 @@ NeatoVacuumRobotPlatform.prototype = {
robots.forEach((robot) =>
{
// Get all maps for each robot
robot.getPersistentMaps((error, result) =>
// Get additional information for the robot
robot.getState((error, state) =>
{
if (error)
{
this.log.error("Error updating persistent maps: " + error + ": " + result);
this.log.error("Error getting robot meta information: " + error + ": " + state);
callback();
}
// Robot has no maps
else if (result.length === 0)
{
robot.maps = [];
this.saveRobot(robot, loadedRobots, robots.length, callback);
}
// Robot has maps
else
{
robot.maps = result;
let loadedMaps = 0;
robot.maps.forEach((map) =>
// Get all maps for each robot
robot.getPersistentMaps((error, maps) =>
{
// Save zones in each map
robot.getMapBoundaries(map.id, (error, result) =>
if (error)
{
if (error)
this.log.error("Error updating persistent maps: " + error + ": " + maps);
callback();
}
// Robot has no maps
else if (maps.length === 0)
{
robot.maps = [];
this.robots.push({device: robot, meta: state.meta, availableServices: state.availableServices});
loadedRobots++;
if (loadedRobots === robots.length)
{
this.log.error("Error getting boundaries: " + error + ": " + result)
callback();
}
else
}
// Robot has maps
else
{
robot.maps = maps;
let loadedMaps = 0;
robot.maps.forEach((map) =>
{
map.boundaries = result.boundaries;
}
loadedMaps++;
// Save zones in each map
robot.getMapBoundaries(map.id, (error, result) =>
{
if (error)
{
this.log.error("Error getting boundaries: " + error + ": " + result)
}
else
{
map.boundaries = result.boundaries;
}
loadedMaps++;
// Robot is completely requested if zones for all maps are loaded
if (loadedMaps === robot.maps.length)
{
this.saveRobot(robot, loadedRobots, robots.length, callback);
}
})
// Robot is completely requested if zones for all maps are loaded
if (loadedMaps === robot.maps.length)
{
this.robots.push({device: robot, meta: state.meta, availableServices: state.availableServices});
loadedRobots++;
if (loadedRobots === robots.length)
{
callback();
}
}
})
});
}
});
}
});
@@ -187,31 +231,6 @@ NeatoVacuumRobotPlatform.prototype = {
});
},
saveRobot: function (robot, loadedRobots, size, callback)
{
// Get additional information for the robot
robot.getState((error, result) =>
{
if (error)
{
this.log.error("Error getting robot meta information: " + error + ": " + result);
callback();
}
else
{
// Store the robot with his information, maps and zones
this.robots.push({device: robot, meta: result.meta, availableServices: result.availableServices});
loadedRobots++;
// Initial request is complete if all robots are loaded.
if (loadedRobots === size)
{
callback();
}
}
});
},
updateRobot: function (serial, callback)
{
let robot = this.getRobot(serial);

View File

@@ -1,6 +1,6 @@
{
"name": "homebridge-neato",
"version": "0.7.1",
"version": "0.7.2",
"description": "A Neato vacuum robot plugin for homebridge.",
"license": "MIT",
"keywords": [