From e40ba9b6e1580fbd9bb9354409816ec85a154c46 Mon Sep 17 00:00:00 2001 From: Tobias Tiemerding Date: Thu, 11 Oct 2018 21:12:04 +0200 Subject: [PATCH] Update of values in the background. (#11) * Fixes #6 and #10. * Update dependencies (e.g. fakegato 0.5.2) --- index.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 4 ++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6fdecfe..672561d 100755 --- a/index.js +++ b/index.js @@ -57,6 +57,35 @@ function MiFlowerCarePlugin(log, config) { temp: data.temperature, humidity: data.moisture }); + + that.lightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel) + .updateValue(data.lux); + that.lightService.getCharacteristic(Characteristic.StatusActive) + .updateValue(true); + + that.tempService.getCharacteristic(Characteristic.CurrentTemperature) + .updateValue(data.temperature); + that.tempService.getCharacteristic(Characteristic.StatusActive) + .updateValue(true); + + that.humidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity) + .updateValue(data.moisture); + that.humidityService.getCharacteristic(Characteristic.StatusActive) + .updateValue(true); + + if (that.humidityAlert) { + that.humidityAlertService.getCharacteristic(Characteristic.ContactSensorState) + .updateValue(data.moisture <= that.humidityAlertLevel ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED); + that.humidityAlertService.getCharacteristic(Characteristic.StatusActive) + .updateValue(true); + } + + if (that.lowLightAlert) { + that.lowLightAlertService.getCharacteristic(Characteristic.ContactSensorState) + .updateValue(data.lux <= that.lowLightAlertLevel ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED); + that.lowLightAlertService.getCharacteristic(Characteristic.StatusActive) + .updateValue(true); + } } }); @@ -64,6 +93,34 @@ function MiFlowerCarePlugin(log, config) { if (data.deviceId = that.deviceId) { that.log("Firmware: %s, Battery level: %s", data.firmwareVersion, data.batteryLevel); that.storedData.firmware = data; + + // Update values + that.informationService.getCharacteristic(Characteristic.FirmwareRevision) + .updateValue(data.firmwareVersion); + + that.batteryService.getCharacteristic(Characteristic.BatteryLevel) + .updateValue(data.batteryLevel); + that.batteryService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + + that.lightService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + + that.tempService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + + that.humidityService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + + if (that.humidityAlert) { + that.humidityAlertService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + } + + if (that.lowLightAlert) { + that.lowLightAlertService.getCharacteristic(Characteristic.StatusLowBattery) + .updateValue(data.batteryLevel <= 10 ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + } } }); @@ -253,7 +310,6 @@ MiFlowerCarePlugin.prototype.setUpServices = function () { PlantSensor.UUID = '3C233958-B5C4-4218-A0CD-60B8B971AA0A'; - this.plantSensorService = new PlantSensor(this.name); this.plantSensorService.getCharacteristic(SoilMoisture) .on('get', this.getCurrentMoisture.bind(this)); diff --git a/package.json b/package.json index 5bdd60e..c0c2edf 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-mi-flower-care", - "version": "1.0.8", + "version": "1.1.0", "description": "This is a homebridge plugin for the Xiaomi Mi Flora / Xiaomi Flower Care devices.", "main": "index.js", "scripts": { @@ -29,6 +29,6 @@ }, "dependencies" :{ "node-mi-flora" : "0.1.1", - "fakegato-history": "^0.4.0" + "fakegato-history": "^0.5.2" } }