-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[tellstick] Add null annotations #17974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
75b5110
Update async-http-client
lsiepel f6e7960
Add annotations and fix some warnings
lsiepel f62861b
Update bundles/org.openhab.binding.tellstick/src/main/java/org/openha…
lsiepel 1329b3e
Update bundles/org.openhab.binding.tellstick/src/main/java/org/openha…
lsiepel e83c197
Update bundles/org.openhab.binding.tellstick/src/main/java/org/openha…
lsiepel b5baad7
Merge branch 'openhab:main' into tellstick-null-annotations
lsiepel d718cb6
Fix review comments
lsiepel c2e35e3
Merge branch 'main' into tellstick-null-annotations
lsiepel 2605c8b
Update bundles/org.openhab.binding.tellstick/src/main/java/org/openha…
lsiepel 7f33244
Update bundles/org.openhab.binding.tellstick/src/main/java/org/openha…
lsiepel df5622a
Fix review comment
lsiepel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |||
| import java.util.Vector; | ||||
| import java.util.concurrent.ConcurrentHashMap; | ||||
|
|
||||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||||
| import org.eclipse.jdt.annotation.Nullable; | ||||
| import org.openhab.binding.tellstick.internal.conf.TellstickBridgeConfiguration; | ||||
| import org.openhab.binding.tellstick.internal.handler.DeviceStatusListener; | ||||
| import org.openhab.binding.tellstick.internal.handler.TelldusBridgeHandler; | ||||
|
|
@@ -54,6 +56,7 @@ | |||
| * | ||||
| * @author Jarle Hjortland - Initial contribution | ||||
| */ | ||||
| @NonNullByDefault | ||||
| public class TelldusCoreBridgeHandler extends BaseBridgeHandler | ||||
| implements DeviceChangeListener, SensorListener, TelldusBridgeHandler { | ||||
|
|
||||
|
|
@@ -62,10 +65,10 @@ public TelldusCoreBridgeHandler(Bridge br) { | |||
| } | ||||
|
|
||||
| private Logger logger = LoggerFactory.getLogger(TelldusCoreBridgeHandler.class); | ||||
| private TelldusDeviceController deviceController = null; | ||||
| private @Nullable TelldusDeviceController deviceController; | ||||
| private List<TellstickDevice> deviceList = new Vector<>(); | ||||
| private List<TellstickSensor> sensorList = new Vector<>(); | ||||
| private TellstickEventHandler eventHandler; | ||||
| private @Nullable TellstickEventHandler eventHandler; | ||||
| private static boolean initialized = false; | ||||
| private Set<DeviceStatusListener> deviceStatusListeners = ConcurrentHashMap.newKeySet(); | ||||
|
|
||||
|
|
@@ -82,21 +85,24 @@ public void handleCommand(ChannelUID channelUID, Command command) { | |||
| @Override | ||||
| public void dispose() { | ||||
| logger.debug("Telldus Core Handler disposed."); | ||||
| TelldusDeviceController deviceController = this.deviceController; | ||||
| if (deviceController != null) { | ||||
| deviceController.dispose(); | ||||
| deviceController = null; | ||||
| this.deviceController = null; | ||||
| } | ||||
|
|
||||
| TellstickEventHandler eventHandler = this.eventHandler; | ||||
| if (eventHandler != null) { | ||||
| eventHandler.remove(); | ||||
| eventHandler = null; | ||||
| this.eventHandler = null; | ||||
| } | ||||
| clearDeviceList(); | ||||
| initialized = false; | ||||
| JNA.CLibrary.INSTANCE.tdClose(); | ||||
| super.dispose(); | ||||
| } | ||||
|
|
||||
| private String init(String libraryPath) { | ||||
| private @Nullable String init(@Nullable String libraryPath) { | ||||
| if (!initialized) { | ||||
| if (libraryPath != null) { | ||||
| logger.info("Loading {} from {}", JNA.nativeLibrary, libraryPath); | ||||
|
|
@@ -131,7 +137,10 @@ public void initialize() { | |||
| private void setupDeviceController(TellstickBridgeConfiguration configuration) { | ||||
| deviceController = new TelldusCoreDeviceController(configuration.resendInterval, | ||||
| "OH-binding-" + getThing().getUID() + "-worker"); | ||||
| eventHandler.addListener((TelldusCoreDeviceController) deviceController); | ||||
| TellstickEventHandler eventHandler = this.eventHandler; | ||||
| if (eventHandler != null) { | ||||
| eventHandler.addListener((TelldusCoreDeviceController) deviceController); | ||||
| } | ||||
| } | ||||
|
|
||||
| @Override | ||||
|
|
@@ -168,8 +177,9 @@ public void rescanTelldusDevices() { | |||
| } | ||||
|
|
||||
| private synchronized void setupListeners() { | ||||
| eventHandler = new TellstickEventHandler(deviceList); | ||||
| TellstickEventHandler eventHandler = new TellstickEventHandler(deviceList); | ||||
| eventHandler.addListener(this); | ||||
| this.eventHandler = eventHandler; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed anymore, since already assigned in line 180.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot about this when merging, but it's quite minor. |
||||
| } | ||||
|
|
||||
| public void onConnectionLost() { | ||||
|
|
@@ -183,7 +193,7 @@ public void onConnection() { | |||
| } | ||||
|
|
||||
| @Override | ||||
| public boolean registerDeviceStatusListener(DeviceStatusListener deviceStatusListener) { | ||||
| public boolean registerDeviceStatusListener(@Nullable DeviceStatusListener deviceStatusListener) { | ||||
| if (deviceStatusListener == null) { | ||||
| throw new IllegalArgumentException("It's not allowed to pass a null deviceStatusListener."); | ||||
| } | ||||
|
|
@@ -200,7 +210,7 @@ public void clearDeviceList() { | |||
| sensorList.clear(); | ||||
| } | ||||
|
|
||||
| private Device getDevice(String id, List<TellstickDevice> devices) { | ||||
| private @Nullable Device getDevice(String id, List<TellstickDevice> devices) { | ||||
| for (Device device : devices) { | ||||
| if (device.getId() == Integer.valueOf(id)) { | ||||
| return device; | ||||
|
|
@@ -210,12 +220,12 @@ private Device getDevice(String id, List<TellstickDevice> devices) { | |||
| } | ||||
|
|
||||
| @Override | ||||
| public Device getDevice(String serialNumber) { | ||||
| public @Nullable Device getDevice(String serialNumber) { | ||||
| return getDevice(serialNumber, deviceList); | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public void onRequest(TellstickSensorEvent newEvent) { | ||||
| public void onRequest(@NonNullByDefault({}) TellstickSensorEvent newEvent) { | ||||
| String uuid = TellstickSensor.createUUId(newEvent.getSensorId(), newEvent.getModel(), newEvent.getProtocol()); | ||||
| Device device = getSensor(uuid); | ||||
| logger.debug("Sensor Event for {} event {}", device, newEvent); | ||||
|
|
@@ -248,7 +258,7 @@ public void onRequest(TellstickSensorEvent newEvent) { | |||
| } | ||||
|
|
||||
| @Override | ||||
| public void onRequest(TellstickDeviceEvent newEvent) { | ||||
| public void onRequest(@NonNullByDefault({}) TellstickDeviceEvent newEvent) { | ||||
| if (newEvent.getChangeType() == ChangeType.ADDED) { | ||||
| for (DeviceStatusListener listener : deviceStatusListeners) { | ||||
| listener.onDeviceAdded(getThing(), newEvent.getDevice()); | ||||
|
|
@@ -265,7 +275,7 @@ public void onRequest(TellstickDeviceEvent newEvent) { | |||
| } | ||||
|
|
||||
| @Override | ||||
| public Device getSensor(String deviceUUId) { | ||||
| public @Nullable Device getSensor(String deviceUUId) { | ||||
| for (Device device : sensorList) { | ||||
| if (device.getUUId().equals(deviceUUId)) { | ||||
| return device; | ||||
|
|
@@ -275,7 +285,7 @@ public Device getSensor(String deviceUUId) { | |||
| } | ||||
|
|
||||
| @Override | ||||
| public TelldusDeviceController getController() { | ||||
| public @Nullable TelldusDeviceController getController() { | ||||
| return this.deviceController; | ||||
| } | ||||
| } | ||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.