Fixed homebridge crash when 2 zones have the same name
This commit is contained in:
parent
c43a666378
commit
54f303394e
15
index.js
15
index.js
@ -37,8 +37,8 @@ function NeatoVacuumRobotPlatform(log, config) {
|
||||
NeatoVacuumRobotPlatform.prototype = {
|
||||
accessories: function (callback) {
|
||||
let accessories = [];
|
||||
|
||||
let that = this;
|
||||
that.boundaryNames = [];
|
||||
this.getRobots(function () {
|
||||
if (that.robots) {
|
||||
that.robots.forEach((robot, i) => {
|
||||
@ -135,6 +135,19 @@ function NeatoVacuumRobotAccessory(robot, platform, boundary) {
|
||||
if (!this.boundary) {
|
||||
this.name = robot.name;
|
||||
} else {
|
||||
// if boundary name already exists
|
||||
if (platform.boundaryNames.includes(this.boundary.name)) {
|
||||
let lastChar = this.boundary.name.slice(-1);
|
||||
// boundary name already contains a count number
|
||||
if (!isNaN(lastChar)) {
|
||||
// Increment existing count number
|
||||
this.boundary.name = this.boundary.name.slice(0, -1) + (parseInt(lastChar) + 1);
|
||||
} else {
|
||||
// Add a new count number
|
||||
this.boundary.name = this.boundary.name + " 2";
|
||||
}
|
||||
}
|
||||
platform.boundaryNames.push(this.boundary.name);
|
||||
this.name = this.robot.name + ' - ' + this.boundary.name;
|
||||
}
|
||||
this.lastUpdate = null;
|
||||
|
Loading…
Reference in New Issue
Block a user