Skip to content

Commit

Permalink
[fronius] fixed checkstyle error; removed some warnings (eg. StringUt…
Browse files Browse the repository at this point in the history
…ils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
  • Loading branch information
THKDev committed Jul 5, 2021
1 parent 50fa24b commit 73065c6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
*/
package org.openhab.binding.fronius.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link FroniusBaseDeviceConfiguration} is the class used to match the
* thing configuration.
*
* @author Thomas Rokohl - Initial contribution
*/
@NonNullByDefault
public class FroniusBaseDeviceConfiguration {
@Nullable
public Integer deviceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
*/
package org.openhab.binding.fronius.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link FroniusBridgeConfiguration} is the class used to match the
* bridge configuration.
*
* @author Thomas Rokohl - Initial contribution
*/
@NonNullByDefault
public class FroniusBridgeConfiguration {
@Nullable
public String hostname;
@Nullable
public Integer refreshInterval;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.fronius.internal.handler.FroniusBridgeHandler;
import org.openhab.binding.fronius.internal.handler.FroniusMeterHandler;
import org.openhab.binding.fronius.internal.handler.FroniusSymoInverterHandler;
Expand All @@ -34,10 +36,11 @@
*
* @author Thomas Rokohl - Initial contribution
*/
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.fronius")
public class FroniusHandlerFactory extends BaseThingHandlerFactory {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<ThingTypeUID>() {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>() {

private static final long serialVersionUID = 1L;
{
Expand All @@ -53,6 +56,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
}

@Override
@Nullable
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ protected void updateChannel(String channelId) {
} else if (value instanceof ValueUnit) {
state = new DecimalType(((ValueUnit) value).getValue());
} else if (value instanceof String) {
state = new StringType((String) value);
state = StringType.valueOf((String) value);
} else if (value instanceof QuantityType) {
state = (QuantityType) value;
state = (QuantityType<?>) value;
} else {
logger.warn("Update channel {}: Unsupported value type {}", channelId, value.getClass().getSimpleName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration;
import org.openhab.core.io.net.http.HttpUtil;
import org.openhab.core.thing.Bridge;
Expand All @@ -36,12 +38,13 @@
* @author Thomas Rokohl - Refactoring to merge the concepts.
* Check if host is reachable.
*/
@NonNullByDefault
public class FroniusBridgeHandler extends BaseBridgeHandler {

private final Logger logger = LoggerFactory.getLogger(FroniusBridgeHandler.class);
private static final int DEFAULT_REFRESH_PERIOD = 10;
private final Set<FroniusBaseThingHandler> services = new HashSet<>();
private ScheduledFuture<?> refreshJob;
private @Nullable ScheduledFuture<?> refreshJob;

public FroniusBridgeHandler(Bridge bridge) {
super(bridge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package org.openhab.binding.fronius.internal.handler;

import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration;
import org.openhab.binding.fronius.internal.FroniusBindingConstants;
import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration;
Expand Down Expand Up @@ -70,7 +70,7 @@ protected Object getValue(String channelId) {
return null;
}

final String[] fields = StringUtils.split(channelId, "#");
final String[] fields = channelId.split("#");
if (fields.length < 1) {
return null;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ private void updateProperties() {
return;
}

Map<String, String> properties = editProperties();
final Map<String, String> properties = editProperties();

properties.put(FroniusBindingConstants.METER_MODEL, meterRealtimeBodyData.getDetails().getModel());
properties.put(FroniusBindingConstants.METER_SERIAL, meterRealtimeBodyData.getDetails().getSerial());
Expand Down Expand Up @@ -149,8 +149,11 @@ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusB
* @param deviceId of the device
* @return {MeterRealtimeResponse} the object representation of the json response
*/
private MeterRealtimeResponseDTO getMeterRealtimeData(String ip, int deviceId) {
String location = FroniusBindingConstants.METER_REALTIME_DATA_URL.replace("%IP%", StringUtils.trimToEmpty(ip));
private MeterRealtimeResponseDTO getMeterRealtimeData(final String ip, final Integer deviceId) {
Objects.requireNonNull(ip, "IP address must be set in the configuration.");
Objects.requireNonNull(deviceId, "Device ID must be set in the configuration.");

String location = FroniusBindingConstants.METER_REALTIME_DATA_URL.replace("%IP%", ip.trim());
location = location.replace("%DEVICEID%", Integer.toString(deviceId));
return collectDataFormUrl(MeterRealtimeResponseDTO.class, location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
*/
package org.openhab.binding.fronius.internal.handler;

import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration;
import org.openhab.binding.fronius.internal.FroniusBindingConstants;
import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void initialize() {
*/
@Override
protected Object getValue(String channelId) {
final String[] fields = StringUtils.split(channelId, "#");
final String[] fields = channelId.split("#");
if (fields.length < 1) {
return null;
}
Expand Down Expand Up @@ -159,18 +158,18 @@ protected Object getValue(String channelId) {
* @return
*/
private Object getInverterFlowValue(final String fieldName, final String number) {
final Map<String, PowerFlowRealtimeInverter> inverters = powerFlowResponse.getBody().getData().getInverters();
if ((inverters == null) || (inverters.get(number) == null)) {
logger.debug("No data for inverter '" + number + "' found.");
return null;
}
switch (fieldName) {
case INVERTER_POWER:
return new QuantityType<>(inverters.get(number).getP(), Units.WATT);
case INVERTER_SOC:
return new QuantityType<>(inverters.get(number).getSoc(), Units.PERCENT);
default:
break;
final PowerFlowRealtimeInverter inverter = powerFlowResponse.getBody().getData().getInverters().get(number);
if (inverter == null) {
logger.debug("No data for inverter '{}' found.", number);
} else {
switch (fieldName) {
case INVERTER_POWER:
return new QuantityType<>(inverter.getP(), Units.WATT);
case INVERTER_SOC:
return new QuantityType<>(inverter.getSoc(), Units.PERCENT);
default:
break;
}
}
return null;
}
Expand All @@ -189,8 +188,9 @@ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusB
* @param ip address of the device
* @return {PowerFlowRealtimeResponse} the object representation of the json response
*/
private PowerFlowRealtimeResponse getPowerFlowRealtime(String ip) {
String location = FroniusBindingConstants.POWERFLOW_REALTIME_DATA.replace("%IP%", StringUtils.trimToEmpty(ip));
private PowerFlowRealtimeResponse getPowerFlowRealtime(final String ip) {
Objects.requireNonNull(ip, "IP address must be set in the configuration.");
String location = FroniusBindingConstants.POWERFLOW_REALTIME_DATA.replace("%IP%", ip.trim());
return collectDataFormUrl(PowerFlowRealtimeResponse.class, location);
}

Expand All @@ -201,10 +201,12 @@ private PowerFlowRealtimeResponse getPowerFlowRealtime(String ip) {
* @param deviceId of the device
* @return {InverterRealtimeResponse} the object representation of the json response
*/
private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) {
String location = FroniusBindingConstants.INVERTER_REALTIME_DATA_URL.replace("%IP%",
StringUtils.trimToEmpty(ip));
location = location.replace("%DEVICEID%", Integer.toString(deviceId));
private InverterRealtimeResponse getRealtimeData(final String ip, final Integer deviceId) {
Objects.requireNonNull(ip, "IP address must be set in the configuration.");
Objects.requireNonNull(deviceId, "Device ID must be set in the configuration.");

String location = FroniusBindingConstants.INVERTER_REALTIME_DATA_URL.replace("%IP%", ip.trim());
location = location.replace("%DEVICEID%", deviceId.toString());
return collectDataFormUrl(InverterRealtimeResponse.class, location);
}
}

0 comments on commit 73065c6

Please sign in to comment.