SAT solving

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2024-11-18 13:55:12 +01:00
parent 3bd53b764a
commit 838816c033
3 changed files with 9 additions and 4 deletions

View File

@ -101,8 +101,7 @@ public class AirParifIconProvider implements IconProvider {
if (POLLEN_ICONS.contains(category) && state != null) {
try {
int ordinal = Integer.valueOf(state);
PollenAlertLevel alertLevel = PollenAlertLevel.AS_SET.stream()
.filter(pal -> pal.riskLevel == ordinal).findFirst().orElse(PollenAlertLevel.UNKNOWN);
PollenAlertLevel alertLevel = PollenAlertLevel.valueOf(ordinal);
result = result.replaceAll(NEUTRAL_COLOR, alertLevel.color);
} catch (NumberFormatException ignore) {
}

View File

@ -124,11 +124,11 @@ public class AirParifDto {
}
private Set<ZonedDateTime> getValidities() {
Set<ZonedDateTime> local;
final Set<ZonedDateTime> local;
if (validities != null) {
local = validities;
} else {
local = new TreeSet<>();
local = new TreeSet<ZonedDateTime>();
getData().ifPresent(pollens -> {
Matcher matcher = PATTERN.matcher(pollens.periode);
while (matcher.find()) {

View File

@ -13,6 +13,7 @@
package org.openhab.binding.airparif.internal.api;
import java.util.EnumSet;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -42,4 +43,9 @@ public enum PollenAlertLevel {
this.riskLevel = riskLevel;
this.color = color;
}
public static PollenAlertLevel valueOf(int ordinal) {
return Objects
.requireNonNull(AS_SET.stream().filter(pal -> pal.riskLevel == ordinal).findFirst().orElse(UNKNOWN));
}
}