Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[persistence] Handle null value for unit field of filters #3716

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
Expand All @@ -38,11 +39,12 @@ public class PersistenceIncludeFilter extends PersistenceFilter {
private final String unit;
private final boolean inverted;

public PersistenceIncludeFilter(String name, BigDecimal lower, BigDecimal upper, String unit, boolean inverted) {
public PersistenceIncludeFilter(String name, BigDecimal lower, BigDecimal upper, @Nullable String unit,
boolean inverted) {
super(name);
this.lower = lower;
this.upper = upper;
this.unit = unit;
this.unit = (unit == null) ? "" : unit;
this.inverted = inverted;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.measure.UnconvertibleException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
Expand Down Expand Up @@ -47,10 +48,10 @@ public class PersistenceThresholdFilter extends PersistenceFilter {

private final transient Map<String, State> valueCache = new HashMap<>();

public PersistenceThresholdFilter(String name, BigDecimal value, String unit, boolean relative) {
public PersistenceThresholdFilter(String name, BigDecimal value, @Nullable String unit, boolean relative) {
super(name);
this.value = value;
this.unit = unit;
this.unit = (unit == null) ? "" : unit;
this.relative = relative;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class PersistenceTimeFilter extends PersistenceFilter {
private transient @Nullable Duration duration;
private final transient Map<String, ZonedDateTime> nextPersistenceTimes = new HashMap<>();

public PersistenceTimeFilter(String name, int value, String unit) {
public PersistenceTimeFilter(String name, int value, @Nullable String unit) {
super(name);
this.value = value;
this.unit = unit;
this.unit = (unit == null) ? "s" : unit;
}

public int getValue() {
Expand Down