Java 17 features (A-G) (#15516)

- add missing @override
- Java style array syntax
- remove redundant modifiers
- always move String constants to left side in comparisons
- simplify lambda expressions and return statements
- use replace instead of replaceAll w/o regex
- instanceof matching and multiline strings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2023-09-05 22:30:16 +02:00 committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
486 changed files with 2053 additions and 1955 deletions

View File

@ -14,7 +14,7 @@ package org.openhab.binding.adorne.internal.discovery;
import static org.openhab.binding.adorne.internal.AdorneBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -52,7 +52,7 @@ public class AdorneDiscoveryService extends AbstractDiscoveryService implements
*/
public AdorneDiscoveryService() {
// Passing false as last argument to super constructor turns off background discovery
super(Collections.singleton(new ThingTypeUID(BINDING_ID, "-")), DISCOVERY_TIMEOUT_SECONDS, false);
super(Set.of(new ThingTypeUID(BINDING_ID, "-")), DISCOVERY_TIMEOUT_SECONDS, false);
// We create the hub controller with default host and port. In the future we could let users create hubs
// manually with custom host and port settings and then perform discovery here for those hubs.
@ -76,10 +76,9 @@ public class AdorneDiscoveryService extends AbstractDiscoveryService implements
// Future enhancement: Need a timeout for each future execution to recover from bugs in the hub controller, but
// Java8 doesn't yet offer that
adorneHubController.start().thenCompose(Void -> {
// We use the hub's MAC address as its unique identifier
return adorneHubController.getMACAddress();
}).thenCompose(macAddress -> {
adorneHubController.start().thenCompose(Void ->
// We use the hub's MAC address as its unique identifier
adorneHubController.getMACAddress()).thenCompose(macAddress -> {
String macAddressNoColon = macAddress.replace(':', '-'); // Colons are not allowed in ThingUIDs
bridgeUID[0] = new ThingUID(THING_TYPE_HUB, macAddressNoColon);
// We have fully discovered the hub

View File

@ -50,10 +50,10 @@ public class AdorneDimmerHandler extends AdorneSwitchHandler {
if (channelUID.getId().equals(CHANNEL_BRIGHTNESS)) {
if (command instanceof RefreshType) {
refreshBrightness();
} else if (command instanceof PercentType) {
} else if (command instanceof PercentType percentCommand) {
// Change the brightness through the hub controller
AdorneHubController adorneHubController = getAdorneHubController();
int level = ((PercentType) command).intValue();
int level = percentCommand.intValue();
if (level >= 1 && level <= 100) { // Ignore commands outside of the supported 1-100 range
adorneHubController.setBrightness(zoneId, level);
} else {

View File

@ -86,8 +86,8 @@ public class AdorneHubConnection {
return null; // Eat empty messages
}
logger.debug("Received message {}", msg);
if (msg instanceof JsonObject) {
msgJsonObject = (JsonObject) msg;
if (msg instanceof JsonObject object) {
msgJsonObject = object;
}
return msgJsonObject;
}

View File

@ -81,7 +81,7 @@ final class AhaCollectionScheduleImpl implements AhaCollectionSchedule {
final Elements table = doc.select("table");
if (table.size() == 0) {
if (table.isEmpty()) {
logger.warn("No result table found.");
return Collections.emptyMap();
}
@ -91,7 +91,7 @@ final class AhaCollectionScheduleImpl implements AhaCollectionSchedule {
while (rowIt.hasNext()) {
final Element currentRow = rowIt.next();
if (!currentRow.tagName().equals("tr")) {
if (!"tr".equals(currentRow.tagName())) {
continue;
}
// Skip header, empty and download button rows.

View File

@ -14,7 +14,6 @@ package org.openhab.binding.airq.internal;
import static org.openhab.binding.airq.internal.AirqBindingConstants.THING_TYPE_AIRQ;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -38,7 +37,7 @@ import org.osgi.service.component.annotations.Reference;
@Component(configurationPid = "binding.airq", service = ThingHandlerFactory.class)
public class AirqHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AIRQ);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AIRQ);
private final HttpClientFactory httpClientFactory;
@Activate

View File

@ -64,12 +64,12 @@ public enum Pollutant {
new ConcentrationRange(205, 404, TWO_HUNDRED), new ConcentrationRange(405, 504, THREE_HUNDRED),
new ConcentrationRange(505, 604, FOUR_HUNDRED));
public static enum SensitiveGroup {
public enum SensitiveGroup {
RESPIRATORY,
HEART,
ELDERLY,
CHILDREN,
ASTHMA;
ASTHMA
}
public final Set<SensitiveGroup> sensitiveGroups;

View File

@ -22,11 +22,11 @@ import com.google.gson.annotations.SerializedName;
* @author Gaël L'hopital - Initial contribution
*/
public class ResponseRoot {
public static enum ResponseStatus {
public enum ResponseStatus {
@SerializedName("error")
ERROR,
@SerializedName("ok")
OK;
OK
}
protected ResponseStatus status = ResponseStatus.OK;

View File

@ -28,8 +28,7 @@ public class SensitiveGroupConfiguration {
public @Nullable SensitiveGroup asSensitiveGroup() {
try {
SensitiveGroup value = SensitiveGroup.valueOf(group);
return value;
return SensitiveGroup.valueOf(group);
} catch (IllegalArgumentException e) {
return null;
}

View File

@ -15,7 +15,6 @@ package org.openhab.binding.airquality.internal.discovery;
import static org.openhab.binding.airquality.internal.AirQualityBindingConstants.*;
import static org.openhab.binding.airquality.internal.config.AirQualityConfiguration.LOCATION;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -43,7 +42,7 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class AirQualityDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService {
private static final int DISCOVER_TIMEOUT_SECONDS = 2;
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_STATION);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_STATION);
private final Logger logger = LoggerFactory.getLogger(AirQualityDiscoveryService.class);
@ -59,9 +58,8 @@ public class AirQualityDiscoveryService extends AbstractDiscoveryService impleme
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof AirQualityBridgeHandler) {
final AirQualityBridgeHandler bridgeHandler = (AirQualityBridgeHandler) handler;
this.bridgeHandler = bridgeHandler;
if (handler instanceof AirQualityBridgeHandler bridgeHandlerInstance) {
this.bridgeHandler = bridgeHandlerInstance;
this.locationProvider = bridgeHandler.getLocationProvider();
}
}

View File

@ -12,9 +12,6 @@
*/
package org.openhab.binding.airvisualnode.internal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -51,12 +48,10 @@ public class AirVisualNodeBindingConstants {
.getUID().getId();
// List of all supported Thing UIDs
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_AVNODE)));
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AVNODE);
// List of all supported Channel ids
public static final Set<String> SUPPORTED_CHANNEL_IDS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(CHANNEL_CO2, CHANNEL_HUMIDITY, CHANNEL_AQI_US, CHANNEL_PM_25,
CHANNEL_PM_10, CHANNEL_PM_01, CHANNEL_TEMP_CELSIUS, CHANNEL_BATTERY_LEVEL, CHANNEL_WIFI_STRENGTH,
CHANNEL_TIMESTAMP, CHANNEL_USED_MEMORY)));
public static final Set<String> SUPPORTED_CHANNEL_IDS = Set.of(CHANNEL_CO2, CHANNEL_HUMIDITY, CHANNEL_AQI_US,
CHANNEL_PM_25, CHANNEL_PM_10, CHANNEL_PM_01, CHANNEL_TEMP_CELSIUS, CHANNEL_BATTERY_LEVEL,
CHANNEL_WIFI_STRENGTH, CHANNEL_TIMESTAMP, CHANNEL_USED_MEMORY);
}

View File

@ -14,7 +14,7 @@ package org.openhab.binding.airvisualnode.internal.discovery;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
@ -55,7 +55,7 @@ public class AirVisualNodeDiscoveryService extends AbstractDiscoveryService {
private @Nullable ScheduledFuture<?> backgroundDiscoveryFuture;
public AirVisualNodeDiscoveryService() {
super(Collections.singleton(AirVisualNodeBindingConstants.THING_TYPE_AVNODE), 600, true);
super(Set.of(AirVisualNodeBindingConstants.THING_TYPE_AVNODE), 600, true);
}
@Override

View File

@ -49,6 +49,7 @@ public class Measurements implements MeasurementsInterface {
this.vocPpb = vocPpb;
}
@Override
public int getCo2Ppm() {
return co2Ppm;
}
@ -57,6 +58,7 @@ public class Measurements implements MeasurementsInterface {
this.co2Ppm = co2Ppm;
}
@Override
public int getHumidityRH() {
return humidityRH;
}
@ -65,6 +67,7 @@ public class Measurements implements MeasurementsInterface {
this.humidityRH = humidityRH;
}
@Override
public int getPm25AQICN() {
return pm25AQICN;
}
@ -73,6 +76,7 @@ public class Measurements implements MeasurementsInterface {
this.pm25AQICN = pm25AQICN;
}
@Override
public int getPm25AQIUS() {
return pm25AQIUS;
}
@ -91,6 +95,7 @@ public class Measurements implements MeasurementsInterface {
return 0;
}
@Override
public float getPm25Ugm3() {
return pm25Ugm3;
}
@ -99,6 +104,7 @@ public class Measurements implements MeasurementsInterface {
this.pm25Ugm3 = pm25Ugm3;
}
@Override
public float getTemperatureC() {
return temperatureC;
}
@ -107,6 +113,7 @@ public class Measurements implements MeasurementsInterface {
this.temperatureC = temperatureC;
}
@Override
public float getTemperatureF() {
return temperatureF;
}
@ -115,6 +122,7 @@ public class Measurements implements MeasurementsInterface {
this.temperatureF = temperatureF;
}
@Override
public int getVocPpb() {
return vocPpb;
}

View File

@ -40,6 +40,7 @@ public class NodeData implements NodeDataInterface {
this.status = status;
}
@Override
public DateAndTime getDateAndTime() {
return dateAndTime;
}
@ -48,6 +49,7 @@ public class NodeData implements NodeDataInterface {
this.dateAndTime = dateAndTime;
}
@Override
public MeasurementsInterface getMeasurements() {
return measurements;
}
@ -56,6 +58,7 @@ public class NodeData implements NodeDataInterface {
this.measurements = measurements;
}
@Override
public String getSerialNumber() {
return serialNumber;
}
@ -64,6 +67,7 @@ public class NodeData implements NodeDataInterface {
this.serialNumber = serialNumber;
}
@Override
public Settings getSettings() {
return settings;
}
@ -72,6 +76,7 @@ public class NodeData implements NodeDataInterface {
this.settings = settings;
}
@Override
public Status getStatus() {
return status;
}

View File

@ -66,6 +66,7 @@ public class Measurements implements MeasurementsInterface {
this.vocPpb = vocPpb;
}
@Override
public int getCo2Ppm() {
return co2Ppm;
}
@ -74,6 +75,7 @@ public class Measurements implements MeasurementsInterface {
this.co2Ppm = co2Ppm;
}
@Override
public int getHumidityRH() {
return humidityRH;
}
@ -82,6 +84,7 @@ public class Measurements implements MeasurementsInterface {
this.humidityRH = humidityRH;
}
@Override
public int getPm25AQICN() {
return pm25AQICN;
}
@ -90,6 +93,7 @@ public class Measurements implements MeasurementsInterface {
this.pm25AQICN = pm25AQICN;
}
@Override
public int getPm25AQIUS() {
return pm25AQIUS;
}
@ -98,6 +102,7 @@ public class Measurements implements MeasurementsInterface {
this.pm25AQIUS = pm25AQIUS;
}
@Override
public float getPm01Ugm3() {
return pm01Ugm3;
}
@ -106,6 +111,7 @@ public class Measurements implements MeasurementsInterface {
this.pm01Ugm3 = pm01Ugm3;
}
@Override
public float getPm10Ugm3() {
return pm10Ugm3;
}
@ -114,6 +120,7 @@ public class Measurements implements MeasurementsInterface {
this.pm10Ugm3 = pm10Ugm3;
}
@Override
public float getPm25Ugm3() {
return pm25Ugm3;
}
@ -122,6 +129,7 @@ public class Measurements implements MeasurementsInterface {
this.pm25Ugm3 = pm25Ugm3;
}
@Override
public float getTemperatureC() {
return temperatureC;
}
@ -130,6 +138,7 @@ public class Measurements implements MeasurementsInterface {
this.temperatureC = temperatureC;
}
@Override
public float getTemperatureF() {
return temperatureF;
}
@ -138,6 +147,7 @@ public class Measurements implements MeasurementsInterface {
this.temperatureF = temperatureF;
}
@Override
public int getVocPpb() {
return vocPpb;
}

View File

@ -44,6 +44,7 @@ public class ProNodeData implements NodeDataInterface {
this.status = status;
}
@Override
public DateAndTime getDateAndTime() {
return dateAndTime;
}
@ -52,6 +53,7 @@ public class ProNodeData implements NodeDataInterface {
this.dateAndTime = dateAndTime;
}
@Override
public MeasurementsInterface getMeasurements() {
return measurements.get(0);
}
@ -60,6 +62,7 @@ public class ProNodeData implements NodeDataInterface {
this.measurements = measurements;
}
@Override
public String getSerialNumber() {
return serialNumber;
}
@ -68,6 +71,7 @@ public class ProNodeData implements NodeDataInterface {
this.serialNumber = serialNumber;
}
@Override
public Settings getSettings() {
return settings;
}
@ -76,6 +80,7 @@ public class ProNodeData implements NodeDataInterface {
this.settings = settings;
}
@Override
public Status getStatus() {
return status;
}

View File

@ -42,8 +42,8 @@ public class BridgeActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof ADBridgeHandler) {
this.bridge = (ADBridgeHandler) handler;
if (handler instanceof ADBridgeHandler bridgeHandler) {
this.bridge = bridgeHandler;
}
}

View File

@ -20,8 +20,8 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -87,7 +87,7 @@ public abstract class ADBridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(BridgeActions.class);
return List.of(BridgeActions.class);
}
public void setDiscoveryService(AlarmDecoderDiscoveryService discoveryService) {

View File

@ -113,13 +113,13 @@ public class KeypadHandler extends ADThingHandler {
IntCommandMap intCommandMap = this.intCommandMap;
if (channelUID.getId().equals(CHANNEL_KP_COMMAND)) {
if (command instanceof StringType) {
String cmd = ((StringType) command).toString();
if (command instanceof StringType commandString) {
String cmd = commandString.toString();
handleKeypadCommand(cmd);
}
} else if (channelUID.getId().equals(CHANNEL_KP_INTCOMMAND)) {
if (command instanceof Number) {
int icmd = ((Number) command).intValue();
if (command instanceof Number numberCommand) {
int icmd = numberCommand.intValue();
if (intCommandMap != null) {
String cmd = intCommandMap.getCommand(icmd);
if (cmd != null) {

View File

@ -78,8 +78,8 @@ public class VZoneHandler extends ADThingHandler {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals(CHANNEL_COMMAND)) {
if (command instanceof StringType) {
String cmd = ((StringType) command).toString();
if (command instanceof StringType stringCommand) {
String cmd = stringCommand.toString();
if (CMD_OPEN.equalsIgnoreCase(cmd)) {
sendCommand(ADCommand.setZone(config.address, ADCommand.ZONE_OPEN));
setChannelState(OnOffType.OFF);

View File

@ -46,7 +46,7 @@ public class ZoneHandler extends ADThingHandler {
}
/** Construct zone id from address and channel */
public static final String zoneID(int address, int channel) {
public static String zoneID(int address, int channel) {
return String.format("%d-%d", address, channel);
}

View File

@ -40,7 +40,7 @@ public class EXPMessage extends ADMessage {
public EXPMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in EXP message");
}

View File

@ -143,8 +143,7 @@ public class KeypadMessage extends ADMessage {
return false;
} else if (this == obj) {
return true;
} else if (obj instanceof KeypadMessage) {
KeypadMessage other = (KeypadMessage) obj;
} else if (obj instanceof KeypadMessage other) {
return this.message.equals(other.message);
} else {
return false;

View File

@ -43,7 +43,7 @@ public class LRRMessage extends ADMessage {
public LRRMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("multiple colons in LRR message");
}

View File

@ -43,7 +43,7 @@ public class RFXMessage extends ADMessage {
public RFXMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in RFX message");
}

View File

@ -38,7 +38,7 @@ public class VersionMessage extends ADMessage {
public VersionMessage(String message) throws IllegalArgumentException {
super(message);
String topLevel[] = message.split(":");
String[] topLevel = message.split(":");
if (topLevel.length != 2) {
throw new IllegalArgumentException("Multiple colons found in VER message");
}

View File

@ -63,9 +63,9 @@ public class AllPlayBindingProperties {
private int getIntegerProperty(Dictionary<String, Object> properties, String propertyKey, int defaultValue) {
Object configValue = properties.get(propertyKey);
int value = defaultValue;
if (configValue instanceof String) {
if (configValue instanceof String stringValue) {
try {
value = Integer.parseInt((String) configValue);
value = Integer.parseInt(stringValue);
} catch (NumberFormatException e) {
logger.warn("Unable to convert value {} for config property {} to integer. Using default value.",
configValue, propertyKey);

View File

@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal;
import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Map;
@ -54,7 +53,7 @@ public class AllPlayHandlerFactory extends BaseThingHandlerFactory {
private final Logger logger = LoggerFactory.getLogger(AllPlayHandlerFactory.class);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE);
private final Map<String, ServiceRegistration<AudioSink>> audioSinkRegistrations = new ConcurrentHashMap<>();
private AllPlay allPlay;

View File

@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal.discovery;
import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -46,7 +45,7 @@ public class AllPlaySpeakerDiscoveryService extends AbstractDiscoveryService imp
private final Logger logger = LoggerFactory.getLogger(AllPlaySpeakerDiscoveryService.class);
private static final int DISCOVERY_TIMEOUT = 30;
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE);
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE);
private AllPlay allPlay;
public AllPlaySpeakerDiscoveryService() {

View File

@ -343,8 +343,8 @@ public class AllPlayHandler extends BaseThingHandler
* @throws SpeakerException Exception if the volume change failed
*/
public void handleVolumeCommand(Command command) throws SpeakerException {
if (command instanceof PercentType) {
speaker.volume().setVolume(convertPercentToAbsoluteVolume((PercentType) command));
if (command instanceof PercentType percentCommand) {
speaker.volume().setVolume(convertPercentToAbsoluteVolume(percentCommand));
} else if (command instanceof IncreaseDecreaseType) {
int stepSize = (command == IncreaseDecreaseType.DECREASE ? -getVolumeStepSize() : getVolumeStepSize());
speaker.volume().adjustVolume(stepSize);

View File

@ -14,7 +14,6 @@ package org.openhab.binding.amazondashbutton.internal;
import static org.openhab.binding.amazondashbutton.internal.AmazonDashButtonBindingConstants.DASH_BUTTON_THING_TYPE;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.amazondashbutton.internal.handler.AmazonDashButtonHandler;
@ -34,7 +33,7 @@ import org.osgi.service.component.annotations.Component;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.amazondashbutton")
public class AmazonDashButtonHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(DASH_BUTTON_THING_TYPE);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(DASH_BUTTON_THING_TYPE);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {

View File

@ -15,7 +15,6 @@ package org.openhab.binding.amazondashbutton.internal.discovery;
import static org.openhab.binding.amazondashbutton.internal.AmazonDashButtonBindingConstants.*;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -108,7 +107,7 @@ public class AmazonDashButtonDiscoveryService extends AbstractDiscoveryService i
private boolean backgroundScanning = false;
public AmazonDashButtonDiscoveryService() {
super(Collections.singleton(DASH_BUTTON_THING_TYPE), DISCOVER_TIMEOUT_SECONDS, false);
super(Set.of(DASH_BUTTON_THING_TYPE), DISCOVER_TIMEOUT_SECONDS, false);
}
@Override

View File

@ -36,9 +36,8 @@ public class PcapUtil {
*/
public static Set<PcapNetworkInterfaceWrapper> getAllNetworkInterfaces() {
try {
final Set<PcapNetworkInterfaceWrapper> allNetworkInterfaces = Collections.unmodifiableSet(Pcaps
.findAllDevs().stream().map(PcapNetworkInterfaceWrapper.TRANSFORMER).collect(Collectors.toSet()));
return allNetworkInterfaces;
return Collections.unmodifiableSet(Pcaps.findAllDevs().stream().map(PcapNetworkInterfaceWrapper.TRANSFORMER)
.collect(Collectors.toSet()));
} catch (PcapNativeException e) {
throw new RuntimeException(e);
}

View File

@ -146,10 +146,10 @@ public class AmazonEchoControlHandlerFactory extends BaseThingHandlerFactory {
.getService(serviceReg.getReference());
serviceReg.unregister();
if (service != null) {
if (service instanceof AmazonEchoDiscovery) {
((AmazonEchoDiscovery) service).deactivate();
} else if (service instanceof SmartHomeDevicesDiscovery) {
((SmartHomeDevicesDiscovery) service).deactivate();
if (service instanceof AmazonEchoDiscovery discovery) {
discovery.deactivate();
} else if (service instanceof SmartHomeDevicesDiscovery discovery) {
discovery.deactivate();
} else {
logger.warn("Found unknown discovery-service instance: {}", service);
}

View File

@ -49,8 +49,8 @@ public class ChannelHandlerAnnouncement extends ChannelHandler {
public boolean tryHandleCommand(Device device, Connection connection, String channelId, Command command)
throws IOException, URISyntaxException {
if (channelId.equals(CHANNEL_NAME)) {
if (command instanceof StringType) {
String commandValue = ((StringType) command).toFullString();
if (command instanceof StringType stringCommand) {
String commandValue = stringCommand.toFullString();
String body = commandValue;
String title = null;
String speak = commandValue;

View File

@ -26,6 +26,7 @@ import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device;
*/
@NonNullByDefault
public interface IEchoThingHandler extends IAmazonThingHandler {
@Override
void startAnnouncement(Device device, String speak, String bodyText, @Nullable String title,
@Nullable Integer volume) throws IOException, URISyntaxException;
}

View File

@ -143,8 +143,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
String deviceName = null;
Map<String, Object> props = new HashMap<>();
if (smartHomeDevice instanceof SmartHomeDevice) {
SmartHomeDevice shd = (SmartHomeDevice) smartHomeDevice;
if (smartHomeDevice instanceof SmartHomeDevice shd) {
logger.trace("Found SmartHome device: {}", shd);
String entityId = shd.entityId;
@ -165,7 +164,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
// Connected through skill
continue;
}
if (!(smartHomeDeviceDiscoveryMode == 2) && "openHAB".equalsIgnoreCase(shd.manufacturerName)) {
if (smartHomeDeviceDiscoveryMode != 2 && "openHAB".equalsIgnoreCase(shd.manufacturerName)) {
// OpenHAB device
continue;
}
@ -203,8 +202,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
deviceName = shd.friendlyName;
}
props.put(DEVICE_PROPERTY_ID, id);
} else if (smartHomeDevice instanceof SmartHomeGroup) {
SmartHomeGroup shg = (SmartHomeGroup) smartHomeDevice;
} else if (smartHomeDevice instanceof SmartHomeGroup shg) {
logger.trace("Found SmartHome device: {}", shg);
String id = shg.findId();

View File

@ -821,8 +821,7 @@ public class AccountHandler extends BaseBridgeHandler implements IWebSocketComma
// create new id map
Map<String, SmartHomeBaseDevice> newJsonIdSmartHomeDeviceMapping = new HashMap<>();
for (Object smartHomeDevice : smartHomeDevices) {
if (smartHomeDevice instanceof SmartHomeBaseDevice) {
SmartHomeBaseDevice smartHomeBaseDevice = (SmartHomeBaseDevice) smartHomeDevice;
if (smartHomeDevice instanceof SmartHomeBaseDevice smartHomeBaseDevice) {
String id = smartHomeBaseDevice.findId();
if (id != null) {
newJsonIdSmartHomeDeviceMapping.put(id, smartHomeBaseDevice);

View File

@ -293,8 +293,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
}
// Notification commands
if (channelId.equals(CHANNEL_NOTIFICATION_VOLUME)) {
if (command instanceof PercentType) {
int volume = ((PercentType) command).intValue();
if (command instanceof PercentType percentCommand) {
int volume = percentCommand.intValue();
connection.notificationVolume(device, volume);
this.notificationVolumeLevel = volume;
waitForUpdate = -1;
@ -318,21 +318,18 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
// Media progress commands
Long mediaPosition = null;
if (channelId.equals(CHANNEL_MEDIA_PROGRESS)) {
if (command instanceof PercentType) {
PercentType value = (PercentType) command;
int percent = value.intValue();
if (command instanceof PercentType percentCommand) {
int percent = percentCommand.intValue();
mediaPosition = Math.round((mediaLengthMs / 1000d) * (percent / 100d));
}
}
if (channelId.equals(CHANNEL_MEDIA_PROGRESS_TIME)) {
if (command instanceof DecimalType) {
DecimalType value = (DecimalType) command;
mediaPosition = value.longValue();
if (command instanceof DecimalType decimalCommand) {
mediaPosition = decimalCommand.longValue();
}
if (command instanceof QuantityType<?>) {
QuantityType<?> value = (QuantityType<?>) command;
if (command instanceof QuantityType<?> quantityCommand) {
@Nullable
QuantityType<?> seconds = value.toUnit(Units.SECOND);
QuantityType<?> seconds = quantityCommand.toUnit(Units.SECOND);
if (seconds != null) {
mediaPosition = seconds.longValue();
}
@ -353,9 +350,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
// Volume commands
if (channelId.equals(CHANNEL_VOLUME)) {
Integer volume = null;
if (command instanceof PercentType) {
PercentType value = (PercentType) command;
volume = value.intValue();
if (command instanceof PercentType percentCommand) {
volume = percentCommand.intValue();
} else if (command == OnOffType.OFF) {
volume = 0;
} else if (command == OnOffType.ON) {
@ -393,8 +389,7 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
// shuffle command
if (channelId.equals(CHANNEL_SHUFFLE)) {
if (command instanceof OnOffType) {
OnOffType value = (OnOffType) command;
if (command instanceof OnOffType value) {
connection.command(device, "{\"type\":\"ShuffleCommand\",\"shuffle\":\""
+ (value == OnOffType.ON ? "true" : "false") + "\"}");
@ -429,8 +424,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
// bluetooth commands
if (channelId.equals(CHANNEL_BLUETOOTH_MAC)) {
needBluetoothRefresh = true;
if (command instanceof StringType) {
String address = ((StringType) command).toFullString();
if (command instanceof StringType stringCommand) {
String address = stringCommand.toFullString();
if (!address.isEmpty()) {
waitForUpdate = 4000;
}
@ -566,9 +561,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
}
}
if (channelId.equals(CHANNEL_TEXT_TO_SPEECH_VOLUME)) {
if (command instanceof PercentType) {
PercentType value = (PercentType) command;
textToSpeechVolume = value.intValue();
if (command instanceof PercentType percentCommand) {
textToSpeechVolume = percentCommand.intValue();
} else if (command == OnOffType.OFF) {
textToSpeechVolume = 0;
} else if (command == OnOffType.ON) {
@ -680,8 +674,7 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
if (command instanceof RefreshType) {
this.lastKnownEqualizer = null;
}
if (command instanceof DecimalType) {
DecimalType value = (DecimalType) command;
if (command instanceof DecimalType decimalCommand) {
if (this.lastKnownEqualizer == null) {
updateEqualizerState();
}
@ -689,13 +682,13 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler {
if (lastKnownEqualizer != null) {
JsonEqualizer newEqualizerSetting = lastKnownEqualizer.createClone();
if (channelId.equals(CHANNEL_EQUALIZER_BASS)) {
newEqualizerSetting.bass = value.intValue();
newEqualizerSetting.bass = decimalCommand.intValue();
}
if (channelId.equals(CHANNEL_EQUALIZER_MIDRANGE)) {
newEqualizerSetting.mid = value.intValue();
newEqualizerSetting.mid = decimalCommand.intValue();
}
if (channelId.equals(CHANNEL_EQUALIZER_TREBLE)) {
newEqualizerSetting.treble = value.intValue();
newEqualizerSetting.treble = decimalCommand.intValue();
}
try {
connection.setEqualizer(device, newEqualizerSetting);

View File

@ -191,8 +191,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
boolean stateFound = false;
Map<String, List<JsonObject>> mapInterfaceToStates = new HashMap<>();
SmartHomeDevice firstDevice = null;
for (SmartHomeDevice shd : getSupportedSmartHomeDevices(smartHomeBaseDevice, allDevices)) {
String applianceId = shd.applianceId;
for (SmartHomeDevice smartHomeDevice : getSupportedSmartHomeDevices(smartHomeBaseDevice, allDevices)) {
String applianceId = smartHomeDevice.applianceId;
if (applianceId == null) {
continue;
}
@ -210,7 +210,7 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
}
}
if (firstDevice == null) {
firstDevice = shd;
firstDevice = smartHomeDevice;
}
for (JsonElement stateElement : states) {
String stateJson = stateElement.getAsString();
@ -240,9 +240,9 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
}
}
if (result.needSingleUpdate && smartHomeBaseDevice instanceof SmartHomeDevice && accountHandler != null) {
SmartHomeDevice shd = (SmartHomeDevice) smartHomeBaseDevice;
accountHandler.forceDelayedSmartHomeStateUpdate(shd.findId());
if (result.needSingleUpdate && smartHomeBaseDevice instanceof SmartHomeDevice smartHomeDevice
&& accountHandler != null) {
accountHandler.forceDelayedSmartHomeStateUpdate(smartHomeDevice.findId());
}
}
@ -257,8 +257,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
Bridge bridge = getBridge();
if (bridge != null) {
BridgeHandler bridgeHandler = bridge.getHandler();
if (bridgeHandler instanceof AccountHandler) {
return (AccountHandler) bridgeHandler;
if (bridgeHandler instanceof AccountHandler accountHandler) {
return accountHandler;
}
}
@ -297,17 +297,17 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
if (handlerBase == null || !handlerBase.hasChannel(channelId)) {
continue;
}
for (SmartHomeDevice shd : devices) {
String entityId = shd.entityId;
for (SmartHomeDevice smartHomeDevice : devices) {
String entityId = smartHomeDevice.entityId;
if (entityId == null) {
continue;
}
accountHandler.forceDelayedSmartHomeStateUpdate(getId()); // block updates
if (handlerBase.handleCommand(connection, shd, entityId, shd.getCapabilities(), channelUID.getId(),
command)) {
if (handlerBase.handleCommand(connection, smartHomeDevice, entityId,
smartHomeDevice.getCapabilities(), channelUID.getId(), command)) {
accountHandler.forceDelayedSmartHomeStateUpdate(getId()); // force update again to restart
// update timer
logger.debug("Command {} sent to {}", command, shd.findId());
logger.debug("Command {} sent to {}", command, smartHomeDevice.findId());
}
}
}
@ -318,9 +318,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
private static void getCapabilities(Map<String, List<SmartHomeCapability>> result, AccountHandler accountHandler,
SmartHomeBaseDevice device) {
if (device instanceof SmartHomeDevice) {
SmartHomeDevice shd = (SmartHomeDevice) device;
for (SmartHomeCapability capability : shd.getCapabilities()) {
if (device instanceof SmartHomeDevice smartHomeDevice) {
for (SmartHomeCapability capability : smartHomeDevice.getCapabilities()) {
String interfaceName = capability.interfaceName;
if (interfaceName != null) {
Objects.requireNonNull(result.computeIfAbsent(interfaceName, name -> new ArrayList<>()))
@ -329,9 +328,9 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
}
}
if (device instanceof SmartHomeGroup) {
for (SmartHomeDevice shd : getSupportedSmartHomeDevices(device,
for (SmartHomeDevice smartHomeDevice : getSupportedSmartHomeDevices(device,
accountHandler.getLastKnownSmartHomeDevices())) {
getCapabilities(result, accountHandler, shd);
getCapabilities(result, accountHandler, smartHomeDevice);
}
}
}
@ -342,29 +341,28 @@ public class SmartHomeDeviceHandler extends BaseThingHandler {
return Collections.emptySet();
}
Set<SmartHomeDevice> result = new HashSet<>();
if (baseDevice instanceof SmartHomeDevice) {
SmartHomeDevice shd = (SmartHomeDevice) baseDevice;
if (shd.getCapabilities().stream().map(capability -> capability.interfaceName)
if (baseDevice instanceof SmartHomeDevice smartHomeDevice) {
if (smartHomeDevice.getCapabilities().stream().map(capability -> capability.interfaceName)
.anyMatch(SUPPORTED_INTERFACES::contains)) {
result.add(shd);
result.add(smartHomeDevice);
}
} else {
SmartHomeGroup shg = (SmartHomeGroup) baseDevice;
SmartHomeGroup smartHomeGroup = (SmartHomeGroup) baseDevice;
for (SmartHomeBaseDevice device : allDevices) {
if (device instanceof SmartHomeDevice) {
SmartHomeDevice shd = (SmartHomeDevice) device;
JsonSmartHomeTags.JsonSmartHomeTag tags = shd.tags;
if (device instanceof SmartHomeDevice smartHomeDevice) {
JsonSmartHomeTags.JsonSmartHomeTag tags = smartHomeDevice.tags;
if (tags != null) {
JsonSmartHomeGroupIdentity.SmartHomeGroupIdentity tagNameToValueSetMap = tags.tagNameToValueSetMap;
JsonSmartHomeGroupIdentifiers.SmartHomeGroupIdentifier applianceGroupIdentifier = shg.applianceGroupIdentifier;
JsonSmartHomeGroupIdentifiers.SmartHomeGroupIdentifier applianceGroupIdentifier = smartHomeGroup.applianceGroupIdentifier;
if (tagNameToValueSetMap != null) {
List<String> groupIdentity = Objects.requireNonNullElse(tagNameToValueSetMap.groupIdentity,
List.of());
if (applianceGroupIdentifier != null && applianceGroupIdentifier.value != null
&& groupIdentity.contains(applianceGroupIdentifier.value)) {
if (shd.getCapabilities().stream().map(capability -> capability.interfaceName)
if (smartHomeDevice.getCapabilities().stream()
.map(capability -> capability.interfaceName)
.anyMatch(SUPPORTED_INTERFACES::contains)) {
result.add(shd);
result.add(smartHomeDevice);
}
}
}

View File

@ -55,11 +55,10 @@ public class DynamicStateDescriptionSmartHome implements DynamicStateDescription
return null;
}
ThingHandler handler = thing.getHandler();
if (!(handler instanceof SmartHomeDeviceHandler)) {
return null;
if (handler instanceof SmartHomeDeviceHandler smartHomeHandler) {
return smartHomeHandler;
}
SmartHomeDeviceHandler smartHomeHandler = (SmartHomeDeviceHandler) handler;
return smartHomeHandler;
return null;
}
@Override

View File

@ -263,11 +263,10 @@ public class AmbientWeatherEventListener {
private void handleError(String event, Object... args) {
String reason = "Unknown";
if (args.length > 0) {
if (args[0] instanceof String) {
reason = (String) args[0];
} else if (args[0] instanceof Exception) {
reason = String.format("Exception=%s Message=%s", args[0].getClass(),
((Exception) args[0]).getMessage());
if (args[0] instanceof String stringArg) {
reason = stringArg;
} else if (args[0] instanceof Exception exception) {
reason = String.format("Exception=%s Message=%s", args[0].getClass(), exception.getMessage());
}
}
logger.debug("Listener: Received socket event: {}, Reason: {}", event, reason);

View File

@ -39,7 +39,7 @@ public enum StreamCommand {
@Override
public String toString() {
return String.valueOf(value);
return value;
}
public static StreamCommand fromValue(String value) {

View File

@ -109,8 +109,8 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
}
break;
case AmpliPiBindingConstants.CHANNEL_VOLUME:
if (command instanceof PercentType) {
update.setVolDelta(AmpliPiUtils.percentTypeToVolume((PercentType) command));
if (command instanceof PercentType percentCommand) {
update.setVolDelta(AmpliPiUtils.percentTypeToVolume(percentCommand));
} else if (command instanceof IncreaseDecreaseType) {
if (groupState != null) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
@ -125,14 +125,13 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
}
break;
case AmpliPiBindingConstants.CHANNEL_SOURCE:
if (command instanceof DecimalType) {
update.setSourceId(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
update.setSourceId(decimalCommand.intValue());
}
break;
}
if (bridgeHandler != null) {
String url = bridgeHandler.getUrl() + "/api/groups/" + getId(thing);
;
StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update));
try {
ContentResponse response = httpClient.newRequest(url).method(HttpMethod.PATCH)

View File

@ -99,12 +99,11 @@ public class AmpliPiHandler extends BaseBridgeHandler {
if (CHANNEL_PRESET.equals(channelUID.getId())) {
if (command instanceof RefreshType) {
updateState(channelUID, UnDefType.NULL);
} else if (command instanceof DecimalType) {
DecimalType preset = (DecimalType) command;
} else if (command instanceof DecimalType decimalCommand) {
try {
ContentResponse response = this.httpClient
.newRequest(url + "/api/presets/" + preset.intValue() + "/load").method(HttpMethod.POST)
.timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send();
.newRequest(url + "/api/presets/" + decimalCommand.intValue() + "/load")
.method(HttpMethod.POST).timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send();
if (response.getStatus() != HttpStatus.OK_200) {
logger.error("AmpliPi API returned HTTP status {}.", response.getStatus());
logger.debug("Content: {}", response.getContentAsString());
@ -115,11 +114,10 @@ public class AmpliPiHandler extends BaseBridgeHandler {
}
}
} else if (channelUID.getId().startsWith(CHANNEL_INPUT)) {
if (command instanceof StringType) {
StringType input = (StringType) command;
if (command instanceof StringType stringCommand) {
int source = Integer.valueOf(channelUID.getId().substring(CHANNEL_INPUT.length())) - 1;
SourceUpdate update = new SourceUpdate();
update.setInput(input.toString());
update.setInput(stringCommand.toString());
try {
StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update));
ContentResponse response = this.httpClient.newRequest(url + "/api/sources/" + source)

View File

@ -109,8 +109,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
}
break;
case AmpliPiBindingConstants.CHANNEL_VOLUME:
if (command instanceof PercentType) {
update.setVol(AmpliPiUtils.percentTypeToVolume((PercentType) command));
if (command instanceof PercentType percentCommand) {
update.setVol(AmpliPiUtils.percentTypeToVolume(percentCommand));
} else if (command instanceof IncreaseDecreaseType) {
if (zoneState != null) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
@ -125,8 +125,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
}
break;
case AmpliPiBindingConstants.CHANNEL_SOURCE:
if (command instanceof DecimalType) {
update.setSourceId(((DecimalType) command).intValue());
if (command instanceof DecimalType decimalCommand) {
update.setSourceId(decimalCommand.intValue());
}
break;
}

View File

@ -65,7 +65,7 @@ public class InputStateOptionProvider extends BaseDynamicStateDescriptionProvide
}
private @Nullable String getLabel(Stream stream) {
if (stream.getType().equals("internetradio")) {
if ("internetradio".equals(stream.getType())) {
return stream.getName();
} else {
return stream.getType().substring(0, 1).toUpperCase() + stream.getType().substring(1);

View File

@ -54,10 +54,9 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant
public @Nullable DiscoveryResult createResult(ServiceInfo service) {
ThingUID uid = getThingUID(service);
if (uid != null) {
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller")
return DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller")
.withProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME, getIpAddress(service).getHostAddress())
.withRepresentationProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME).build();
return result;
} else {
return null;
}
@ -68,7 +67,7 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant
if (service.getName().equals(AMPLIPI_API)) {
InetAddress ip = getIpAddress(service);
if (ip != null) {
String id = ip.toString().substring(1).replaceAll("\\.", "");
String id = ip.toString().substring(1).replace(".", "");
return new ThingUID(AmpliPiBindingConstants.THING_TYPE_CONTROLLER, id);
}
}

View File

@ -246,13 +246,13 @@ public class AndroidDebugBridgeDevice {
AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException {
if (isAtLeastVersion(12)) {
String devicesResp = runAdbShell("getprop", "debug.tracing.screen_state");
return devicesResp.replace("\n", "").equals("2");
return "2".equals(devicesResp.replace("\n", ""));
}
String devicesResp = runAdbShell("dumpsys", "power", "|", "grep", "'Display Power'");
if (devicesResp.contains("=")) {
try {
var state = devicesResp.split("=")[1].trim();
return state.equals("ON");
return "ON".equals(state);
} catch (NumberFormatException e) {
logger.debug("Unable to parse device screen state: {}", e.getMessage());
}

View File

@ -161,7 +161,7 @@ public class AndroidDebugBridgeDiscoveryService extends AbstractDiscoveryService
String brand, String macAddress) {
String friendlyName = String.format("%s (%s)", model, ip);
thingDiscovered(
DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", ""))) //
DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", ""))) //
.withProperties(Map.of( //
PARAMETER_IP, ip, //
PARAMETER_PORT, port, //

View File

@ -104,7 +104,7 @@ public class AndroidTVMDNSDiscoveryParticipant implements MDNSDiscoveryParticipa
public @Nullable ThingUID getThingUID(ServiceInfo service) {
String macAddress = service.getPropertyString(MDNS_PROPERTY_MAC_ADDRESS);
if (macAddress != null && !macAddress.isBlank()) {
return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", "").toLowerCase());
return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", "").toLowerCase());
}
return null;
}

View File

@ -104,7 +104,7 @@ public class FireTVStickMDNSDiscoveryParticipant implements MDNSDiscoveryPartici
public @Nullable ThingUID getThingUID(ServiceInfo service) {
String macAddress = service.getPropertyString(MDNS_PROPERTY_MAC_ADDRESS);
if (macAddress != null && !macAddress.isBlank()) {
return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", "").toLowerCase());
return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", "").toLowerCase());
}
return null;
}

View File

@ -135,8 +135,8 @@ public class AnelStateUpdaterTest implements IAnelTestStatus, IAnelConstants {
private void assertTemperature(@Nullable State state, double value) {
assertThat(state, isA(QuantityType.class));
if (state instanceof QuantityType<?>) {
assertThat(((QuantityType<?>) state).doubleValue(), closeTo(value, 0.0001d));
if (state instanceof QuantityType<?> temperature) {
assertThat(temperature.doubleValue(), closeTo(value, 0.0001d));
}
}
}

View File

@ -144,7 +144,7 @@ public class AnelUdpConnectorTest {
// toggle state of switch 1
final String auth = AnelAuthentication.getUserPasswordString(USER, PASSWORD, AuthMethod.of(status));
final String command = "Sw_" + (switch1state ? "off" : "on") + String.valueOf(switchNr) + auth;
final String command = "Sw_" + (switch1state ? "off" : "on") + switchNr + auth;
final String status2 = sendAndReceiveSingle(command);
// assert new state of switch 1

View File

@ -22,26 +22,40 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public interface IAnelTestStatus {
String STATUS_INVALID_NAME = "NET-PwrCtrl:NET-CONTROL :192.168.6.63:255.255.255.0:192.168.6.1:0.4.163.21.4.71:"
+ "Nr. 1,0:Nr. 2,1:Nr: 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,0:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:";
String STATUS_HUT_V61_POW = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:"
+ "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:"
+ "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:"
+ "p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:xor:";
String STATUS_HUT_V61_SENSOR = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:"
+ "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:"
+ "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:"
+ "n:s:20.61:40.7:7.0:xor:";
String STATUS_HUT_V61_POW_SENSOR = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:"
+ "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:"
+ "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:"
+ "p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:s:20.61:40.7:7.0:xor";
String STATUS_HUT_V5 = "NET-PwrCtrl:ANEL1 :192.168.0.244:255.255.255.0:192.168.0.1:0.5.163.14.7.91:"
+ "hoch,0:links hoch,0:runter,0:rechts run,0:runter,0:hoch,0:links runt,0:rechts hoc,0:0:80:"
+ "WHN_UP,1,1:LI_DOWN,1,1:RE_DOWN,1,1:LI_UP,1,1:RE_UP,1,1:DOWN,1,1:DOWN,1,1:UP,1,1:27.3°C:NET-PWRCTRL_05.0";
String STATUS_HUT_V65 = "NET-PwrCtrl:NET-CONTROL :192.168.0.64:255.255.255.0:192.168.6.1:0.5.163.17.9.116:"
+ "Nr.1,0:Nr.2,1:Nr.3,0:Nr.4,1:Nr.5,0:Nr.6,1:Nr.7,0:Nr.8,1:248:80:"
+ "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,1,0:IO-6,1,0:IO-7,1,0:IO-8,1,0:27.0<EFBFBD>C:NET-PWRCTRL_06.5:h:n:xor:";
String STATUS_HOME_V46 = "NET-PwrCtrl:NET-CONTROL :192.168.0.63:255.255.255.0:192.168.6.1:0.5.163.21.4.71:"
+ "Nr. 1,1:Nr. 2,0:Nr. 3,1:Nr. 4,0:Nr. 5,1:Nr. 6,0:Nr. 7,1:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:";
String STATUS_INVALID_NAME = """
NET-PwrCtrl:NET-CONTROL :192.168.6.63:255.255.255.0:192.168.6.1:0.4.163.21.4.71:\
Nr. 1,0:Nr. 2,1:Nr: 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,0:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:\
""";
String STATUS_HUT_V61_POW = """
NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\
Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\
IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:\
p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:xor:\
""";
String STATUS_HUT_V61_SENSOR = """
NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\
Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\
IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:\
n:s:20.61:40.7:7.0:xor:\
""";
String STATUS_HUT_V61_POW_SENSOR = """
NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\
Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\
IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7°C:NET-PWRCTRL_06.1:h:\
p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:s:20.61:40.7:7.0:xor\
""";
String STATUS_HUT_V5 = """
NET-PwrCtrl:ANEL1 :192.168.0.244:255.255.255.0:192.168.0.1:0.5.163.14.7.91:\
hoch,0:links hoch,0:runter,0:rechts run,0:runter,0:hoch,0:links runt,0:rechts hoc,0:0:80:\
WHN_UP,1,1:LI_DOWN,1,1:RE_DOWN,1,1:LI_UP,1,1:RE_UP,1,1:DOWN,1,1:DOWN,1,1:UP,1,1:27.3°C:NET-PWRCTRL_05.0\
""";
String STATUS_HUT_V65 = """
NET-PwrCtrl:NET-CONTROL :192.168.0.64:255.255.255.0:192.168.6.1:0.5.163.17.9.116:\
Nr.1,0:Nr.2,1:Nr.3,0:Nr.4,1:Nr.5,0:Nr.6,1:Nr.7,0:Nr.8,1:248:80:\
IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,1,0:IO-6,1,0:IO-7,1,0:IO-8,1,0:27.0<EFBFBD>C:NET-PWRCTRL_06.5:h:n:xor:\
""";
String STATUS_HOME_V46 = """
NET-PwrCtrl:NET-CONTROL :192.168.0.63:255.255.255.0:192.168.6.1:0.5.163.21.4.71:\
Nr. 1,1:Nr. 2,0:Nr. 3,1:Nr. 4,0:Nr. 5,1:Nr. 6,0:Nr. 7,1:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:\
""";
}

View File

@ -116,7 +116,7 @@ public class AnthemHandler extends BaseThingHandler {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("Command {} received for channel {}", command, channelUID.getId().toString());
logger.trace("Command {} received for channel {}", command, channelUID.getId());
String groupId = channelUID.getGroupId();
if (groupId == null) {
return;
@ -166,8 +166,8 @@ public class AnthemHandler extends BaseThingHandler {
}
break;
case CHANNEL_VOLUME_DB:
if (command instanceof DecimalType) {
sendCommand(AnthemCommand.volume(zone, ((DecimalType) command).intValue()));
if (command instanceof DecimalType decimalCommand) {
sendCommand(AnthemCommand.volume(zone, decimalCommand.intValue()));
}
break;
case CHANNEL_MUTE:
@ -180,8 +180,8 @@ public class AnthemHandler extends BaseThingHandler {
}
break;
case CHANNEL_ACTIVE_INPUT:
if (command instanceof DecimalType) {
sendCommand(AnthemCommand.activeInput(zone, ((DecimalType) command).intValue()));
if (command instanceof DecimalType decimalCommand) {
sendCommand(AnthemCommand.activeInput(zone, decimalCommand.intValue()));
}
break;
default:

View File

@ -52,8 +52,8 @@ public class AstroActions implements ThingActions {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof AstroThingHandler) {
this.handler = (AstroThingHandler) handler;
if (handler instanceof AstroThingHandler thingHandler) {
this.handler = thingHandler;
}
}
@ -115,10 +115,9 @@ public class AstroActions implements ThingActions {
try {
AstroThingHandler theHandler = this.handler;
if (theHandler != null) {
if (theHandler instanceof SunHandler) {
SunHandler handler = (SunHandler) theHandler;
if (theHandler instanceof SunHandler sunHandler) {
SunPhaseName phase = SunPhaseName.valueOf(phaseName.toUpperCase());
return handler.getEventTime(phase, date != null ? date : ZonedDateTime.now(),
return sunHandler.getEventTime(phase, date != null ? date : ZonedDateTime.now(),
moment == null || AstroBindingConstants.EVENT_START.equalsIgnoreCase(moment));
} else {
logger.info("Astro Action service ThingHandler is not a SunHandler!");

View File

@ -490,8 +490,7 @@ public class MoonCalc {
double m1 = 134.9634114 + 477198.8676313 * t + .008997 * t * t + t * t * t / 69699 - t * t * t * t / 14712000;
double f = 93.27209929999999 + 483202.0175273 * t - .0034029 * t * t - t * t * t / 3526000
+ t * t * t * t / 863310000;
double sr = 385000.56 + getCoefficient(d, m, m1, f) / 1000;
return sr;
return 385000.56 + getCoefficient(d, m, m1, f) / 1000;
}
private double[] calcMoon(double t) {
@ -540,7 +539,7 @@ public class MoonCalc {
private double SINALT(double moonJd, int hour, double lambda, double cphi, double sphi) {
double jdo = moonJd + hour / 24.0;
double t = (jdo - 51544.5) / 36525.0;
double decra[] = calcMoon(t);
double[] decra = calcMoon(t);
double tau = 15.0 * (LMST(jdo, lambda) - decra[1]);
return sphi * SN(decra[0]) + cphi * CS(decra[0]) * CS(tau);
}
@ -688,12 +687,12 @@ public class MoonCalc {
double moonLon = mod2Pi(n2 + Math.atan2(Math.sin(l3 - n2) * Math.cos(i), Math.cos(l3 - n2)));
double moonLat = Math.asin(Math.sin(l3 - n2) * Math.sin(i));
double raDec[] = ecl2Equ(moonLat, moonLon, julianDate);
double[] raDec = ecl2Equ(moonLat, moonLon, julianDate);
double distance = (1 - 0.00301401) / (1 + 0.054900 * Math.cos(mMoon2 + ec)) * 384401;
double raDecTopo[] = geoEqu2TopoEqu(raDec, distance, lat, lmst);
double azAlt[] = equ2AzAlt(raDecTopo[0], raDecTopo[1], lat, lmst);
double[] raDecTopo = geoEqu2TopoEqu(raDec, distance, lat, lmst);
double[] azAlt = equ2AzAlt(raDecTopo[0], raDecTopo[1], lat, lmst);
Position position = moon.getPosition();
position.setAzimuth(azAlt[0] * SunCalc.RAD2DEG);

View File

@ -22,7 +22,6 @@ import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
@ -366,6 +365,6 @@ public abstract class AstroThingHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singletonList(AstroActions.class);
return List.of(AstroActions.class);
}
}

View File

@ -12,7 +12,6 @@
*/
package org.openhab.binding.astro.internal.job;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.openhab.binding.astro.internal.AstroBindingConstants.*;
import static org.openhab.binding.astro.internal.util.DateTimeUtils.*;
@ -72,7 +71,7 @@ public interface Job extends SchedulerRunnable, Runnable {
*/
static void scheduleEvent(String thingUID, AstroThingHandler astroHandler, Calendar eventAt, String event,
String channelId, boolean configAlreadyApplied) {
scheduleEvent(thingUID, astroHandler, eventAt, singletonList(event), channelId, configAlreadyApplied);
scheduleEvent(thingUID, astroHandler, eventAt, List.of(event), channelId, configAlreadyApplied);
}
/**

View File

@ -53,9 +53,8 @@ public final class SunPhaseJob extends AbstractJob {
Channel phaseNameChannel = astroHandler.getThing().getChannel(CHANNEL_ID_SUN_PHASE_NAME);
if (phaseNameChannel != null) {
Planet planet = astroHandler.getPlanet();
if (planet != null && planet instanceof Sun) {
final Sun typedSun = (Sun) planet;
typedSun.getPhase().setName(sunPhaseName);
if (planet instanceof Sun theSun) {
theSun.getPhase().setName(sunPhaseName);
astroHandler.publishChannelIfLinked(phaseNameChannel.getUID());
}
} else {

View File

@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
public enum EclipseKind {
PARTIAL,
TOTAL,
RING;
RING
}

View File

@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public enum EclipseType {
SUN,
MOON;
MOON
}

View File

@ -57,10 +57,9 @@ public class PropertyUtils {
Object value = getPropertyValue(channelUID, instance);
if (value == null) {
return UnDefType.UNDEF;
} else if (value instanceof State) {
return (State) value;
} else if (value instanceof Calendar) {
Calendar cal = (Calendar) value;
} else if (value instanceof State state) {
return state;
} else if (value instanceof Calendar cal) {
GregorianCalendar gregorianCal = (GregorianCalendar) DateTimeUtils.applyConfig(cal, config);
cal.setTimeZone(TimeZone.getTimeZone(zoneId));
ZonedDateTime zoned = gregorianCal.toZonedDateTime().withFixedOffsetZone();

View File

@ -14,7 +14,6 @@ package org.openhab.binding.atlona.internal;
import static org.openhab.binding.atlona.internal.AtlonaBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -69,7 +68,7 @@ public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_PRO3_44M)) {
return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Collections.singleton(5), true));
return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Set.of(5), true));
}
if (thingTypeUID.equals(THING_TYPE_PRO3_66M)) {

View File

@ -197,17 +197,17 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
String name = msg.substring(0, idx);
if ("Host".equalsIgnoreCase(name)) {
host = msg.substring(idx + 1).trim().replaceAll("\"", "");
host = msg.substring(idx + 1).trim().replace("\"", "");
int sep = host.indexOf('_');
if (sep >= 0) {
host = host.substring(sep + 1);
}
} else if ("Model".equalsIgnoreCase(name)) {
model = msg.substring(idx + 1).trim().replaceAll("\"", "");
model = msg.substring(idx + 1).trim().replace("\"", "");
} else if ("Manufacturer".equalsIgnoreCase(name)) {
manufacturer = msg.substring(idx + 1).trim().replaceAll("\"", "");
manufacturer = msg.substring(idx + 1).trim().replace("\"", "");
} else if ("From".equalsIgnoreCase(name)) {
from = msg.substring(idx + 1).trim().replaceAll("\"", "");
from = msg.substring(idx + 1).trim().replace("\"", "");
int sep = from.indexOf(':');
if (sep >= 0) {
from = from.substring(0, sep);

View File

@ -349,23 +349,23 @@ public class SocketChannelSession implements SocketSession {
final Object response = responses.poll(1, TimeUnit.SECONDS);
if (response != null) {
if (response instanceof String) {
if (response instanceof String stringResponse) {
try {
logger.debug("Dispatching response: {}", response);
final SocketSessionListener[] listeners = SocketChannelSession.this.listeners
.toArray(new SocketSessionListener[0]);
for (SocketSessionListener listener : listeners) {
listener.responseReceived((String) response);
listener.responseReceived(stringResponse);
}
} catch (Exception e) {
logger.warn("Exception occurred processing the response '{}': ", response, e);
}
} else if (response instanceof Exception) {
} else if (response instanceof Exception exceptionResponse) {
logger.debug("Dispatching exception: {}", response);
final SocketSessionListener[] listeners = SocketChannelSession.this.listeners
.toArray(new SocketSessionListener[0]);
for (SocketSessionListener listener : listeners) {
listener.responseException((Exception) response);
listener.responseException(exceptionResponse);
}
} else {
logger.warn("Unknown response class: {}", response);

View File

@ -133,8 +133,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
if ((m = GROUP_PRIMARY_PATTERN.matcher(group)).matches()) {
switch (id) {
case AtlonaPro3Constants.CHANNEL_POWER:
if (command instanceof OnOffType) {
final boolean makeOn = ((OnOffType) command) == OnOffType.ON;
if (command instanceof OnOffType onOffCommand) {
final boolean makeOn = onOffCommand == OnOffType.ON;
atlonaHandler.setPower(makeOn);
} else {
logger.debug("Received a POWER channel command with a non OnOffType: {}", command);
@ -143,8 +143,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
break;
case AtlonaPro3Constants.CHANNEL_PANELLOCK:
if (command instanceof OnOffType) {
final boolean makeOn = ((OnOffType) command) == OnOffType.ON;
if (command instanceof OnOffType onOffCommand) {
final boolean makeOn = onOffCommand == OnOffType.ON;
atlonaHandler.setPanelLock(makeOn);
} else {
logger.debug("Received a PANELLOCK channel command with a non OnOffType: {}", command);
@ -152,8 +152,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
break;
case AtlonaPro3Constants.CHANNEL_IRENABLE:
if (command instanceof OnOffType) {
final boolean makeOn = ((OnOffType) command) == OnOffType.ON;
if (command instanceof OnOffType onOffCommand) {
final boolean makeOn = onOffCommand == OnOffType.ON;
atlonaHandler.setIrOn(makeOn);
} else {
logger.debug("Received an IRLOCK channel command with a non OnOffType: {}", command);
@ -232,8 +232,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
switch (id) {
case AtlonaPro3Constants.CHANNEL_PORTOUTPUT:
if (command instanceof DecimalType) {
final int inpNbr = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
final int inpNbr = decimalCommand.intValue();
atlonaHandler.setPortSwitch(inpNbr, portNbr);
} else {
logger.debug("Received a PORTOUTPUT channel command with a non DecimalType: {}",
@ -243,8 +243,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
break;
case AtlonaPro3Constants.CHANNEL_PORTPOWER:
if (command instanceof OnOffType) {
final boolean makeOn = ((OnOffType) command) == OnOffType.ON;
if (command instanceof OnOffType onOffCommand) {
final boolean makeOn = onOffCommand == OnOffType.ON;
atlonaHandler.setPortPower(portNbr, makeOn);
} else {
logger.debug("Received a PORTPOWER channel command with a non OnOffType: {}", command);
@ -265,8 +265,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
switch (id) {
case AtlonaPro3Constants.CHANNEL_PORTMIRROR:
if (command instanceof DecimalType) {
final int outPortNbr = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
final int outPortNbr = decimalCommand.intValue();
if (outPortNbr <= 0) {
atlonaHandler.removePortMirror(hdmiPortNbr);
} else {
@ -285,8 +285,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
.getCallback();
final State state = callback.getState(AtlonaPro3Constants.CHANNEL_PORTMIRROR);
int outPortNbr = 1;
if (state != null && state instanceof DecimalType) {
outPortNbr = ((DecimalType) state).intValue();
if (state instanceof DecimalType decimalCommand) {
outPortNbr = decimalCommand.intValue();
}
atlonaHandler.setPortMirror(hdmiPortNbr, outPortNbr);
} else {
@ -313,8 +313,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
switch (id) {
case AtlonaPro3Constants.CHANNEL_VOLUME_MUTE:
if (command instanceof OnOffType) {
atlonaHandler.setVolumeMute(portNbr, ((OnOffType) command) == OnOffType.ON);
if (command instanceof OnOffType onOffCommand) {
atlonaHandler.setVolumeMute(portNbr, onOffCommand == OnOffType.ON);
} else {
logger.debug("Received a VOLUME MUTE channel command with a non OnOffType: {}",
command);
@ -322,8 +322,8 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
break;
case AtlonaPro3Constants.CHANNEL_VOLUME:
if (command instanceof DecimalType) {
final int level = ((DecimalType) command).intValue();
if (command instanceof DecimalType decimalCommand) {
final int level = decimalCommand.intValue();
atlonaHandler.setVolume(portNbr, level);
} else {
logger.debug("Received a VOLUME channel command with a non DecimalType: {}", command);

View File

@ -1253,10 +1253,10 @@ class AtlonaPro3PortocolHandler {
*/
String getResponse() throws Exception {
final Object lastResponse = responses.poll(5, TimeUnit.SECONDS);
if (lastResponse instanceof String) {
return (String) lastResponse;
} else if (lastResponse instanceof Exception) {
throw (Exception) lastResponse;
if (lastResponse instanceof String stringResponse) {
return stringResponse;
} else if (lastResponse instanceof Exception exceptionResponse) {
throw exceptionResponse;
} else if (lastResponse == null) {
throw new Exception("Didn't receive response in time");
} else {

View File

@ -86,7 +86,7 @@ public class AutelisDiscoveryParticipant implements UpnpDiscoveryParticipant {
device.getDetails().getModelDetails().getModelNumber());
if (device.getDetails().getManufacturerDetails().getManufacturer().toLowerCase().startsWith(MANUFACTURER)) {
logger.debug("Autelis Pool Control Found at {}", device.getDetails().getBaseURL());
String id = device.getIdentity().getUdn().getIdentifierString().replaceAll(":", "").toUpperCase();
String id = device.getIdentity().getUdn().getIdentifierString().replace(":", "").toUpperCase();
if (device.getDetails().getModelDetails().getModelNumber().toLowerCase().startsWith(MODEL_PENTAIR)) {
return new ThingUID(AutelisBindingConstants.PENTAIR_THING_TYPE_UID, id);
}

View File

@ -14,7 +14,6 @@ package org.openhab.binding.automower.internal.bridge;
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_BRIDGE;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
@ -49,7 +48,7 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
private static final String HUSQVARNA_API_TOKEN_URL = "https://api.authentication.husqvarnagroup.dev/v1/oauth2/token";
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE);
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.HOURS.toSeconds(1);
private final OAuthFactory oAuthFactory;

View File

@ -14,10 +14,10 @@ package org.openhab.binding.automower.internal.discovery;
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_AUTOMOWER;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.automower.internal.AutomowerBindingConstants;
@ -42,7 +42,7 @@ public class AutomowerDiscoveryService extends AbstractDiscoveryService {
private final AutomowerBridgeHandler bridgeHandler;
public AutomowerDiscoveryService(AutomowerBridgeHandler bridgeHandler) {
super(Collections.singleton(THING_TYPE_AUTOMOWER), 10, false);
super(Set.of(THING_TYPE_AUTOMOWER), 10, false);
this.bridgeHandler = bridgeHandler;
}

View File

@ -18,7 +18,6 @@ import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@ -73,7 +72,7 @@ import com.google.gson.Gson;
*/
@NonNullByDefault
public class AutomowerHandler extends BaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_AUTOMOWER);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_AUTOMOWER);
private static final String NO_ID = "NO_ID";
private static final long DEFAULT_COMMAND_DURATION_MIN = 60;
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.MINUTES.toSeconds(10);
@ -120,8 +119,8 @@ public class AutomowerHandler extends BaseThingHandler {
}
private Optional<Integer> getCommandValue(Type type) {
if (type instanceof DecimalType) {
return Optional.of(((DecimalType) type).intValue());
if (type instanceof DecimalType command) {
return Optional.of(command.intValue());
}
return Optional.empty();
}
@ -132,7 +131,7 @@ public class AutomowerHandler extends BaseThingHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(AutomowerActions.class);
return Set.of(AutomowerActions.class);
}
@Override
@ -163,8 +162,7 @@ public class AutomowerHandler extends BaseThingHandler {
Bridge bridge = getBridge();
if (bridge != null) {
ThingHandler handler = bridge.getHandler();
if (handler instanceof AutomowerBridgeHandler) {
AutomowerBridgeHandler bridgeHandler = (AutomowerBridgeHandler) handler;
if (handler instanceof AutomowerBridgeHandler bridgeHandler) {
return bridgeHandler.getAutomowerBridge();
}
}

View File

@ -87,8 +87,8 @@ public class AVMFritzDiscoveryService extends AbstractDiscoveryService
@Override
public void setThingHandler(@NonNullByDefault({}) ThingHandler handler) {
if (handler instanceof AVMFritzBaseBridgeHandler) {
bridgeHandler = (AVMFritzBaseBridgeHandler) handler;
if (handler instanceof AVMFritzBaseBridgeHandler baseBridgeHandler) {
bridgeHandler = baseBridgeHandler;
}
}
@ -128,9 +128,9 @@ public class AVMFritzDiscoveryService extends AbstractDiscoveryService
properties.put(PRODUCT_NAME, device.getProductName());
properties.put(PROPERTY_SERIAL_NUMBER, device.getIdentifier());
properties.put(PROPERTY_FIRMWARE_VERSION, device.getFirmwareVersion());
if (device instanceof GroupModel && ((GroupModel) device).getGroupinfo() != null) {
properties.put(PROPERTY_MASTER, ((GroupModel) device).getGroupinfo().getMasterdeviceid());
properties.put(PROPERTY_MEMBERS, ((GroupModel) device).getGroupinfo().getMembers());
if (device instanceof GroupModel model && model.getGroupinfo() != null) {
properties.put(PROPERTY_MASTER, model.getGroupinfo().getMasterdeviceid());
properties.put(PROPERTY_MEMBERS, model.getGroupinfo().getMembers());
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)

View File

@ -17,9 +17,9 @@ import static org.openhab.binding.avmfritz.internal.dto.DeviceModel.ETSUnitInfoM
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -172,21 +172,21 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler {
@Override
public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
if (childHandler instanceof FritzAhaStatusListener) {
registerStatusListener((FritzAhaStatusListener) childHandler);
if (childHandler instanceof FritzAhaStatusListener listener) {
registerStatusListener(listener);
}
}
@Override
public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) {
if (childHandler instanceof FritzAhaStatusListener) {
unregisterStatusListener((FritzAhaStatusListener) childHandler);
if (childHandler instanceof FritzAhaStatusListener listener) {
unregisterStatusListener(listener);
}
}
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(AVMFritzDiscoveryService.class);
return Set.of(AVMFritzDiscoveryService.class);
}
public boolean registerStatusListener(FritzAhaStatusListener listener) {
@ -327,7 +327,7 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler {
} else if (device.isSwitchableOutlet()) {
return GROUP_SWITCH;
}
} else if (device instanceof DeviceModel && device.isHANFUNUnit()) {
} else if (device instanceof DeviceModel deviceModel && device.isHANFUNUnit()) {
if (device.isHANFUNBlinds()) {
return DEVICE_HAN_FUN_BLINDS;
} else if (device.isColorLight()) {
@ -335,8 +335,7 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler {
} else if (device.isDimmableLight()) {
return DEVICE_HAN_FUN_DIMMABLE_BULB;
}
List<String> interfaces = Arrays
.asList(((DeviceModel) device).getEtsiunitinfo().getInterfaces().split(","));
List<String> interfaces = Arrays.asList(deviceModel.getEtsiunitinfo().getInterfaces().split(","));
if (interfaces.contains(HAN_FUN_INTERFACE_ALERT)) {
return DEVICE_HAN_FUN_CONTACT;
} else if (interfaces.contains(HAN_FUN_INTERFACE_SIMPLE_BUTTON)) {

View File

@ -187,8 +187,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
if (device.isHeatingThermostat()) {
updateHeatingThermostat(device.getHkr());
}
if (device instanceof DeviceModel) {
DeviceModel deviceModel = (DeviceModel) device;
if (device instanceof DeviceModel deviceModel) {
if (deviceModel.isTemperatureSensor()) {
updateTemperatureSensor(deviceModel.getTemperature());
}
@ -497,13 +496,12 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
case CHANNEL_COLOR:
case CHANNEL_BRIGHTNESS:
BigDecimal brightness = null;
if (command instanceof HSBType) {
HSBType hsbType = (HSBType) command;
brightness = hsbType.getBrightness().toBigDecimal();
fritzBox.setUnmappedHueAndSaturation(ain, hsbType.getHue().intValue(),
ColorControlModel.fromPercent(hsbType.getSaturation()), 0);
} else if (command instanceof PercentType) {
brightness = ((PercentType) command).toBigDecimal();
if (command instanceof HSBType hsbCommand) {
brightness = hsbCommand.getBrightness().toBigDecimal();
fritzBox.setUnmappedHueAndSaturation(ain, hsbCommand.getHue().intValue(),
ColorControlModel.fromPercent(hsbCommand.getSaturation()), 0);
} else if (command instanceof PercentType brightnessPercent) {
brightness = brightnessPercent.toBigDecimal();
} else if (command instanceof OnOffType) {
fritzBox.setSwitch(ain, OnOffType.ON.equals(command));
} else if (command instanceof IncreaseDecreaseType) {
@ -525,8 +523,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
break;
case CHANNEL_COLORTEMPERATURE:
BigDecimal colorTemperaturePct = null;
if (command instanceof PercentType) {
colorTemperaturePct = ((PercentType) command).toBigDecimal();
if (command instanceof PercentType percentCommand) {
colorTemperaturePct = percentCommand.toBigDecimal();
}
if (colorTemperaturePct != null) {
int pct = colorTemperaturePct.intValue();
@ -540,13 +538,13 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
break;
case CHANNEL_COLORTEMPERATURE_ABS:
BigDecimal colorTemperature = null;
if (command instanceof QuantityType) {
QuantityType<?> convertedCommand = ((QuantityType<?>) command).toInvertibleUnit(Units.KELVIN);
if (command instanceof QuantityType quantityCommand) {
QuantityType<?> convertedCommand = quantityCommand.toInvertibleUnit(Units.KELVIN);
if (convertedCommand != null) {
colorTemperature = convertedCommand.toBigDecimal();
}
} else if (command instanceof DecimalType) {
colorTemperature = ((DecimalType) command).toBigDecimal();
} else if (command instanceof DecimalType decimalCommand) {
colorTemperature = decimalCommand.toBigDecimal();
}
if (colorTemperature != null) {
fritzBox.setColorTemperature(ain, colorTemperature.intValue(), 0);
@ -554,9 +552,9 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
break;
case CHANNEL_SETTEMP:
BigDecimal temperature = null;
if (command instanceof DecimalType) {
temperature = normalizeCelsius(((DecimalType) command).toBigDecimal());
} else if (command instanceof QuantityType) {
if (command instanceof DecimalType decimalCommand) {
temperature = normalizeCelsius(decimalCommand.toBigDecimal());
} else if (command instanceof QuantityType quantityCommand) {
@SuppressWarnings("unchecked")
QuantityType<Temperature> convertedCommand = ((QuantityType<Temperature>) command)
.toUnit(SIUnits.CELSIUS);
@ -564,7 +562,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
temperature = normalizeCelsius(convertedCommand.toBigDecimal());
} else {
logger.warn("Unable to convert unit from '{}' to '{}'. Skipping command.",
((QuantityType<?>) command).getUnit(), SIUnits.CELSIUS);
quantityCommand.getUnit(), SIUnits.CELSIUS);
}
} else if (command instanceof IncreaseDecreaseType) {
temperature = currentDevice.getHkr().getTsoll();
@ -615,22 +613,20 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
break;
case CHANNEL_ROLLERSHUTTER:
if (command instanceof StopMoveType) {
StopMoveType rollershutterCommand = (StopMoveType) command;
if (command instanceof StopMoveType rollershutterCommand) {
if (StopMoveType.STOP.equals(rollershutterCommand)) {
fritzBox.setBlind(ain, BlindCommand.STOP);
} else {
logger.debug("Received unknown rollershutter StopMove command MOVE");
}
} else if (command instanceof UpDownType) {
UpDownType rollershutterCommand = (UpDownType) command;
} else if (command instanceof UpDownType rollershutterCommand) {
if (UpDownType.UP.equals(rollershutterCommand)) {
fritzBox.setBlind(ain, BlindCommand.OPEN);
} else {
fritzBox.setBlind(ain, BlindCommand.CLOSE);
}
} else if (command instanceof PercentType) {
BigDecimal levelPercentage = ((PercentType) command).toBigDecimal();
} else if (command instanceof PercentType percentCommand) {
BigDecimal levelPercentage = percentCommand.toBigDecimal();
fritzBox.setLevelPercentage(ain, levelPercentage);
} else {
logger.debug("Received unknown rollershutter command type '{}'", command.toString());
@ -686,8 +682,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
Bridge bridge = getBridge();
if (bridge != null) {
BridgeHandler handler = bridge.getHandler();
if (handler instanceof AVMFritzBaseBridgeHandler) {
return ((AVMFritzBaseBridgeHandler) handler).getWebInterface();
if (handler instanceof AVMFritzBaseBridgeHandler bridgeHandler) {
return bridgeHandler.getWebInterface();
}
}
return null;
@ -700,8 +696,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
Bridge bridge = getBridge();
if (bridge != null) {
BridgeHandler handler = bridge.getHandler();
if (handler instanceof AVMFritzBaseBridgeHandler) {
((AVMFritzBaseBridgeHandler) handler).handleRefreshCommand();
if (handler instanceof AVMFritzBaseBridgeHandler bridgeHandler) {
bridgeHandler.handleRefreshCommand();
}
}
}

View File

@ -78,8 +78,7 @@ public class AVMFritzButtonHandler extends DeviceHandler {
if (thing.getUID().equals(thingUID)) {
super.onDeviceUpdated(thingUID, device);
if (device instanceof DeviceModel) {
DeviceModel deviceModel = (DeviceModel) device;
if (device instanceof DeviceModel deviceModel) {
if (deviceModel.isHANFUNButton()) {
updateHANFUNButton(deviceModel.getButtons());
}

View File

@ -13,7 +13,7 @@
package org.openhab.binding.avmfritz.internal.handler;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.avmfritz.internal.actions.AVMFritzHeatingActions;
@ -30,7 +30,7 @@ public interface AVMFritzHeatingActionsHandler extends ThingHandler {
@Override
default Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(AVMFritzHeatingActions.class);
return Set.of(AVMFritzHeatingActions.class);
}
/**

View File

@ -35,8 +35,7 @@ public class GroupHandler extends AVMFritzBaseThingHandler {
@Override
protected void updateProperties(AVMFritzBaseModel device, Map<String, String> editProperties) {
if (device instanceof GroupModel) {
GroupModel groupModel = (GroupModel) device;
if (device instanceof GroupModel groupModel) {
if (groupModel.getGroupinfo() != null) {
editProperties.put(PROPERTY_MASTER, groupModel.getGroupinfo().getMasterdeviceid());
editProperties.put(PROPERTY_MEMBERS, groupModel.getGroupinfo().getMembers());

View File

@ -45,72 +45,74 @@ public class AVMFritzDeviceListModelTest {
public void setUp() throws JAXBException, XMLStreamException {
//@formatter:off
final String xml =
"<devicelist version=\"1\">"
+ "<group identifier=\"F0:A3:7F-900\" id=\"20000\" functionbitmask=\"6784\" fwversion=\"1.0\" manufacturer=\"AVM\" productname=\"\"><present>1</present><name>Schlafzimmer</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><groupinfo><masterdeviceid>17</masterdeviceid><members>17,18</members></groupinfo></group>"
+ "<group identifier=\"F0:A3:7F-901\" id=\"20001\" functionbitmask=\"4160\" fwversion=\"1.0\" manufacturer=\"AVM\" productname=\"\"><present>1</present><name>Schlafzimmer</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr><groupinfo><masterdeviceid>0</masterdeviceid><members>20,21,22</members></groupinfo></group>"
+ "<device identifier=\"08761 0000434\" id=\"17\" functionbitmask=\"35712\" fwversion=\"03.83\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 200\"><present>1</present><name>FRITZ!DECT 200 #1</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><temperature><celsius>255</celsius><offset>0</offset></temperature></device>"
+ "<device identifier=\"08761 0000438\" id=\"18\" functionbitmask=\"35712\" fwversion=\"03.83\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 210\"><present>1</present><name>FRITZ!DECT 210 #8</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><temperature><celsius>255</celsius><offset>0</offset></temperature></device>"
+ "<device identifier=\"08761 0000437\" id=\"20\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 300\"><present>0</present><name>FRITZ!DECT 300 #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>"
+ "<device identifier=\"08761 0000436\" id=\"21\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 301\"><present>0</present><name>FRITZ!DECT 301 #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>"
+ "<device identifier=\"08761 0000435\" id=\"22\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"Comet DECT\"><present>0</present><name>Comet DECT #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>"
+ "<device identifier=\"5C:49:79:F0:A3:84\" id=\"30\" functionbitmask=\"640\" fwversion=\"06.92\" manufacturer=\"AVM\" productname=\"FRITZ!Powerline 546E\"><present>1</present><name>FRITZ!Powerline 546E #1</name><switch><state>0</state><mode>manuell</mode><lock>0</lock><devicelock>1</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter></device>"
+ "<device identifier=\"08761 0000439\" id=\"40\" functionbitmask=\"1280\" fwversion=\"03.86\" manufacturer=\"AVM\" productname=\"FRITZ!DECT Repeater 100\"><present>1</present><name>FRITZ!DECT Repeater 100 #5</name><temperature><celsius>230</celsius><offset>0</offset></temperature></device>"
+ "<device identifier=\"11934 0059978-1\" id=\"2000\" functionbitmask=\"8208\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\"><present>0</present><name>HAN-FUN #2: Unit #2</name><etsiunitinfo><etsideviceid>406</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>1</state></alert></device>"
+ "<device identifier=\"11934 0059979-1\" id=\"2001\" functionbitmask=\"8200\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\"><present>0</present><name>HAN-FUN #2: Unit #2</name><etsiunitinfo><etsideviceid>412</etsideviceid><unittype>273</unittype><interfaces>772</interfaces></etsiunitinfo><button><lastpressedtimestamp>1529590797</lastpressedtimestamp></button></device>"
+ "<device identifier=\"13096 0007307\" id=\"29\" functionbitmask=\"32\" fwversion=\"04.90\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 400\"><present>1</present><name>FRITZ!DECT 400 #14</name><battery>100</battery><batterylow>0</batterylow><button identifier=\"13096 0007307-0\" id=\"5000\"><name>FRITZ!DECT 400 #14: kurz</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier=\"13096 0007307-9\" id=\"5001\"><name>FRITZ!DECT 400 #14: lang</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button></device>"
+ "<device identifier=\"13096 0007308\" id=\"30\" functionbitmask=\"1048864\" fwversion=\"05.10\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 440\"><present>1</present><name>FRITZ!DECT 440 #15</name><temperature><celsius>230</celsius><offset>0</offset></temperature><humidity><rel_humidity>43</rel_humidity></humidity><battery>100</battery><batterylow>0</batterylow><button identifier=\"13096 0007308-1\" id=\"5000\"><name>FRITZ!DECT 440 #15: Oben rechts</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier=\"13096 0007308-3\" id=\"5001\"><name>FRITZ!DECT 440 #15: Unten rechts</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button><button identifier=\"13096 0007308-5\" id=\"5002\"><name>FRITZ!DECT 440 #15: Unten links</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier=\"13096 0007308-7\" id=\"5003\"><name>FRITZ!DECT 440 #15: Oben links</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button></device>"
+ "<device identifier=\"14276 0503450-1\" id=\"2000\" functionbitmask=\"335888\" fwversion=\"0.0\" manufacturer=\"0x37c4\" productname=\"Rollotron 1213\"><present>1</present><txbusy>0</txbusy><name>Rollotron 1213 #1</name><blind><endpositionsset>1</endpositionsset><mode>manuell</mode></blind><levelcontrol><level>26</level><levelpercentage>10</levelpercentage></levelcontrol><etsiunitinfo><etsideviceid>406</etsideviceid><unittype>281</unittype><interfaces>256,513,516,517</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp></lastalertchgtimestamp></alert></device>"
+ "<device identifier=\"11324 0824499-1\" id=\"2002\" functionbitmask=\"40960\" fwversion=\"0.0\" manufacturer=\"0x2c3c\" productname=\"HAN-FUN\">\n"
+ " <present>1</present>\n"
+ " <txbusy>0</txbusy>\n"
+ " <name>Steckdose innen</name>\n"
+ " <simpleonoff>\n"
+ " <state>0</state>\n"
+ " </simpleonoff>\n"
+ " <etsiunitinfo>\n"
+ " <etsideviceid>408</etsideviceid>\n"
+ " <unittype>263</unittype>\n"
+ " <interfaces>512,768</interfaces>\n"
+ " </etsiunitinfo>\n"
+ "</device>"
+ "<device identifier=\"11324 0584796-1\" id=\"2001\" functionbitmask=\"40960\" fwversion=\"0.0\" manufacturer=\"0x2c3c\" productname=\"HAN-FUN\">\n"
+ " <present>1</present>\n"
+ " <txbusy>0</txbusy>\n"
+ " <name>Steckdose außen</name>\n"
+ " <simpleonoff>\n"
+ " <state>0</state>\n"
+ " </simpleonoff>\n"
+ " <etsiunitinfo>\n"
+ " <etsideviceid>407</etsideviceid>\n"
+ " <unittype>262</unittype>\n"
+ " <interfaces>512</interfaces>\n"
+ " </etsiunitinfo>\n"
+ "</device>"
+ "<device identifier=\"12701 0027533-1\" id=\"2002\" functionbitmask=\"237572\" fwversion=\"0.0\" manufacturer=\"0x319d\" productname=\"HAN-FUN\">\n"
+ " <present>0</present>\n"
+ " <txbusy>0</txbusy>\n"
+ " <name>SmartHome LED-Lampe #1</name>\n"
+ " <simpleonoff>\n"
+ " <state>0</state>\n"
+ " </simpleonoff>\n"
+ " <levelcontrol>\n"
+ " <level>26</level>\n"
+ " <levelpercentage>10</levelpercentage>\n"
+ " </levelcontrol>\n"
+ " <colorcontrol supported_modes=\"0\" current_mode=\"\" fullcolorsupport=\"0\" mapped=\"0\">\n"
+ " <hue>254</hue>\n"
+ " <saturation>100</saturation>\n"
+ " <unmapped_hue></unmapped_hue>\n"
+ " <unmapped_saturation></unmapped_saturation>\n"
+ " <temperature>2700</temperature>\n"
+ " </colorcontrol>\n"
+ " <etsiunitinfo>\n"
+ " <etsideviceid>407</etsideviceid>\n"
+ " <unittype>278</unittype>\n"
+ " <interfaces>512,514,513</interfaces>\n"
+ " </etsiunitinfo>\n"
+ "</device>" +
"</devicelist>";
"""
<devicelist version="1">\
<group identifier="F0:A3:7F-900" id="20000" functionbitmask="6784" fwversion="1.0" manufacturer="AVM" productname=""><present>1</present><name>Schlafzimmer</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><groupinfo><masterdeviceid>17</masterdeviceid><members>17,18</members></groupinfo></group>\
<group identifier="F0:A3:7F-901" id="20001" functionbitmask="4160" fwversion="1.0" manufacturer="AVM" productname=""><present>1</present><name>Schlafzimmer</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr><groupinfo><masterdeviceid>0</masterdeviceid><members>20,21,22</members></groupinfo></group>\
<device identifier="08761 0000434" id="17" functionbitmask="35712" fwversion="03.83" manufacturer="AVM" productname="FRITZ!DECT 200"><present>1</present><name>FRITZ!DECT 200 #1</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><temperature><celsius>255</celsius><offset>0</offset></temperature></device>\
<device identifier="08761 0000438" id="18" functionbitmask="35712" fwversion="03.83" manufacturer="AVM" productname="FRITZ!DECT 210"><present>1</present><name>FRITZ!DECT 210 #8</name><switch><state>1</state><mode>manuell</mode><lock>0</lock><devicelock>0</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter><temperature><celsius>255</celsius><offset>0</offset></temperature></device>\
<device identifier="08761 0000437" id="20" functionbitmask="320" fwversion="03.50" manufacturer="AVM" productname="FRITZ!DECT 300"><present>0</present><name>FRITZ!DECT 300 #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>\
<device identifier="08761 0000436" id="21" functionbitmask="320" fwversion="03.50" manufacturer="AVM" productname="FRITZ!DECT 301"><present>0</present><name>FRITZ!DECT 301 #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>\
<device identifier="08761 0000435" id="22" functionbitmask="320" fwversion="03.50" manufacturer="AVM" productname="Comet DECT"><present>0</present><name>Comet DECT #1</name><temperature><celsius>220</celsius><offset>-10</offset></temperature><hkr><tist>44</tist><tsoll>42</tsoll><absenk>28</absenk><komfort>42</komfort><lock>1</lock><devicelock>1</devicelock><errorcode>0</errorcode><windowopenactiv>0</windowopenactiv><windowopenactiveendtime>0</windowopenactiveendtime><boostactive>0</boostactive><boostactiveendtime>0</boostactiveendtime><batterylow>0</batterylow><battery>100</battery><nextchange><endperiod>1484341200</endperiod><tchange>28</tchange></nextchange></hkr></device>\
<device identifier="5C:49:79:F0:A3:84" id="30" functionbitmask="640" fwversion="06.92" manufacturer="AVM" productname="FRITZ!Powerline 546E"><present>1</present><name>FRITZ!Powerline 546E #1</name><switch><state>0</state><mode>manuell</mode><lock>0</lock><devicelock>1</devicelock></switch><powermeter><voltage>230051</voltage><power>0</power><energy>2087</energy></powermeter></device>\
<device identifier="08761 0000439" id="40" functionbitmask="1280" fwversion="03.86" manufacturer="AVM" productname="FRITZ!DECT Repeater 100"><present>1</present><name>FRITZ!DECT Repeater 100 #5</name><temperature><celsius>230</celsius><offset>0</offset></temperature></device>\
<device identifier="11934 0059978-1" id="2000" functionbitmask="8208" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>0</present><name>HAN-FUN #2: Unit #2</name><etsiunitinfo><etsideviceid>406</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>1</state></alert></device>\
<device identifier="11934 0059979-1" id="2001" functionbitmask="8200" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>0</present><name>HAN-FUN #2: Unit #2</name><etsiunitinfo><etsideviceid>412</etsideviceid><unittype>273</unittype><interfaces>772</interfaces></etsiunitinfo><button><lastpressedtimestamp>1529590797</lastpressedtimestamp></button></device>\
<device identifier="13096 0007307" id="29" functionbitmask="32" fwversion="04.90" manufacturer="AVM" productname="FRITZ!DECT 400"><present>1</present><name>FRITZ!DECT 400 #14</name><battery>100</battery><batterylow>0</batterylow><button identifier="13096 0007307-0" id="5000"><name>FRITZ!DECT 400 #14: kurz</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier="13096 0007307-9" id="5001"><name>FRITZ!DECT 400 #14: lang</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button></device>\
<device identifier="13096 0007308" id="30" functionbitmask="1048864" fwversion="05.10" manufacturer="AVM" productname="FRITZ!DECT 440"><present>1</present><name>FRITZ!DECT 440 #15</name><temperature><celsius>230</celsius><offset>0</offset></temperature><humidity><rel_humidity>43</rel_humidity></humidity><battery>100</battery><batterylow>0</batterylow><button identifier="13096 0007308-1" id="5000"><name>FRITZ!DECT 440 #15: Oben rechts</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier="13096 0007308-3" id="5001"><name>FRITZ!DECT 440 #15: Unten rechts</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button><button identifier="13096 0007308-5" id="5002"><name>FRITZ!DECT 440 #15: Unten links</name><lastpressedtimestamp>1549195586</lastpressedtimestamp></button><button identifier="13096 0007308-7" id="5003"><name>FRITZ!DECT 440 #15: Oben links</name><lastpressedtimestamp>1549195595</lastpressedtimestamp></button></device>\
<device identifier="14276 0503450-1" id="2000" functionbitmask="335888" fwversion="0.0" manufacturer="0x37c4" productname="Rollotron 1213"><present>1</present><txbusy>0</txbusy><name>Rollotron 1213 #1</name><blind><endpositionsset>1</endpositionsset><mode>manuell</mode></blind><levelcontrol><level>26</level><levelpercentage>10</levelpercentage></levelcontrol><etsiunitinfo><etsideviceid>406</etsideviceid><unittype>281</unittype><interfaces>256,513,516,517</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp></lastalertchgtimestamp></alert></device>\
<device identifier="11324 0824499-1" id="2002" functionbitmask="40960" fwversion="0.0" manufacturer="0x2c3c" productname="HAN-FUN">
<present>1</present>
<txbusy>0</txbusy>
<name>Steckdose innen</name>
<simpleonoff>
<state>0</state>
</simpleonoff>
<etsiunitinfo>
<etsideviceid>408</etsideviceid>
<unittype>263</unittype>
<interfaces>512,768</interfaces>
</etsiunitinfo>
</device>\
<device identifier="11324 0584796-1" id="2001" functionbitmask="40960" fwversion="0.0" manufacturer="0x2c3c" productname="HAN-FUN">
<present>1</present>
<txbusy>0</txbusy>
<name>Steckdose außen</name>
<simpleonoff>
<state>0</state>
</simpleonoff>
<etsiunitinfo>
<etsideviceid>407</etsideviceid>
<unittype>262</unittype>
<interfaces>512</interfaces>
</etsiunitinfo>
</device>\
<device identifier="12701 0027533-1" id="2002" functionbitmask="237572" fwversion="0.0" manufacturer="0x319d" productname="HAN-FUN">
<present>0</present>
<txbusy>0</txbusy>
<name>SmartHome LED-Lampe #1</name>
<simpleonoff>
<state>0</state>
</simpleonoff>
<levelcontrol>
<level>26</level>
<levelpercentage>10</levelpercentage>
</levelcontrol>
<colorcontrol supported_modes="0" current_mode="" fullcolorsupport="0" mapped="0">
<hue>254</hue>
<saturation>100</saturation>
<unmapped_hue></unmapped_hue>
<unmapped_saturation></unmapped_saturation>
<temperature>2700</temperature>
</colorcontrol>
<etsiunitinfo>
<etsideviceid>407</etsideviceid>
<unittype>278</unittype>
<interfaces>512,514,513</interfaces>
</etsiunitinfo>
</device>\
</devicelist>\
""";
//@formatter:on
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(xml));
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();

View File

@ -44,10 +44,12 @@ public class AVMFritzTemplateListModelTest {
public void setUp() throws JAXBException, XMLStreamException {
//@formatter:off
String xml =
"<templatelist version=\"1\">" +
"<template identifier=\"tmpXXXXX-39DC738C5\" id=\"30103\" functionbitmask=\"6784\" applymask=\"64\"><name>Test template #1</name><devices><device identifier=\"YY:5D:AA-900\" /><device identifier=\"XX:5D:AA-900\" /></devices><applymask><relay_automatic /></applymask></template>" +
"<template identifier=\"tmpXXXXX-39722FC0F\" id=\"30003\" functionbitmask=\"6784\" applymask=\"64\"><name>Test template #2</name><devices><device identifier=\"YY:5D:AA-900\" /></devices><applymask><relay_automatic /></applymask></template>" +
"</templatelist>";
"""
<templatelist version="1">\
<template identifier="tmpXXXXX-39DC738C5" id="30103" functionbitmask="6784" applymask="64"><name>Test template #1</name><devices><device identifier="YY:5D:AA-900" /><device identifier="XX:5D:AA-900" /></devices><applymask><relay_automatic /></applymask></template>\
<template identifier="tmpXXXXX-39722FC0F" id="30003" functionbitmask="6784" applymask="64"><name>Test template #2</name><devices><device identifier="YY:5D:AA-900" /></devices><applymask><relay_automatic /></applymask></template>\
</templatelist>\
""";
//@formatter:on
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(xml));
Unmarshaller u = JAXBUtils.JAXBCONTEXT_TEMPLATES.createUnmarshaller();

View File

@ -27,6 +27,7 @@ public class AwattarBestpriceConfiguration {
public int length;
public boolean consecutive;
@Override
public String toString() {
return String.format("{ s: %d, d: %d, l: %d, c: %b )", rangeStart, rangeDuration, length, consecutive);
}

View File

@ -66,11 +66,13 @@ public class AwattarConsecutiveBestPriceResult extends AwattarBestPriceResult {
return priceSum;
}
@Override
public String toString() {
return String.format("{%s, %s, %.2f}", formatDate(getStart(), zoneId), formatDate(getEnd(), zoneId),
priceSum / length);
}
@Override
public String getHours() {
return hours;
}

View File

@ -52,6 +52,7 @@ public class AwattarNonConsecutiveBestPriceResult extends AwattarBestPriceResult
return members.stream().anyMatch(x -> x.contains(Instant.now().toEpochMilli()));
}
@Override
public String toString() {
return String.format("NonConsecutiveBestpriceResult with %s", members.toString());
}
@ -67,6 +68,7 @@ public class AwattarNonConsecutiveBestPriceResult extends AwattarBestPriceResult
}
}
@Override
public String getHours() {
boolean second = false;
sort();

View File

@ -50,6 +50,7 @@ public class AwattarPrice implements Comparable<AwattarPrice> {
return price;
}
@Override
public String toString() {
return String.format("(%1$tF %1$tR - %2$tR: %3$.3f)", startTimestamp, endTimestamp, getPrice());
}

View File

@ -40,9 +40,7 @@ public class AwattarUtil {
int offset = min % mod;
offset = offset == 0 ? mod : offset;
dt = dt.plusMinutes(offset);
long result = dt.toInstant().toEpochMilli() - now;
return result;
return dt.toInstant().toEpochMilli() - now;
}
public static ZonedDateTime getCalendarForHour(int hour, ZoneId zone) {

View File

@ -97,6 +97,7 @@ public class AwattarPriceHandler extends BaseThingHandler {
updateStatus(ThingStatus.UNKNOWN);
}
@Override
public void dispose() {
ScheduledFuture<?> localRefresher = thingRefresher;
if (localRefresher != null) {

View File

@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public enum Switch {
ON,
OFF;
OFF
}

View File

@ -187,8 +187,8 @@ public class BigAssFanHandler extends BaseThingHandler {
logger.debug("Handling fan speed command for {}: {}", thing.getUID(), command);
// <mac;FAN;SPD;SET;0..7>
if (command instanceof PercentType) {
sendCommand(macAddress, ";FAN;SPD;SET;".concat(BigAssFanConverter.percentToSpeed((PercentType) command)));
if (command instanceof PercentType percentCommand) {
sendCommand(macAddress, ";FAN;SPD;SET;".concat(BigAssFanConverter.percentToSpeed(percentCommand)));
}
}
@ -238,52 +238,48 @@ public class BigAssFanHandler extends BaseThingHandler {
private void handleFanLearnSpeedMin(Command command) {
logger.debug("Handling fan learn speed minimum command {}", command);
// <mac;FAN;SPD;SET;MIN;0..7>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send min speed set command
sendCommand(macAddress,
";LEARN;MINSPEED;SET;".concat(BigAssFanConverter.percentToSpeed((PercentType) command)));
fanStateMap.put(CHANNEL_FAN_LEARN_MINSPEED, (PercentType) command);
sendCommand(macAddress, ";LEARN;MINSPEED;SET;".concat(BigAssFanConverter.percentToSpeed(percentCommand)));
fanStateMap.put(CHANNEL_FAN_LEARN_MINSPEED, percentCommand);
// Don't let max be less than min
adjustMaxSpeed((PercentType) command, CHANNEL_FAN_LEARN_MAXSPEED, ";LEARN;MAXSPEED;");
adjustMaxSpeed(percentCommand, CHANNEL_FAN_LEARN_MAXSPEED, ";LEARN;MAXSPEED;");
}
}
private void handleFanLearnSpeedMax(Command command) {
logger.debug("Handling fan learn speed maximum command {}", command);
// <mac;FAN;SPD;SET;MAX;0..7>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send max speed set command
sendCommand(macAddress,
";LEARN;MAXSPEED;SET;;".concat(BigAssFanConverter.percentToSpeed((PercentType) command)));
fanStateMap.put(CHANNEL_FAN_LEARN_MAXSPEED, (PercentType) command);
sendCommand(macAddress, ";LEARN;MAXSPEED;SET;;".concat(BigAssFanConverter.percentToSpeed(percentCommand)));
fanStateMap.put(CHANNEL_FAN_LEARN_MAXSPEED, percentCommand);
// Don't let min be greater than max
adjustMinSpeed((PercentType) command, CHANNEL_FAN_LEARN_MINSPEED, ";LEARN;MINSPEED;");
adjustMinSpeed(percentCommand, CHANNEL_FAN_LEARN_MINSPEED, ";LEARN;MINSPEED;");
}
}
private void handleFanSpeedMin(Command command) {
logger.debug("Handling fan speed minimum command {}", command);
// <mac;FAN;SPD;SET;MIN;0..7>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send min speed set command
sendCommand(macAddress,
";FAN;SPD;SET;MIN;".concat(BigAssFanConverter.percentToSpeed((PercentType) command)));
fanStateMap.put(CHANNEL_FAN_SPEED_MIN, (PercentType) command);
sendCommand(macAddress, ";FAN;SPD;SET;MIN;".concat(BigAssFanConverter.percentToSpeed(percentCommand)));
fanStateMap.put(CHANNEL_FAN_SPEED_MIN, percentCommand);
// Don't let max be less than min
adjustMaxSpeed((PercentType) command, CHANNEL_FAN_SPEED_MAX, ";FAN;SPD;SET;MAX;");
adjustMaxSpeed(percentCommand, CHANNEL_FAN_SPEED_MAX, ";FAN;SPD;SET;MAX;");
}
}
private void handleFanSpeedMax(Command command) {
logger.debug("Handling fan speed maximum command {}", command);
// <mac;FAN;SPD;SET;MAX;0..7>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send max speed set command
sendCommand(macAddress,
";FAN;SPD;SET;MAX;".concat(BigAssFanConverter.percentToSpeed((PercentType) command)));
fanStateMap.put(CHANNEL_FAN_SPEED_MAX, (PercentType) command);
sendCommand(macAddress, ";FAN;SPD;SET;MAX;".concat(BigAssFanConverter.percentToSpeed(percentCommand)));
fanStateMap.put(CHANNEL_FAN_SPEED_MAX, percentCommand);
// Don't let min be greater than max
adjustMinSpeed((PercentType) command, CHANNEL_FAN_SPEED_MIN, ";FAN;SPD;SET;MIN;");
adjustMinSpeed(percentCommand, CHANNEL_FAN_SPEED_MIN, ";FAN;SPD;SET;MIN;");
}
}
@ -364,9 +360,8 @@ public class BigAssFanHandler extends BaseThingHandler {
logger.debug("Handling light level command {}", command);
// <mac;LIGHT;LEVEL;SET;0..16>
if (command instanceof PercentType) {
sendCommand(macAddress,
";LIGHT;LEVEL;SET;".concat(BigAssFanConverter.percentToLevel((PercentType) command)));
if (command instanceof PercentType percentCommand) {
sendCommand(macAddress, ";LIGHT;LEVEL;SET;".concat(BigAssFanConverter.percentToLevel(percentCommand)));
}
}
@ -378,9 +373,9 @@ public class BigAssFanHandler extends BaseThingHandler {
logger.debug("Handling light hue command {}", command);
// <mac;LIGHT;COLOR;TEMP;SET;2200..5000>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
sendCommand(macAddress,
";LIGHT;COLOR;TEMP;VALUE;SET;".concat(BigAssFanConverter.percentToHue((PercentType) command)));
";LIGHT;COLOR;TEMP;VALUE;SET;".concat(BigAssFanConverter.percentToHue(percentCommand)));
}
}
@ -426,12 +421,11 @@ public class BigAssFanHandler extends BaseThingHandler {
logger.debug("Handling light level minimum command {}", command);
// <mac;LIGHT;LEVEL;MIN;0-16>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send min light level set command
sendCommand(macAddress,
";LIGHT;LEVEL;MIN;".concat(BigAssFanConverter.percentToLevel((PercentType) command)));
sendCommand(macAddress, ";LIGHT;LEVEL;MIN;".concat(BigAssFanConverter.percentToLevel(percentCommand)));
// Don't let max be less than min
adjustMaxLevel((PercentType) command);
adjustMaxLevel(percentCommand);
}
}
@ -443,12 +437,11 @@ public class BigAssFanHandler extends BaseThingHandler {
logger.debug("Handling light level maximum command {}", command);
// <mac;LIGHT;LEVEL;MAX;0-16>
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
// Send max light level set command
sendCommand(macAddress,
";LIGHT;LEVEL;MAX;".concat(BigAssFanConverter.percentToLevel((PercentType) command)));
sendCommand(macAddress, ";LIGHT;LEVEL;MAX;".concat(BigAssFanConverter.percentToLevel(percentCommand)));
// Don't let min be greater than max
adjustMinLevel((PercentType) command);
adjustMinLevel(percentCommand);
}
}

View File

@ -12,7 +12,6 @@
*/
package org.openhab.binding.bluetooth.am43.internal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -42,7 +41,7 @@ public class AM43DiscoveryParticipant implements BluetoothDiscoveryParticipant {
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(AM43BindingConstants.THING_TYPE_AM43);
return Set.of(AM43BindingConstants.THING_TYPE_AM43);
}
@Override

View File

@ -235,27 +235,28 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
}
switch (channelUID.getId()) {
case AM43BindingConstants.CHANNEL_ID_POSITION:
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
MotorSettings settings = motorSettings;
if (settings == null) {
logger.warn("Cannot set position before settings have been received.");
return;
}
if (!settings.isTopLimitSet() || !settings.isBottomLimitSet()) {
logger.warn("Cannot set position of blinds. Top or bottom limits have not been set. "
+ "Please configure manually.");
logger.warn("""
Cannot set position of blinds. Top or bottom limits have not been set. \
Please configure manually.\
""");
return;
}
PercentType percent = (PercentType) command;
int value = percent.intValue();
int value = percentCommand.intValue();
if (getAM43Config().invertPosition) {
value = 100 - value;
}
submitCommand(new SetPositionCommand(value));
return;
}
if (command instanceof StopMoveType) {
switch ((StopMoveType) command) {
if (command instanceof StopMoveType stopMoveCommand) {
switch (stopMoveCommand) {
case STOP:
submitCommand(new ControlCommand(ControlAction.STOP));
return;
@ -264,8 +265,8 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
return;
}
}
if (command instanceof UpDownType) {
switch ((UpDownType) command) {
if (command instanceof UpDownType upDownCommand) {
switch (upDownCommand) {
case UP:
submitCommand(new ControlCommand(ControlAction.OPEN));
return;
@ -276,11 +277,10 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
}
return;
case AM43BindingConstants.CHANNEL_ID_SPEED:
if (command instanceof DecimalType) {
if (command instanceof DecimalType decimalCommand) {
MotorSettings settings = motorSettings;
if (settings != null) {
DecimalType speedType = (DecimalType) command;
settings.setSpeed(speedType.intValue());
settings.setSpeed(decimalCommand.intValue());
submitCommand(new SetSettingsCommand(settings));
} else {
logger.warn("Cannot set Speed before setting have been received");

View File

@ -12,7 +12,6 @@
*/
package org.openhab.binding.bluetooth.am43.internal;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -33,8 +32,7 @@ import org.osgi.service.component.annotations.Component;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.am43")
public class AM43HandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(AM43BindingConstants.THING_TYPE_AM43);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(AM43BindingConstants.THING_TYPE_AM43);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {

View File

@ -35,6 +35,7 @@ public class BlueGigaBluetoothCharacteristic extends BluetoothCharacteristic {
super(null, handle);
}
@Override
public void setProperties(int properties) {
this.properties = properties;
}

View File

@ -356,33 +356,33 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
@Override
public void bluegigaEventReceived(BlueGigaResponse event) {
if (event instanceof BlueGigaScanResponseEvent) {
handleScanEvent((BlueGigaScanResponseEvent) event);
if (event instanceof BlueGigaScanResponseEvent responseEvent) {
handleScanEvent(responseEvent);
}
else if (event instanceof BlueGigaGroupFoundEvent) {
handleGroupFoundEvent((BlueGigaGroupFoundEvent) event);
else if (event instanceof BlueGigaGroupFoundEvent foundEvent) {
handleGroupFoundEvent(foundEvent);
}
else if (event instanceof BlueGigaFindInformationFoundEvent) {
else if (event instanceof BlueGigaFindInformationFoundEvent foundEvent) {
// A Characteristic has been discovered
handleFindInformationFoundEvent((BlueGigaFindInformationFoundEvent) event);
handleFindInformationFoundEvent(foundEvent);
}
else if (event instanceof BlueGigaProcedureCompletedEvent) {
handleProcedureCompletedEvent((BlueGigaProcedureCompletedEvent) event);
else if (event instanceof BlueGigaProcedureCompletedEvent completedEvent) {
handleProcedureCompletedEvent(completedEvent);
}
else if (event instanceof BlueGigaConnectionStatusEvent) {
handleConnectionStatusEvent((BlueGigaConnectionStatusEvent) event);
else if (event instanceof BlueGigaConnectionStatusEvent statusEvent) {
handleConnectionStatusEvent(statusEvent);
}
else if (event instanceof BlueGigaDisconnectedEvent) {
handleDisconnectedEvent((BlueGigaDisconnectedEvent) event);
else if (event instanceof BlueGigaDisconnectedEvent disconnectedEvent) {
handleDisconnectedEvent(disconnectedEvent);
}
else if (event instanceof BlueGigaAttributeValueEvent) {
handleAttributeValueEvent((BlueGigaAttributeValueEvent) event);
else if (event instanceof BlueGigaAttributeValueEvent valueEvent) {
handleAttributeValueEvent(valueEvent);
}
}

View File

@ -779,9 +779,8 @@ public class BlueGigaBridgeHandler extends AbstractBluetoothBridgeHandler<BlueGi
@Override
public void bluegigaEventReceived(@Nullable BlueGigaResponse event) {
if (event instanceof BlueGigaScanResponseEvent) {
if (event instanceof BlueGigaScanResponseEvent scanEvent) {
if (initComplete) {
BlueGigaScanResponseEvent scanEvent = (BlueGigaScanResponseEvent) event;
// We use the scan event to add any devices we hear to the devices list
// The device gets created, and then manages itself for discovery etc.
@ -795,13 +794,11 @@ public class BlueGigaBridgeHandler extends AbstractBluetoothBridgeHandler<BlueGi
return;
}
if (event instanceof BlueGigaConnectionStatusEvent) {
BlueGigaConnectionStatusEvent connectionEvent = (BlueGigaConnectionStatusEvent) event;
if (event instanceof BlueGigaConnectionStatusEvent connectionEvent) {
connections.put(connectionEvent.getConnection(), new BluetoothAddress(connectionEvent.getAddress()));
}
if (event instanceof BlueGigaDisconnectedEvent) {
BlueGigaDisconnectedEvent disconnectedEvent = (BlueGigaDisconnectedEvent) event;
if (event instanceof BlueGigaDisconnectedEvent disconnectedEvent) {
connections.remove(disconnectedEvent.getConnection());
}
}

View File

@ -35,11 +35,11 @@ public class BlueGigaConfiguration extends BaseBluetoothBridgeHandlerConfigurati
@Override
public String toString() {
return String.format(
"[discovery=%b, port=%s, passiveScanIdleTime=%d, passiveScanInterval=%d, passiveScanWindow=%d"
+ ", activeScanInterval=%d, activeScanWindow=%d, connIntervalMin=%d, connIntervalMax=%d"
+ ", connLatency=%d, connTimeout=%d]",
backgroundDiscovery, port, passiveScanIdleTime, passiveScanInterval, passiveScanWindow,
return String.format("""
[discovery=%b, port=%s, passiveScanIdleTime=%d, passiveScanInterval=%d, passiveScanWindow=%d\
, activeScanInterval=%d, activeScanWindow=%d, connIntervalMin=%d, connIntervalMax=%d\
, connLatency=%d, connTimeout=%d]\
""", backgroundDiscovery, port, passiveScanIdleTime, passiveScanInterval, passiveScanWindow,
activeScanInterval, activeScanWindow, connIntervalMin, connIntervalMax, connLatency, connTimeout);
}
}

View File

@ -194,8 +194,7 @@ class BlueGigaResponsePackets {
try {
ctor = bleClass.getConstructor(int[].class);
BlueGigaResponse bleFrame = (BlueGigaResponse) ctor.newInstance(data);
return bleFrame;
return (BlueGigaResponse) ctor.newInstance(data);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
logger.debug("Error instantiating BLE class", e);

View File

@ -260,8 +260,10 @@ public class BlueGigaSerialHandler {
private void checkIfAlive() {
if (!isAlive()) {
throw new IllegalStateException("Bluegiga handler is dead. Most likely because of IO errors. "
+ "Re-initialization of the BlueGigaSerialHandler is required.");
throw new IllegalStateException("""
Bluegiga handler is dead. Most likely because of IO errors. \
Re-initialization of the BlueGigaSerialHandler is required.\
""");
}
}

View File

@ -154,7 +154,7 @@ public class BlueGigaTransactionManager implements BlueGigaSerialEventListener {
private void sendNextTransactionIfNoOngoing() {
synchronized (this) {
logger.trace("Send next transaction if no ongoing");
if (!ongoingTransactionId.isPresent()) {
if (ongoingTransactionId.isEmpty()) {
sendNextFrame();
}
}
@ -243,9 +243,8 @@ public class BlueGigaTransactionManager implements BlueGigaSerialEventListener {
logger.trace("Expected frame: {}, received frame: {}", expected.getSimpleName(), bleResponse);
if (bleCommand instanceof BlueGigaDeviceCommand && bleResponse instanceof BlueGigaDeviceResponse) {
BlueGigaDeviceCommand devCommand = (BlueGigaDeviceCommand) bleCommand;
BlueGigaDeviceResponse devResponse = (BlueGigaDeviceResponse) bleResponse;
if (bleCommand instanceof BlueGigaDeviceCommand devCommand
&& bleResponse instanceof BlueGigaDeviceResponse devResponse) {
logger.trace("Expected connection id: {}, received connection id: {}", devCommand.getConnection(),
devResponse.getConnection());

View File

@ -12,7 +12,6 @@
*/
package org.openhab.binding.bluetooth.bluegiga.internal.factory;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@ -48,8 +47,8 @@ import org.osgi.service.component.annotations.Reference;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.bluegiga")
public class BlueGigaHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
.of(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA);
private final Map<ThingUID, ServiceRegistration<?>> serviceRegs = new HashMap<>();
@ -90,8 +89,8 @@ public class BlueGigaHandlerFactory extends BaseThingHandlerFactory {
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof BluetoothAdapter) {
UID uid = ((BluetoothAdapter) thingHandler).getUID();
if (thingHandler instanceof BluetoothAdapter bluetoothAdapter) {
UID uid = bluetoothAdapter.getUID();
ServiceRegistration<?> serviceReg = this.serviceRegs.remove(uid);
if (serviceReg != null) {
serviceReg.unregister();

View File

@ -194,8 +194,7 @@ public class BlueZBridgeHandler extends AbstractBluetoothBridgeHandler<BlueZBlue
@Override
protected BlueZBluetoothDevice createDevice(BluetoothAddress address) {
logger.debug("createDevice {}", address);
BlueZBluetoothDevice device = new BlueZBluetoothDevice(this, address);
return device;
return new BlueZBluetoothDevice(this, address);
}
@Override

Some files were not shown because too many files have changed in this diff Show More