Skip to content

Commit

Permalink
Fix characteristic warning (#1104)
Browse files Browse the repository at this point in the history
## ♻️ Current situation

This warning can appear:
```
This plugin generated a warning from the characteristic 'Battery Level': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.
```

See #1093.
  • Loading branch information
dnicolson authored Nov 5, 2024
1 parent d65a396 commit 1b9e752
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,15 @@ export class Curtain extends deviceBase {
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
}
// BatteryLevel
this.Battery.BatteryLevel = this.serviceData.battery
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
// StatusLowBattery
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
if (this.serviceData.battery) {
this.Battery.BatteryLevel = this.serviceData.battery
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
// StatusLowBattery
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
}
}

async openAPIparseStatus(): Promise<void> {
Expand Down

0 comments on commit 1b9e752

Please sign in to comment.