[boschshc] Fix compiler warnings and SAT/Sonar issues (#18656)
* refactored code Signed-off-by: David Pace <dev@davidpace.de>pull/18690/head
parent
c6c63bd609
commit
05b095f4e1
|
@ -410,6 +410,7 @@ A keystore file with a self-signed certificate is created automatically.
|
||||||
This certificate is used for pairing between the Bridge and the Bosch Smart Home Controller.
|
This certificate is used for pairing between the Bridge and the Bosch Smart Home Controller.
|
||||||
|
|
||||||
On the Smart Home Controller Bridge, paring mode must be enabled after the `shc` Thing was created:
|
On the Smart Home Controller Bridge, paring mode must be enabled after the `shc` Thing was created:
|
||||||
|
|
||||||
- Smart Home Controller: _Press and hold the button until the LED starts blinking to enable pairing mode_.
|
- Smart Home Controller: _Press and hold the button until the LED starts blinking to enable pairing mode_.
|
||||||
- Smart Home Controller II: _Press the button briefly to enable pairing mode_.
|
- Smart Home Controller II: _Press the button briefly to enable pairing mode_.
|
||||||
|
|
||||||
|
|
|
@ -182,13 +182,15 @@ public class BoschShcCommandExtension extends AbstractConsoleCommandExtension im
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(String.format(" deviceID: %1s%n", device.id));
|
builder.append(String.format(" deviceID: %1s%n", device.id));
|
||||||
builder.append(String.format(" type: %1s -> ", device.deviceModel));
|
builder.append(String.format(" type: %1s -> ", device.deviceModel));
|
||||||
if (DEVICEMODEL_TO_THINGTYPE_MAP.containsKey(device.deviceModel)) {
|
|
||||||
builder.append(DEVICEMODEL_TO_THINGTYPE_MAP.get(device.deviceModel).getId());
|
ThingTypeUID thingTypeUID = DEVICEMODEL_TO_THINGTYPE_MAP.get(device.deviceModel);
|
||||||
|
if (thingTypeUID != null) {
|
||||||
|
builder.append(thingTypeUID.getId());
|
||||||
} else {
|
} else {
|
||||||
builder.append("!UNSUPPORTED!");
|
builder.append("!UNSUPPORTED!");
|
||||||
}
|
}
|
||||||
builder.append(String.format("%n"));
|
|
||||||
|
|
||||||
|
builder.append(String.format("%n"));
|
||||||
builder.append(buildDeviceServices(device.deviceServiceIds));
|
builder.append(buildDeviceServices(device.deviceServiceIds));
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
@ -260,9 +262,7 @@ public class BoschShcCommandExtension extends AbstractConsoleCommandExtension im
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
|
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
|
||||||
if (cursorArgumentIndex <= 0) {
|
return cursorArgumentIndex <= 0
|
||||||
return SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
|
&& SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,10 +166,6 @@ public abstract class BoschSHCDeviceHandler extends BoschSHCHandler {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String getBoschID() {
|
public @Nullable String getBoschID() {
|
||||||
if (config != null) {
|
return config != null ? config.id : null;
|
||||||
return config.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,6 @@ public class BoschSHCHandlerFactory extends BaseThingHandlerFactory {
|
||||||
|
|
||||||
// Search for mapping for thing type and return handler for it if found. Otherwise return null.
|
// Search for mapping for thing type and return handler for it if found. Otherwise return null.
|
||||||
return supportedThingTypes.stream().filter(mapping -> mapping.thingTypeUID.equals(thingTypeUID)).findFirst()
|
return supportedThingTypes.stream().filter(mapping -> mapping.thingTypeUID.equals(thingTypeUID)).findFirst()
|
||||||
.<@Nullable BaseThingHandler> map(mapping -> mapping.handlerSupplier.apply(thing)).orElse(null);
|
.map(mapping -> mapping.handlerSupplier.apply(thing)).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,6 @@ public class BoschSslUtil {
|
||||||
return keyStore;
|
return keyStore;
|
||||||
}
|
}
|
||||||
} catch (OperatorCreationException | GeneralSecurityException | IOException e) {
|
} catch (OperatorCreationException | GeneralSecurityException | IOException e) {
|
||||||
logger.debug("Exception during keystore creation {}", e.getMessage());
|
|
||||||
throw new PairingFailedException("Can not create or load keystore file: " + keystorePath
|
throw new PairingFailedException("Can not create or load keystore file: " + keystorePath
|
||||||
+ ". Check path, write access and JKS content.", e);
|
+ ". Check path, write access and JKS content.", e);
|
||||||
}
|
}
|
||||||
|
@ -154,7 +153,7 @@ public class BoschSslUtil {
|
||||||
logger.debug("Creating a new self signed certificate: {}", dirName);
|
logger.debug("Creating a new self signed certificate: {}", dirName);
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Date notBefore = Date.from(now);
|
final Date notBefore = Date.from(now);
|
||||||
final Date notAfter = Date.from(now.plus(Duration.ofDays(365 * 10)));
|
final Date notAfter = Date.from(now.plus(Duration.ofDays(365 * 10l)));
|
||||||
X500Name name = new X500Name(dirName);
|
X500Name name = new X500Name(dirName);
|
||||||
|
|
||||||
// create the certificate
|
// create the certificate
|
||||||
|
|
|
@ -38,18 +38,6 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class ShutterControlHandler extends BoschSHCDeviceHandler {
|
public class ShutterControlHandler extends BoschSHCDeviceHandler {
|
||||||
/**
|
|
||||||
* Utility functions to convert data between Bosch things and openHAB items
|
|
||||||
*/
|
|
||||||
static final class DataConversion {
|
|
||||||
public static int levelToOpenPercentage(double level) {
|
|
||||||
return (int) Math.round((1 - level) * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double openPercentageToLevel(double openPercentage) {
|
|
||||||
return (100 - openPercentage) / 100.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
@ -74,13 +62,13 @@ public class ShutterControlHandler extends BoschSHCDeviceHandler {
|
||||||
if (command instanceof UpDownType upDownCommand) {
|
if (command instanceof UpDownType upDownCommand) {
|
||||||
// Set full close/open as target state
|
// Set full close/open as target state
|
||||||
ShutterControlServiceState state = new ShutterControlServiceState();
|
ShutterControlServiceState state = new ShutterControlServiceState();
|
||||||
if (upDownCommand == UpDownType.UP) {
|
switch (upDownCommand) {
|
||||||
state.level = 1.0;
|
case UpDownType.UP -> state.level = 1.0;
|
||||||
} else if (upDownCommand == UpDownType.DOWN) {
|
case UpDownType.DOWN -> state.level = 0.0;
|
||||||
state.level = 0.0;
|
default -> {
|
||||||
} else {
|
logger.warn("Received unknown UpDownType command: {}", upDownCommand);
|
||||||
logger.warn("Received unknown UpDownType command: {}", upDownCommand);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
this.updateServiceState(this.shutterControlService, state);
|
this.updateServiceState(this.shutterControlService, state);
|
||||||
} else if (command instanceof StopMoveType stopMoveCommand) {
|
} else if (command instanceof StopMoveType stopMoveCommand) {
|
||||||
|
@ -92,16 +80,24 @@ public class ShutterControlHandler extends BoschSHCDeviceHandler {
|
||||||
}
|
}
|
||||||
} else if (command instanceof PercentType percentCommand) {
|
} else if (command instanceof PercentType percentCommand) {
|
||||||
// Set specific level
|
// Set specific level
|
||||||
double level = DataConversion.openPercentageToLevel(percentCommand.doubleValue());
|
double level = openPercentageToLevel(percentCommand.doubleValue());
|
||||||
this.updateServiceState(this.shutterControlService, new ShutterControlServiceState(level));
|
this.updateServiceState(this.shutterControlService, new ShutterControlServiceState(level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double openPercentageToLevel(double openPercentage) {
|
||||||
|
return (100 - openPercentage) / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateChannels(ShutterControlServiceState state) {
|
private void updateChannels(ShutterControlServiceState state) {
|
||||||
if (state.level != null) {
|
if (state.level != null) {
|
||||||
// Convert level to open ratio
|
// Convert level to open ratio
|
||||||
int openPercentage = DataConversion.levelToOpenPercentage(state.level);
|
int openPercentage = levelToOpenPercentage(state.level);
|
||||||
updateState(CHANNEL_LEVEL, new PercentType(openPercentage));
|
updateState(CHANNEL_LEVEL, new PercentType(openPercentage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int levelToOpenPercentage(double level) {
|
||||||
|
return (int) Math.round((1 - level) * 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -246,8 +245,7 @@ class BoschShcCommandExtensionTest {
|
||||||
.walk(Paths.get("src/main/java/org/openhab/binding/boschshc/internal/services").toAbsolutePath(), 1)
|
.walk(Paths.get("src/main/java/org/openhab/binding/boschshc/internal/services").toAbsolutePath(), 1)
|
||||||
.filter(Files::isDirectory).map(Path::getFileName).map(Path::toString)
|
.filter(Files::isDirectory).map(Path::getFileName).map(Path::toString)
|
||||||
// exclude folders which no service implementation
|
// exclude folders which no service implementation
|
||||||
.filter(name -> !name.equals("dto")).filter(name -> !name.equals("services")).sorted()
|
.filter(name -> !name.equals("dto")).filter(name -> !name.equals("services")).sorted().toList();
|
||||||
.collect(Collectors.toList());
|
|
||||||
assertThat(services, is(fixture.getAllBoschShcServices()));
|
assertThat(services, is(fixture.getAllBoschShcServices()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ public abstract class AbstractPowerSwitchHandlerWithPowerMeterTest<T extends Abs
|
||||||
private @Captor @NonNullByDefault({}) ArgumentCaptor<QuantityType<Energy>> energyCaptor;
|
private @Captor @NonNullByDefault({}) ArgumentCaptor<QuantityType<Energy>> energyCaptor;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@Override
|
||||||
public void beforeEach(TestInfo testInfo)
|
public void beforeEach(TestInfo testInfo)
|
||||||
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
|
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
|
||||||
PowerMeterServiceState powerMeterServiceState = new PowerMeterServiceState();
|
PowerMeterServiceState powerMeterServiceState = new PowerMeterServiceState();
|
||||||
|
|
Loading…
Reference in New Issue