feat: add info cards for environment and power metrics

This commit is contained in:
andrekir 2024-10-19 12:35:07 -03:00
parent 46b3146d6d
commit c98a5c7caf
3 changed files with 285 additions and 65 deletions

View file

@ -72,9 +72,15 @@ data class NodeEntity(
val environmentMetrics: TelemetryProtos.EnvironmentMetrics
get() = environmentTelemetry.environmentMetrics
val hasEnvironmentMetrics: Boolean
get() = environmentMetrics != TelemetryProtos.EnvironmentMetrics.getDefaultInstance()
val powerMetrics: TelemetryProtos.PowerMetrics
get() = powerTelemetry.powerMetrics
val hasPowerMetrics: Boolean
get() = powerMetrics != TelemetryProtos.PowerMetrics.getDefaultInstance()
val colors: Pair<Int, Int>
get() { // returns foreground and background @ColorInt for each 'num'
val r = (num and 0xFF0000) shr 16
@ -145,8 +151,6 @@ data class NodeEntity(
null
}
val humidity = if (relativeHumidity != 0f) "%.0f%%".format(relativeHumidity) else null
val pressure = if (barometricPressure != 0f) "%.1fhPa".format(barometricPressure) else null
val gas = if (gasResistance != 0f) "%.0fMΩ".format(gasResistance) else null
val voltage = if (this.voltage != 0f) "%.2fV".format(this.voltage) else null
val current = if (current != 0f) "%.1fmA".format(current) else null
val iaq = if (iaq != 0) "IAQ: $iaq" else null
@ -154,21 +158,12 @@ data class NodeEntity(
return listOfNotNull(
temp,
humidity,
pressure,
gas,
voltage,
current,
iaq,
).joinToString(" ")
}
private fun TelemetryProtos.PowerMetrics.getDisplayString(): String = listOfNotNull(
"%.2fV".format(ch2Voltage).takeIf { hasCh2Voltage() },
"%.1fmA".format(ch2Current).takeIf { hasCh2Current() },
"%.2fV".format(ch3Voltage).takeIf { hasCh3Voltage() },
"%.1fmA".format(ch3Current).takeIf { hasCh3Current() },
).joinToString(" ")
private fun PaxcountProtos.Paxcount.getDisplayString() =
"PAX: ${ble + wifi} (B:$ble/W:$wifi)".takeIf { ble != 0 && wifi != 0 }
@ -176,7 +171,6 @@ data class NodeEntity(
return listOfNotNull(
paxcounter.getDisplayString(),
environmentMetrics.getDisplayString(isFahrenheit),
powerMetrics.getDisplayString(),
).joinToString(" ")
}