Skip to content

Commit 0d59228

Browse files
authored
[groheondus] Fix warnings and SAT (#20551)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
1 parent 29d082a commit 0d59228

8 files changed

Lines changed: 24 additions & 22 deletions

File tree

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/GroheOndusAccountConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
*/
1313
package org.openhab.binding.groheondus.internal;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
1517
/**
1618
* @author Florian Schmidt and Arne Wohlert - Initial contribution
1719
*/
20+
@NonNullByDefault
1821
public class GroheOndusAccountConfiguration {
1922

20-
public String username;
21-
public String password;
23+
public String username = "";
24+
public String password = "";
2225
}

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/GroheOndusApplianceConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
*/
1313
package org.openhab.binding.groheondus.internal;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
1517
/**
1618
* @author Florian Schmidt and Arne Wohlert - Initial contribution
1719
*/
20+
@NonNullByDefault
1821
public class GroheOndusApplianceConfiguration {
1922

20-
public String applianceId;
23+
public String applianceId = "";
2124
public int roomId;
2225
public int locationId;
23-
public int pollingInterval;
26+
public int pollingInterval = 0;
2427
}

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/GroheOndusBindingConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public class GroheOndusBindingConstants {
3838
public static final String CHANNEL_BATTERY = "battery";
3939

4040
public static final String CHANNEL_CONFIG_TIMEFRAME = "timeframe";
41+
42+
public static final int DEFAULT_POLLING_INTERVAL = 900;
4143
}

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusAccountHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
7070

7171
@Override
7272
public void dispose() {
73-
if (ondusService != null) {
74-
ondusService = null;
75-
}
73+
this.ondusService = null;
74+
75+
ScheduledFuture<?> reloginFuture = this.reloginFuture;
7676
if (reloginFuture != null) {
7777
reloginFuture.cancel(true);
7878
}
@@ -81,7 +81,7 @@ public void dispose() {
8181

8282
private void login() {
8383
GroheOndusAccountConfiguration config = getConfigAs(GroheOndusAccountConfiguration.class);
84-
if (config.username == null || config.password == null) {
84+
if (config.username.isBlank() || config.password.isBlank()) {
8585
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
8686
"@text/error.login.missing.credentials");
8787
} else {

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusBaseHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
public abstract class GroheOndusBaseHandler<T extends BaseAppliance, M> extends BaseThingHandler {
4343
private final Logger logger = LoggerFactory.getLogger(GroheOndusBaseHandler.class);
4444

45-
protected @Nullable GroheOndusApplianceConfiguration config;
45+
protected @NonNullByDefault({}) GroheOndusApplianceConfiguration config;
4646

4747
private @Nullable ScheduledFuture<?> poller;
4848

@@ -154,7 +154,8 @@ protected Location getLocation() {
154154

155155
protected @Nullable T getAppliance(OndusService ondusService) {
156156
try {
157-
BaseAppliance appliance = ondusService.getAppliance(getRoom(), config.applianceId).orElse(null);
157+
BaseAppliance appliance = config.applianceId.isEmpty() ? null
158+
: ondusService.getAppliance(getRoom(), config.applianceId).orElse(null);
158159
if (appliance != null) {
159160
if (appliance.getType() != getType()) {
160161
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/error.wrongtype");

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusHandlerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
7474
onAccountCreated(thing, handler);
7575
return handler;
7676
} else if (THING_TYPE_SENSEGUARD.equals(thingTypeUID)) {
77-
return new GroheOndusSenseGuardHandler(thing, thingCounter++);
77+
return new GroheOndusSenseGuardHandler<>(thing, thingCounter++);
7878
} else if (THING_TYPE_SENSE.equals(thingTypeUID)) {
79-
return new GroheOndusSenseHandler(thing, thingCounter++);
79+
return new GroheOndusSenseHandler<>(thing, thingCounter++);
8080
}
8181

8282
return null;

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseGuardHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
*/
1313
package org.openhab.binding.groheondus.internal.handler;
1414

15-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_CONFIG_TIMEFRAME;
16-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_NAME;
17-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_PRESSURE;
18-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_TEMPERATURE_GUARD;
19-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_VALVE_OPEN;
20-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_WATERCONSUMPTION;
21-
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.CHANNEL_WATERCONSUMPTION_SINCE_MIDNIGHT;
15+
import static org.openhab.binding.groheondus.internal.GroheOndusBindingConstants.*;
2216

2317
import java.io.IOException;
2418
import java.math.BigDecimal;

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.eclipse.jdt.annotation.NonNullByDefault;
2929
import org.eclipse.jdt.annotation.Nullable;
30+
import org.openhab.binding.groheondus.internal.GroheOndusBindingConstants;
3031
import org.openhab.core.library.types.DecimalType;
3132
import org.openhab.core.library.types.QuantityType;
3233
import org.openhab.core.library.types.StringType;
@@ -56,8 +57,6 @@
5657
@NonNullByDefault
5758
public class GroheOndusSenseHandler<T, M> extends GroheOndusBaseHandler<Appliance, Measurement> {
5859

59-
private static final int DEFAULT_POLLING_INTERVAL = 900;
60-
6160
private final Logger logger = LoggerFactory.getLogger(GroheOndusSenseHandler.class);
6261

6362
public GroheOndusSenseHandler(Thing thing, int thingCounter) {
@@ -69,7 +68,7 @@ protected int getPollingInterval(Appliance appliance) {
6968
if (config.pollingInterval > 0) {
7069
return config.pollingInterval;
7170
}
72-
return DEFAULT_POLLING_INTERVAL;
71+
return GroheOndusBindingConstants.DEFAULT_POLLING_INTERVAL;
7372
}
7473

7574
@Override

0 commit comments

Comments
 (0)