mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)
Signed-off-by: THKDev <THKDev@users.noreply.github.com>
This commit is contained in:
parent
50fa24b2f3
commit
73065c657b
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import static org.openhab.binding.fronius.internal.FroniusBindingConstants.*;
|
||||
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;
|
||||
@ -34,10 +36,11 @@ import org.osgi.service.component.annotations.Component;
|
||||
*
|
||||
* @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;
|
||||
{
|
||||
@ -53,6 +56,7 @@ public class FroniusHandlerFactory extends BaseThingHandlerFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected ThingHandler createHandler(Thing thing) {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
|
@ -129,9 +129,9 @@ public abstract class FroniusBaseThingHandler extends BaseThingHandler {
|
||||
} 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());
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import java.util.Set;
|
||||
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;
|
||||
@ -36,12 +38,13 @@ import org.slf4j.LoggerFactory;
|
||||
* @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);
|
||||
|
@ -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;
|
||||
@ -70,7 +70,7 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] fields = StringUtils.split(channelId, "#");
|
||||
final String[] fields = channelId.split("#");
|
||||
if (fields.length < 1) {
|
||||
return null;
|
||||
}
|
||||
@ -121,7 +121,7 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler {
|
||||
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());
|
||||
@ -149,8 +149,11 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler {
|
||||
* @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);
|
||||
}
|
||||
|
@ -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;
|
||||
@ -77,7 +76,7 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler {
|
||||
*/
|
||||
@Override
|
||||
protected Object getValue(String channelId) {
|
||||
final String[] fields = StringUtils.split(channelId, "#");
|
||||
final String[] fields = channelId.split("#");
|
||||
if (fields.length < 1) {
|
||||
return null;
|
||||
}
|
||||
@ -159,18 +158,18 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler {
|
||||
* @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;
|
||||
}
|
||||
@ -189,8 +188,9 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler {
|
||||
* @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);
|
||||
}
|
||||
|
||||
@ -201,10 +201,12 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler {
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user