Fix Java and Jetty deprecations (#10349)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-03-19 10:40:14 +01:00 committed by GitHub
parent 580f293766
commit fe0c35d22f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 98 additions and 80 deletions

View File

@ -65,7 +65,7 @@ public class AutelisDiscoveryParticipant implements UpnpDiscoveryParticipant {
properties.put("host", url.getHost()); properties.put("host", url.getHost());
properties.put("user", "admin"); properties.put("user", "admin");
properties.put("password", "admin"); properties.put("password", "admin");
properties.put("port", new Integer(port)); properties.put("port", Integer.valueOf(port));
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label) DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
.build(); .build();

View File

@ -13,6 +13,8 @@
package org.openhab.binding.autelis.internal.handler; package org.openhab.binding.autelis.internal.handler;
import java.io.StringReader; import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -30,8 +32,6 @@ import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.openhab.binding.autelis.internal.AutelisBindingConstants; import org.openhab.binding.autelis.internal.AutelisBindingConstants;
import org.openhab.binding.autelis.internal.config.AutelisConfiguration; import org.openhab.binding.autelis.internal.config.AutelisConfiguration;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
@ -313,7 +313,8 @@ public class AutelisHandler extends BaseThingHandler {
} }
baseURL = "http://" + host + ":" + port; baseURL = "http://" + host + ":" + port;
basicAuthentication = "Basic " + B64Code.encode(username + ":" + password, StringUtil.__ISO_8859_1); basicAuthentication = "Basic "
+ Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
logger.debug("Autelius binding configured with base url {} and refresh period of {}", baseURL, refresh); logger.debug("Autelius binding configured with base url {} and refresh period of {}", baseURL, refresh);
initPolling(0); initPolling(0);

View File

