Skip to content

Commit

Permalink
Update of values in the background. (#11)
Browse files Browse the repository at this point in the history
* Fixes #6 and #10.
* Update dependencies (e.g. fakegato 0.5.2)
  • Loading branch information
honkmaster authored Oct 11, 2018
1 parent 1357658 commit e40ba9b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
58 changes: 57 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,70 @@ 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);
}
}
});

this.flora.on('firmware', function (data) {
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);
}
}
});

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -29,6 +29,6 @@
},
"dependencies" :{
"node-mi-flora" : "0.1.1",
"fakegato-history": "^0.4.0"
"fakegato-history": "^0.5.2"
}
}

0 comments on commit e40ba9b

Please sign in to comment.