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 = {
|
NeatoVacuumRobotPlatform.prototype = {
|
||||||
accessories: function (callback) {
|
accessories: function (callback) {
|
||||||
let accessories = [];
|
let accessories = [];
|
||||||
|
|
||||||
let that = this;
|
let that = this;
|
||||||
|
that.boundaryNames = [];
|
||||||
this.getRobots(function () {
|
this.getRobots(function () {
|
||||||
if (that.robots) {
|
if (that.robots) {
|
||||||
that.robots.forEach((robot, i) => {
|
that.robots.forEach((robot, i) => {
|
||||||
@ -135,6 +135,19 @@ function NeatoVacuumRobotAccessory(robot, platform, boundary) {
|
|||||||
if (!this.boundary) {
|
if (!this.boundary) {
|
||||||
this.name = robot.name;
|
this.name = robot.name;
|
||||||
} else {
|
} 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.name = this.robot.name + ' - ' + this.boundary.name;
|
||||||
}
|
}
|
||||||
this.lastUpdate = null;
|
this.lastUpdate = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user