[venstarthermostat] Use doubles over Int or float types when processing temperatures, fix Checkstyle Warnings (#10740)

* Use a single numeric type (double), remove ints and floats

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Rebases with master.  Fixes All Checkstyle warning, renames package 'model' -> 'dto'

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
This commit is contained in:
Dan Cunningham 2021-06-06 10:34:35 -07:00 committed by GitHub
parent 5533643a3a
commit 32c1e65799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 75 additions and 73 deletions

View File

@ -31,30 +31,30 @@ public class VenstarThermostatBindingConstants {
public static final String BINDING_ID = "venstarthermostat"; public static final String BINDING_ID = "venstarthermostat";
// List of all Thing Type UIDs // List of all Thing Type UIDs
public final static ThingTypeUID THING_TYPE_COLOR_TOUCH = new ThingTypeUID(BINDING_ID, "colorTouchThermostat"); public static final ThingTypeUID THING_TYPE_COLOR_TOUCH = new ThingTypeUID(BINDING_ID, "colorTouchThermostat");
public final static Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_COLOR_TOUCH); public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_COLOR_TOUCH);
// List of all Channel ids // List of all Channel ids
public final static String CHANNEL_TEMPERATURE = "temperature"; public static final String CHANNEL_TEMPERATURE = "temperature";
public final static String CHANNEL_HUMIDITY = "humidity"; public static final String CHANNEL_HUMIDITY = "humidity";
public final static String CHANNEL_EXTERNAL_TEMPERATURE = "outdoorTemperature"; public static final String CHANNEL_EXTERNAL_TEMPERATURE = "outdoorTemperature";
public final static String CHANNEL_HEATING_SETPOINT = "heatingSetpoint"; public static final String CHANNEL_HEATING_SETPOINT = "heatingSetpoint";
public final static String CHANNEL_COOLING_SETPOINT = "coolingSetpoint"; public static final String CHANNEL_COOLING_SETPOINT = "coolingSetpoint";
public final static String CHANNEL_SYSTEM_STATE = "systemState"; public static final String CHANNEL_SYSTEM_STATE = "systemState";
public final static String CHANNEL_SYSTEM_MODE = "systemMode"; public static final String CHANNEL_SYSTEM_MODE = "systemMode";
public final static String CHANNEL_SYSTEM_STATE_RAW = "systemStateRaw"; public static final String CHANNEL_SYSTEM_STATE_RAW = "systemStateRaw";
public final static String CHANNEL_SYSTEM_MODE_RAW = "systemModeRaw"; public static final String CHANNEL_SYSTEM_MODE_RAW = "systemModeRaw";
public final static String CHANNEL_AWAY_MODE = "awayMode"; public static final String CHANNEL_AWAY_MODE = "awayMode";
public final static String CHANNEL_AWAY_MODE_RAW = "awayModeRaw"; public static final String CHANNEL_AWAY_MODE_RAW = "awayModeRaw";
public final static String CONFIG_USERNAME = "username"; public static final String CONFIG_USERNAME = "username";
public final static String CONFIG_PASSWORD = "password"; public static final String CONFIG_PASSWORD = "password";
public final static String CONFIG_REFRESH = "refresh"; public static final String CONFIG_REFRESH = "refresh";
public final static String PROPERTY_URL = "url"; public static final String PROPERTY_URL = "url";
public final static String PROPERTY_UUID = "uuid"; public static final String PROPERTY_UUID = "uuid";
public final static String REFRESH_INVALID = "refresh-invalid"; public static final String REFRESH_INVALID = "refresh-invalid";
public final static String EMPTY_INVALID = "empty-invalid"; public static final String EMPTY_INVALID = "empty-invalid";
} }

View File

@ -12,15 +12,17 @@
*/ */
package org.openhab.binding.venstarthermostat.internal; package org.openhab.binding.venstarthermostat.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* The {@link VenstarThermostatConfiguration} is responsible for holding configuration information. * The {@link VenstarThermostatConfiguration} is responsible for holding configuration information.
* *
* @author William Welliver - Initial contribution * @author William Welliver - Initial contribution
*/ */
@NonNullByDefault
public class VenstarThermostatConfiguration { public class VenstarThermostatConfiguration {
public String username; public String username = "";
public String password; public String password = "";
public String url; public String url = "";
public Integer refresh; public Integer refresh = 30;
} }

View File

