mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[Smhi] Ensure trailing zeroes are removed before updating channels (#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>
This commit is contained in:
parent
19cd505b0c
commit
1e57450e3f
@ -15,6 +15,7 @@ package org.openhab.binding.smhi.internal;
|
||||
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;
|
||||
@ -218,7 +219,7 @@ public class SmhiHandler extends BaseThingHandler {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,14 @@ import static org.openhab.binding.smhi.internal.SmhiBindingConstants.*;
|
||||
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
|
||||
@ -101,7 +103,8 @@ public class SmhiTest {
|
||||
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);
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user