mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[airparif] Concentrations can be nullable (#20438)
* Handle concentrations being nullable Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
+11
-1
@@ -17,6 +17,7 @@ import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.measure.Unit;
|
||||
|
||||
@@ -87,7 +88,7 @@ public class AirParifDto {
|
||||
@SerializedName("date_previ") LocalDate productionDate, //
|
||||
@SerializedName("disponible") boolean available, //
|
||||
Message bulletin, //
|
||||
Set<PollutantConcentration> concentrations) {
|
||||
@Nullable Set<PollutantConcentration> concentrations) {
|
||||
public String dayDescription() {
|
||||
return bulletin.fr;
|
||||
}
|
||||
@@ -95,6 +96,11 @@ public class AirParifDto {
|
||||
public boolean isToday() {
|
||||
return previsionDate.equals(LocalDate.now(DEFAULT_TZ));
|
||||
}
|
||||
|
||||
public Set<PollutantConcentration> concentrations() {
|
||||
Set<PollutantConcentration> local = concentrations;
|
||||
return local == null ? Set.of() : local;
|
||||
}
|
||||
}
|
||||
|
||||
public record DailyEpisode(//
|
||||
@@ -105,6 +111,10 @@ public class AirParifDto {
|
||||
public record Bulletin( //
|
||||
@SerializedName("jour") DailyBulletin today, //
|
||||
@SerializedName("demain") DailyBulletin tomorrow) {
|
||||
|
||||
public Stream<DailyBulletin> days() {
|
||||
return Set.of(today, tomorrow).stream();
|
||||
}
|
||||
}
|
||||
|
||||
public record Episode( //
|
||||
|
||||
+2
-2
@@ -212,10 +212,10 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU
|
||||
return;
|
||||
}
|
||||
|
||||
Set.of(bulletin.today(), bulletin.tomorrow()).stream().forEach(aq -> {
|
||||
bulletin.days().forEach(aq -> {
|
||||
ChannelGroupUID groupUID = aq.isToday() ? todayGroupUID : tomorrowGroupUID;
|
||||
updateState(new ChannelUID(groupUID, CHANNEL_COMMENT),
|
||||
!aq.available() ? UnDefType.NULL : new StringType(aq.bulletin().fr()));
|
||||
aq.available() ? new StringType(aq.bulletin().fr()) : UnDefType.NULL);
|
||||
|
||||
aq.concentrations().forEach(measure -> {
|
||||
Pollutant pollutant = measure.pollutant();
|
||||
|
||||
Reference in New Issue
Block a user