@ -37,7 +37,7 @@ import org.osgi.service.component.annotations.Component;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.venstarthermostat") @Component(service = ThingHandlerFactory.class, configurationPid = "binding.venstarthermostat")
public class VenstarThermostatHandlerFactory extends BaseThingHandlerFactory { public class VenstarThermostatHandlerFactory extends BaseThingHandlerFactory {
private final static Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_COLOR_TOUCH); private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_COLOR_TOUCH);
@Override @Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) { public boolean supportsThingType(ThingTypeUID thingTypeUID) {
@ -46,7 +46,6 @@ public class VenstarThermostatHandlerFactory extends BaseThingHandlerFactory {
@Override @Override
protected @Nullable ThingHandler createHandler(Thing thing) { protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_COLOR_TOUCH)) { if (thingTypeUID.equals(THING_TYPE_COLOR_TOUCH)) {

View File

@ -29,6 +29,8 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.venstarthermostat.internal.VenstarThermostatBindingConstants; import org.openhab.binding.venstarthermostat.internal.VenstarThermostatBindingConstants;
import org.openhab.core.config.discovery.AbstractDiscoveryService; import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResult;
@ -47,6 +49,7 @@ import org.slf4j.LoggerFactory;
* @author Dan Cunningham - Refactoring and Improvements * @author Dan Cunningham - Refactoring and Improvements
*/ */
@NonNullByDefault
@Component(service = DiscoveryService.class, configurationPid = "discovery.venstarthermostat") @Component(service = DiscoveryService.class, configurationPid = "discovery.venstarthermostat")
public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService { public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService {
private final Logger logger = LoggerFactory.getLogger(VenstarThermostatDiscoveryService.class); private final Logger logger = LoggerFactory.getLogger(VenstarThermostatDiscoveryService.class);
@ -57,7 +60,7 @@ public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService
private static final String SSDP_MATCH = "colortouch:ecp"; private static final String SSDP_MATCH = "colortouch:ecp";
private static final int BACKGROUND_SCAN_INTERVAL_SECONDS = 300; private static final int BACKGROUND_SCAN_INTERVAL_SECONDS = 300;
private ScheduledFuture<?> scheduledFuture = null; private @Nullable ScheduledFuture<?> scheduledFuture = null;
public VenstarThermostatDiscoveryService() { public VenstarThermostatDiscoveryService() {
super(VenstarThermostatBindingConstants.SUPPORTED_THING_TYPES, 30, true); super(VenstarThermostatBindingConstants.SUPPORTED_THING_TYPES, 30, true);
@ -67,14 +70,15 @@ public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService
protected void startBackgroundDiscovery() { protected void startBackgroundDiscovery() {
logger.debug("Starting Background Scan"); logger.debug("Starting Background Scan");
stopBackgroundDiscovery(); stopBackgroundDiscovery();
scheduledFuture = scheduler.scheduleAtFixedRate(this::doRunRun, 0, BACKGROUND_SCAN_INTERVAL_SECONDS, scheduledFuture = scheduler.scheduleWithFixedDelay(this::doRunRun, 0, BACKGROUND_SCAN_INTERVAL_SECONDS,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
@Override @Override
protected void stopBackgroundDiscovery() { protected void stopBackgroundDiscovery() {
if (scheduledFuture != null && !scheduledFuture.isCancelled()) { ScheduledFuture<?> scheduledFutureLocal = scheduledFuture;
scheduledFuture.cancel(true); if (scheduledFutureLocal != null && !scheduledFutureLocal.isCancelled()) {
scheduledFutureLocal.cancel(true);
} }
} }
@ -112,7 +116,7 @@ public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService
* @throws SocketException * @throws SocketException
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
private MulticastSocket sendDiscoveryBroacast(NetworkInterface ni) private @Nullable MulticastSocket sendDiscoveryBroacast(NetworkInterface ni)
throws UnknownHostException, SocketException, UnsupportedEncodingException { throws UnknownHostException, SocketException, UnsupportedEncodingException {
InetAddress m = InetAddress.getByName("239.255.255.250"); InetAddress m = InetAddress.getByName("239.255.255.250");
final int port = 1900; final int port = 1900;

View File

@ -10,13 +10,13 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarSystemMode} represents the value of the system mode returned * The {@link VenstarSystemMode} represents the value of the system mode returned
* from the REST API. * from the REST API.
* *
* @author Matthew Davies - created new class to add away mode to binding * @author Matthew Davies - Initial contribution
*/ */
public enum VenstarAwayMode { public enum VenstarAwayMode {
HOME(0, "home", "Home"), HOME(0, "home", "Home"),

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -23,7 +23,7 @@ import com.google.gson.JsonParseException;
* The {@link VenstarSystemModeSerializer} parses system mode values * The {@link VenstarSystemModeSerializer} parses system mode values
* from the REST API JSON. * from the REST API JSON.
* *
* @author Matthew Davies - created new class to include away mode in binding * @author Matthew Davies - Initial contribution
*/ */
public class VenstarAwayModeSerializer implements JsonDeserializer<VenstarAwayMode> { public class VenstarAwayModeSerializer implements JsonDeserializer<VenstarAwayMode> {
@Override @Override

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarInfoData} represents a thermostat state from the REST API. * The {@link VenstarInfoData} represents a thermostat state from the REST API.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarResponse} represents a response message from the REST API. * The {@link VenstarResponse} represents a response message from the REST API.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarSensor} represents a sensor returned from the REST API. * The {@link VenstarSensor} represents a sensor returned from the REST API.
@ -19,8 +19,8 @@ package org.openhab.binding.venstarthermostat.internal.model;
*/ */
public class VenstarSensor { public class VenstarSensor {
String name; String name;
float temp; double temp;
float hum; double hum;
public String getName() { public String getName() {
return name; return name;
@ -30,19 +30,19 @@ public class VenstarSensor {
this.name = name; this.name = name;
} }
public float getTemp() { public double getTemp() {
return temp; return temp;
} }
public void setTemp(float temp) { public void setTemp(double temp) {
this.temp = temp; this.temp = temp;
} }
public float getHum() { public double getHum() {
return hum; return hum;
} }
public void setHum(float hum) { public void setHum(double hum) {
this.hum = hum; this.hum = hum;
} }
} }

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
import java.util.List; import java.util.List;

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarSystemMode} represents the value of the system mode returned * The {@link VenstarSystemMode} represents the value of the system mode returned

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
/** /**
* The {@link VenstarSystemState} represents the value of the system state * The {@link VenstarSystemState} represents the value of the system state

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.venstarthermostat.internal.model; package org.openhab.binding.venstarthermostat.internal.dto;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -47,16 +47,16 @@ import org.eclipse.jetty.client.util.DigestAuthentication;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.openhab.binding.venstarthermostat.internal.VenstarThermostatConfiguration; import org.openhab.binding.venstarthermostat.internal.VenstarThermostatConfiguration;
import org.openhab.binding.venstarthermostat.internal.model.VenstarAwayMode; import org.openhab.binding.venstarthermostat.internal.dto.VenstarAwayMode;
import org.openhab.binding.venstarthermostat.internal.model.VenstarAwayModeSerializer; import org.openhab.binding.venstarthermostat.internal.dto.VenstarAwayModeSerializer;
import org.openhab.binding.venstarthermostat.internal.model.VenstarInfoData; import org.openhab.binding.venstarthermostat.internal.dto.VenstarInfoData;
import org.openhab.binding.venstarthermostat.internal.model.VenstarResponse; import org.openhab.binding.venstarthermostat.internal.dto.VenstarResponse;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSensor; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSensor;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSensorData; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSensorData;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSystemMode; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSystemMode;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSystemModeSerializer; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSystemModeSerializer;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSystemState; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSystemState;
import org.openhab.binding.venstarthermostat.internal.model.VenstarSystemStateSerializer; import org.openhab.binding.venstarthermostat.internal.dto.VenstarSystemStateSerializer;
import org.openhab.core.config.core.status.ConfigStatusMessage; import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.QuantityType;
@ -117,7 +117,6 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
log.trace("VenstarThermostatHandler for thing {}", getThing().getUID()); log.trace("VenstarThermostatHandler for thing {}", getThing().getUID());
} }
@SuppressWarnings("null") // compiler does not see conf.refresh == null check
@Override @Override
public Collection<ConfigStatusMessage> getConfigStatus() { public Collection<ConfigStatusMessage> getConfigStatus() {
Collection<ConfigStatusMessage> status = new ArrayList<>(); Collection<ConfigStatusMessage> status = new ArrayList<>();
@ -134,7 +133,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
.withArguments(CONFIG_PASSWORD).build()); .withArguments(CONFIG_PASSWORD).build());
} }
if (config.refresh == null || config.refresh < 10) { if (config.refresh < 10) {
log.warn("refresh is too small: {}", config.refresh); log.warn("refresh is too small: {}", config.refresh);
status.add(ConfigStatusMessage.Builder.error(CONFIG_REFRESH).withMessageKeySuffix(REFRESH_INVALID) status.add(ConfigStatusMessage.Builder.error(CONFIG_REFRESH).withMessageKeySuffix(REFRESH_INVALID)
@ -145,7 +144,6 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
@Override @Override
public void handleCommand(ChannelUID channelUID, Command command) { public void handleCommand(ChannelUID channelUID, Command command) {
if (getThing().getStatus() != ThingStatus.ONLINE) { if (getThing().getStatus() != ThingStatus.ONLINE) {
log.debug("Controller is NOT ONLINE and is not responding to commands"); log.debug("Controller is NOT ONLINE and is not responding to commands");
return; return;
@ -160,12 +158,12 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
stateMap.remove(channelUID.getAsString()); stateMap.remove(channelUID.getAsString());
if (channelUID.getId().equals(CHANNEL_HEATING_SETPOINT)) { if (channelUID.getId().equals(CHANNEL_HEATING_SETPOINT)) {
QuantityType<Temperature> quantity = commandToQuantityType(command, unitSystem); QuantityType<Temperature> quantity = commandToQuantityType(command, unitSystem);
int value = quantityToRoundedTemperature(quantity, unitSystem).intValue(); double value = quantityToRoundedTemperature(quantity, unitSystem).doubleValue();
log.debug("Setting heating setpoint to {}", value); log.debug("Setting heating setpoint to {}", value);
setHeatingSetpoint(value); setHeatingSetpoint(value);
} else if (channelUID.getId().equals(CHANNEL_COOLING_SETPOINT)) { } else if (channelUID.getId().equals(CHANNEL_COOLING_SETPOINT)) {
QuantityType<Temperature> quantity = commandToQuantityType(command, unitSystem); QuantityType<Temperature> quantity = commandToQuantityType(command, unitSystem);
int value = quantityToRoundedTemperature(quantity, unitSystem).intValue(); double value = quantityToRoundedTemperature(quantity, unitSystem).doubleValue();
log.debug("Setting cooling setpoint to {}", value); log.debug("Setting cooling setpoint to {}", value);
setCoolingSetpoint(value); setCoolingSetpoint(value);
} else if (channelUID.getId().equals(CHANNEL_SYSTEM_MODE)) { } else if (channelUID.getId().equals(CHANNEL_SYSTEM_MODE)) {
@ -298,20 +296,20 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
private void setCoolingSetpoint(int cool) { private void setCoolingSetpoint(double cool) {
int heat = getHeatingSetpoint().intValue(); double heat = getHeatingSetpoint().doubleValue();
VenstarSystemMode mode = getSystemMode(); VenstarSystemMode mode = getSystemMode();
updateControls(heat, cool, mode); updateControls(heat, cool, mode);
} }
private void setSystemMode(VenstarSystemMode mode) { private void setSystemMode(VenstarSystemMode mode) {
int cool = getCoolingSetpoint().intValue(); double cool = getCoolingSetpoint().doubleValue();
int heat = getHeatingSetpoint().intValue(); double heat = getHeatingSetpoint().doubleValue();
updateControls(heat, cool, mode); updateControls(heat, cool, mode);
} }
private void setHeatingSetpoint(int heat) { private void setHeatingSetpoint(double heat) {
int cool = getCoolingSetpoint().intValue(); double cool = getCoolingSetpoint().doubleValue();
VenstarSystemMode mode = getSystemMode(); VenstarSystemMode mode = getSystemMode();
updateControls(heat, cool, mode); updateControls(heat, cool, mode);
} }
@ -354,7 +352,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
} }
} }
private void updateControls(int heat, int cool, VenstarSystemMode mode) { private void updateControls(double heat, double cool, VenstarSystemMode mode) {
// this function corresponds to the thermostat local API POST /control instruction // this function corresponds to the thermostat local API POST /control instruction
// the function can be expanded with other parameters which are changed via POST /control // the function can be expanded with other parameters which are changed via POST /control
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
@ -503,7 +501,6 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
return content; return content;
} catch (InterruptedException | TimeoutException | ExecutionException e) { } catch (InterruptedException | TimeoutException | ExecutionException e) {
throw new VenstarCommunicationException(e); throw new VenstarCommunicationException(e);
} }
} }