Skip to content

Commit

Permalink
[Smhi] Ensure trailing zeroes are removed before updating channels (o…
Browse files Browse the repository at this point in the history
…penhab#11353)

* Ensure unnecessary trailing zeroes are removed, to avoid issues with transformations.

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>

* Change to use setScale()

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
  • Loading branch information
pacive authored Oct 16, 2021
1 parent 631c232 commit 553ca08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.openhab.binding.smhi.internal.SmhiBindingConstants.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -218,7 +219,7 @@ private void updateChannel(Channel channel, Optional<BigDecimal> value) {
newState = new QuantityType<>(value.get(), MetricPrefix.MILLI(SIUnits.METRE));
break;
default:
newState = new DecimalType(value.get());
newState = new DecimalType(value.get().setScale(0, RoundingMode.DOWN));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.ZonedDateTime;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DecimalType;

/**
* @author Anders Alfredsson - Initial contribution
Expand Down Expand Up @@ -101,7 +103,8 @@ public void parameterTest() {
assertEquals(0, pcat0.compareTo(BigDecimal.valueOf(0)));
assertEquals(0, pmean0.compareTo(BigDecimal.valueOf(0)));
assertEquals(0, pmedian0.compareTo(BigDecimal.valueOf(0)));
assertEquals(0, wsymb0.compareTo(BigDecimal.valueOf(2)));
assertEquals(0, wsymb0.compareTo(BigDecimal.valueOf(20)));
assertEquals("20", new DecimalType(wsymb0.setScale(0, RoundingMode.DOWN)).toString());

Forecast forecast1 = timeSeries1.getForecast(TIME.plusHours(1), 0).orElseThrow(AssertionError::new);

Expand Down

Large diffs are not rendered by default.

0 comments on commit 553ca08

Please sign in to comment.