Huami: Fix sending air quality index

This commit is contained in:
a161803398
2025-04-05 07:47:00 +00:00
committed by José Rebelo
parent 3ad5412d04
commit 12df9f719c
2 changed files with 23 additions and 2 deletions
@@ -632,6 +632,26 @@ public class Weather {
}
}
public static String getAqiLevelString(int aqi) {
// Uses the [2023 Plume index](https://plumelabs.files.wordpress.com/2023/06/plume_aqi_2023.pdf) as a reference
if (aqi < 0) {
return "(n/a)";
}
if (aqi < 20) {
return "excellent";
} else if (aqi < 50) {
return "fair";
} else if (aqi < 100) {
return "poor";
} else if (aqi < 150) {
return "unhealthy";
} else if (aqi < 250) {
return "very unhealthy";
} else {
return "dangerous";
}
}
public static byte mapToZeTimeConditionOld(int openWeatherMapCondition) {
/* deducted values:
0 = partly cloudy
@@ -3173,7 +3173,8 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
TransactionBuilder builder;
builder = performInitialized("Sending air quality index");
int length = 8;
String aqiString = "(n/a)";
int aqi = weatherSpec.airQuality != null ? weatherSpec.airQuality.aqi : -1;
String aqiString = Weather.getAqiLevelString(aqi);
if (supportsConditionString) {
length += aqiString.getBytes().length + 1;
}
@@ -3182,7 +3183,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
buf.put((byte) 4);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.putShort((short) -1);
buf.putShort((short) aqi);
if (supportsConditionString) {
buf.put(aqiString.getBytes());
buf.put((byte) 0);