Skip to content

Commit

Permalink
[powermax] Add null annotations (openhab#11275)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Oct 10, 2021
1 parent 28c3095 commit bd582c5
Show file tree
Hide file tree
Showing 46 changed files with 720 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@
*/
package org.openhab.binding.powermax.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link PowermaxIpConfiguration} is responsible for holding
* configuration informations associated to a Powermax IP thing type
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public class PowermaxIpConfiguration {

public String ip;
public Integer tcpPort;
public Integer motionOffDelay;
public Boolean allowArming;
public Boolean allowDisarming;
public String pinCode;
public Boolean forceStandardMode;
public String panelType;
public Boolean autoSyncTime;
public String ip = "";
public int tcpPort = 0;
public int motionOffDelay = 3;
public boolean allowArming = false;
public boolean allowDisarming = false;
public String pinCode = "";
public boolean forceStandardMode = false;
public String panelType = "PowerMaxPro";
public boolean autoSyncTime = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
*/
package org.openhab.binding.powermax.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link PowermaxSerialConfiguration} is responsible for holding
* configuration informations associated to a Powermax serial thing type
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public class PowermaxSerialConfiguration {

public String serialPort;
public Integer motionOffDelay;
public Boolean allowArming;
public Boolean allowDisarming;
public String pinCode;
public Boolean forceStandardMode;
public String panelType;
public Boolean autoSyncTime;
public String serialPort = "";
public int motionOffDelay = 3;
public boolean allowArming = false;
public boolean allowDisarming = false;
public String pinCode = "";
public boolean forceStandardMode = false;
public String panelType = "PowerMaxPro";
public boolean autoSyncTime = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
*/
package org.openhab.binding.powermax.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link PowermaxX10Configuration} is responsible for holding
* configuration informations associated to a Powermax IP thing type
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public class PowermaxX10Configuration {

public static final String DEVICE_NUMBER = "deviceNumber";

public Integer deviceNumber;
public int deviceNumber = -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
*/
package org.openhab.binding.powermax.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link PowermaxZoneConfiguration} is responsible for holding
* configuration informations associated to a Powermax IP thing type
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public class PowermaxZoneConfiguration {

public static final String ZONE_NUMBER = "zoneNumber";

public Integer zoneNumber;
public int zoneNumber = -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.powermax.internal.message.PowermaxBaseMessage;
import org.openhab.binding.powermax.internal.message.PowermaxMessageEvent;
import org.openhab.binding.powermax.internal.message.PowermaxMessageEventListener;
Expand All @@ -30,17 +32,19 @@
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public abstract class PowermaxConnector implements PowermaxConnectorInterface {

private final Logger logger = LoggerFactory.getLogger(PowermaxConnector.class);

private InputStream input;
private OutputStream output;
protected final String readerThreadName;
private final List<PowermaxMessageEventListener> listeners = new ArrayList<>();

private @Nullable InputStream input;
private @Nullable OutputStream output;
private boolean connected;
protected String readerThreadName;
private Thread readerThread;
private @Nullable Thread readerThread;
private long waitingForResponse;
private List<PowermaxMessageEventListener> listeners = new ArrayList<>();

public PowermaxConnector(String readerThreadName) {
this.readerThreadName = readerThreadName;
Expand All @@ -58,26 +62,29 @@ public PowermaxConnector(String readerThreadName) {
protected void cleanup(boolean closeStreams) {
logger.debug("cleanup(): cleaning up Connection");

if (readerThread != null) {
readerThread.interrupt();
Thread thread = readerThread;
if (thread != null) {
thread.interrupt();
try {
readerThread.join();
thread.join();
} catch (InterruptedException e) {
}
}

if (closeStreams) {
if (output != null) {
OutputStream out = output;
if (out != null) {
try {
output.close();
out.close();
} catch (IOException e) {
logger.debug("Error while closing the output stream: {}", e.getMessage());
}
}

if (input != null) {
InputStream in = input;
if (in != null) {
try {
input.close();
in.close();
} catch (IOException e) {
logger.debug("Error while closing the input stream: {}", e.getMessage());
}
Expand Down Expand Up @@ -107,16 +114,20 @@ public void handleIncomingMessage(byte[] incomingMessage) {
/**
* Handles a communication failure
*/
public void handleCommunicationFailure(String message) {
public void handleCommunicationFailure(@Nullable String message) {
close();
listeners.forEach(listener -> listener.onCommunicationFailure(message));
listeners.forEach(listener -> listener.onCommunicationFailure(message != null ? message : ""));
}

@Override
public void sendMessage(byte[] data) {
try {
output.write(data);
output.flush();
OutputStream out = output;
if (out == null) {
throw new IOException("output stream is undefined");
}
out.write(data);
out.flush();
} catch (IOException e) {
logger.debug("sendMessage(): Writing error: {}", e.getMessage(), e);
handleCommunicationFailure(e.getMessage());
Expand All @@ -125,7 +136,11 @@ public void sendMessage(byte[] data) {

@Override
public int read(byte[] buffer) throws IOException {
return input.read(buffer);
InputStream in = input;
if (in == null) {
throw new IOException("input stream is undefined");
}
return in.read(buffer);
}

@Override
Expand All @@ -141,7 +156,7 @@ public void removeEventListener(PowermaxMessageEventListener listener) {
/**
* @return the input stream
*/
public InputStream getInput() {
public @Nullable InputStream getInput() {
return input;
}

Expand All @@ -150,14 +165,14 @@ public InputStream getInput() {
*
* @param input the input stream
*/
public void setInput(InputStream input) {
public void setInput(@Nullable InputStream input) {
this.input = input;
}

/**
* @return the output stream
*/
public OutputStream getOutput() {
public @Nullable OutputStream getOutput() {
return output;
}

Expand All @@ -166,7 +181,7 @@ public OutputStream getOutput() {
*
* @param output the output stream
*/
public void setOutput(OutputStream output) {
public void setOutput(@Nullable OutputStream output) {
this.output = output;
}

Expand All @@ -190,7 +205,7 @@ public void setConnected(boolean connected) {
/**
* @return the thread that handles the message reading
*/
public Thread getReaderThread() {
public @Nullable Thread getReaderThread() {
return readerThread;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

import java.io.IOException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.powermax.internal.message.PowermaxMessageEventListener;

/**
* Interface for communication with the Visonic alarm panel
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public interface PowermaxConnectorInterface {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.InterruptedIOException;
import java.util.Arrays;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.powermax.internal.message.PowermaxCommManager;
import org.openhab.binding.powermax.internal.message.PowermaxReceiveType;
import org.openhab.core.util.HexUtils;
Expand All @@ -27,14 +28,15 @@
*
* @author Laurent Garnier - Initial contribution
*/
@NonNullByDefault
public class PowermaxReaderThread extends Thread {

private final Logger logger = LoggerFactory.getLogger(PowermaxReaderThread.class);

private static final int READ_BUFFER_SIZE = 20;
private static final int MAX_MSG_SIZE = 0xC0;

private PowermaxConnector connector;
private final Logger logger = LoggerFactory.getLogger(PowermaxReaderThread.class);

private final PowermaxConnector connector;

/**
* Constructor
Expand Down
Loading

0 comments on commit bd582c5

Please sign in to comment.