Skip to content

Commit

Permalink
Update deebot.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Oct 11, 2020
1 parent 04437dd commit 782f93b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/deebot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class Deebot {
this.log = log
this.config = config
this.api = api
this.debug = this.config.debug || false
this.debug = this.config.debug
this.devicesInHB = new Map()
this.devicesInEC = new Map()
this.refreshFlag = true
this.refreshInterval = this.config.ref >= 30 && this.config.ref <= 600 ? this.config.ref * 1000 : 120000
this.ecovacsAPI = new deebot.EcoVacsAPI(
deebot.EcoVacsAPI.md5(nodeMachineId.machineIdSync()),
this.config.countryCode,
Expand Down Expand Up @@ -49,11 +50,10 @@ class Deebot {
this.log('[%s] devices loaded from your ECOVACS account.', this.devicesInEC.size)
this.refreshDevices = promInterval(
async () => {
if (this.refreshFlag) {
await this.deebotSync()
}
if (!this.refreshFlag) return
await this.deebotSync()
},
this.config.ref >= 30 && this.config.ref <= 600 ? this.config.ref * 1000 : 120000,
this.refreshInterval,
{ stopOnError: false }
)
this.log("ECOVACS sync complete. Don't forget to ⭐️ this plugin on GitHub if you're finding it useful!")
Expand Down Expand Up @@ -114,7 +114,7 @@ class Deebot {
device.on('Error', err => this.externalErrorUpdate(accessory, err))
if (!device.is_ready) device.connect_and_wait_until_ready()
} catch (err) {
this.log.warn('[%s] could not be refreshed as .', device.vacuum.nick || device.vacuum.did, this.debug ? err : err.message)
this.log.warn('[%s] could not be initialised as .', device.vacuum.nick || device.vacuum.did, this.debug ? err : err.message)
}
}

Expand Down Expand Up @@ -156,9 +156,12 @@ class Deebot {
if (!accessory.getService(Service.BatteryService)) {
accessory.addService(Service.BatteryService)
}
if (!accessory.getService('Battery Level')) {
if (!accessory.getService('Battery Level') && !this.config.hideBattHumidity) {
accessory.addService(Service.HumiditySensor, 'Battery Level', 'batterylevel')
}
if (accessory.getService('Battery Level') && this.config.hideBattHumidity) {
accessory.removeService(accessory.getService('Battery Level'))
}
this.devicesInHB.set(accessory.context.ecoDeviceId, accessory)
} catch (err) {
if (this.debug) this.log.warn(err)
Expand Down Expand Up @@ -274,19 +277,25 @@ class Deebot {
}

async externalMessageUpdate (accessory, msg) {
if (accessory.context.inUse) return
accessory.context.inUse = true
this.log.warn('[%s] has sent a message - %s', accessory.displayName, msg)
accessory.getService('Attention').getCharacteristic(Characteristic.MotionDetected, true)
await utils.sleep(10000)
accessory.getService('Attention').getCharacteristic(Characteristic.MotionDetected, false)
accessory.context.inUse = false
}

async externalErrorUpdate (accessory, err) {
this.log.warn('[%s] has sent a message - %s.', accessory.displayName, err)
if (accessory.context.inUse) return
accessory.context.inUse = true
this.log.warn('[%s] has sent an error message - %s.', accessory.displayName, err)
accessory.getService('Attention').getCharacteristic(Characteristic.MotionDetected, true)
accessory.getService('Clean').updateCharacteristic(Characteristic.On, false)
accessory.getService('Go Charge').updateCharacteristic(Characteristic.On, false)
await utils.sleep(10000)
accessory.getService('Attention').getCharacteristic(Characteristic.MotionDetected, false)
accessory.context.inUse = false
}
}
module.exports = function (homebridge) {
Expand Down

0 comments on commit 782f93b

Please sign in to comment.