Skip to content

Commit

Permalink
Added default battery level for file and w1
Browse files Browse the repository at this point in the history
To prevent false low battery warnings
  • Loading branch information
kiwi-cam committed Jun 16, 2023
1 parent d347c36 commit 359d815
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion accessories/aircon.js
Expand Up @@ -522,6 +522,7 @@ class AirConAccessory extends BroadlinkRMAccessory {
const { temperatureFilePath, noHumidity, batteryAlerts } = config;
let humidity = null;
let temperature = null;
let battery = null;

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromFile reading file: ${temperatureFilePath}`);}

Expand All @@ -545,11 +546,18 @@ class AirConAccessory extends BroadlinkRMAccessory {
let value = line.split(':');
if(value[0] == 'temperature') {temperature = parseFloat(value[1]);}
if(value[0] == 'humidity' && !noHumidity) {humidity = parseFloat(value[1]);}
if(value[0] == 'battery' && batteryAlerts) {state.batteryLevel = parseFloat(value[1]);}
if(value[0] == 'battery' && batteryAlerts) {battery = parseFloat(value[1]);}
}
});
}

//Default battery level if none returned
if (battery) {
state.batteryLevel = battery;
}else{
state.batteryLevel = 100;
}

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromFile (parsed temperature: ${temperature} humidity: ${humidity})`);}

this.onTemperature(temperature, humidity);
Expand Down Expand Up @@ -578,6 +586,8 @@ class AirConAccessory extends BroadlinkRMAccessory {
if (logLevel <=3) {log(`\x1b[33m[WARNING]\x1b[0m ${name} updateTemperatureFromW1 error reading file: ${fName}, using previous Temperature`);}
temperature = (state.currentTemperature || 0);
}
//Default battery level
state.batteryLevel = 100;

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromW1 (parsed temperature: ${temperature})`);}
this.onTemperature(temperature);
Expand Down

0 comments on commit 359d815

Please sign in to comment.