Skip to content

Commit

Permalink
Update to openHAB 3.2 release.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Aug 25, 2024
1 parent 71a26c7 commit 856d7ab
Show file tree
Hide file tree
Showing 24 changed files with 141 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public void run() {
ValueBlock params = client.getValueBlock();
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "status"), new DecimalType(params.getStatus()));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "load"), QuantityType.valueOf(params.getLoad(), Units.WATT));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "temperatureLimit"), QuantityType.valueOf(params.getTemperatureLimit(), tec.uom.se.unit.Units.CELSIUS));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "temperatureSensor0"), QuantityType.valueOf(params.getTemperatureSensor0(), tec.uom.se.unit.Units.CELSIUS));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "maximumTemperature"), QuantityType.valueOf(params.getMaximumTemperature(), tec.uom.se.unit.Units.CELSIUS));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "temperatureLimit"), QuantityType.valueOf(params.getTemperatureLimit(), tech.units.indriya.unit.Units.CELSIUS));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "temperatureSensor0"), QuantityType.valueOf(params.getTemperatureSensor0(), tech.units.indriya.unit.Units.CELSIUS));
getCallback().stateUpdated(new ChannelUID(getThing().getUID(), "maximumTemperature"), QuantityType.valueOf(params.getMaximumTemperature(), tech.units.indriya.unit.Units.CELSIUS));
}
}, 1000L, getRefreshInterval(), TimeUnit.MILLISECONDS));
tasks.add(scheduler.scheduleAtFixedRate(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import javax.measure.quantity.Length;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import tec.uom.se.AbstractConverter;
import tec.uom.se.AbstractUnit;
import tec.uom.se.format.SimpleUnitFormat;
import tec.uom.se.unit.TransformedUnit;
import tech.units.indriya.AbstractUnit;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.AbstractConverter;
import tech.units.indriya.unit.TransformedUnit;

public class TAUnits {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.Units;
import tec.uom.se.AbstractUnit;
import tech.units.indriya.AbstractUnit;

public enum AnalogUnit implements TAUnit {

Expand Down Expand Up @@ -58,14 +58,14 @@ public enum AnalogUnit implements TAUnit {
/* 22 analog */ LITRE_PER_MINUTE (22, Units.LITRE_PER_MINUTE, 1),
/* 23 analog */ BAR (23, Units.BAR, 0.01),
/* 24 analog */ POWER_FACTOR(24, AbstractUnit.ONE, 0.01),
/* 25 analog */ KILO_METRE (25, MetricPrefix.KILO(tec.uom.se.unit.Units.METRE), 1),
/* 26 analog */ METRE (26, tec.uom.se.unit.Units.METRE, 1),
/* 27 analog */ MILLIMETER (27, MetricPrefix.MILLI(tec.uom.se.unit.Units.METRE), 1),
/* 28 analog */ CUBIC_METRE (28, tec.uom.se.unit.Units.CUBIC_METRE, 1),
/* 29 analog */ HERTZ_KM_HOUR (29, Units.HERTZ.divide(MetricPrefix.KILO(tec.uom.se.unit.Units.METRE).divide(Units.HOUR)), 1),
/* 30 analog */ HERTZ_M_SECOND (30, Units.HERTZ.divide(tec.uom.se.unit.Units.METRE.divide(Units.SECOND)), 1),
/* 25 analog */ KILO_METRE (25, MetricPrefix.KILO(SIUnits.METRE), 1),
/* 26 analog */ METRE (26, SIUnits.METRE, 1),
/* 27 analog */ MILLIMETER (27, MetricPrefix.MILLI(SIUnits.METRE), 1),
/* 28 analog */ CUBIC_METRE (28, SIUnits.CUBIC_METRE, 1),
/* 29 analog */ HERTZ_KM_HOUR (29, Units.HERTZ.divide(MetricPrefix.KILO(SIUnits.METRE).divide(Units.HOUR)), 1),
/* 30 analog */ HERTZ_M_SECOND (30, Units.HERTZ.divide(SIUnits.METRE.divide(Units.SECOND)), 1),
/* 31 analog */ KILOWATT_PER_IMPULSE (31, Units.KILOWATT_HOUR.divide(TAUnits.IMPULSE), 1),
/* 32 analog */ CUBICMETRE_PER_IMPULSE (32, tec.uom.se.unit.Units.CUBIC_METRE.divide(TAUnits.IMPULSE), 1),
/* 32 analog */ CUBICMETRE_PER_IMPULSE (32, SIUnits.CUBIC_METRE.divide(TAUnits.IMPULSE), 1),
/* 33 analog */ MILLIMETRE_PER_IMPULSE(33, TAUnits.MILLIMETRE.divide(TAUnits.IMPULSE), 1),
/* 34 analog */ LITER_PER_IMPULSE (34, Units.LITRE.divide(TAUnits.IMPULSE), 1),
/* 35 analog */ LITER_PER_DAY (35, Units.LITRE.divide(Units.DAY), 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.stream.Collectors;

import org.connectorio.addons.binding.canopen.ta.internal.type.TAUnit;
import tec.uom.se.quantity.Quantities;
import tec.uom.se.unit.Units;
import org.openhab.core.library.unit.SIUnits;
import tech.units.indriya.quantity.Quantities;

/**
* Compound units whcih require additional parsing. Result of computation is list and not single value.
Expand All @@ -38,7 +38,7 @@ public enum ComplexUnit implements TAUnit {

double value = 0.1 * (raw & 0x1FF) * (negative ? -1 : 1);
return Arrays.asList(
Quantities.getQuantity(value, Units.CELSIUS),
Quantities.getQuantity(value, SIUnits.CELSIUS),
(raw & 0x600) >> 9
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public class AnalogChannelHandler extends BaseChannelHandler<AnalogValue, AnalogUnit, AnalogObjectConfig> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public class RASChannelHandler extends BaseChannelHandler<RASValue, AnalogUnit, AnalogObjectConfig> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.connectorio.addons.binding.canopen.ta.internal.config.ComplexUnit;
import org.connectorio.addons.binding.canopen.ta.internal.config.DigitalUnit;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public class TAValue {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.measure.Quantity;
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.connectorio.addons.binding.canopen.ta.internal.type.TAUnit;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public abstract class BaseAnalogValue<T extends Number> implements AnalogValue {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.plc4x.java.spi.generation.WriteBuffer;
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.connectorio.addons.binding.canopen.ta.internal.type.TAUnit;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public class RASValue extends ShortAnalogValue {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import javax.measure.Quantity;
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.connectorio.addons.binding.canopen.ta.internal.type.TAUnit;
import tec.uom.se.quantity.Quantities;

public class ShortAnalogValue extends BaseAnalogValue<Short> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.unit.Units;
import tec.uom.se.ComparableQuantity;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.ComparableQuantity;
import tech.units.indriya.quantity.Quantities;

class AnalogValueTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.connectorio.addons.binding.canopen.ta.internal.config.AnalogUnit;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import tec.uom.se.quantity.Quantities;
import tec.uom.se.unit.Units;
import org.openhab.core.library.unit.SIUnits;
import tech.units.indriya.quantity.Quantities;

class RASValueTest {

Expand All @@ -37,7 +37,7 @@ class RASValueTest {
void verifyRasValue(Argument argument) {
RASValue rasValue = new RASValue(argument.raw, AnalogUnit.TEMPERATURE_REGULATOR);

Quantity<Temperature> quantity = Quantities.getQuantity(argument.temperature, Units.CELSIUS);
Quantity<Temperature> quantity = Quantities.getQuantity(argument.temperature, SIUnits.CELSIUS);
assertThat(rasValue.getValue().getValue().doubleValue())
.isCloseTo(quantity.getValue().doubleValue(), Percentage.withPercentage(1));
assertThat(rasValue.getMode()).isEqualTo(argument.mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.openhab.core.library.dimension.DataAmount;
import org.openhab.core.library.dimension.DataTransferRate;
import org.openhab.core.library.unit.Units;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

/**
* Bit ratio calculation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.function.Supplier;
import javax.measure.Quantity;
import javax.measure.quantity.Dimensionless;
import tec.uom.se.AbstractUnit;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.AbstractUnit;
import tech.units.indriya.quantity.Quantities;

/**
* Ratio calculation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.measure.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

public class SysfsReader<Q extends Quantity<Q>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.openhab.core.library.dimension.DataAmount;
import org.openhab.core.library.dimension.DataTransferRate;
import org.openhab.core.library.unit.Units;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.quantity.Quantities;

@ExtendWith(MockitoExtension.class)
class BandwidthStatisticCollectorTest {
Expand All @@ -52,8 +52,8 @@ protected Quantity<DataAmount> readStatistic() {
statistic.set(Quantities.getQuantity(0, Units.BYTE));
assertThat(collector.getStatistic())
.extracting(Quantity::getValue)
.extracting(Number::intValue)
.isEqualTo(0);
.extracting(Number::doubleValue)
.isEqualTo(0.0);

// one second and one byte later we expect 8 bit/s ratio.
when(clock.get()).thenReturn(2000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import tec.uom.se.AbstractUnit;
import tec.uom.se.quantity.Quantities;
import tech.units.indriya.AbstractUnit;
import tech.units.indriya.quantity.Quantities;

@ExtendWith(MockitoExtension.class)
class RatioStatisticCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
Expand All @@ -78,11 +79,11 @@ abstract class AbstractMeterThingHandler<B extends WeblogBridgeHandler, C extend
.toFormatter();

private final static Map<String, MappingEntry> MAPPING = Map.of(
"kW", new MappingEntry(Power.class, MetricPrefix.KILO(tec.uom.se.unit.Units.WATT)),
"kW", new MappingEntry(Power.class, MetricPrefix.KILO(Units.WATT)),
"kWh", new MappingEntry(Energy.class, Units.KILOWATT_HOUR),
"m^3", new MappingEntry(Volume.class, tec.uom.se.unit.Units.CUBIC_METRE),
"m^3", new MappingEntry(Volume.class, SIUnits.CUBIC_METRE),
"m^3/h", new MappingEntry(VolumetricFlowRate.class, Units.CUBICMETRE_PER_HOUR),
"C", new MappingEntry(Temperature.class, tec.uom.se.unit.Units.CELSIUS),
"C", new MappingEntry(Temperature.class, SIUnits.CELSIUS),
"h", new MappingEntry(Time.class, Units.HOUR),
"s", new MappingEntry(Time.class, Units.SECOND)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ public void setSerialPortParams(int baudrate, int dataBits, int stopBits, int pa
}
}

@Override
public int getBaudRate() {
return port.getBaudRate();
}

@Override
public int getDataBits() {
return port.getDataBits();
}

@Override
public int getStopBits() {
return port.getStopBits();
}

@Override
public int getParity() {
return port.getParity();
}

@Override
public InputStream getInputStream() throws IOException {
return port.getInputStream();
Expand Down Expand Up @@ -114,6 +134,31 @@ public void notifyOnParityError(boolean enable) {
port.notifyOnParityError(enable);
}

@Override
public void notifyOnOutputEmpty(boolean enable) {
port.notifyOnOutputEmpty(enable);
}

@Override
public void notifyOnCTS(boolean enable) {
port.notifyOnCTS(enable);
}

@Override
public void notifyOnDSR(boolean enable) {
port.notifyOnDSR(enable);
}

@Override
public void notifyOnRingIndicator(boolean enable) {
port.notifyOnRingIndicator(enable);
}

@Override
public void notifyOnCarrierDetect(boolean enable) {
port.notifyOnCarrierDetect(enable);
}

@Override
public void enableReceiveTimeout(int timeout) throws UnsupportedCommOperationException, IllegalArgumentException {
try {
Expand All @@ -137,6 +182,11 @@ public void setFlowControlMode(int flowcontrolRtsctsOut) throws UnsupportedCommO
}
}

@Override
public int getFlowControlMode() {
return port.getFlowControlMode();
}

@Override
public void enableReceiveThreshold(int i) throws UnsupportedCommOperationException {
try {
Expand All @@ -151,4 +201,44 @@ public void setRTS(boolean rts) {
port.setRTS(rts);
}

@Override
public boolean isRTS() {
return port.isRTS();
}

@Override
public void setDTR(boolean enable) {
port.setDTR(enable);
}

@Override
public boolean isDTR() {
return port.isDTR();
}

@Override
public boolean isCTS() {
return port.isCTS();
}

@Override
public boolean isDSR() {
return port.isDSR();
}

@Override
public boolean isCD() {
return port.isCD();
}

@Override
public boolean isRI() {
return port.isRI();
}

@Override
public void sendBreak(int duration) {
port.sendBreak(duration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public SerialPort open(String owner, int timeout) throws PortInUseException {
try {
return new PureJavaCommSerialPort((purejavacomm.SerialPort) identifier.open(owner, timeout));
} catch (purejavacomm.PortInUseException e) {
PortInUseException exception = new PortInUseException();
exception.initCause(e);
throw exception;
throw new PortInUseException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.Mockito.when;

import java.util.HashMap;
import javax.measure.MetricPrefix;
import javax.measure.Unit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -31,8 +32,9 @@
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.profiles.ProfileCallback;
import org.openhab.core.thing.profiles.ProfileContext;
import tec.uom.se.unit.MetricPrefix;
import tec.uom.se.unit.Units;
import tech.units.indriya.unit.Units;
import javax.measure.MetricPrefix;
import javax.measure.Unit;

@ExtendWith(MockitoExtension.class)
public class LimitBottomQuantityProfileTest {
Expand Down
Loading

0 comments on commit 856d7ab

Please sign in to comment.