Skip to content

Commit

Permalink
[knx] Code cleanup (#16199)
Browse files Browse the repository at this point in the history
- Enhance trace logging
- Remove unused file
- Null annotations

Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich authored Jan 3, 2024
1 parent 18da507 commit ce1f366
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 73 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ public void writeToKNX(OutboundSpec commandSpec) throws KNXException {
}
GroupAddress groupAddress = commandSpec.getGroupAddress();

logger.trace("writeToKNX groupAddress '{}', commandSpec '{}'", groupAddress, commandSpec);
logger.trace("writeToKNX groupAddress '{}', commandSpec '{}:{} {}'", groupAddress, groupAddress,
commandSpec.getDPT(), commandSpec.getValue());

sendToKNX(processCommunicator, groupAddress, commandSpec.getDPT(), commandSpec.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ private synchronized void startDiscovery() {
for (Result<SearchResponse> r : responses) {
@Nullable
SearchResponse response = r.getResponse();
if (response == null) {
continue;
}
Map<ServiceFamily, Integer> services = response.getServiceFamilies().families();

if (services.containsKey(ServiceFamiliesDIB.ServiceFamily.Tunneling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public class KNXProfileAdvisor implements ProfileAdvisor {
if (channelTypeUID == null || !channelTypeUID.getBindingId().equals(BINDING_ID)) {
return null;
}
return getSuggestedProfieTypeUID(channelTypeUID);
return getSuggestedProfileTypeUID(channelTypeUID);
}

@Override
public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
return getSuggestedProfieTypeUID(channelType.getUID());
return getSuggestedProfileTypeUID(channelType.getUID());
}

private ProfileTypeUID getSuggestedProfieTypeUID(ChannelTypeUID channelTypeUID) {
private ProfileTypeUID getSuggestedProfileTypeUID(ChannelTypeUID channelTypeUID) {
if (isControl(channelTypeUID)) {
return SystemProfiles.FOLLOW;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
package org.openhab.binding.knx.internal.client;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.util.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,27 +44,27 @@
*
* @author Holger Friedrich - Initial contribution
*/
@NonNullByDefault({})
@NonNullByDefault
public class DummyKNXNetworkLink implements KNXNetworkLink {
public static final Logger LOGGER = LoggerFactory.getLogger(DummyKNXNetworkLink.class);
public static final int GROUP_WRITE = 0x80;

private byte[] lastFrame = new byte[0];
private Set<NetworkLinkListener> listeners = new HashSet<>();
private Set<@Nullable NetworkLinkListener> listeners = new HashSet<>();

public void setKNXMedium(KNXMediumSettings settings) {
LOGGER.warn(settings.toString());
public void setKNXMedium(@Nullable KNXMediumSettings settings) {
LOGGER.warn(Objects.toString(settings));
}

public KNXMediumSettings getKNXMedium() {
return KNXMediumSettings.create(KNXMediumSettings.MEDIUM_TP1, new IndividualAddress(1, 2, 3));
}

public void addLinkListener(NetworkLinkListener l) {
public void addLinkListener(@Nullable NetworkLinkListener l) {
listeners.add(l);
}

public void removeLinkListener(NetworkLinkListener l) {
public void removeLinkListener(@Nullable NetworkLinkListener l) {
listeners.remove(l);
}

Expand All @@ -73,13 +75,16 @@ public int getHopCount() {
return 0;
}

public void sendRequest(KNXAddress dst, Priority p, byte[] nsdu)
public void sendRequest(@Nullable KNXAddress dst, @Nullable Priority p, byte @Nullable [] nsdu)
throws KNXTimeoutException, KNXLinkClosedException {
sendRequestWait(dst, p, nsdu);
}

public void sendRequestWait(KNXAddress dst, Priority p, byte[] nsdu)
public void sendRequestWait(@Nullable KNXAddress dst, @Nullable Priority p, byte @Nullable [] nsdu)
throws KNXTimeoutException, KNXLinkClosedException {
if (nsdu == null) {
return;
}
LOGGER.info("sendRequestWait() {} {} {}", dst, p, HexUtils.bytesToHex(nsdu, " "));

lastFrame = nsdu.clone();
Expand Down Expand Up @@ -109,11 +114,13 @@ public void sendRequestWait(KNXAddress dst, Priority p, byte[] nsdu)
FrameEvent f = new FrameEvent(this, new CEMILData(CEMILData.MC_LDATA_IND, src, dst, nsdu, p, repeat, hopCount));

listeners.forEach(listener -> {
listener.indication(f);
if (listener != null) {
listener.indication(f);
}
});
}

public void send(CEMILData msg, boolean waitForCon) throws KNXTimeoutException, KNXLinkClosedException {
public void send(@Nullable CEMILData msg, boolean waitForCon) throws KNXTimeoutException, KNXLinkClosedException {
LOGGER.warn("send() not implemented");
}

Expand Down

0 comments on commit ce1f366

Please sign in to comment.