From 8ae7bca0fd4e070be054edde6e03d16f4cc0b074 Mon Sep 17 00:00:00 2001 From: Nicolas Dujardin Date: Sun, 15 Nov 2020 17:48:45 +0100 Subject: [PATCH] 1.4.0 --- CHANGELOG.md | 4 + config.schema.json | 9 +- deebotEcovacsAPI.js | 13 +- index.js | 464 +++++++++++++++++++++++--------------------- package.json | 2 +- readme.md | 27 +-- 6 files changed, 269 insertions(+), 250 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa1b1a2..5e60f69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ You can also use the [PACKAGES](https://github.com/oznu/docker-homebridge#option All notable changes to this project will be documented in this file. +## 1.4.1 + +- [NEW] Reverting the one deebot per platform limit, since it won't be supported by homebridge in the futur to have multiple platform of the same plugin. Keeping a property to expose only some deebots (by defautl will try all). + ## 1.4.0 - [NEW] specify the deebotname to make it works with multiple deebots. You will need to have one instance of the plugin per deebot. #37 #40 diff --git a/config.schema.json b/config.schema.json index 77522e1..593b50b 100644 --- a/config.schema.json +++ b/config.schema.json @@ -122,10 +122,13 @@ } ] }, - "deebotName": { + "deebotNames": { "title": "Name of the deebot to publish", - "type": "string", - "description": "In case of multiple ones, you will need to use this in order to specify which one you want. Defaults to first one on your account." + "type": "array", + "items": { + "title": "NickName of the deebot you want to add. ", + "type": "string" + } }, "refreshTimer": { "title": "Refresh timer", diff --git a/deebotEcovacsAPI.js b/deebotEcovacsAPI.js index a973107..cd7cfdb 100644 --- a/deebotEcovacsAPI.js +++ b/deebotEcovacsAPI.js @@ -20,11 +20,13 @@ function DeebotEcovacsAPI(log, platform) { this.device_id = EcoVacsAPI.md5(nodeMachineId.machineIdSync()); this.password_hash = EcoVacsAPI.md5(platform.password); this.continent = countries[this.countryCode].continent.toUpperCase(); - this.deebotName = platform.deebotName; + this.deebotNames = platform.deebotNames; this.log('INFO - API :' + this.continent + '/' + this.countryCode); this.api = new EcoVacsAPI(this.device_id, this.countryCode, this.continent); + + this.vacbots = []; } DeebotEcovacsAPI.prototype = { @@ -41,9 +43,9 @@ DeebotEcovacsAPI.prototype = { let foundDeebotName = vacuum.nick ? vacuum.nick : vacuum.name; if ( - this.deebotName == undefined || - this.deebotName == '' || - this.deebotName === foundDeebotName + this.deebotNames == undefined || + this.deebotNames.length == 0 || + this.deebotNames.includes(foundDeebotName) ) { const vacbot = this.api.getVacBot( this.api.uid, @@ -53,8 +55,7 @@ DeebotEcovacsAPI.prototype = { vacuum, this.continent ); - this.vacbot = vacbot; - break; + this.vacbots.push(vacbot); } } diff --git a/index.js b/index.js index b010ee1..7b086b6 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ function myDeebotEcovacsPlatform(log, config, api) { this.countryCode = config['countryCode']; this.refreshTimer = checkTimer(config['refreshTimer']); this.cleanCache = config['cleanCache']; - this.deebotName = config['deebotName']; + this.deebotNames = config['deebotNames']; this.publishBipSwitch = checkParameter(config['publishBipSwitch'], true); this.publishSwitch = checkParameter(config['publishSwitch'], true); @@ -182,14 +182,12 @@ myDeebotEcovacsPlatform.prototype = { //deebot discovered this.deebotEcovacsAPI.on('deebotsDiscovered', () => { let nbDeebots = 0; - if (this.deebotEcovacsAPI.vacbot) { - let deebotName = this.deebotEcovacsAPI.vacbot.vacuum.nick - ? this.deebotEcovacsAPI.vacbot.vacuum.nick - : this.deebotEcovacsAPI.vacbot.vacuum.name; - this.log('INFO - stopping deebots discovery, deebot found : ' + deebotName); - this.loadDeebots(); - } else { - this.log('INFO - no deebot found matching config, will retry discovery in 1 minute'); + if (this.deebotEcovacsAPI.vacbots) nbDeebots = this.deebotEcovacsAPI.vacbots.length; + this.log('INFO - stopping deebots discovery, number of deebots found : ' + nbDeebots); + + if (nbDeebots > 0) this.loadDeebots(); + else { + this.log('INFO - no deebot found, will retry discovery in 1 minute'); setTimeout(() => { this.deebotEcovacsAPI.getDeebots(); }, 60000); @@ -208,267 +206,301 @@ myDeebotEcovacsPlatform.prototype = { }, loadDeebots: function () { - if (this.deebotEcovacsAPI.vacbot) { - let vacBot = this.deebotEcovacsAPI.vacbot; - - let deebotName = vacBot.vacuum.nick ? vacBot.vacuum.nick : vacBot.vacuum.name; + if (this.deebotEcovacsAPI.vacbots) { + for (let s = 0; s < this.deebotEcovacsAPI.vacbots.length; s++) { + let vacBot = this.deebotEcovacsAPI.vacbots[s]; - this.log('INFO - Discovered Deebot : ' + deebotName); + let deebotName = vacBot.vacuum.nick ? vacBot.vacuum.nick : vacBot.vacuum.name; + this.log('INFO - Discovered Deebot : ' + deebotName); - this.log('INFO - Edge Cleaning for ' + deebotName + ' : ' + vacBot.hasEdgeCleaningMode()); - this.log('INFO - Spot Cleaning for ' + deebotName + ' : ' + vacBot.hasSpotCleaningMode()); - this.log( - 'INFO - SpotArea Cleaning for ' + deebotName + ' : ' + vacBot.hasSpotAreaCleaningMode() - ); - this.log( - 'INFO - CustomArea Cleaning for ' + deebotName + ' : ' + vacBot.hasCustomAreaCleaningMode() - ); + this.log('INFO - Edge Cleaning for ' + deebotName + ' : ' + vacBot.hasEdgeCleaningMode()); + this.log('INFO - Spot Cleaning for ' + deebotName + ' : ' + vacBot.hasSpotCleaningMode()); + this.log( + 'INFO - SpotArea Cleaning for ' + deebotName + ' : ' + vacBot.hasSpotAreaCleaningMode() + ); + this.log( + 'INFO - CustomArea Cleaning for ' + + deebotName + + ' : ' + + vacBot.hasCustomAreaCleaningMode() + ); - let uuid = UUIDGen.generate(deebotName); - let myDeebotEcovacsAccessory = this.foundAccessories.find((x) => x.UUID == uuid); + let uuid = UUIDGen.generate(deebotName); + let myDeebotEcovacsAccessory = this.foundAccessories.find((x) => x.UUID == uuid); + + if (!myDeebotEcovacsAccessory) { + myDeebotEcovacsAccessory = new Accessory(deebotName, uuid); + myDeebotEcovacsAccessory.name = deebotName; + myDeebotEcovacsAccessory.manufacturer = vacBot.vacuum.company; + myDeebotEcovacsAccessory.serialNumber = vacBot.vacuum.did; + + myDeebotEcovacsAccessory + .getService(Service.AccessoryInformation) + .setCharacteristic(Characteristic.Manufacturer, myDeebotEcovacsAccessory.manufacturer) + .setCharacteristic(Characteristic.Model, myDeebotEcovacsAccessory.model) + .setCharacteristic(Characteristic.SerialNumber, myDeebotEcovacsAccessory.serialNumber); + this.api.registerPlatformAccessories('homebridge-deebotecovacs', 'DeebotEcovacs', [ + myDeebotEcovacsAccessory, + ]); + this.foundAccessories.push(myDeebotEcovacsAccessory); + } - if (!myDeebotEcovacsAccessory) { - myDeebotEcovacsAccessory = new Accessory(deebotName, uuid); + myDeebotEcovacsAccessory.vacBot = vacBot; myDeebotEcovacsAccessory.name = deebotName; - myDeebotEcovacsAccessory.manufacturer = vacBot.vacuum.company; - myDeebotEcovacsAccessory.serialNumber = vacBot.vacuum.did; - - myDeebotEcovacsAccessory - .getService(Service.AccessoryInformation) - .setCharacteristic(Characteristic.Manufacturer, myDeebotEcovacsAccessory.manufacturer) - .setCharacteristic(Characteristic.Model, myDeebotEcovacsAccessory.model) - .setCharacteristic(Characteristic.SerialNumber, myDeebotEcovacsAccessory.serialNumber); - this.api.registerPlatformAccessories('homebridge-deebotecovacs', 'DeebotEcovacs', [ - myDeebotEcovacsAccessory, - ]); - this.foundAccessories.push(myDeebotEcovacsAccessory); - } - - myDeebotEcovacsAccessory.vacBot = vacBot; - myDeebotEcovacsAccessory.name = deebotName; - - let HKBatteryService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - deebotName, - 'BatteryService' + deebotName - ); - - if (!HKBatteryService) { - this.log('INFO - Creating Battery Service ' + deebotName); - HKBatteryService = new Service.BatteryService(deebotName, 'BatteryService' + deebotName); - HKBatteryService.subtype = 'BatteryService' + deebotName; - myDeebotEcovacsAccessory.addService(HKBatteryService); - } - this.bindBatteryLevelCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); - this.bindChargingStateCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); - this.bindStatusLowBatteryCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); - this._confirmedServices.push(HKBatteryService); - - myDeebotEcovacsAccessory.HKBatteryService = HKBatteryService; - if (this.publishFan) { - let HKFanService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Start/Pause ' + deebotName, - 'FanService' + deebotName + let HKBatteryService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( + deebotName, + 'BatteryService' + deebotName ); - if (!HKFanService) { - this.log('INFO - Creating Fan Service ' + deebotName); - HKFanService = new Service.Fan('Start/Pause ' + deebotName, 'FanService' + deebotName); - HKFanService.subtype = 'FanService' + deebotName; - myDeebotEcovacsAccessory.addService(HKFanService); + if (!HKBatteryService) { + this.log('INFO - Creating Battery Service ' + deebotName); + HKBatteryService = new Service.BatteryService(deebotName, 'BatteryService' + deebotName); + HKBatteryService.subtype = 'BatteryService' + deebotName; + myDeebotEcovacsAccessory.addService(HKBatteryService); } + this.bindBatteryLevelCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); + this.bindChargingStateCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); + this.bindStatusLowBatteryCharacteristic(myDeebotEcovacsAccessory, HKBatteryService); + this._confirmedServices.push(HKBatteryService); - HKFanService.type = 'fan'; + myDeebotEcovacsAccessory.HKBatteryService = HKBatteryService; - this.bindOnCharacteristic(myDeebotEcovacsAccessory, HKFanService); - this.bindRotationSpeedCharacteristic(myDeebotEcovacsAccessory, HKFanService); - HKFanService.setPrimaryService(true); - this._confirmedServices.push(HKFanService); - myDeebotEcovacsAccessory.HKFanService = HKFanService; - } + if (this.publishFan) { + let HKFanService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( + 'Start/Pause ' + deebotName, + 'FanService' + deebotName + ); - if (this.publishSwitch) { - let HKSwitchOnService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Start/Stop ' + deebotName, - 'SwitchOnService' + deebotName - ); + if (!HKFanService) { + this.log('INFO - Creating Fan Service ' + deebotName); + HKFanService = new Service.Fan('Start/Pause ' + deebotName, 'FanService' + deebotName); + HKFanService.subtype = 'FanService' + deebotName; + myDeebotEcovacsAccessory.addService(HKFanService); + } + + HKFanService.type = 'fan'; - if (!HKSwitchOnService) { - this.log('INFO - Creating Main Switch Service ' + deebotName); - HKSwitchOnService = new Service.Switch( + this.bindOnCharacteristic(myDeebotEcovacsAccessory, HKFanService); + this.bindRotationSpeedCharacteristic(myDeebotEcovacsAccessory, HKFanService); + HKFanService.setPrimaryService(true); + this._confirmedServices.push(HKFanService); + myDeebotEcovacsAccessory.HKFanService = HKFanService; + } + + if (this.publishSwitch) { + let HKSwitchOnService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( 'Start/Stop ' + deebotName, 'SwitchOnService' + deebotName ); - HKSwitchOnService.subtype = 'SwitchOnService' + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchOnService); - } - this.bindSwitchOnCharacteristic(myDeebotEcovacsAccessory, HKSwitchOnService); - HKSwitchOnService.setPrimaryService(true); - this._confirmedServices.push(HKSwitchOnService); - myDeebotEcovacsAccessory.HKSwitchOnService = HKSwitchOnService; - } + if (!HKSwitchOnService) { + this.log('INFO - Creating Main Switch Service ' + deebotName); + HKSwitchOnService = new Service.Switch( + 'Start/Stop ' + deebotName, + 'SwitchOnService' + deebotName + ); + HKSwitchOnService.subtype = 'SwitchOnService' + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchOnService); + } + this.bindSwitchOnCharacteristic(myDeebotEcovacsAccessory, HKSwitchOnService); - if (this.publishBipSwitch) { - let HKSwitchBipService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Bip ' + deebotName, - 'SwitchBipService' + deebotName - ); + HKSwitchOnService.setPrimaryService(true); + this._confirmedServices.push(HKSwitchOnService); + myDeebotEcovacsAccessory.HKSwitchOnService = HKSwitchOnService; + } - if (!HKSwitchBipService) { - this.log('INFO - Creating Sound stateless Switch Service ' + deebotName); - HKSwitchBipService = new Service.Switch( + if (this.publishBipSwitch) { + let HKSwitchBipService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( 'Bip ' + deebotName, 'SwitchBipService' + deebotName ); - HKSwitchBipService.subtype = 'SwitchBipService' + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchBipService); - } - this.bindSwitchBipCharacteristic(myDeebotEcovacsAccessory, HKSwitchBipService); - this._confirmedServices.push(HKSwitchBipService); - } - if (this.publishMotionDetector) { - let HKMotionService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - deebotName + ' needs attention', - 'MotionService' + deebotName - ); + if (!HKSwitchBipService) { + this.log('INFO - Creating Sound stateless Switch Service ' + deebotName); + HKSwitchBipService = new Service.Switch( + 'Bip ' + deebotName, + 'SwitchBipService' + deebotName + ); + HKSwitchBipService.subtype = 'SwitchBipService' + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchBipService); + } + this.bindSwitchBipCharacteristic(myDeebotEcovacsAccessory, HKSwitchBipService); + this._confirmedServices.push(HKSwitchBipService); + } - if (!HKMotionService) { - this.log('INFO - Creating Motion Service ' + deebotName); - HKMotionService = new Service.MotionSensor( + if (this.publishMotionDetector) { + let HKMotionService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( deebotName + ' needs attention', 'MotionService' + deebotName ); - HKMotionService.subtype = 'MotionService' + deebotName; - myDeebotEcovacsAccessory.addService(HKMotionService); - } - this.bindMotionCharacteristic(HKMotionService); - this._confirmedServices.push(HKMotionService); - myDeebotEcovacsAccessory.HKMotionService = HKMotionService; - } - if (this.publishAutoSwitch) { - let HKSwitchAutoService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Auto ' + deebotName, - 'SwitchAutoService' + deebotName - ); + if (!HKMotionService) { + this.log('INFO - Creating Motion Service ' + deebotName); + HKMotionService = new Service.MotionSensor( + deebotName + ' needs attention', + 'MotionService' + deebotName + ); + HKMotionService.subtype = 'MotionService' + deebotName; + myDeebotEcovacsAccessory.addService(HKMotionService); + } + this.bindMotionCharacteristic(HKMotionService); + this._confirmedServices.push(HKMotionService); + myDeebotEcovacsAccessory.HKMotionService = HKMotionService; + } - if (!HKSwitchAutoService) { - this.log('INFO - Creating Auto stateless Switch Service ' + deebotName); - HKSwitchAutoService = new Service.Switch( + if (this.publishAutoSwitch) { + let HKSwitchAutoService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( 'Auto ' + deebotName, 'SwitchAutoService' + deebotName ); - HKSwitchAutoService.subtype = 'SwitchAutoService' + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchAutoService); - } - this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchAutoService, [ - 'Clean', - 'auto', - ]); - this._confirmedServices.push(HKSwitchAutoService); - } - if (this.publishEdgeSwitch && vacBot.hasEdgeCleaningMode()) { - let HKSwitchEdgeService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Edge ' + deebotName, - 'SwitchEdgeService' + deebotName - ); + if (!HKSwitchAutoService) { + this.log('INFO - Creating Auto stateless Switch Service ' + deebotName); + HKSwitchAutoService = new Service.Switch( + 'Auto ' + deebotName, + 'SwitchAutoService' + deebotName + ); + HKSwitchAutoService.subtype = 'SwitchAutoService' + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchAutoService); + } + this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchAutoService, [ + 'Clean', + 'auto', + ]); + this._confirmedServices.push(HKSwitchAutoService); + } - if (!HKSwitchEdgeService) { - this.log('INFO - Creating Edge stateless Switch Service ' + deebotName); - HKSwitchEdgeService = new Service.Switch( + if (this.publishEdgeSwitch && vacBot.hasEdgeCleaningMode()) { + let HKSwitchEdgeService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( 'Edge ' + deebotName, 'SwitchEdgeService' + deebotName ); - HKSwitchEdgeService.subtype = 'SwitchEdgeService' + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchEdgeService); - } - this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchEdgeService, ['Edge']); - this._confirmedServices.push(HKSwitchEdgeService); - } + if (!HKSwitchEdgeService) { + this.log('INFO - Creating Edge stateless Switch Service ' + deebotName); + HKSwitchEdgeService = new Service.Switch( + 'Edge ' + deebotName, + 'SwitchEdgeService' + deebotName + ); + HKSwitchEdgeService.subtype = 'SwitchEdgeService' + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchEdgeService); + } + this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchEdgeService, [ + 'Edge', + ]); - if (this.publishSpotSwitch && vacBot.hasSpotCleaningMode()) { - let HKSwitchSpotService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'Spot ' + deebotName, - 'SwitchSpotService' + deebotName - ); + this._confirmedServices.push(HKSwitchEdgeService); + } - if (!HKSwitchSpotService) { - this.log('INFO - Creating Spot stateless Switch Service ' + deebotName); - HKSwitchSpotService = new Service.Switch( + if (this.publishSpotSwitch && vacBot.hasSpotCleaningMode()) { + let HKSwitchSpotService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( 'Spot ' + deebotName, 'SwitchSpotService' + deebotName ); - HKSwitchSpotService.subtype = 'SwitchSpotService' + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchSpotService); - } - this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchSpotService, ['Spot']); - this._confirmedServices.push(HKSwitchSpotService); - } - //bind to deebot - if (this.publishSpotAreaSwitches !== undefined && vacBot.hasSpotAreaCleaningMode()) { - for (let i = 0; i < this.publishSpotAreaSwitches.length; i++) { - var command = this.publishSpotAreaSwitches[i]; - - let HKSwitchSpotAreaService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'SpotArea ' + i + ' ' + deebotName, - 'SwitchSpotAreaService' + i + deebotName - ); - - if (!HKSwitchSpotAreaService) { - this.log('INFO - Creating SpotArea ' + i + ' stateless Switch Service ' + deebotName); - HKSwitchSpotAreaService = new Service.Switch( - 'SpotArea ' + i + ' ' + deebotName, - 'SwitchSpotAreaService' + i + deebotName + if (!HKSwitchSpotService) { + this.log('INFO - Creating Spot stateless Switch Service ' + deebotName); + HKSwitchSpotService = new Service.Switch( + 'Spot ' + deebotName, + 'SwitchSpotService' + deebotName ); - HKSwitchSpotAreaService.subtype = 'SwitchSpotAreaService' + i + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchSpotAreaService); + HKSwitchSpotService.subtype = 'SwitchSpotService' + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchSpotService); } - - this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchSpotAreaService, [ - 'SpotArea', - 'start', - command, + this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchSpotService, [ + 'Spot', ]); - this._confirmedServices.push(HKSwitchSpotAreaService); + this._confirmedServices.push(HKSwitchSpotService); } - } - - if (this.publishCustomAreaSwitches !== undefined && vacBot.hasCustomAreaCleaningMode()) { - for (let i = 0; i < this.publishCustomAreaSwitches.length; i++) { - var command = this.publishCustomAreaSwitches[i]; - let HKSwitchCustomAreaService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( - 'CustomArea ' + i + ' ' + deebotName, - 'SwitchCustomAreaService' + i + deebotName - ); - if (!HKSwitchCustomAreaService) { - this.log('INFO - Creating CustomArea ' + i + ' stateless Switch Service ' + deebotName); - HKSwitchCustomAreaService = new Service.Switch( - 'CustomArea ' + i + ' ' + deebotName, - 'SwitchCustomAreaService' + i + deebotName - ); - HKSwitchCustomAreaService.subtype = 'SwitchCustomAreaService' + i + deebotName; - myDeebotEcovacsAccessory.addService(HKSwitchCustomAreaService); + //bind to deebot + if (this.publishSpotAreaSwitches !== undefined && vacBot.hasSpotAreaCleaningMode()) { + for (let i = 0; i < this.publishSpotAreaSwitches.length; i++) { + let isForThisDeebot = true; + var command = ''; + + if (this.publishSpotAreaSwitches[i].indexOf('|') > -1) { + let expectedDeebotName = this.publishSpotAreaSwitches[i].split('|')[0]; + command = this.publishSpotAreaSwitches[i].split('|')[1]; + isForThisDeebot = expectedDeebotName === deebotName; + } else { + command = this.publishSpotAreaSwitches[i]; + } + + if (isForThisDeebot) { + let HKSwitchSpotAreaService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( + 'SpotArea ' + i + ' ' + deebotName, + 'SwitchSpotAreaService' + i + deebotName + ); + + if (!HKSwitchSpotAreaService) { + this.log( + 'INFO - Creating SpotArea ' + i + ' stateless Switch Service ' + deebotName + ); + HKSwitchSpotAreaService = new Service.Switch( + 'SpotArea ' + i + ' ' + deebotName, + 'SwitchSpotAreaService' + i + deebotName + ); + HKSwitchSpotAreaService.subtype = 'SwitchSpotAreaService' + i + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchSpotAreaService); + } + + this.bindSwitchOrderCharacteristic( + myDeebotEcovacsAccessory, + HKSwitchSpotAreaService, + ['SpotArea', 'start', command] + ); + this._confirmedServices.push(HKSwitchSpotAreaService); + } } + } - this.bindSwitchOrderCharacteristic(myDeebotEcovacsAccessory, HKSwitchCustomAreaService, [ - 'CustomArea', - 'start', - command, - 1, - ]); - this._confirmedServices.push(HKSwitchCustomAreaService); + if (this.publishCustomAreaSwitches !== undefined && vacBot.hasCustomAreaCleaningMode()) { + for (let i = 0; i < this.publishCustomAreaSwitches.length; i++) { + let isForThisDeebot = true; + var command = ''; + + if (this.publishCustomAreaSwitches[i].indexOf('|') > -1) { + let expectedDeebotName = this.publishCustomAreaSwitches[i].split('|')[0]; + command = this.publishCustomAreaSwitches[i].split('|')[1]; + isForThisDeebot = expectedDeebotName === deebotName; + } else { + command = this.publishCustomAreaSwitches[i]; + } + + if (isForThisDeebot) { + let HKSwitchCustomAreaService = myDeebotEcovacsAccessory.getServiceByUUIDAndSubType( + 'CustomArea ' + i + ' ' + deebotName, + 'SwitchCustomAreaService' + i + deebotName + ); + + if (!HKSwitchCustomAreaService) { + this.log( + 'INFO - Creating CustomArea ' + i + ' stateless Switch Service ' + deebotName + ); + HKSwitchCustomAreaService = new Service.Switch( + 'CustomArea ' + i + ' ' + deebotName, + 'SwitchCustomAreaService' + i + deebotName + ); + HKSwitchCustomAreaService.subtype = 'SwitchCustomAreaService' + i + deebotName; + myDeebotEcovacsAccessory.addService(HKSwitchCustomAreaService); + } + + this.bindSwitchOrderCharacteristic( + myDeebotEcovacsAccessory, + HKSwitchCustomAreaService, + ['CustomArea', 'start', command, 1] + ); + this._confirmedServices.push(HKSwitchCustomAreaService); + } + } } - } - this.deebotEcovacsAPI.configureEvents(myDeebotEcovacsAccessory); + this.deebotEcovacsAPI.configureEvents(myDeebotEcovacsAccessory); - this._confirmedAccessories.push(myDeebotEcovacsAccessory); + this._confirmedAccessories.push(myDeebotEcovacsAccessory); + } this.cleanPlatform(); //timer for background refresh diff --git a/package.json b/package.json index 3036467..977945f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-deebotecovacs", - "version": "1.4.0", + "version": "1.4.1", "author": "Nicolas Dujardin", "description": "Publish your deebot ecovacs as an homekit accessory", "main": "index.js", diff --git a/readme.md b/readme.md index d569c7b..b6f63b8 100644 --- a/readme.md +++ b/readme.md @@ -58,27 +58,6 @@ Config as below: ] ``` -If you have more than oneDeebot, please use deebotName property and add one platform per Deebot, like : - -```json -"platforms": [ - { - "platform": "DeebotEcovacs", - "email": "toto@titi.com", - "password": "toto", - "countryCode" : "FR", - "deebotName" : "Deebot1" - }, - { - "platform": "DeebotEcovacs", - "email": "toto@titi.com", - "password": "toto", - "countryCode" : "FR", - "deebotName" : "Deebot2" - } -] -``` - Fields: - `platform` must be "DeebotEcovacs" (required). @@ -87,7 +66,7 @@ Fields: - `country code` : country code for your account , value in : CH, TW, MY, JP, SG, TH, HK, IN, KR,US,FR, ES, UK, NO, MX, DE, PT, CH, AU, IT, NL, SE, BE, DK, OTHER (required). - `refreshTimer` Optional - enable refresh of deebot state every X seconds, for automation purpose if you need to activate something else based on its state change (defaults : disable, accepted range : 30-600s). - `cleanCache` Set it to true in case you want to remove the cached accessory (only those from this plugin). You have to restart homebridge after applying the option. Remove it after restart, otherwise it will be recreated at each startup. -- `deebotName` Name of the deebot to publish. In case of multiple ones, you will need to use this in order to specify which one you want. Defaults to first one on your account. +- `deebotNames` Array of NickNames of the deebot to publish. Defaults to all found on your account. - `publishBipSwitch` Optional - defaults to true - Publish the switch that makes the deebot beeps - `publishFan` Optional - defaults to true - Publish the fan that makes speed cleaning available - `publishSwitch` Optional - defaults to true - Publish the switch that makes on/off available @@ -95,8 +74,8 @@ Fields: - `publishAutoSwitch` Optional - Publish a switch to start in auto Mode. - `publishEdgeSwitch` Optional - Publish a switch to start in edge Mode. - `publishSpotSwitch` Optional - Publish a switch to start in spot Mode. -- `publishSpotAreaSwitches` Optional - Publish switches to start for each spot Area. Must be something like ["1","1,2"] -- `publishCustomAreaSwitches` Optional - Publish switches to start for each Custom Area. Must be something like ["(x1,y1,x2,y2)","(x1,y1,x2,y2)"] +- `publishSpotAreaSwitches` Optional - Publish switches to start for each spot Area. Must be something like ["1","1,2"] or ["deebotName|1","deebotName2|1,2"] if you have multiple deebots +- `publishCustomAreaSwitches` Optional - Publish switches to start for each Custom Area. Must be something like ["(x1,y1,x2,y2)","(x1,y1,x2,y2)"] or ["deebotName|(x1,y1,x2,y2)","deebotName2|(x1,y1,x2,y2)"] if you have multiple deebots See : https://github.com/mrbungle64/ecovacs-deebot.js/wiki/Clean-modes