Fix NPE on shutdown when Thing disabled and fix a bunch of warnings (#13215)

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2022-08-04 08:56:52 -05:00 committed by GitHub
parent 0d73ed8150
commit 9f3a23c55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 61 additions and 57 deletions

View File

@ -211,19 +211,19 @@ As of firmware 1.6.8 (rev 14),
Here is an example with minimal configuration parameters (using default values with no telnet login):
```java
```
atlona:pro3-88m:home [ ipAddress="192.168.1.30" ]
```
Here is another example with minimal configuration parameters (using default values with telnet login):
```java
```
atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345" ]
```
Here is a full configuration example:
```java
```
atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345", polling=600, ping=30, retryPolling=10 ]
```
@ -231,7 +231,7 @@ atlona:pro3-88m:home [ ipAddress="192.168.1.30", userName="me", password="12345"
Here is an example of items for the AT-UHD-PRO33-88M:
```java
```
Switch Atlona_Power "Power" { channel = "atlona:pro3-88m:home:primary#power" }
Switch Atlona_PanelLock "Panel Lock" { channel = "atlona:pro3-88m:home:primary#panellock" }
Switch Atlona_Presets "Preset Command" { channel = "atlona:pro3-88m:home:primary#presetcmd" }
@ -274,7 +274,7 @@ Switch Atlona_VolumeMute6 "Mute 6" { channel = "atlona:pro3-88m:home:volume1#vol
### SiteMap
```perl
```
sitemap demo label="Main Menu" {
Frame label="Atlona" {
Text label="Device" {
@ -332,7 +332,7 @@ Be sure they are in sync with the mappings above.
### atlonainputports.map
```text
```
1=CableBox
2=BluRay Player
3=Roku
@ -347,7 +347,7 @@ NULL=-
### atlonaoutputports.map
```text
```
1=Living Room
2=Master Bed
3=Kitchen

View File

@ -12,7 +12,8 @@
*/
package org.openhab.binding.atlona.internal;
import org.openhab.binding.atlona.internal.handler.AtlonaHandler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.types.State;
@ -23,6 +24,7 @@ import org.openhab.core.types.State;
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
public interface AtlonaHandlerCallback {
/**
* Callback to the {@link AtlonaHandler} to update the status of the thing.
@ -31,7 +33,7 @@ public interface AtlonaHandlerCallback {
* @param detail a non-null {@link org.openhab.core.thing.ThingStatusDetail}
* @param msg a possibly null, possibly empty message
*/
void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg);
void statusChanged(ThingStatus status, ThingStatusDetail detail, @Nullable String msg);
/**
* Callback to the {@link AtlonaHandler} to update the state of an item

View File

@ -17,6 +17,8 @@ import static org.openhab.binding.atlona.internal.AtlonaBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Capabilities;
import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Handler;
import org.openhab.core.thing.Thing;
@ -35,6 +37,7 @@ import org.slf4j.LoggerFactory;
* @author Tim Roberts - Initial contribution
* @author Michael Lobstein - Add support for AT-PRO3HD66M
*/
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.atlona")
public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
@ -62,7 +65,7 @@ public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
* Creates the handler for the given thing given its thingTypeUID
*/
@Override
protected ThingHandler createHandler(Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_PRO3_44M)) {

View File

@ -88,7 +88,7 @@ public class StatefulHandlerCallback implements AtlonaHandlerCallback {
*/
@Override
public void stateChanged(String channelId, State state) {
if (channelId == null || "".equals(channelId)) {
if ("".equals(channelId)) {
return;
}

View File

@ -137,7 +137,7 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
multiSocket.receive(receivePacket);
String message = new String(receivePacket.getData()).trim();
if (message != null && message.length() > 0) {
if (message.length() > 0) {
messageReceive(message);
}
} catch (SocketTimeoutException e) {
@ -196,17 +196,17 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
if (idx > 0) {
String name = msg.substring(0, idx);
if (name.equalsIgnoreCase("Host")) {
if ("Host".equalsIgnoreCase(name)) {
host = msg.substring(idx + 1).trim().replaceAll("\"", "");
int sep = host.indexOf('_');
if (sep >= 0) {
host = host.substring(sep + 1);
}
} else if (name.equalsIgnoreCase("Model")) {
} else if ("Model".equalsIgnoreCase(name)) {
model = msg.substring(idx + 1).trim().replaceAll("\"", "");
} else if (name.equalsIgnoreCase("Manufacturer")) {
} else if ("Manufacturer".equalsIgnoreCase(name)) {
manufacturer = msg.substring(idx + 1).trim().replaceAll("\"", "");
} else if (name.equalsIgnoreCase("From")) {
} else if ("From".equalsIgnoreCase(name)) {
from = msg.substring(idx + 1).trim().replaceAll("\"", "");
int sep = from.indexOf(':');
if (sep >= 0) {
@ -223,13 +223,13 @@ public class AtlonaDiscovery extends AbstractDiscoveryService {
if (host != null && model != null && from != null) {
ThingTypeUID typeId = null;
if (model.equalsIgnoreCase("AT-UHD-PRO3-44M")) {
if ("AT-UHD-PRO3-44M".equalsIgnoreCase(model)) {
typeId = THING_TYPE_PRO3_44M;
} else if (model.equalsIgnoreCase("AT-UHD-PRO3-66M")) {
} else if ("AT-UHD-PRO3-66M".equalsIgnoreCase(model)) {
typeId = THING_TYPE_PRO3_66M;
} else if (model.equalsIgnoreCase("AT-UHD-PRO3-88M")) {
} else if ("AT-UHD-PRO3-88M".equalsIgnoreCase(model)) {
typeId = THING_TYPE_PRO3_88M;
} else if (model.equalsIgnoreCase("AT-UHD-PRO3-1616M")) {
} else if ("AT-UHD-PRO3-1616M".equalsIgnoreCase(model)) {
typeId = THING_TYPE_PRO3_1616M;
} else {
logger.warn("Unknown model #: {}", model);

View File

@ -12,12 +12,15 @@
*/
package org.openhab.binding.atlona.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Any model specific capabilities class should inherit from this base class. Currently doesn't provide any generic
* functionality.
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
public abstract class AtlonaCapabilities {
}

View File

@ -100,9 +100,6 @@ public class SocketChannelSession implements SocketSession {
@Override
public void addListener(SocketSessionListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener cannot be null");
}
listeners.add(listener);
}
@ -166,10 +163,6 @@ public class SocketChannelSession implements SocketSession {
@Override
public synchronized void sendCommand(String command) throws IOException {
if (command == null) {
throw new IllegalArgumentException("command cannot be null");
}
if (!isConnected()) {
throw new IOException("Cannot send message - disconnected");
}

View File

@ -14,12 +14,15 @@ package org.openhab.binding.atlona.internal.net;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This is a socket session interface that defines the contract for a socket session. A socket session will initiate
* communications with the underlying device and provide message back via the {@link SocketSessionListener}
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
public interface SocketSession {
/**

View File

@ -12,12 +12,15 @@
*/
package org.openhab.binding.atlona.internal.net;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Interface defining a listener to a {@link SocketSession} that will receive responses and/or exceptions from the
* socket
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
public interface SocketSessionListener {
/**
* Called when a command has completed with the response for the command

View File

@ -16,6 +16,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.atlona.internal.handler.AtlonaCapabilities;
/**
@ -25,6 +26,7 @@ import org.openhab.binding.atlona.internal.handler.AtlonaCapabilities;
* @author Tim Roberts - Initial contribution
* @author Michael Lobstein - Add support for AT-PRO3HD66M
*/
@NonNullByDefault
public class AtlonaPro3Capabilities extends AtlonaCapabilities {
/**
@ -57,10 +59,6 @@ public class AtlonaPro3Capabilities extends AtlonaCapabilities {
public AtlonaPro3Capabilities(int nbrPowerPorts, int nbrAudioPorts, Set<Integer> hdmiPorts, boolean isUHDModel) {
super();
if (hdmiPorts == null) {
throw new IllegalArgumentException("hdmiPorts cannot be null");
}
if (hdmiPorts.isEmpty()) {
throw new IllegalArgumentException("hdmiPorts cannot be empty");
}

View File

@ -12,8 +12,6 @@
*/
package org.openhab.binding.atlona.internal.pro3;
import org.openhab.binding.atlona.internal.discovery.AtlonaDiscovery;
/**
* Configuration class for the Atlona Pro3 line of switchers
*

View File

@ -12,12 +12,15 @@
*/
package org.openhab.binding.atlona.internal.pro3;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link AtlonaPro3Binding} class defines common constants, which are
* used across the whole binding.
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
class AtlonaPro3Constants {
// Properties
@ -44,7 +47,6 @@ class AtlonaPro3Constants {
static final String CHANNEL_VOLUME = "volume";
static final String CHANNEL_VOLUME_MUTE = "volumemute";
// static final String CHANNEL_RS232 = "rs232cmd";
static final String CONFIG_HOSTNAME = "hostname";
static final String CONFIG_OUTPUT = "output";

View File

@ -554,10 +554,12 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
ping = null;
}
try {
session.disconnect();
} catch (IOException e) {
// ignore - we don't care
if (session != null) {
try {
session.disconnect();
} catch (IOException e) {
// ignore - we don't care
}
}
if (retryConnection) {
@ -588,16 +590,10 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
/**
* Simple gets the {@link AtlonaPro3Config} from the {@link Thing} and will set the status to offline if not found.
*
* @return a possible null {@link AtlonaPro3Config}
* @return {@link AtlonaPro3Config}
*/
private AtlonaPro3Config getAtlonaConfig() {
final AtlonaPro3Config config = getThing().getConfiguration().as(AtlonaPro3Config.class);
if (config == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
return config;
return getThing().getConfiguration().as(AtlonaPro3Config.class);
}
/**

View File

@ -199,7 +199,7 @@ class AtlonaPro3PortocolHandler {
String response;
try {
response = callback.getResponse();
if (!response.equals("")) {
if (!"".equals(response)) {
logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
}
} catch (Exception e) {
@ -223,13 +223,13 @@ class AtlonaPro3PortocolHandler {
// We should have been presented with a new "\r\nLogin: "
response = callback.getResponse();
if (!response.equals("")) {
if (!"".equals(response)) {
logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
}
// Get the new "Login: " prompt response
response = callback.getResponse();
if (response.equals(RSP_LOGIN)) {
if (RSP_LOGIN.equals(response)) {
if (config.getUserName() == null || config.getUserName().trim().length() == 0) {
return "Atlona PRO3 has enabled Telnet/IP Login but no username was provided in the configuration.";
}
@ -244,12 +244,12 @@ class AtlonaPro3PortocolHandler {
response = callback.getResponse();
// Burn the empty response if we got one (
if (response.equals("")) {
if ("".equals(response)) {
response = callback.getResponse();
}
if (!response.equals(RSP_PASSWORD)) {
if (!RSP_PASSWORD.equals(response)) {
// If we got another login response, username wasn't valid
if (response.equals(RSP_LOGIN)) {
if (RSP_LOGIN.equals(response)) {
return "Username " + config.getUserName() + " is not a valid user on the atlona";
}
return "Atlona protocol violation - invalid response to a login: " + response;
@ -270,7 +270,7 @@ class AtlonaPro3PortocolHandler {
// Send an invalid command to see if we get the failed command response
// First make sure we had an empty response (the "\r\n" part)
if (!response.equals("")) {
if (!"".equals(response)) {
logger.debug("Atlona protocol violation - not an empty response after password: '{}'", response);
}
@ -307,7 +307,7 @@ class AtlonaPro3PortocolHandler {
String response;
try {
response = callback.getResponse();
if (!response.equals("")) {
if (!"".equals(response)) {
logger.debug("Atlona protocol violation - didn't start with an inital empty response: '{}'", response);
}
} catch (Exception e) {
@ -335,7 +335,7 @@ class AtlonaPro3PortocolHandler {
// Check for an empty response after the login prompt (the "\r\n" part)
response = callback.getResponse();
if (!response.equals("")) {
if (!"".equals(response)) {
logger.debug("Atlona protocol violation - not an empty response after password: '{}'", response);
}
@ -907,7 +907,7 @@ class AtlonaPro3PortocolHandler {
// could be "off" (if mirror off), "on"/"Out" (with 3rd group representing out)
String oper = (m.group(2) == null ? "" : m.group(2).trim()).toLowerCase();
if (oper.equals("off")) {
if ("off".equals(oper)) {
callback.stateChanged(AtlonaPro3Utilities.createChannelID(AtlonaPro3Constants.GROUP_MIRROR,
hdmiPortNbr, AtlonaPro3Constants.CHANNEL_PORTMIRRORENABLED), OnOffType.OFF);
} else {
@ -1088,7 +1088,7 @@ class AtlonaPro3PortocolHandler {
@Override
public void responseReceived(String response) {
if (response == null || response.isEmpty()) {
if (response.isEmpty()) {
return;
}

View File

@ -12,10 +12,13 @@
*/
package org.openhab.binding.atlona.internal.pro3;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
*
* @author Tim Roberts - Initial contribution
*/
@NonNullByDefault
public class AtlonaPro3Utilities {
/**
* Helper method to create a channel id from a group with no port number attached