[neeo] improve code (#9028)

* create forwardactionsservlet only if forwardchain is not empty
* remove dependency on apache commons

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
J-N-K 2020-11-18 01:25:46 +01:00 committed by GitHub
parent 158cbe0c65
commit 6e3c640043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 134 additions and 167 deletions

View File

@ -13,7 +13,10 @@
package org.openhab.binding.neeo.internal; package org.openhab.binding.neeo.internal;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -31,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/** /**
* The class provides the API for communicating with a NEEO brain * The class provides the API for communicating with a NEEO brain
@ -162,7 +166,7 @@ public class NeeoBrainApi implements AutoCloseable {
* @return the non-null, possibly empty list of active scenarios keys * @return the non-null, possibly empty list of active scenarios keys
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
public String[] getActiveScenarios() throws IOException { public List<String> getActiveScenarios() throws IOException {
final String url = urlBuilder.append(NeeoConstants.GET_ACTIVESCENARIOS).toString(); final String url = urlBuilder.append(NeeoConstants.GET_ACTIVESCENARIOS).toString();
final HttpRequest rqst = request.get(); final HttpRequest rqst = request.get();
@ -171,7 +175,9 @@ public class NeeoBrainApi implements AutoCloseable {
throw resp.createException(); throw resp.createException();
} }
return Objects.requireNonNull(gson.fromJson(resp.getContent(), String[].class)); Type arrayListType = new TypeToken<ArrayList<String>>() {
}.getType();
return Objects.requireNonNull(gson.fromJson(resp.getContent(), arrayListType));
} }
/** /**

View File

@ -132,4 +132,11 @@ public class NeeoBrainConfig {
public void setCheckStatusInterval(int checkStatusInterval) { public void setCheckStatusInterval(int checkStatusInterval) {
this.checkStatusInterval = checkStatusInterval; this.checkStatusInterval = checkStatusInterval;
} }
@Override
public String toString() {
return "NeeoBrainConfig{" + "ipAddress='" + ipAddress + '\'' + ", enableForwardActions=" + enableForwardActions
+ ", forwardChain='" + forwardChain + '\'' + ", discoverEmptyRooms=" + discoverEmptyRooms
+ ", checkStatusInterval=" + checkStatusInterval + '}';
}
} }

View File

@ -13,11 +13,11 @@
package org.openhab.binding.neeo.internal; package org.openhab.binding.neeo.internal;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.models.ExecuteResult; import org.openhab.binding.neeo.internal.models.ExecuteResult;
@ -53,7 +53,7 @@ public class NeeoRoomProtocol {
private final NeeoRoom neeoRoom; private final NeeoRoom neeoRoom;
/** The currently active scenarios */ /** The currently active scenarios */
private final AtomicReference<String[]> activeScenarios = new AtomicReference<>(new String[0]); private final AtomicReference<List<String>> activeScenarios = new AtomicReference<>(new ArrayList<>());
/** /**
* Instantiates a new neeo room protocol. * Instantiates a new neeo room protocol.
@ -95,8 +95,8 @@ public class NeeoRoomProtocol {
Objects.requireNonNull(action, "action cannot be null"); Objects.requireNonNull(action, "action cannot be null");
final NeeoRecipes recipes = neeoRoom.getRecipes(); final NeeoRecipes recipes = neeoRoom.getRecipes();
final boolean launch = StringUtils.equalsIgnoreCase(NeeoRecipe.LAUNCH, action.getAction()); final boolean launch = NeeoRecipe.LAUNCH.equalsIgnoreCase(action.getAction());
final boolean poweroff = StringUtils.equalsIgnoreCase(NeeoRecipe.POWEROFF, action.getAction()); final boolean poweroff = NeeoRecipe.POWEROFF.equalsIgnoreCase(action.getAction());
// Can't be both true but if both false - it's neither one // Can't be both true but if both false - it's neither one
if (launch == poweroff) { if (launch == poweroff) {
@ -107,7 +107,7 @@ public class NeeoRoomProtocol {
final NeeoRecipe recipe = recipeName == null ? null : recipes.getRecipeByName(recipeName); final NeeoRecipe recipe = recipeName == null ? null : recipes.getRecipeByName(recipeName);
final String scenarioKey = recipe == null ? null : recipe.getScenarioKey(); final String scenarioKey = recipe == null ? null : recipe.getScenarioKey();
if (scenarioKey != null && StringUtils.isNotEmpty(scenarioKey)) { if (scenarioKey != null && !scenarioKey.isEmpty()) {
processScenarioChange(scenarioKey, launch); processScenarioChange(scenarioKey, launch);
} else { } else {
logger.debug("Could not find a recipe named '{}' for the action {}", recipeName, action); logger.debug("Could not find a recipe named '{}' for the action {}", recipeName, action);
@ -123,18 +123,27 @@ public class NeeoRoomProtocol {
private void processScenarioChange(String scenarioKey, boolean launch) { private void processScenarioChange(String scenarioKey, boolean launch) {
NeeoUtil.requireNotEmpty(scenarioKey, "scenarioKey cannot be empty"); NeeoUtil.requireNotEmpty(scenarioKey, "scenarioKey cannot be empty");
final String[] activeScenarios = this.activeScenarios.get(); List<String> oldActiveScenarios;
final int idx = ArrayUtils.indexOf(activeScenarios, scenarioKey); List<String> newActiveScenarios;
// already set that way do {
if ((idx < 0 && !launch) || (idx >= 0 && launch)) { oldActiveScenarios = this.activeScenarios.get();
return; newActiveScenarios = new ArrayList<>(oldActiveScenarios);
}
final String[] newScenarios = idx >= 0 ? (String[]) ArrayUtils.remove(activeScenarios, idx) if (newActiveScenarios.contains(scenarioKey)) {
: (String[]) ArrayUtils.add(activeScenarios, scenarioKey); if (launch) {
return;
this.activeScenarios.set(newScenarios); } else {
newActiveScenarios.remove(scenarioKey);
}
} else {
if (launch) {
newActiveScenarios.add(scenarioKey);
} else {
return;
}
}
} while (!this.activeScenarios.compareAndSet(oldActiveScenarios, newActiveScenarios));
refreshScenarioStatus(scenarioKey); refreshScenarioStatus(scenarioKey);
} }
@ -247,10 +256,9 @@ public class NeeoRoomProtocol {
final NeeoScenario scenario = neeoRoom.getScenarios().getScenario(scenarioKey); final NeeoScenario scenario = neeoRoom.getScenarios().getScenario(scenarioKey);
if (scenario != null) { if (scenario != null) {
final String[] active = activeScenarios.get(); final boolean isActive = activeScenarios.get().contains(scenarioKey);
final boolean isActive = ArrayUtils.contains(active, scenarioKey);
callback.stateChanged(UidUtils.createChannelId(NeeoConstants.ROOM_GROUP_SCENARIO_ID, callback.stateChanged(UidUtils.createChannelId(NeeoConstants.ROOM_GROUP_SCENARIO_ID,
NeeoConstants.ROOM_CHANNEL_STATUS, scenarioKey), isActive ? OnOffType.ON : OnOffType.OFF); NeeoConstants.ROOM_CHANNEL_STATUS, scenarioKey), OnOffType.from(isActive));
} }
} }
@ -263,19 +271,13 @@ public class NeeoRoomProtocol {
logger.debug("API is null [likely bridge is offline]"); logger.debug("API is null [likely bridge is offline]");
} else { } else {
try { try {
final String[] activeScenarios = api.getActiveScenarios(); final List<String> activeScenarios = api.getActiveScenarios();
final String[] oldScenarios = this.activeScenarios.getAndSet(activeScenarios); final List<String> oldScenarios = this.activeScenarios.getAndSet(activeScenarios);
if (!ArrayUtils.isEquals(activeScenarios, oldScenarios)) { if (!activeScenarios.equals(oldScenarios)) {
for (String scenario : activeScenarios) { activeScenarios.forEach(this::refreshScenarioStatus);
refreshScenarioStatus(scenario); oldScenarios.removeIf(activeScenarios::contains);
} oldScenarios.forEach(this::refreshScenarioStatus);
for (String oldScenario : oldScenarios) {
if (!ArrayUtils.contains(activeScenarios, oldScenario)) {
refreshScenarioStatus(oldScenario);
}
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.debug("Exception requesting active scenarios: {}", e.getMessage(), e); logger.debug("Exception requesting active scenarios: {}", e.getMessage(), e);
@ -292,7 +294,7 @@ public class NeeoRoomProtocol {
private void sendCurrentStepTrigger(@Nullable String step) { private void sendCurrentStepTrigger(@Nullable String step) {
callback.triggerEvent( callback.triggerEvent(
UidUtils.createChannelId(NeeoConstants.ROOM_GROUP_STATE_ID, NeeoConstants.ROOM_CHANNEL_CURRENTSTEP), UidUtils.createChannelId(NeeoConstants.ROOM_GROUP_STATE_ID, NeeoConstants.ROOM_CHANNEL_CURRENTSTEP),
step == null || StringUtils.isEmpty(step) ? "" : step); step == null || step.isEmpty() ? "" : step);
} }
/** /**
@ -312,10 +314,10 @@ public class NeeoRoomProtocol {
if (recipe != null) { if (recipe != null) {
if (recipe.isEnabled()) { if (recipe.isEnabled()) {
final boolean isLaunch = StringUtils.equalsIgnoreCase(NeeoRecipe.LAUNCH, recipe.getType()); final boolean isLaunch = NeeoRecipe.LAUNCH.equalsIgnoreCase(recipe.getType());
try { try {
if (isLaunch || scenarioKey == null || StringUtils.isEmpty(scenarioKey)) { if (isLaunch || scenarioKey == null || scenarioKey.isEmpty()) {
handleExecuteResult(scenarioKey, recipeKey, true, api.executeRecipe(roomKey, recipeKey)); handleExecuteResult(scenarioKey, recipeKey, true, api.executeRecipe(roomKey, recipeKey));
} else { } else {
handleExecuteResult(scenarioKey, recipeKey, false, api.stopScenario(roomKey, scenarioKey)); handleExecuteResult(scenarioKey, recipeKey, false, api.stopScenario(roomKey, scenarioKey));
@ -345,7 +347,7 @@ public class NeeoRoomProtocol {
start ? NeeoRecipe.LAUNCH : NeeoRecipe.POWEROFF); start ? NeeoRecipe.LAUNCH : NeeoRecipe.POWEROFF);
final String recipeKey = recipe == null ? null : recipe.getKey(); final String recipeKey = recipe == null ? null : recipe.getKey();
if (recipe != null && recipeKey != null && StringUtils.isNotEmpty(recipeKey)) { if (recipe != null && recipeKey != null && !recipeKey.isEmpty()) {
if (recipe.isEnabled()) { if (recipe.isEnabled()) {
startRecipe(recipeKey); startRecipe(recipeKey);
} else { } else {
@ -370,7 +372,7 @@ public class NeeoRoomProtocol {
NeeoUtil.requireNotEmpty(recipeKey, "recipeKey cannot be empty"); NeeoUtil.requireNotEmpty(recipeKey, "recipeKey cannot be empty");
int nextStep = 0; int nextStep = 0;
if (scenarioKey != null && StringUtils.isNotEmpty(scenarioKey)) { if (scenarioKey != null && !scenarioKey.isEmpty()) {
callback.scheduleTask(() -> { callback.scheduleTask(() -> {
processScenarioChange(scenarioKey, launch); processScenarioChange(scenarioKey, launch);
}, 1); }, 1);

View File

@ -12,10 +12,8 @@
*/ */
package org.openhab.binding.neeo.internal; package org.openhab.binding.neeo.internal;
import java.util.Objects;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.models.NeeoDevices; import org.openhab.binding.neeo.internal.models.NeeoDevices;
@ -104,8 +102,7 @@ public class NeeoUtil {
* @throws IllegalArgumentException if value is an empty string * @throws IllegalArgumentException if value is an empty string
*/ */
public static void requireNotEmpty(@Nullable String value, String msg) { public static void requireNotEmpty(@Nullable String value, String msg) {
Objects.requireNonNull(value, msg); if (value == null || value.isEmpty()) {
if (StringUtils.isEmpty(value)) {
throw new IllegalArgumentException(msg); throw new IllegalArgumentException(msg);
} }
} }

View File

@ -12,9 +12,6 @@
*/ */
package org.openhab.binding.neeo.internal; package org.openhab.binding.neeo.internal;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.models.NeeoDevice; import org.openhab.binding.neeo.internal.models.NeeoDevice;
@ -66,8 +63,6 @@ public class UidUtils {
* @return the non-null, non empty (only 1 or 2 element) list of parts * @return the non-null, non empty (only 1 or 2 element) list of parts
*/ */
public static String[] parseChannelId(ChannelUID uid) { public static String[] parseChannelId(ChannelUID uid) {
Objects.requireNonNull(uid, "uid cannot be null");
final String channelId = uid.getIdWithoutGroup(); final String channelId = uid.getIdWithoutGroup();
final int idx = channelId.indexOf(DELIMITER); final int idx = channelId.indexOf(DELIMITER);
if (idx < 0 || idx == channelId.length() - 1) { if (idx < 0 || idx == channelId.length() - 1) {
@ -101,8 +96,8 @@ public class UidUtils {
public static String createChannelId(@Nullable String groupId, String channelId, @Nullable String channelKey) { public static String createChannelId(@Nullable String groupId, String channelId, @Nullable String channelKey) {
NeeoUtil.requireNotEmpty(channelId, "channelId cannot be empty"); NeeoUtil.requireNotEmpty(channelId, "channelId cannot be empty");
return (StringUtils.isEmpty(groupId) ? "" : (groupId + "#")) return ((groupId == null || groupId.isEmpty()) ? "" : (groupId + "#"))
+ (StringUtils.isEmpty(channelKey) ? channelId : (channelId + DELIMITER + channelKey)); + ((channelKey == null || channelKey.isEmpty()) ? channelId : (channelId + DELIMITER + channelKey));
} }
/** /**
@ -129,6 +124,6 @@ public class UidUtils {
public static ChannelUID createChannelUID(ThingUID thingUid, String groupId, String channelId, public static ChannelUID createChannelUID(ThingUID thingUid, String groupId, String channelId,
@Nullable String channelKey) { @Nullable String channelKey) {
return new ChannelUID(thingUid, groupId, return new ChannelUID(thingUid, groupId,
channelId + (StringUtils.isEmpty(channelKey) ? "" : (DELIMITER + channelKey))); channelId + ((channelKey == null || channelKey.isEmpty()) ? "" : (DELIMITER + channelKey)));
} }
} }

View File

@ -24,7 +24,6 @@ import java.util.Set;
import javax.jmdns.ServiceInfo; import javax.jmdns.ServiceInfo;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoConstants; import org.openhab.binding.neeo.internal.NeeoConstants;
@ -100,7 +99,7 @@ public class NeeoBrainDiscovery implements MDNSDiscoveryParticipant {
} }
logger.debug("getThingUID is evaluating: {}", service); logger.debug("getThingUID is evaluating: {}", service);
if (!StringUtils.equals("neeo", service.getApplication())) { if (!"neeo".equals(service.getApplication())) {
logger.debug("Application not 'neeo' in MDNS serviceinfo: {}", service); logger.debug("Application not 'neeo' in MDNS serviceinfo: {}", service);
return null; return null;
} }

View File

@ -17,7 +17,6 @@ import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoBrainApi; import org.openhab.binding.neeo.internal.NeeoBrainApi;
import org.openhab.binding.neeo.internal.NeeoConstants; import org.openhab.binding.neeo.internal.NeeoConstants;
@ -73,7 +72,7 @@ public class NeeoDeviceDiscoveryService extends AbstractDiscoveryService {
final ThingUID roomUid = roomBridge.getUID(); final ThingUID roomUid = roomBridge.getUID();
final String brainId = roomHandler.getNeeoBrainId(); final String brainId = roomHandler.getNeeoBrainId();
if (brainId == null || StringUtils.isEmpty(brainId)) { if (brainId == null || brainId.isEmpty()) {
logger.debug("Unknown brain ID for roomHandler: {}", roomHandler); logger.debug("Unknown brain ID for roomHandler: {}", roomHandler);
return; return;
} }
@ -86,7 +85,7 @@ public class NeeoDeviceDiscoveryService extends AbstractDiscoveryService {
final NeeoRoomConfig config = roomBridge.getConfiguration().as(NeeoRoomConfig.class); final NeeoRoomConfig config = roomBridge.getConfiguration().as(NeeoRoomConfig.class);
final String roomKey = config.getRoomKey(); final String roomKey = config.getRoomKey();
if (roomKey == null || StringUtils.isEmpty(roomKey)) { if (roomKey == null || roomKey.isEmpty()) {
logger.debug("RoomKey wasn't configured for {} - skipping", brainId); logger.debug("RoomKey wasn't configured for {} - skipping", brainId);
return; return;
} }
@ -103,7 +102,7 @@ public class NeeoDeviceDiscoveryService extends AbstractDiscoveryService {
logger.debug("Room {} found, scanning {} devices in it", room.getName(), devices.length); logger.debug("Room {} found, scanning {} devices in it", room.getName(), devices.length);
for (NeeoDevice device : devices) { for (NeeoDevice device : devices) {
final String deviceKey = device.getKey(); final String deviceKey = device.getKey();
if (deviceKey == null || StringUtils.isEmpty(deviceKey)) { if (deviceKey == null || deviceKey.isEmpty()) {
logger.debug("Device key wasn't found for device: {}", device); logger.debug("Device key wasn't found for device: {}", device);
continue; continue;
} }

View File

@ -17,7 +17,6 @@ import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoBrainApi; import org.openhab.binding.neeo.internal.NeeoBrainApi;
import org.openhab.binding.neeo.internal.NeeoBrainConfig; import org.openhab.binding.neeo.internal.NeeoBrainConfig;
@ -91,7 +90,7 @@ public class NeeoRoomDiscoveryService extends AbstractDiscoveryService {
logger.debug("Brain {} ({}) found, scanning {} rooms in it", brain.getName(), brainId, rooms.length); logger.debug("Brain {} ({}) found, scanning {} rooms in it", brain.getName(), brainId, rooms.length);
for (NeeoRoom room : rooms) { for (NeeoRoom room : rooms) {
final String roomKey = room.getKey(); final String roomKey = room.getKey();
if (roomKey == null || StringUtils.isEmpty(roomKey)) { if (roomKey == null || roomKey.isEmpty()) {
logger.debug("Room didn't have a room key: {}", room); logger.debug("Room didn't have a room key: {}", room);
continue; continue;
} }

View File

@ -14,9 +14,7 @@ package org.openhab.binding.neeo.internal.handler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoConstants; import org.openhab.binding.neeo.internal.NeeoConstants;
import org.openhab.binding.neeo.internal.UidUtils; import org.openhab.binding.neeo.internal.UidUtils;
@ -47,18 +45,16 @@ class ChannelUtils {
* @return a non-null but possibly empty list of {@link Channel} s * @return a non-null but possibly empty list of {@link Channel} s
*/ */
static List<Channel> generateChannels(ThingUID thingUid, NeeoDevice device) { static List<Channel> generateChannels(ThingUID thingUid, NeeoDevice device) {
Objects.requireNonNull(thingUid, "thingUid cannot be null");
Objects.requireNonNull(device, "device cannot be null");
final List<Channel> channels = new ArrayList<>(); final List<Channel> channels = new ArrayList<>();
for (NeeoMacro macro : device.getMacros().getMacros()) { for (NeeoMacro macro : device.getMacros().getMacros()) {
final String key = macro.getKey(); final String key = macro.getKey();
if (key != null && StringUtils.isNotEmpty(key)) { if (key != null && !key.isEmpty()) {
final String label = StringUtils.isEmpty(macro.getName()) ? macro.getLabel() : macro.getName(); String name = macro.getName();
final String label = (name == null || name.isEmpty()) ? macro.getLabel() : name;
channels.add(ChannelBuilder channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.DEVICE_GROUP_MACROS_ID, .create(UidUtils.createChannelUID(thingUid, NeeoConstants.DEVICE_GROUP_MACROS_ID,
NeeoConstants.DEVICE_CHANNEL_STATUS, key), "Switch") NeeoConstants.DEVICE_CHANNEL_STATUS, key), "Switch")
.withLabel(label == null || StringUtils.isEmpty(label) ? key : label) .withLabel((label == null || label.isEmpty()) ? key : label)
.withType(NeeoConstants.DEVICE_MACRO_STATUS_UID).build()); .withType(NeeoConstants.DEVICE_MACRO_STATUS_UID).build());
} }
} }
@ -74,9 +70,6 @@ class ChannelUtils {
* @return a non-null but possibly empty list of {@link Channel} s * @return a non-null but possibly empty list of {@link Channel} s
*/ */
static List<Channel> generateChannels(ThingUID thingUid, NeeoRoom room) { static List<Channel> generateChannels(ThingUID thingUid, NeeoRoom room) {
Objects.requireNonNull(thingUid, "thingUid cannot be null");
Objects.requireNonNull(room, "room cannot be null");
final List<Channel> channels = new ArrayList<>(); final List<Channel> channels = new ArrayList<>();
channels.addAll(generateStateChannels(thingUid)); channels.addAll(generateStateChannels(thingUid));
channels.addAll(generateScenarioChannels(thingUid, room.getScenarios())); channels.addAll(generateScenarioChannels(thingUid, room.getScenarios()));
@ -91,8 +84,6 @@ class ChannelUtils {
* @return a non-null but possibly empty list of {@link Channel} s * @return a non-null but possibly empty list of {@link Channel} s
*/ */
private static List<Channel> generateStateChannels(ThingUID thingUid) { private static List<Channel> generateStateChannels(ThingUID thingUid) {
Objects.requireNonNull(thingUid, "thingUid cannot be null");
final List<Channel> channels = new ArrayList<>(); final List<Channel> channels = new ArrayList<>();
channels.add(ChannelBuilder channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_STATE_ID, .create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_STATE_ID,
@ -109,20 +100,15 @@ class ChannelUtils {
* @return a non-null but possibly empty list of {@link Channel} s * @return a non-null but possibly empty list of {@link Channel} s
*/ */
private static List<Channel> generateScenarioChannels(ThingUID thingUid, NeeoScenarios scenarios) { private static List<Channel> generateScenarioChannels(ThingUID thingUid, NeeoScenarios scenarios) {
Objects.requireNonNull(thingUid, "thingUid cannot be null");
Objects.requireNonNull(scenarios, "scenarios cannot be null");
final List<Channel> channels = new ArrayList<>(); final List<Channel> channels = new ArrayList<>();
for (NeeoScenario scenario : scenarios.getScenarios()) { for (NeeoScenario scenario : scenarios.getScenarios()) {
final String key = scenario.getKey(); final String key = scenario.getKey();
if (key != null && StringUtils.isNotEmpty(key)) { if (key != null && !key.isEmpty()) {
final String scenarioLabel = StringUtils.isEmpty(scenario.getName()) ? null : scenario.getName(); final String name = scenario.getName();
final String nameLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key final String scenarioLabel = (name == null || name.isEmpty()) ? key : name;
: scenarioLabel) + " Name"; final String nameLabel = scenarioLabel + " Name";
final String configuredLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key final String configuredLabel = scenarioLabel + " Configured";
: scenarioLabel) + " Configured"; final String statusLabel = scenarioLabel + " Status";
final String statusLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key
: scenarioLabel) + " Status";
channels.add(ChannelBuilder channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_SCENARIO_ID, .create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_SCENARIO_ID,
@ -149,22 +135,16 @@ class ChannelUtils {
* @return a non-null but possibly empty list of {@link Channel} s * @return a non-null but possibly empty list of {@link Channel} s
*/ */
private static List<Channel> generateRecipeChannels(ThingUID thingUid, NeeoRecipes recipes) { private static List<Channel> generateRecipeChannels(ThingUID thingUid, NeeoRecipes recipes) {
Objects.requireNonNull(thingUid, "thingUid cannot be null");
Objects.requireNonNull(recipes, "recipes cannot be null");
final List<Channel> channels = new ArrayList<>(); final List<Channel> channels = new ArrayList<>();
for (NeeoRecipe recipe : recipes.getRecipes()) { for (NeeoRecipe recipe : recipes.getRecipes()) {
final String key = recipe.getKey(); final String key = recipe.getKey();
if (key != null && StringUtils.isNotEmpty(key)) { if (key != null && !key.isEmpty()) {
final String recipeLabel = StringUtils.isEmpty(recipe.getName()) ? null : recipe.getName(); final String name = recipe.getName();
final String nameLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel) final String recipeLabel = (name == null || name.isEmpty()) ? key : name;
+ " Name (" + recipe.getType() + ")"; final String nameLabel = recipeLabel + " Name (" + recipe.getType() + ")";
final String typeLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel) final String typeLabel = recipeLabel + " Type (" + recipe.getType() + ")";
+ " Type (" + recipe.getType() + ")"; final String enabledLabel = recipeLabel + " Enabled (" + recipe.getType() + ")";
final String enabledLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key final String statusLabel = recipeLabel + " Status (" + recipe.getType() + ")";
: recipeLabel) + " Enabled (" + recipe.getType() + ")";
final String statusLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel)
+ " Status (" + recipe.getType() + ")";
channels.add(ChannelBuilder channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_RECIPE_ID, .create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_RECIPE_ID,

View File

@ -31,7 +31,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientBuilder;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi; import org.openhab.binding.neeo.internal.NeeoBrainApi;
@ -130,7 +129,7 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
} }
/** /**
* Handles any {@Commands} sent - this bridge has no commands and does nothing * Handles any {@link Command} sent - this bridge has no commands and does nothing
* *
* @see * @see
* org.openhab.core.thing.binding.ThingHandler#handleCommand(org.openhab.core.thing.ChannelUID, * org.openhab.core.thing.binding.ThingHandler#handleCommand(org.openhab.core.thing.ChannelUID,
@ -163,8 +162,10 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
NeeoUtil.checkInterrupt(); NeeoUtil.checkInterrupt();
final NeeoBrainConfig config = getBrainConfig(); final NeeoBrainConfig config = getBrainConfig();
logger.trace("Brain-UID {}: config is {}", thing.getUID(), config);
final String ipAddress = config.getIpAddress(); final String ipAddress = config.getIpAddress();
if (ipAddress == null || StringUtils.isEmpty(ipAddress)) { if (ipAddress == null || ipAddress.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Brain IP Address must be specified"); "Brain IP Address must be specified");
return; return;
@ -186,7 +187,8 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
addProperty(properties, "Last Change", String.valueOf(brain.getLastChange())); addProperty(properties, "Last Change", String.valueOf(brain.getLastChange()));
updateProperties(properties); updateProperties(properties);
if (config.isEnableForwardActions()) { String forwardChain = config.getForwardChain();
if (config.isEnableForwardActions() && forwardChain != null && !forwardChain.isEmpty()) {
NeeoUtil.checkInterrupt(); NeeoUtil.checkInterrupt();
forwardActionServlet = new NeeoForwardActionsServlet(scheduler, json -> { forwardActionServlet = new NeeoForwardActionsServlet(scheduler, json -> {
@ -200,7 +202,7 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
((NeeoRoomHandler) th).processAction(action); ((NeeoRoomHandler) th).processAction(action);
} }
} }
}, config.getForwardChain(), clientBuilder); }, forwardChain, clientBuilder);
NeeoUtil.checkInterrupt(); NeeoUtil.checkInterrupt();
try { try {
@ -240,7 +242,7 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Exception occurred connecting to brain: " + e.getMessage()); "Exception occurred connecting to brain: " + e.getMessage());
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.debug("Initializtion was interrupted", e); logger.debug("Initialization was interrupted", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR,
"Initialization was interrupted"); "Initialization was interrupted");
} finally { } finally {
@ -256,9 +258,7 @@ public class NeeoBrainHandler extends BaseBridgeHandler {
* @param value a possibly null, possibly empty key * @param value a possibly null, possibly empty key
*/ */
private void addProperty(Map<String, String> properties, String key, @Nullable String value) { private void addProperty(Map<String, String> properties, String key, @Nullable String value) {
Objects.requireNonNull(properties, "properties cannot be null"); if (value != null && !value.isEmpty()) {
NeeoUtil.requireNotEmpty(key, "key cannot be empty");
if (value != null && StringUtils.isNotEmpty(value)) {
properties.put(key, value); properties.put(key, value);
} }
} }

View File

@ -13,6 +13,7 @@
package org.openhab.binding.neeo.internal.handler; package org.openhab.binding.neeo.internal.handler;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -20,8 +21,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi; import org.openhab.binding.neeo.internal.NeeoBrainApi;
@ -104,11 +105,11 @@ public class NeeoDeviceHandler extends BaseThingHandler {
} }
final String localGroupId = channelUID.getGroupId(); final String localGroupId = channelUID.getGroupId();
final String groupId = localGroupId == null || StringUtils.isEmpty(localGroupId) ? "" : localGroupId; final String groupId = localGroupId == null || localGroupId.isEmpty() ? "" : localGroupId;
final String channelId = channelIds[0]; final String channelId = channelIds[0];
final String channelKey = channelIds.length > 1 ? channelIds[1] : ""; final String channelKey = channelIds.length > 1 ? channelIds[1] : "";
if (StringUtils.isEmpty(groupId)) { if (groupId.isEmpty()) {
logger.debug("GroupID for channel is null - ignoring command: {}", channelUID); logger.debug("GroupID for channel is null - ignoring command: {}", channelUID);
return; return;
} }
@ -176,14 +177,14 @@ public class NeeoDeviceHandler extends BaseThingHandler {
final NeeoDeviceConfig config = getConfigAs(NeeoDeviceConfig.class); final NeeoDeviceConfig config = getConfigAs(NeeoDeviceConfig.class);
final String roomKey = getRoomKey(); final String roomKey = getRoomKey();
if (roomKey == null || StringUtils.isEmpty(roomKey)) { if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Room key (from the parent room bridge) was not found"); "Room key (from the parent room bridge) was not found");
return; return;
} }
final String deviceKey = config.getDeviceKey(); final String deviceKey = config.getDeviceKey();
if (deviceKey == null || StringUtils.isEmpty(deviceKey)) { if (deviceKey == null || deviceKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Device key was not found or empty"); "Device key was not found or empty");
return; return;
@ -225,7 +226,8 @@ public class NeeoDeviceHandler extends BaseThingHandler {
properties.put("Shutdown Delay", toString(timing.getShutdownDelay())); properties.put("Shutdown Delay", toString(timing.getShutdownDelay()));
} }
properties.put("Device Capabilities", StringUtils.join(details.getDeviceCapabilities(), ',')); properties.put("Device Capabilities",
Arrays.stream(details.getDeviceCapabilities()).collect(Collectors.joining(",")));
} }
final ThingBuilder thingBuilder = editThing(); final ThingBuilder thingBuilder = editThing();
@ -292,7 +294,7 @@ public class NeeoDeviceHandler extends BaseThingHandler {
private void addProperty(Map<String, String> properties, String key, @Nullable String value) { private void addProperty(Map<String, String> properties, String key, @Nullable String value) {
Objects.requireNonNull(properties, "properties cannot be null"); Objects.requireNonNull(properties, "properties cannot be null");
NeeoUtil.requireNotEmpty(key, "key cannot be empty"); NeeoUtil.requireNotEmpty(key, "key cannot be empty");
if (value != null && StringUtils.isNotEmpty(value)) { if (value != null && !value.isEmpty()) {
properties.put(key, value); properties.put(key, value);
} }
} }

View File

@ -13,15 +13,14 @@
package org.openhab.binding.neeo.internal.handler; package org.openhab.binding.neeo.internal.handler;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientBuilder;
import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
@ -48,7 +47,6 @@ public class NeeoForwardActionsServlet extends HttpServlet {
private final Callback callback; private final Callback callback;
/** The forwarding chain */ /** The forwarding chain */
@Nullable
private final String forwardChain; private final String forwardChain;
/** The {@link ClientBuilder} to use */ /** The {@link ClientBuilder} to use */
@ -64,13 +62,10 @@ public class NeeoForwardActionsServlet extends HttpServlet {
* @param callback a non-null {@link Callback} * @param callback a non-null {@link Callback}
* @param forwardChain a possibly null, possibly empty forwarding chain * @param forwardChain a possibly null, possibly empty forwarding chain
*/ */
NeeoForwardActionsServlet(ScheduledExecutorService scheduler, Callback callback, @Nullable String forwardChain, NeeoForwardActionsServlet(ScheduledExecutorService scheduler, Callback callback, String forwardChain,
ClientBuilder clientBuilder) { ClientBuilder clientBuilder) {
super(); super();
Objects.requireNonNull(scheduler, "scheduler cannot be null");
Objects.requireNonNull(callback, "callback cannot be null");
this.scheduler = scheduler; this.scheduler = scheduler;
this.callback = callback; this.callback = callback;
this.forwardChain = forwardChain; this.forwardChain = forwardChain;
@ -78,7 +73,7 @@ public class NeeoForwardActionsServlet extends HttpServlet {
} }
/** /**
* Processes the post action from the NEEO brain. Simply get's the specified json and then forwards it on (if * Processes the post action from the NEEO brain. Simply gets the specified json and then forwards it on (if
* needed) * needed)
* *
* @param req the non-null request * @param req the non-null request
@ -91,27 +86,24 @@ public class NeeoForwardActionsServlet extends HttpServlet {
return; return;
} }
final String json = IOUtils.toString(req.getReader()); final String json = req.getReader().lines().collect(Collectors.joining("\n"));
logger.debug("handleForwardActions {}", json); logger.debug("handleForwardActions {}", json);
callback.post(json); callback.post(json);
final String fc = forwardChain; scheduler.execute(() -> {
if (fc != null && !fc.isEmpty()) { try (final HttpRequest request = new HttpRequest(clientBuilder)) {
scheduler.execute(() -> { for (final String forwardUrl : forwardChain.split(",")) {
try (final HttpRequest request = new HttpRequest(clientBuilder)) { if (forwardUrl != null && !forwardUrl.isEmpty()) {
for (final String forwardUrl : fc.split(",")) { final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json);
if (forwardUrl != null && !forwardUrl.isEmpty()) { if (httpResponse.getHttpCode() != HttpStatus.OK_200) {
final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json); logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl,
if (httpResponse.getHttpCode() != HttpStatus.OK_200) { httpResponse.getHttpCode());
logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl,
httpResponse.getHttpCode());
}
} }
} }
} }
}); }
} });
} }
interface Callback { interface Callback {

View File

@ -20,7 +20,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi; import org.openhab.binding.neeo.internal.NeeoBrainApi;
@ -99,7 +98,7 @@ public class NeeoRoomHandler extends BaseBridgeHandler {
} }
final String localGroupId = channelUID.getGroupId(); final String localGroupId = channelUID.getGroupId();
final String groupId = localGroupId == null || StringUtils.isEmpty(localGroupId) ? "" : localGroupId; final String groupId = localGroupId == null || localGroupId.isEmpty() ? "" : localGroupId;
final String channelId = channelIds[0]; final String channelId = channelIds[0];
final String channelKey = channelIds.length > 1 ? channelIds[1] : ""; final String channelKey = channelIds.length > 1 ? channelIds[1] : "";
@ -195,7 +194,7 @@ public class NeeoRoomHandler extends BaseBridgeHandler {
final NeeoRoomConfig config = getConfigAs(NeeoRoomConfig.class); final NeeoRoomConfig config = getConfigAs(NeeoRoomConfig.class);
final String roomKey = config.getRoomKey(); final String roomKey = config.getRoomKey();
if (roomKey == null || StringUtils.isEmpty(roomKey)) { if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Room key (from the parent room bridge) was not found"); "Room key (from the parent room bridge) was not found");
return; return;

View File

@ -12,7 +12,8 @@
*/ */
package org.openhab.binding.neeo.internal.models; package org.openhab.binding.neeo.internal.models;
import org.apache.commons.lang.StringUtils; import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -123,8 +124,8 @@ public class NeeoDeviceDetails {
@Override @Override
public String toString() { public String toString() {
return "NeeoDeviceDetails [sourceName=" + sourceName + ", adapterName=" + adapterName + ", type=" + type return "NeeoDeviceDetails{" + "sourceName='" + sourceName + '\'' + ", adapterName='" + adapterName + '\''
+ ", manufacturer=" + manufacturer + ", name=" + name + ", timing=" + timing + ", deviceCapabilities=" + ", type='" + type + '\'' + ", manufacturer='" + manufacturer + '\'' + ", name='" + name + '\''
+ StringUtils.join(deviceCapabilities, ',') + "]"; + ", timing=" + timing + ", deviceCapabilities=" + Arrays.toString(deviceCapabilities) + '}';
} }
} }

View File

@ -15,7 +15,6 @@ package org.openhab.binding.neeo.internal.models;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -59,7 +58,7 @@ public class NeeoDevices {
@Nullable @Nullable
public NeeoDevice getDevice(String key) { public NeeoDevice getDevice(String key) {
for (NeeoDevice device : getDevices()) { for (NeeoDevice device : getDevices()) {
if (StringUtils.equalsIgnoreCase(key, device.getKey())) { if (key.equalsIgnoreCase(device.getKey())) {
return device; return device;
} }
} }

View File

@ -15,7 +15,6 @@ package org.openhab.binding.neeo.internal.models;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -59,7 +58,7 @@ public class NeeoMacros {
@Nullable @Nullable
public NeeoMacro getMacro(String key) { public NeeoMacro getMacro(String key) {
for (NeeoMacro macro : getMacros()) { for (NeeoMacro macro : getMacros()) {
if (StringUtils.equalsIgnoreCase(key, macro.getKey())) { if (key.equalsIgnoreCase(macro.getKey())) {
return macro; return macro;
} }
} }

View File

@ -13,9 +13,7 @@
package org.openhab.binding.neeo.internal.models; package org.openhab.binding.neeo.internal.models;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -28,7 +26,7 @@ import org.eclipse.jdt.annotation.Nullable;
public class NeeoRecipes { public class NeeoRecipes {
/** The recipes. */ /** The recipes. */
private NeeoRecipe @Nullable [] recipes; private NeeoRecipe[] recipes;
/** /**
* Creates the recipes from the given recipes * Creates the recipes from the given recipes
@ -36,7 +34,6 @@ public class NeeoRecipes {
* @param recipes the recipes * @param recipes the recipes
*/ */
NeeoRecipes(NeeoRecipe[] recipes) { NeeoRecipes(NeeoRecipe[] recipes) {
Objects.requireNonNull(recipes, "recipes cannot be null");
this.recipes = recipes; this.recipes = recipes;
} }
@ -46,8 +43,7 @@ public class NeeoRecipes {
* @return the recipes * @return the recipes
*/ */
public NeeoRecipe[] getRecipes() { public NeeoRecipe[] getRecipes() {
final NeeoRecipe[] localRecipes = recipes; return recipes;
return localRecipes == null ? new NeeoRecipe[0] : localRecipes;
} }
/** /**
@ -58,12 +54,12 @@ public class NeeoRecipes {
*/ */
@Nullable @Nullable
public NeeoRecipe getRecipe(String key) { public NeeoRecipe getRecipe(String key) {
if (recipes == null || StringUtils.isEmpty(key)) { if (key.isEmpty()) {
return null; return null;
} }
for (NeeoRecipe recipe : getRecipes()) { for (NeeoRecipe recipe : recipes) {
if (StringUtils.equalsIgnoreCase(key, recipe.getKey())) { if (key.equalsIgnoreCase(recipe.getKey())) {
return recipe; return recipe;
} }
} }
@ -79,13 +75,12 @@ public class NeeoRecipes {
*/ */
@Nullable @Nullable
public NeeoRecipe getRecipeByScenarioKey(String key, String type) { public NeeoRecipe getRecipeByScenarioKey(String key, String type) {
if (recipes == null || StringUtils.isEmpty(key)) { if (key.isEmpty()) {
return null; return null;
} }
for (NeeoRecipe recipe : getRecipes()) { for (NeeoRecipe recipe : recipes) {
if (StringUtils.equalsIgnoreCase(key, recipe.getScenarioKey()) if (key.equalsIgnoreCase(recipe.getScenarioKey()) && type.equalsIgnoreCase(recipe.getType())) {
&& StringUtils.equalsIgnoreCase(type, recipe.getType())) {
return recipe; return recipe;
} }
} }
@ -100,12 +95,12 @@ public class NeeoRecipes {
*/ */
@Nullable @Nullable
public NeeoRecipe getRecipeByName(String name) { public NeeoRecipe getRecipeByName(String name) {
if (recipes == null || StringUtils.isEmpty(name)) { if (name.isEmpty()) {
return null; return null;
} }
for (NeeoRecipe recipe : getRecipes()) { for (NeeoRecipe recipe : recipes) {
if (StringUtils.equalsIgnoreCase(name, recipe.getName())) { if (name.equalsIgnoreCase(recipe.getName())) {
return recipe; return recipe;
} }
} }

View File

@ -15,7 +15,6 @@ package org.openhab.binding.neeo.internal.models;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -58,7 +57,7 @@ public class NeeoRooms {
*/ */
NeeoRoom getRoom(String key) { NeeoRoom getRoom(String key) {
for (NeeoRoom room : getRooms()) { for (NeeoRoom room : getRooms()) {
if (StringUtils.equalsIgnoreCase(key, room.getKey())) { if (key.equalsIgnoreCase(room.getKey())) {
return room; return room;
} }
} }

View File

@ -15,7 +15,6 @@ package org.openhab.binding.neeo.internal.models;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -59,7 +58,7 @@ public class NeeoScenarios {
@Nullable @Nullable
public NeeoScenario getScenario(String key) { public NeeoScenario getScenario(String key) {
for (NeeoScenario scenario : getScenarios()) { for (NeeoScenario scenario : getScenarios()) {
if (StringUtils.equalsIgnoreCase(key, scenario.getKey())) { if (key.equalsIgnoreCase(scenario.getKey())) {
return scenario; return scenario;
} }
} }

View File

@ -21,7 +21,6 @@ import java.util.Objects;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -59,7 +58,7 @@ public class HttpResponse {
if (response.hasEntity()) { if (response.hasEntity()) {
InputStream is = response.readEntity(InputStream.class); InputStream is = response.readEntity(InputStream.class);
contents = IOUtils.toByteArray(is); contents = is.readAllBytes();
} else { } else {
contents = null; contents = null;
} }

View File

@ -30,7 +30,6 @@
<parameter name="forwardChain" type="text"> <parameter name="forwardChain" type="text">
<label>Forward Chaining</label> <label>Forward Chaining</label>
<description>Comma delimited list of URLs to forward NEEO brain actions to</description> <description>Comma delimited list of URLs to forward NEEO brain actions to</description>
<default>true</default>
<advanced>true</advanced> <advanced>true</advanced>
</parameter> </parameter>
<parameter name="checkStatusInterval" type="integer"> <parameter name="checkStatusInterval" type="integer">