fixed uuid reset when restarting homebridge, removed logs
This commit is contained in:
parent
7d824ee0b9
commit
979dc40ccf
26
index.js
26
index.js
@ -6,8 +6,6 @@ var inherits = require('util').inherits,
|
|||||||
Service,
|
Service,
|
||||||
Characteristic
|
Characteristic
|
||||||
|
|
||||||
const uuidv4 = require('uuid/v4');
|
|
||||||
|
|
||||||
module.exports = function (homebridge) {
|
module.exports = function (homebridge) {
|
||||||
Service = homebridge.hap.Service;
|
Service = homebridge.hap.Service;
|
||||||
Characteristic = homebridge.hap.Characteristic;
|
Characteristic = homebridge.hap.Characteristic;
|
||||||
@ -38,23 +36,23 @@ function NeatoVacuumRobotPlatform(log, config) {
|
|||||||
|
|
||||||
NeatoVacuumRobotPlatform.prototype = {
|
NeatoVacuumRobotPlatform.prototype = {
|
||||||
accessories: function (callback) {
|
accessories: function (callback) {
|
||||||
this.accessories = [];
|
let accessories = [];
|
||||||
|
|
||||||
let that = this;
|
let that = this;
|
||||||
this.getRobots(function () {
|
this.getRobots(function () {
|
||||||
for (var i = 0; i < that.robots.length; i++) {
|
for (var i = 0; i < that.robots.length; i++) {
|
||||||
that.log("Found robot #" + (i + 1) + " named \"" + that.robots[i].name + "\" with serial \"" + that.robots[i]._serial + "\"");
|
that.log("Found robot #" + (i + 1) + " named \"" + that.robots[i].name + "\" with serial \"" + that.robots[i]._serial + "\"");
|
||||||
var robotAccessory = new NeatoVacuumRobotAccessory(that.robots[i], that);
|
var robotAccessory = new NeatoVacuumRobotAccessory(that.robots[i], that);
|
||||||
that.accessories.push(robotAccessory);
|
accessories.push(robotAccessory);
|
||||||
that.robots[i].maps.forEach((map) => {
|
that.robots[i].maps.forEach((map) => {
|
||||||
map.boundaries.forEach((boundary) => {
|
map.boundaries.forEach((boundary) => {
|
||||||
if (boundary.type === "polygon") {
|
if (boundary.type === "polygon") {
|
||||||
that.accessories.push(new NeatoVacuumRobotAccessory(that.robots[i], that, boundary))
|
accessories.push(new NeatoVacuumRobotAccessory(that.robots[i], that, boundary))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
callback(that.accessories);
|
callback(accessories);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -103,7 +101,6 @@ NeatoVacuumRobotPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
processedMapCount++;
|
processedMapCount++;
|
||||||
if(processedMapCount == robot.maps.length) {
|
if(processedMapCount == robot.maps.length) {
|
||||||
this.log("Discovered Maps: " + JSON.stringify(robot.maps));
|
|
||||||
updatedRobotCount++
|
updatedRobotCount++
|
||||||
if (updatedRobotCount === that.robots.length) {
|
if (updatedRobotCount === that.robots.length) {
|
||||||
callback();
|
callback();
|
||||||
@ -122,14 +119,17 @@ NeatoVacuumRobotPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function NeatoVacuumRobotAccessory(robot, platform, boundary) {
|
function NeatoVacuumRobotAccessory(robot, platform, boundary) {
|
||||||
this.uuid_base = uuidv4();
|
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.boundary = boundary;
|
this.boundary = boundary;
|
||||||
this.log = platform.log;
|
this.log = platform.log;
|
||||||
this.refresh = platform.refresh;
|
this.refresh = platform.refresh;
|
||||||
this.hiddenServices = platform.hiddenServices;
|
this.hiddenServices = platform.hiddenServices;
|
||||||
this.robot = robot;
|
this.robot = robot;
|
||||||
this.name = robot.name;
|
if(!this.boundary) {
|
||||||
|
this.name = robot.name;
|
||||||
|
} else {
|
||||||
|
this.name = this.robot.name + ' - ' + this.boundary.name;
|
||||||
|
}
|
||||||
this.lastUpdate = null;
|
this.lastUpdate = null;
|
||||||
|
|
||||||
this.vacuumRobotBatteryService = new Service.BatteryService("Battery", "battery");
|
this.vacuumRobotBatteryService = new Service.BatteryService("Battery", "battery");
|
||||||
@ -175,10 +175,16 @@ NeatoVacuumRobotAccessory.prototype = {
|
|||||||
getServices: function () {
|
getServices: function () {
|
||||||
this.informationService = new Service.AccessoryInformation();
|
this.informationService = new Service.AccessoryInformation();
|
||||||
this.informationService
|
this.informationService
|
||||||
.setCharacteristic(Characteristic.Name, this.robot.name)
|
|
||||||
.setCharacteristic(Characteristic.Manufacturer, "Neato Robotics")
|
.setCharacteristic(Characteristic.Manufacturer, "Neato Robotics")
|
||||||
.setCharacteristic(Characteristic.Model, "Coming soon")
|
.setCharacteristic(Characteristic.Model, "Coming soon")
|
||||||
.setCharacteristic(Characteristic.SerialNumber, this.robot._serial);
|
.setCharacteristic(Characteristic.SerialNumber, this.robot._serial);
|
||||||
|
if(!this.boundary) {
|
||||||
|
this.informationService
|
||||||
|
.setCharacteristic(Characteristic.Name, this.robot.name)
|
||||||
|
} else {
|
||||||
|
this.informationService
|
||||||
|
.setCharacteristic(Characteristic.Name, this.robot.name + ' - ' + this.boundary.name)
|
||||||
|
}
|
||||||
|
|
||||||
this.vacuumRobotBatteryService.getCharacteristic(Characteristic.BatteryLevel).on('get', this.getBatteryLevel.bind(this));
|
this.vacuumRobotBatteryService.getCharacteristic(Characteristic.BatteryLevel).on('get', this.getBatteryLevel.bind(this));
|
||||||
this.vacuumRobotBatteryService.getCharacteristic(Characteristic.ChargingState).on('get', this.getBatteryChargingState.bind(this));
|
this.vacuumRobotBatteryService.getCharacteristic(Characteristic.ChargingState).on('get', this.getBatteryChargingState.bind(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user