From cbe704107284e3b4c38b8e9308d1aa21a7cf2822 Mon Sep 17 00:00:00 2001 From: Colin Bendell Date: Sun, 7 Mar 2021 23:16:39 -0500 Subject: [PATCH] Updated the battery voltage algorithm to better express as a % --- src/blink.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/blink.js b/src/blink.js index 6060d08..68aec0f 100644 --- a/src/blink.js +++ b/src/blink.js @@ -361,10 +361,17 @@ class BlinkCamera extends BlinkDevice { } async getBattery() { + // Low battery reports 10% + if (this.getLowBattery() === Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW) return 10; + if (!this.data.fullStatus) { this.data.fullStatus = await this.blink.getCameraStatus(this.networkID, this.cameraID, BATTERY_TTL); } - return Math.round(this.data.fullStatus.camera_status.battery_voltage / 180 * 100) || null; + const alkalineVolts = Math.max(this.data.fullStatus.camera_status.battery_voltage / 100, 0); + + // AA and AAA Alkaline batteries are rated for 1.5V + // assume battery voltage between 1.2V and 1.8V is acceptable and express it as a function of 20% to 100% + return Math.max(Math.min(Math.round((alkalineVolts - 1.2) / (1.8 - 1.2) * 80 + 20), 100), 20); } getLowBattery() {