@ -22,13 +22,13 @@ import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.openhab.binding.bticinosmarther.internal.api.dto.Notification; import org.openhab.binding.bticinosmarther.internal.api.dto.Notification;
import org.openhab.binding.bticinosmarther.internal.api.dto.Sender; import org.openhab.binding.bticinosmarther.internal.api.dto.Sender;
import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException; import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException;
@ -61,7 +61,7 @@ public class SmartherAccountService {
private final Logger logger = LoggerFactory.getLogger(SmartherAccountService.class); private final Logger logger = LoggerFactory.getLogger(SmartherAccountService.class);
private final Set<SmartherAccountHandler> handlers = new ConcurrentHashSet<>(); private final Set<SmartherAccountHandler> handlers = ConcurrentHashMap.newKeySet();
private @Nullable HttpService httpService; private @Nullable HttpService httpService;
private @Nullable BundleContext bundleContext; private @Nullable BundleContext bundleContext;

View File

@ -357,7 +357,7 @@ public class X10Interface extends Thread implements SerialPortEventListener {
*/ */
public static boolean validateAddress(String address) { public static boolean validateAddress(String address) {
return (!(address.length() < 2 || address.length() > 3 return (!(address.length() < 2 || address.length() > 3
|| !HOUSE_CODES.containsKey(new Character(address.charAt(0))) || !HOUSE_CODES.containsKey(Character.valueOf(address.charAt(0)))
|| !DEVICE_CODES.containsKey(Integer.parseInt(address.substring(1))))); || !DEVICE_CODES.containsKey(Integer.parseInt(address.substring(1)))));
} }

View File

@ -136,7 +136,7 @@ public class HVACHandler extends BaseThingHandler {
if (command instanceof RefreshType) { if (command instanceof RefreshType) {
final String currentTemp = query(controller, "a"); final String currentTemp = query(controller, "a");
if (currentTemp != null) { if (currentTemp != null) {
final Integer temp = new Integer(currentTemp); final Integer temp = Integer.parseInt(currentTemp);
final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit()); final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit());
updateState(CURRENT_TEMP, value); updateState(CURRENT_TEMP, value);
} }
@ -157,7 +157,7 @@ public class HVACHandler extends BaseThingHandler {
if (command instanceof RefreshType) { if (command instanceof RefreshType) {
final String setTemp = query(controller, "t"); final String setTemp = query(controller, "t");
if (setTemp != null) { if (setTemp != null) {
final Integer temp = new Integer(setTemp); final Integer temp = Integer.parseInt(setTemp);
final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit()); final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit());
updateState(SET_TEMP, value); updateState(SET_TEMP, value);
} }

View File

@ -62,7 +62,7 @@ public class DaikinHttpClientFactoryImpl implements DaikinHttpClientFactory {
private synchronized void initialize() { private synchronized void initialize() {
if (httpClient == null) { if (httpClient == null) {
httpClient = new HttpClient(new SslContextFactory(true)); httpClient = new HttpClient(new SslContextFactory.Client(true));
try { try {
httpClient.start(); httpClient.start();
logger.debug("Daikin http client started"); logger.debug("Daikin http client started");

View File

@ -15,6 +15,7 @@ package org.openhab.binding.digitalstrom.internal.handler;
import static org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants.*; import static org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -410,7 +411,7 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
if (value <= 0 || max <= 0) { if (value <= 0 || max <= 0) {
return 0; return 0;
} }
int percentValue = new BigDecimal(value * ((float) 100 / max)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); int percentValue = new BigDecimal(value * ((float) 100 / max)).setScale(0, RoundingMode.HALF_UP).intValue();
return percentValue < 0 ? 0 : percentValue > 100 ? 100 : percentValue; return percentValue < 0 ? 0 : percentValue > 100 ? 100 : percentValue;
} }

View File

@ -95,9 +95,10 @@ public class BaseDmxChannel implements Comparable<BaseDmxChannel> {
if (otherDmxChannel == null) { if (otherDmxChannel == null) {
return -1; return -1;
} }
int universeCompare = new Integer(getUniverseId()).compareTo(new Integer(otherDmxChannel.getUniverseId())); int universeCompare = Integer.valueOf(getUniverseId())
.compareTo(Integer.valueOf(otherDmxChannel.getUniverseId()));
if (universeCompare == 0) { if (universeCompare == 0) {
return new Integer(getChannelId()).compareTo(new Integer(otherDmxChannel.getChannelId())); return Integer.valueOf(getChannelId()).compareTo(Integer.valueOf(otherDmxChannel.getChannelId()));
} else { } else {
return universeCompare; return universeCompare;
} }

View File

@ -13,6 +13,7 @@
package org.openhab.binding.feican.internal; package org.openhab.binding.feican.internal;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.HSBType;
@ -82,7 +83,7 @@ public class Commands {
*/ */
private byte convertColorPercentToByte(PercentType percent) { private byte convertColorPercentToByte(PercentType percent) {
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255)) return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).byteValue(); .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).byteValue();
} }
/** /**

View File

@ -16,6 +16,7 @@ import static org.openhab.binding.gree.internal.GreeBindingConstants.*;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
@ -567,7 +568,7 @@ public class GreeHandler extends BaseThingHandler {
public static QuantityType<?> toQuantityType(Number value, int digits, Unit<?> unit) { public static QuantityType<?> toQuantityType(Number value, int digits, Unit<?> unit) {
BigDecimal bd = new BigDecimal(value.doubleValue()); BigDecimal bd = new BigDecimal(value.doubleValue());
return new QuantityType<>(bd.setScale(digits, BigDecimal.ROUND_HALF_EVEN), unit); return new QuantityType<>(bd.setScale(digits, RoundingMode.HALF_EVEN), unit);
} }
private void stopRefreshTask() { private void stopRefreshTask() {

View File

@ -12,7 +12,7 @@
*/ */
package org.openhab.binding.http.internal; package org.openhab.binding.http.internal;
import static org.openhab.binding.http.internal.HttpBindingConstants.*; import static org.openhab.binding.http.internal.HttpBindingConstants.THING_TYPE_URL;
import java.util.Set; import java.util.Set;
@ -59,8 +59,8 @@ public class HttpHandlerFactory extends BaseThingHandlerFactory
@Activate @Activate
public HttpHandlerFactory(@Reference HttpClientFactory httpClientFactory, public HttpHandlerFactory(@Reference HttpClientFactory httpClientFactory,
@Reference HttpDynamicStateDescriptionProvider httpDynamicStateDescriptionProvider) { @Reference HttpDynamicStateDescriptionProvider httpDynamicStateDescriptionProvider) {
this.secureClient = new HttpClient(new SslContextFactory()); this.secureClient = new HttpClient(new SslContextFactory.Client());
this.insecureClient = new HttpClient(new SslContextFactory(true)); this.insecureClient = new HttpClient(new SslContextFactory.Client(true));
try { try {
this.secureClient.start(); this.secureClient.start();
this.insecureClient.start(); this.insecureClient.start();

View File

@ -202,7 +202,7 @@ public class ChannelUtils {
ChannelUID channelUID = new ChannelUID(thing.getUID(), group + resourceId); ChannelUID channelUID = new ChannelUID(thing.getUID(), group + resourceId);
ChannelTypeUID type = new ChannelTypeUID(BINDING_ID, channelType); ChannelTypeUID type = new ChannelTypeUID(BINDING_ID, channelType);
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.put(PARAM_RESOURCE_ID, new Integer(resourceId)); configuration.put(PARAM_RESOURCE_ID, Integer.valueOf(resourceId));
Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withConfiguration(configuration) Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withConfiguration(configuration)
.withLabel(description).withType(type).build(); .withLabel(description).withType(type).build();

View File

@ -149,7 +149,7 @@ public class InnogyWebSocket {
} }
WebSocketClient startWebSocketClient() throws Exception { WebSocketClient startWebSocketClient() throws Exception {
WebSocketClient client = new WebSocketClient(new SslContextFactory()); WebSocketClient client = new WebSocketClient(new SslContextFactory.Client());
client.setMaxIdleTimeout(this.maxIdleTimeout); client.setMaxIdleTimeout(this.maxIdleTimeout);
client.start(); client.start();
return client; return client;

View File

@ -85,6 +85,7 @@ public class Server extends Thread {
* Starts the server * Starts the server
* *
*/ */
@Override
public void run() { public void run() {
this.startRetries = 0; this.startRetries = 0;
while (!this.isInterrupted()) { while (!this.isInterrupted()) {
@ -132,7 +133,7 @@ public class Server extends Thread {
IDataPoint dp = DataPointFactory.createDataPoint(id, knxType, description); IDataPoint dp = DataPointFactory.createDataPoint(id, knxType, description);
if (dp != null) { if (dp != null) {
this.dataPoints.put(new Integer(id), dp); this.dataPoints.put(Integer.valueOf(id), dp);
} }
} }

View File

@ -13,6 +13,7 @@
package org.openhab.binding.knx.internal.dpt; package org.openhab.binding.knx.internal.dpt;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParseException; import java.text.ParseException;
@ -1017,6 +1018,6 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
*/ */
private int convertPercentToByte(PercentType percent) { private int convertPercentToByte(PercentType percent) {
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255)) return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).intValue(); .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).intValue();
} }
} }

View File

@ -402,7 +402,7 @@ public class LifxLightHandler extends BaseThingHandler {
Configuration configuration = channel.getConfiguration(); Configuration configuration = channel.getConfiguration();
Object speed = configuration.get(parameter); Object speed = configuration.get(parameter);
return speed == null ? null : new Double(speed.toString()); return speed == null ? null : Double.valueOf(speed.toString());
} }
private LifxProduct getProduct() { private LifxProduct getProduct() {
@ -414,7 +414,7 @@ public class LifxLightHandler extends BaseThingHandler {
// Without first conversion to double, on a very first thing creation from discovery inbox, // Without first conversion to double, on a very first thing creation from discovery inbox,
// the product type is incorrectly parsed, as framework passed it as a floating point number // the product type is incorrectly parsed, as framework passed it as a floating point number
// (e.g. 50.0 instead of 50) // (e.g. 50.0 instead of 50)
Double d = Double.parseDouble((String) propertyValue); Double d = Double.valueOf((String) propertyValue);
long productID = d.longValue(); long productID = d.longValue();
return LifxProduct.getProductFromProductID(productID); return LifxProduct.getProductFromProductID(productID);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {

View File

@ -71,7 +71,7 @@ public class NestRedirectUrlSupplier {
* @see https://developers.nest.com/documentation/cloud/how-to-handle-redirects * @see https://developers.nest.com/documentation/cloud/how-to-handle-redirects
*/ */
private String resolveRedirectUrl() throws FailedResolvingNestUrlException { private String resolveRedirectUrl() throws FailedResolvingNestUrlException {
HttpClient httpClient = new HttpClient(new SslContextFactory()); HttpClient httpClient = new HttpClient(new SslContextFactory.Client());
httpClient.setFollowRedirects(false); httpClient.setFollowRedirects(false);
Request request = httpClient.newRequest(NestBindingConstants.NEST_URL).method(HttpMethod.GET).timeout(30, Request request = httpClient.newRequest(NestBindingConstants.NEST_URL).method(HttpMethod.GET).timeout(30,

View File

@ -13,6 +13,7 @@
package org.openhab.binding.netatmo.internal; package org.openhab.binding.netatmo.internal;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
@ -83,7 +84,7 @@ public class ChannelTypeUtils {
} }
public static State toDecimalType(@Nullable BigDecimal decimal) { public static State toDecimalType(@Nullable BigDecimal decimal) {
return decimal == null ? UnDefType.NULL : new DecimalType(decimal.setScale(2, BigDecimal.ROUND_HALF_UP)); return decimal == null ? UnDefType.NULL : new DecimalType(decimal.setScale(2, RoundingMode.HALF_UP));
} }
public static State toDecimalType(@Nullable String textualDecimal) { public static State toDecimalType(@Nullable String textualDecimal) {

View File

@ -100,7 +100,7 @@ public class Main {
ipAddress = parser.getIpAddress(); ipAddress = parser.getIpAddress();
logger.info("IP150 IP Address: {}", ipAddress); logger.info("IP150 IP Address: {}", ipAddress);
port = new Integer(parser.getPort()); port = Integer.parseInt(parser.getPort());
logger.info("IP150 port: {}", port); logger.info("IP150 port: {}", port);
} }
} }

View File

@ -18,6 +18,7 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.Pac
import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Message.Commands.*; import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Message.Commands.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
@ -155,7 +156,7 @@ public class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
*/ */
public static int getDimLevelFromPercentType(PercentType pt) { public static int getDimLevelFromPercentType(PercentType pt) {
return pt.toBigDecimal().multiply(BigDecimal.valueOf(15)) return pt.toBigDecimal().multiply(BigDecimal.valueOf(15))
.divide(PercentType.HUNDRED.toBigDecimal(), 0, BigDecimal.ROUND_UP).intValue(); .divide(PercentType.HUNDRED.toBigDecimal(), 0, RoundingMode.UP).intValue();
} }
/** /**
@ -168,7 +169,7 @@ public class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
value = Math.min(value, 15); value = Math.min(value, 15);
return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100)) return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(15), 0, BigDecimal.ROUND_UP).intValue()); .divide(BigDecimal.valueOf(15), 0, RoundingMode.UP).intValue());
} }
@Override @Override

View File

@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte
import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.*; import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -216,7 +217,7 @@ public class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
*/ */
public static int getDimLevelFromPercentType(PercentType pt) { public static int getDimLevelFromPercentType(PercentType pt) {
return pt.toBigDecimal().multiply(BigDecimal.valueOf(31)) return pt.toBigDecimal().multiply(BigDecimal.valueOf(31))
.divide(PercentType.HUNDRED.toBigDecimal(), 0, BigDecimal.ROUND_UP).intValue(); .divide(PercentType.HUNDRED.toBigDecimal(), 0, RoundingMode.UP).intValue();
} }
/** /**
@ -229,7 +230,7 @@ public class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
value = Math.min(value, 31); value = Math.min(value, 31);
return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100)) return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(31), 0, BigDecimal.ROUND_UP).intValue()); .divide(BigDecimal.valueOf(31), 0, RoundingMode.UP).intValue());
} }
@Override @Override

View File

@ -12,8 +12,7 @@
*/ */
package org.openhab.binding.rfxcom.internal.messages; package org.openhab.binding.rfxcom.internal.messages;
import static java.math.BigDecimal.*; import static java.math.RoundingMode.*;
import static java.math.RoundingMode.HALF_DOWN;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte; import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
@ -257,12 +256,12 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
BigDecimal supplyVoltage = ((DecimalType) referenceVoltageState).toBigDecimal(); BigDecimal supplyVoltage = ((DecimalType) referenceVoltageState).toBigDecimal();
// RH = (((A/D voltage / supply voltage) - 0.16) / 0.0062) / (1.0546 - 0.00216 * temperature) // RH = (((A/D voltage / supply voltage) - 0.16) / 0.0062) / (1.0546 - 0.00216 * temperature)
BigDecimal belowTheDivider = adVoltage.divide(supplyVoltage, 4, ROUND_HALF_DOWN) BigDecimal belowTheDivider = adVoltage.divide(supplyVoltage, 4, HALF_DOWN)
.subtract(HUMIDITY_VOLTAGE_SUBTRACTION).divide(HUMIDITY_VOLTAGE_DIVIDER, 4, ROUND_HALF_DOWN); .subtract(HUMIDITY_VOLTAGE_SUBTRACTION).divide(HUMIDITY_VOLTAGE_DIVIDER, 4, HALF_DOWN);
BigDecimal underTheDivider = HUMIDITY_TEMPERATURE_CORRECTION BigDecimal underTheDivider = HUMIDITY_TEMPERATURE_CORRECTION
.subtract(HUMIDITY_TEMPERATURE_MULTIPLIER.multiply(temperature)); .subtract(HUMIDITY_TEMPERATURE_MULTIPLIER.multiply(temperature));
return new DecimalType(belowTheDivider.divide(underTheDivider, 4, ROUND_HALF_DOWN)); return new DecimalType(belowTheDivider.divide(underTheDivider, 4, HALF_DOWN));
} }
private State handlePressure(DeviceState deviceState) { private State handlePressure(DeviceState deviceState) {
@ -277,14 +276,14 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
// hPa = ((A/D voltage / supply voltage) + 0.095) / 0.0009 // hPa = ((A/D voltage / supply voltage) + 0.095) / 0.0009
return new DecimalType((adVoltage.divide(supplyVoltage, 4, HALF_DOWN).add(PRESSURE_ADDITION)) return new DecimalType((adVoltage.divide(supplyVoltage, 4, HALF_DOWN).add(PRESSURE_ADDITION))
.divide(PRESSURE_DIVIDER, 4, ROUND_HALF_DOWN)); .divide(PRESSURE_DIVIDER, 4, HALF_DOWN));
} }
private BigDecimal getVoltage() { private BigDecimal getVoltage() {
if (miliVoltageTimesTen == null) { if (miliVoltageTimesTen == null) {
return null; return null;
} }
return miliVoltageTimesTen.divide(ONE_HUNDRED, 100, ROUND_CEILING); return miliVoltageTimesTen.divide(ONE_HUNDRED, 100, CEILING);
} }
@Override @Override

View File

@ -14,6 +14,7 @@ package org.openhab.binding.robonect.internal;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -25,7 +26,6 @@ import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.B64Code;
import org.openhab.binding.robonect.internal.model.ErrorList; import org.openhab.binding.robonect.internal.model.ErrorList;
import org.openhab.binding.robonect.internal.model.ModelParser; import org.openhab.binding.robonect.internal.model.ModelParser;
import org.openhab.binding.robonect.internal.model.MowerInfo; import org.openhab.binding.robonect.internal.model.MowerInfo;
@ -177,8 +177,9 @@ public class RobonectClient {
private void addPreemptiveAuthentication(HttpClient httpClient, RobonectEndpoint endpoint) { private void addPreemptiveAuthentication(HttpClient httpClient, RobonectEndpoint endpoint) {
AuthenticationStore auth = httpClient.getAuthenticationStore(); AuthenticationStore auth = httpClient.getAuthenticationStore();
URI uri = URI.create(baseUrl); URI uri = URI.create(baseUrl);
auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " auth.addAuthenticationResult(
+ B64Code.encode(endpoint.getUser() + ":" + endpoint.getPassword(), StandardCharsets.ISO_8859_1))); new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " + Base64.getEncoder().encodeToString(
(endpoint.getUser() + ":" + endpoint.getPassword()).getBytes(StandardCharsets.ISO_8859_1))));
} }
/** /**

View File

@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
/** /**
* The goal of this class is to test the model parser to make sure the structures * The goal of this class is to test the model parser to make sure the structures
* returned from the module can be handled. * returned from the module can be handled.
* *
* @author Marco Meyer - Initial contribution * @author Marco Meyer - Initial contribution
*/ */
public class ModelParserTest { public class ModelParserTest {
@ -48,12 +48,12 @@ public class ModelParserTest {
String correctModel = "{\"successful\": false, \"error_code\": 7, \"error_message\": \"Automower already stopped\"}"; String correctModel = "{\"successful\": false, \"error_code\": 7, \"error_message\": \"Automower already stopped\"}";
RobonectAnswer answer = subject.parse(correctModel, RobonectAnswer.class); RobonectAnswer answer = subject.parse(correctModel, RobonectAnswer.class);
assertFalse(answer.isSuccessful()); assertFalse(answer.isSuccessful());
assertEquals(new Integer(7), answer.getErrorCode()); assertEquals(Integer.valueOf(7), answer.getErrorCode());
assertEquals("Automower already stopped", answer.getErrorMessage()); assertEquals("Automower already stopped", answer.getErrorMessage());
MowerInfo info = subject.parse(correctModel, MowerInfo.class); MowerInfo info = subject.parse(correctModel, MowerInfo.class);
assertFalse(info.isSuccessful()); assertFalse(info.isSuccessful());
assertEquals(new Integer(7), info.getErrorCode()); assertEquals(Integer.valueOf(7), info.getErrorCode());
assertEquals("Automower already stopped", info.getErrorMessage()); assertEquals("Automower already stopped", info.getErrorMessage());
} }
@ -143,7 +143,7 @@ public class ModelParserTest {
assertTrue(mowerInfo.getStatus().isStopped()); assertTrue(mowerInfo.getStatus().isStopped());
assertNotNull(mowerInfo.getError()); assertNotNull(mowerInfo.getError());
assertEquals("Mein Automower ist angehoben", mowerInfo.getError().getErrorMessage()); assertEquals("Mein Automower ist angehoben", mowerInfo.getError().getErrorMessage());
assertEquals(new Integer(15), mowerInfo.getError().getErrorCode()); assertEquals(Integer.valueOf(15), mowerInfo.getError().getErrorCode());
assertEquals("02.05.2017", mowerInfo.getError().getDate()); assertEquals("02.05.2017", mowerInfo.getError().getDate());
assertEquals("20:36:43", mowerInfo.getError().getTime()); assertEquals("20:36:43", mowerInfo.getError().getTime());
assertEquals("1493757403", mowerInfo.getError().getUnix()); assertEquals("1493757403", mowerInfo.getError().getUnix());
@ -155,7 +155,7 @@ public class ModelParserTest {
ErrorList errorList = subject.parse(errorsListResponse, ErrorList.class); ErrorList errorList = subject.parse(errorsListResponse, ErrorList.class);
assertTrue(errorList.isSuccessful()); assertTrue(errorList.isSuccessful());
assertEquals(10, errorList.getErrors().size()); assertEquals(10, errorList.getErrors().size());
assertEquals(new Integer(15), errorList.getErrors().get(0).getErrorCode()); assertEquals(Integer.valueOf(15), errorList.getErrors().get(0).getErrorCode());
assertEquals("Grasi ist angehoben", errorList.getErrors().get(0).getErrorMessage()); assertEquals("Grasi ist angehoben", errorList.getErrors().get(0).getErrorMessage());
assertEquals("02.05.2017", errorList.getErrors().get(0).getDate()); assertEquals("02.05.2017", errorList.getErrors().get(0).getDate());
assertEquals("20:36:43", errorList.getErrors().get(0).getTime()); assertEquals("20:36:43", errorList.getErrors().get(0).getTime());

View File

@ -43,7 +43,7 @@ public class SeneyeService {
public int seneyeType; public int seneyeType;
private boolean isInitialized; private boolean isInitialized;
private final Gson gson; private final Gson gson;
private HttpClient httpClient = new HttpClient(new SslContextFactory()); private HttpClient httpClient = new HttpClient(new SslContextFactory.Client());
private ScheduledFuture<?> scheduledJob; private ScheduledFuture<?> scheduledJob;
public SeneyeService(SeneyeConfigurationParameters config) throws CommunicationException { public SeneyeService(SeneyeConfigurationParameters config) throws CommunicationException {

View File

@ -84,8 +84,8 @@ public class SqueezeBoxServerDiscoveryParticipant implements UpnpDiscoveryPartic
String representationPropertyName = "ipAddress"; String representationPropertyName = "ipAddress";
properties.put(representationPropertyName, host); properties.put(representationPropertyName, host);
properties.put("webport", new Integer(webPort)); properties.put("webport", Integer.valueOf(webPort));
properties.put("cliPort", new Integer(cliPort)); properties.put("cliPort", Integer.valueOf(cliPort));
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties) DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
.withRepresentationProperty(representationPropertyName).withLabel(label).build(); .withRepresentationProperty(representationPropertyName).withLabel(label).build();

View File

@ -13,6 +13,7 @@
package org.openhab.binding.systeminfo.internal.model; package org.openhab.binding.systeminfo.internal.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
@ -316,14 +317,14 @@ public class OSHISysteminfo implements SysteminfoInterface {
@Override @Override
public @Nullable DecimalType getSensorsCpuTemperature() { public @Nullable DecimalType getSensorsCpuTemperature() {
BigDecimal cpuTemp = new BigDecimal(sensors.getCpuTemperature()); BigDecimal cpuTemp = new BigDecimal(sensors.getCpuTemperature());
cpuTemp = cpuTemp.setScale(PRECISION_AFTER_DECIMAL_SIGN, BigDecimal.ROUND_HALF_UP); cpuTemp = cpuTemp.setScale(PRECISION_AFTER_DECIMAL_SIGN, RoundingMode.HALF_UP);
return cpuTemp.signum() == 1 ? new DecimalType(cpuTemp) : null; return cpuTemp.signum() == 1 ? new DecimalType(cpuTemp) : null;
} }
@Override @Override
public @Nullable DecimalType getSensorsCpuVoltage() { public @Nullable DecimalType getSensorsCpuVoltage() {
BigDecimal cpuVoltage = new BigDecimal(sensors.getCpuVoltage()); BigDecimal cpuVoltage = new BigDecimal(sensors.getCpuVoltage());
cpuVoltage = cpuVoltage.setScale(PRECISION_AFTER_DECIMAL_SIGN, BigDecimal.ROUND_HALF_UP); cpuVoltage = cpuVoltage.setScale(PRECISION_AFTER_DECIMAL_SIGN, RoundingMode.HALF_UP);
return cpuVoltage.signum() == 1 ? new DecimalType(cpuVoltage) : null; return cpuVoltage.signum() == 1 ? new DecimalType(cpuVoltage) : null;
} }
@ -464,13 +465,13 @@ public class OSHISysteminfo implements SysteminfoInterface {
private BigDecimal getPercentsValue(double decimalFraction) { private BigDecimal getPercentsValue(double decimalFraction) {
BigDecimal result = new BigDecimal(decimalFraction * 100); BigDecimal result = new BigDecimal(decimalFraction * 100);
result = result.setScale(PRECISION_AFTER_DECIMAL_SIGN, BigDecimal.ROUND_HALF_UP); result = result.setScale(PRECISION_AFTER_DECIMAL_SIGN, RoundingMode.HALF_UP);
return result; return result;
} }
private BigDecimal getTimeInMinutes(double timeInSeconds) { private BigDecimal getTimeInMinutes(double timeInSeconds) {
BigDecimal timeInMinutes = new BigDecimal(timeInSeconds / 60); BigDecimal timeInMinutes = new BigDecimal(timeInSeconds / 60);
timeInMinutes = timeInMinutes.setScale(PRECISION_AFTER_DECIMAL_SIGN, BigDecimal.ROUND_UP); timeInMinutes = timeInMinutes.setScale(PRECISION_AFTER_DECIMAL_SIGN, RoundingMode.UP);
return timeInMinutes; return timeInMinutes;
} }
@ -525,7 +526,7 @@ public class OSHISysteminfo implements SysteminfoInterface {
} }
double processorLoads[] = cpu.getSystemLoadAverage(index + 1); double processorLoads[] = cpu.getSystemLoadAverage(index + 1);
BigDecimal result = new BigDecimal(processorLoads[index]); BigDecimal result = new BigDecimal(processorLoads[index]);
result = result.setScale(PRECISION_AFTER_DECIMAL_SIGN, BigDecimal.ROUND_HALF_UP); result = result.setScale(PRECISION_AFTER_DECIMAL_SIGN, RoundingMode.HALF_UP);
return result; return result;
} }

View File

@ -14,6 +14,7 @@ package org.openhab.binding.tacmi.internal.schema;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -36,7 +37,6 @@ import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.B64Code;
import org.openhab.binding.tacmi.internal.TACmiChannelTypeProvider; import org.openhab.binding.tacmi.internal.TACmiChannelTypeProvider;
import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.StringType; import org.openhab.core.library.types.StringType;
@ -109,8 +109,8 @@ public class TACmiSchemaHandler extends BaseThingHandler {
this.online = false; this.online = false;
updateStatus(ThingStatus.UNKNOWN); updateStatus(ThingStatus.UNKNOWN);
this.authHeader = "Basic " this.authHeader = "Basic " + Base64.getEncoder()
+ B64Code.encode(config.username + ":" + config.password, StandardCharsets.ISO_8859_1); .encodeToString((config.username + ":" + config.password).getBytes(StandardCharsets.ISO_8859_1));
final String serverBase = "http://" + config.host + "/"; final String serverBase = "http://" + config.host + "/";
this.serverBase = serverBase; this.serverBase = serverBase;

View File

@ -13,6 +13,7 @@
package org.openhab.binding.tado.internal.adapter; package org.openhab.binding.tado.internal.adapter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import org.openhab.binding.tado.internal.TadoBindingConstants.HvacMode; import org.openhab.binding.tado.internal.TadoBindingConstants.HvacMode;
@ -48,7 +49,7 @@ import org.openhab.core.types.UnDefType;
* *
* @author Dennis Frommknecht - Initial contribution * @author Dennis Frommknecht - Initial contribution
* @author Andrew Fiddian-Green - Added Low Battery Alarm, A/C Power and Open Window channels * @author Andrew Fiddian-Green - Added Low Battery Alarm, A/C Power and Open Window channels
* *
*/ */
public class TadoZoneStateAdapter { public class TadoZoneStateAdapter {
private ZoneState zoneState; private ZoneState zoneState;
@ -199,7 +200,7 @@ public class TadoZoneStateAdapter {
} }
private static DecimalType toDecimalType(double value) { private static DecimalType toDecimalType(double value) {
BigDecimal decimal = new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal decimal = new BigDecimal(value).setScale(2, RoundingMode.HALF_UP);
return new DecimalType(decimal); return new DecimalType(decimal);
} }

View File

@ -31,7 +31,7 @@ public abstract class BaseHomeThingHandler extends BaseThingHandler {
public Long getHomeId() { public Long getHomeId() {
TadoHomeHandler handler = getHomeHandler(); TadoHomeHandler handler = getHomeHandler();
return handler != null ? handler.getHomeId() : new Long(0); return handler != null ? handler.getHomeId() : Long.valueOf(0);
} }
protected TadoHomeHandler getHomeHandler() { protected TadoHomeHandler getHomeHandler() {

View File

@ -36,7 +36,6 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.FutureResponseListener; import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.B64Code;
import org.openhab.binding.telegram.internal.TelegramHandler; import org.openhab.binding.telegram.internal.TelegramHandler;
import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction; import org.openhab.core.automation.annotation.RuleAction;
@ -314,7 +313,8 @@ public class TelegramActions implements ThingActions {
AuthenticationStore auth = client.getAuthenticationStore(); AuthenticationStore auth = client.getAuthenticationStore();
URI uri = URI.create(photoURL); URI uri = URI.create(photoURL);
auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri, auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri,
"Basic " + B64Code.encode(username + ":" + password, StandardCharsets.ISO_8859_1))); "Basic " + Base64.getEncoder().encodeToString(
(username + ":" + password).getBytes(StandardCharsets.ISO_8859_1))));
} }
try { try {
// API has 10mb limit to jpg file size, without this it can only accept 2mb // API has 10mb limit to jpg file size, without this it can only accept 2mb

View File

@ -13,6 +13,7 @@
package org.openhab.binding.tellstick.internal.core; package org.openhab.binding.tellstick.internal.core;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collections; import java.util.Collections;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -119,7 +120,7 @@ public class TelldusCoreDeviceController implements DeviceChangeListener, Sensor
case JNA.CLibrary.TELLSTICK_DIM: case JNA.CLibrary.TELLSTICK_DIM:
dimValue = new BigDecimal(((TellstickDevice) device).getData()); dimValue = new BigDecimal(((TellstickDevice) device).getData());
dimValue = dimValue.multiply(new BigDecimal(100)); dimValue = dimValue.multiply(new BigDecimal(100));
dimValue = dimValue.divide(new BigDecimal(255), 0, BigDecimal.ROUND_HALF_UP); dimValue = dimValue.divide(new BigDecimal(255), 0, RoundingMode.HALF_UP);
break; break;
default: default:
logger.warn("Could not handle {} for {}", ((TellstickDevice) device).getStatus(), device); logger.warn("Could not handle {} for {}", ((TellstickDevice) device).getStatus(), device);

View File

@ -13,6 +13,7 @@
package org.openhab.binding.tellstick.internal.live; package org.openhab.binding.tellstick.internal.live;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -248,7 +249,7 @@ public class TelldusLiveDeviceController implements DeviceChangeListener, Sensor
case JNA.CLibrary.TELLSTICK_DIM: case JNA.CLibrary.TELLSTICK_DIM:
dimValue = new BigDecimal(((TellstickNetDevice) device).getStatevalue()); dimValue = new BigDecimal(((TellstickNetDevice) device).getStatevalue());
dimValue = dimValue.multiply(new BigDecimal(100)); dimValue = dimValue.multiply(new BigDecimal(100));
dimValue = dimValue.divide(new BigDecimal(255), 0, BigDecimal.ROUND_HALF_UP); dimValue = dimValue.divide(new BigDecimal(255), 0, RoundingMode.HALF_UP);
break; break;
default: default:
logger.warn("Could not handle {} for {}", (((TellstickNetDevice) device).getState()), device); logger.warn("Could not handle {} for {}", (((TellstickNetDevice) device).getState()), device);

View File

@ -13,6 +13,7 @@
package org.openhab.binding.tellstick.internal.local; package org.openhab.binding.tellstick.internal.local;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -221,7 +222,7 @@ public class TelldusLocalDeviceController implements DeviceChangeListener, Senso
case JNA.CLibrary.TELLSTICK_DIM: case JNA.CLibrary.TELLSTICK_DIM:
dimValue = new BigDecimal(((TellstickLocalDeviceDTO) device).getStatevalue()); dimValue = new BigDecimal(((TellstickLocalDeviceDTO) device).getStatevalue());
dimValue = dimValue.multiply(new BigDecimal(100)); dimValue = dimValue.multiply(new BigDecimal(100));
dimValue = dimValue.divide(new BigDecimal(255), 0, BigDecimal.ROUND_HALF_UP); dimValue = dimValue.divide(new BigDecimal(255), 0, RoundingMode.HALF_UP);
break; break;
default: default:
logger.warn("Could not handle {} for {}", (((TellstickLocalDeviceDTO) device).getState()), device); logger.warn("Could not handle {} for {}", (((TellstickLocalDeviceDTO) device).getState()), device);

View File

@ -69,7 +69,7 @@ public class TibberHandler extends BaseThingHandler {
private static final int REQUEST_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(20); private static final int REQUEST_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(20);
private final Logger logger = LoggerFactory.getLogger(TibberHandler.class); private final Logger logger = LoggerFactory.getLogger(TibberHandler.class);
private final Properties httpHeader = new Properties(); private final Properties httpHeader = new Properties();
private final SslContextFactory sslContextFactory = new SslContextFactory(true); private final SslContextFactory sslContextFactory = new SslContextFactory.Client(true);
private final Executor websocketExecutor = ThreadPoolManager.getPool("tibber.websocket"); private final Executor websocketExecutor = ThreadPoolManager.getPool("tibber.websocket");
private TibberConfiguration tibberConfig = new TibberConfiguration(); private TibberConfiguration tibberConfig = new TibberConfiguration();
private @Nullable TibberWebSocketListener socket; private @Nullable TibberWebSocketListener socket;

View File

@ -72,7 +72,7 @@ public class TradfriVersionTest {
assertTrue(VERSION.equals(new TradfriVersion(VERSION_STRING))); assertTrue(VERSION.equals(new TradfriVersion(VERSION_STRING)));
assertFalse(VERSION.equals((TradfriVersion) null)); assertFalse(VERSION.equals((TradfriVersion) null));
assertFalse(VERSION.equals(new Integer("1"))); assertFalse(VERSION.equals(Integer.valueOf("1")));
assertFalse(VERSION.equals(new TradfriVersion("1.2.5"))); assertFalse(VERSION.equals(new TradfriVersion("1.2.5")));
} }

View File

@ -46,7 +46,7 @@ public class UniFiThingHandlerFactory extends BaseThingHandlerFactory {
public UniFiThingHandlerFactory(@Reference final HttpClientFactory httpClientFactory) { public UniFiThingHandlerFactory(@Reference final HttpClientFactory httpClientFactory) {
// [wip] mgb: disabled due to missing common name attributes with certs // [wip] mgb: disabled due to missing common name attributes with certs
// this.httpClient = httpClientFactory.getCommonHttpClient(); // this.httpClient = httpClientFactory.getCommonHttpClient();
httpClient = new HttpClient(new SslContextFactory(true)); httpClient = new HttpClient(new SslContextFactory.Client(true));
try { try {
httpClient.start(); httpClient.start();
} catch (Exception e) { } catch (Exception e) {

View File

@ -106,7 +106,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
public VenstarThermostatHandler(Thing thing) { public VenstarThermostatHandler(Thing thing) {
super(thing); super(thing);
httpClient = new HttpClient(new SslContextFactory(true)); httpClient = new HttpClient(new SslContextFactory.Client(true));
gson = new GsonBuilder().registerTypeAdapter(VenstarSystemState.class, new VenstarSystemStateSerializer()) gson = new GsonBuilder().registerTypeAdapter(VenstarSystemState.class, new VenstarSystemStateSerializer())
.registerTypeAdapter(VenstarSystemMode.class, new VenstarSystemModeSerializer()).create(); .registerTypeAdapter(VenstarSystemMode.class, new VenstarSystemModeSerializer()).create();

View File

@ -16,6 +16,7 @@ import static java.lang.Math.*;
import java.awt.Color; import java.awt.Color;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.HSBType;
@ -92,13 +93,13 @@ public class LEDStateDTO {
PercentType b = new PercentType(new BigDecimal(hsv[2]).multiply(new BigDecimal(100.0))); PercentType b = new PercentType(new BigDecimal(hsv[2]).multiply(new BigDecimal(100.0)));
HSBType hsbType = new HSBType(h, s, b); HSBType hsbType = new HSBType(h, s, b);
PercentType w = new PercentType(new BigDecimal(white).divide(new BigDecimal(255.0), 3, BigDecimal.ROUND_HALF_UP) PercentType w = new PercentType(new BigDecimal(white).divide(new BigDecimal(255.0), 3, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100.0)));
PercentType w2 = new PercentType(new BigDecimal(white2).divide(new BigDecimal(255.0), 3, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100.0))); .multiply(new BigDecimal(100.0)));
PercentType w2 = new PercentType(new BigDecimal(white2)
.divide(new BigDecimal(255.0), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)));
// Range: 0x00 .. 0x1F. Speed is inversed // Range: 0x00 .. 0x1F. Speed is inversed
BigDecimal ps = new BigDecimal(programSpeed).divide(new BigDecimal(0x1f), 2, BigDecimal.ROUND_HALF_UP) BigDecimal ps = new BigDecimal(programSpeed).divide(new BigDecimal(0x1f), 2, RoundingMode.HALF_UP)
.multiply(new BigDecimal(100.0)); .multiply(new BigDecimal(100.0));
PercentType e = new PercentType(new BigDecimal(100.0).subtract(ps)); PercentType e = new PercentType(new BigDecimal(100.0).subtract(ps));

View File

@ -181,7 +181,7 @@ public class ZWayZAutomationDeviceHandler extends ZWayDeviceHandler {
} }
Calendar lastUpdateOfDevice = Calendar.getInstance(); Calendar lastUpdateOfDevice = Calendar.getInstance();
lastUpdateOfDevice.setTimeInMillis(new Long(device.getUpdateTime()) * 1000); lastUpdateOfDevice.setTimeInMillis(Long.valueOf(device.getUpdateTime()) * 1000);
if (lastUpdate == null || lastUpdateOfDevice.after(lastUpdate)) { if (lastUpdate == null || lastUpdateOfDevice.after(lastUpdate)) {
lastUpdate = lastUpdateOfDevice; lastUpdate = lastUpdateOfDevice;

View File

@ -211,7 +211,8 @@ public class ZWayZWaveDeviceHandler extends ZWayDeviceHandler {
} }
Calendar lastUpdateOfDevice = Calendar.getInstance(); Calendar lastUpdateOfDevice = Calendar.getInstance();
lastUpdateOfDevice.setTimeInMillis(new Long(zwaveDevice.getData().getLastReceived().getUpdateTime()) * 1000); lastUpdateOfDevice
.setTimeInMillis(Long.valueOf(zwaveDevice.getData().getLastReceived().getUpdateTime()) * 1000);
if (lastUpdate == null || lastUpdateOfDevice.after(lastUpdate)) { if (lastUpdate == null || lastUpdateOfDevice.after(lastUpdate)) {
lastUpdate = lastUpdateOfDevice; lastUpdate = lastUpdateOfDevice;

View File

@ -13,6 +13,7 @@
package org.openhab.io.imperihome.internal.model.device; package org.openhab.io.imperihome.internal.model.device;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.openhab.core.items.Item; import org.openhab.core.items.Item;
@ -84,6 +85,6 @@ public class RgbLightDevice extends AbstractEnergyLinkDevice {
private int convertPercentToByte(PercentType percent) { private int convertPercentToByte(PercentType percent) {
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255)) return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).intValue(); .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).intValue();
} }
} }

View File

@ -108,7 +108,7 @@ public class AstroValidConfigurationTest {
public void testIfTheIntervalForASunThingIsLessThan1_theThingStatusBecomesOFFLINE() { public void testIfTheIntervalForASunThingIsLessThan1_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration(); Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0)); thingConfiguration.put(INTERVAL_PROPERTY, Integer.valueOf(0));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
} }
@ -116,7 +116,7 @@ public class AstroValidConfigurationTest {
public void testIfTheIntervalForAMoonThingIsLessThan1_theThingStatusBecomesOFFLINE() { public void testIfTheIntervalForAMoonThingIsLessThan1_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration(); Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0)); thingConfiguration.put(INTERVAL_PROPERTY, Integer.valueOf(0));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
} }
@ -124,7 +124,7 @@ public class AstroValidConfigurationTest {
public void testIfTheIntervalForASunThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() { public void testIfTheIntervalForASunThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration(); Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401)); thingConfiguration.put(INTERVAL_PROPERTY, Integer.valueOf(86401));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
} }
@ -132,7 +132,7 @@ public class AstroValidConfigurationTest {
public void testIfTheIntervalForAMoonThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() { public void testIfTheIntervalForAMoonThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration(); Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE); thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401)); thingConfiguration.put(INTERVAL_PROPERTY, Integer.valueOf(86401));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
} }