package org.openhab.binding.neeo.internal;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
/**
* The class provides the API for communicating with a NEEO brain
* @return the non-null, possibly empty list of active scenarios keys
* @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 HttpRequest rqst = request.get();
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));
}
/**
public void setCheckStatusInterval(int checkStatusInterval) {
this.checkStatusInterval = checkStatusInterval;
}
+
+ @Override
+ public String toString() {
+ return "NeeoBrainConfig{" + "ipAddress='" + ipAddress + '\'' + ", enableForwardActions=" + enableForwardActions
+ + ", forwardChain='" + forwardChain + '\'' + ", discoverEmptyRooms=" + discoverEmptyRooms
+ + ", checkStatusInterval=" + checkStatusInterval + '}';
+ }
}
package org.openhab.binding.neeo.internal;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
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.Nullable;
import org.openhab.binding.neeo.internal.models.ExecuteResult;
private final NeeoRoom neeoRoom;
/** 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.
Objects.requireNonNull(action, "action cannot be null");
final NeeoRecipes recipes = neeoRoom.getRecipes();
- final boolean launch = StringUtils.equalsIgnoreCase(NeeoRecipe.LAUNCH, action.getAction());
- final boolean poweroff = StringUtils.equalsIgnoreCase(NeeoRecipe.POWEROFF, action.getAction());
+ final boolean launch = NeeoRecipe.LAUNCH.equalsIgnoreCase(action.getAction());
+ final boolean poweroff = NeeoRecipe.POWEROFF.equalsIgnoreCase(action.getAction());
// Can't be both true but if both false - it's neither one
if (launch == poweroff) {
final NeeoRecipe recipe = recipeName == null ? null : recipes.getRecipeByName(recipeName);
final String scenarioKey = recipe == null ? null : recipe.getScenarioKey();
- if (scenarioKey != null && StringUtils.isNotEmpty(scenarioKey)) {
+ if (scenarioKey != null && !scenarioKey.isEmpty()) {
processScenarioChange(scenarioKey, launch);
} else {
logger.debug("Could not find a recipe named '{}' for the action {}", recipeName, action);
private void processScenarioChange(String scenarioKey, boolean launch) {
NeeoUtil.requireNotEmpty(scenarioKey, "scenarioKey cannot be empty");
- final String[] activeScenarios = this.activeScenarios.get();
- final int idx = ArrayUtils.indexOf(activeScenarios, scenarioKey);
+ List<String> oldActiveScenarios;
+ List<String> newActiveScenarios;
- // already set that way
- if ((idx < 0 && !launch) || (idx >= 0 && launch)) {
- return;
- }
+ do {
+ oldActiveScenarios = this.activeScenarios.get();
+ newActiveScenarios = new ArrayList<>(oldActiveScenarios);
- final String[] newScenarios = idx >= 0 ? (String[]) ArrayUtils.remove(activeScenarios, idx)
- : (String[]) ArrayUtils.add(activeScenarios, scenarioKey);
-
- this.activeScenarios.set(newScenarios);
+ if (newActiveScenarios.contains(scenarioKey)) {
+ if (launch) {
+ return;
+ } else {
+ newActiveScenarios.remove(scenarioKey);
+ }
+ } else {
+ if (launch) {
+ newActiveScenarios.add(scenarioKey);
+ } else {
+ return;
+ }
+ }
+ } while (!this.activeScenarios.compareAndSet(oldActiveScenarios, newActiveScenarios));
refreshScenarioStatus(scenarioKey);
}
final NeeoScenario scenario = neeoRoom.getScenarios().getScenario(scenarioKey);
if (scenario != null) {
- final String[] active = activeScenarios.get();
- final boolean isActive = ArrayUtils.contains(active, scenarioKey);
+ final boolean isActive = activeScenarios.get().contains(scenarioKey);
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));
}
}
logger.debug("API is null [likely bridge is offline]");
} else {
try {
- final String[] activeScenarios = api.getActiveScenarios();
- final String[] oldScenarios = this.activeScenarios.getAndSet(activeScenarios);
-
- if (!ArrayUtils.isEquals(activeScenarios, oldScenarios)) {
- for (String scenario : activeScenarios) {
- refreshScenarioStatus(scenario);
- }
+ final List<String> activeScenarios = api.getActiveScenarios();
+ final List<String> oldScenarios = this.activeScenarios.getAndSet(activeScenarios);
- for (String oldScenario : oldScenarios) {
- if (!ArrayUtils.contains(activeScenarios, oldScenario)) {
- refreshScenarioStatus(oldScenario);
- }
- }
+ if (!activeScenarios.equals(oldScenarios)) {
+ activeScenarios.forEach(this::refreshScenarioStatus);
+ oldScenarios.removeIf(activeScenarios::contains);
+ oldScenarios.forEach(this::refreshScenarioStatus);
}
} catch (IOException e) {
logger.debug("Exception requesting active scenarios: {}", e.getMessage(), e);
private void sendCurrentStepTrigger(@Nullable String step) {
callback.triggerEvent(
UidUtils.createChannelId(NeeoConstants.ROOM_GROUP_STATE_ID, NeeoConstants.ROOM_CHANNEL_CURRENTSTEP),
- step == null || StringUtils.isEmpty(step) ? "" : step);
+ step == null || step.isEmpty() ? "" : step);
}
/**
if (recipe != null) {
if (recipe.isEnabled()) {
- final boolean isLaunch = StringUtils.equalsIgnoreCase(NeeoRecipe.LAUNCH, recipe.getType());
+ final boolean isLaunch = NeeoRecipe.LAUNCH.equalsIgnoreCase(recipe.getType());
try {
- if (isLaunch || scenarioKey == null || StringUtils.isEmpty(scenarioKey)) {
+ if (isLaunch || scenarioKey == null || scenarioKey.isEmpty()) {
handleExecuteResult(scenarioKey, recipeKey, true, api.executeRecipe(roomKey, recipeKey));
} else {
handleExecuteResult(scenarioKey, recipeKey, false, api.stopScenario(roomKey, scenarioKey));
start ? NeeoRecipe.LAUNCH : NeeoRecipe.POWEROFF);
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()) {
startRecipe(recipeKey);
} else {
NeeoUtil.requireNotEmpty(recipeKey, "recipeKey cannot be empty");
int nextStep = 0;
- if (scenarioKey != null && StringUtils.isNotEmpty(scenarioKey)) {
+ if (scenarioKey != null && !scenarioKey.isEmpty()) {
callback.scheduleTask(() -> {
processScenarioChange(scenarioKey, launch);
}, 1);
*/
package org.openhab.binding.neeo.internal;
-import java.util.Objects;
import java.util.concurrent.Future;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.models.NeeoDevices;
* @throws IllegalArgumentException if value is an empty string
*/
public static void requireNotEmpty(@Nullable String value, String msg) {
- Objects.requireNonNull(value, msg);
- if (StringUtils.isEmpty(value)) {
+ if (value == null || value.isEmpty()) {
throw new IllegalArgumentException(msg);
}
}
*/
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.Nullable;
import org.openhab.binding.neeo.internal.models.NeeoDevice;
* @return the non-null, non empty (only 1 or 2 element) list of parts
*/
public static String[] parseChannelId(ChannelUID uid) {
- Objects.requireNonNull(uid, "uid cannot be null");
-
final String channelId = uid.getIdWithoutGroup();
final int idx = channelId.indexOf(DELIMITER);
if (idx < 0 || idx == channelId.length() - 1) {
public static String createChannelId(@Nullable String groupId, String channelId, @Nullable String channelKey) {
NeeoUtil.requireNotEmpty(channelId, "channelId cannot be empty");
- return (StringUtils.isEmpty(groupId) ? "" : (groupId + "#"))
- + (StringUtils.isEmpty(channelKey) ? channelId : (channelId + DELIMITER + channelKey));
+ return ((groupId == null || groupId.isEmpty()) ? "" : (groupId + "#"))
+ + ((channelKey == null || channelKey.isEmpty()) ? channelId : (channelId + DELIMITER + channelKey));
}
/**
public static ChannelUID createChannelUID(ThingUID thingUid, String groupId, String channelId,
@Nullable String channelKey) {
return new ChannelUID(thingUid, groupId,
- channelId + (StringUtils.isEmpty(channelKey) ? "" : (DELIMITER + channelKey)));
+ channelId + ((channelKey == null || channelKey.isEmpty()) ? "" : (DELIMITER + channelKey)));
}
}
import javax.jmdns.ServiceInfo;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoConstants;
}
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);
return null;
}
import java.util.Objects;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoBrainApi;
import org.openhab.binding.neeo.internal.NeeoConstants;
final ThingUID roomUid = roomBridge.getUID();
final String brainId = roomHandler.getNeeoBrainId();
- if (brainId == null || StringUtils.isEmpty(brainId)) {
+ if (brainId == null || brainId.isEmpty()) {
logger.debug("Unknown brain ID for roomHandler: {}", roomHandler);
return;
}
final NeeoRoomConfig config = roomBridge.getConfiguration().as(NeeoRoomConfig.class);
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);
return;
}
logger.debug("Room {} found, scanning {} devices in it", room.getName(), devices.length);
for (NeeoDevice device : devices) {
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);
continue;
}
import java.util.Objects;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoBrainApi;
import org.openhab.binding.neeo.internal.NeeoBrainConfig;
logger.debug("Brain {} ({}) found, scanning {} rooms in it", brain.getName(), brainId, rooms.length);
for (NeeoRoom room : rooms) {
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);
continue;
}
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.neeo.internal.NeeoConstants;
import org.openhab.binding.neeo.internal.UidUtils;
* @return a non-null but possibly empty list of {@link Channel} s
*/
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<>();
for (NeeoMacro macro : device.getMacros().getMacros()) {
final String key = macro.getKey();
- if (key != null && StringUtils.isNotEmpty(key)) {
- final String label = StringUtils.isEmpty(macro.getName()) ? macro.getLabel() : macro.getName();
+ if (key != null && !key.isEmpty()) {
+ String name = macro.getName();
+ final String label = (name == null || name.isEmpty()) ? macro.getLabel() : name;
channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.DEVICE_GROUP_MACROS_ID,
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());
}
}
* @return a non-null but possibly empty list of {@link Channel} s
*/
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<>();
channels.addAll(generateStateChannels(thingUid));
channels.addAll(generateScenarioChannels(thingUid, room.getScenarios()));
* @return a non-null but possibly empty list of {@link Channel} s
*/
private static List<Channel> generateStateChannels(ThingUID thingUid) {
- Objects.requireNonNull(thingUid, "thingUid cannot be null");
-
final List<Channel> channels = new ArrayList<>();
channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_STATE_ID,
* @return a non-null but possibly empty list of {@link Channel} s
*/
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<>();
for (NeeoScenario scenario : scenarios.getScenarios()) {
final String key = scenario.getKey();
- if (key != null && StringUtils.isNotEmpty(key)) {
- final String scenarioLabel = StringUtils.isEmpty(scenario.getName()) ? null : scenario.getName();
- final String nameLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key
- : scenarioLabel) + " Name";
- final String configuredLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key
- : scenarioLabel) + " Configured";
- final String statusLabel = (scenarioLabel == null || StringUtils.isEmpty(scenarioLabel) ? key
- : scenarioLabel) + " Status";
+ if (key != null && !key.isEmpty()) {
+ final String name = scenario.getName();
+ final String scenarioLabel = (name == null || name.isEmpty()) ? key : name;
+ final String nameLabel = scenarioLabel + " Name";
+ final String configuredLabel = scenarioLabel + " Configured";
+ final String statusLabel = scenarioLabel + " Status";
channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_SCENARIO_ID,
* @return a non-null but possibly empty list of {@link Channel} s
*/
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<>();
for (NeeoRecipe recipe : recipes.getRecipes()) {
final String key = recipe.getKey();
- if (key != null && StringUtils.isNotEmpty(key)) {
- final String recipeLabel = StringUtils.isEmpty(recipe.getName()) ? null : recipe.getName();
- final String nameLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel)
- + " Name (" + recipe.getType() + ")";
- final String typeLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel)
- + " Type (" + recipe.getType() + ")";
- final String enabledLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key
- : recipeLabel) + " Enabled (" + recipe.getType() + ")";
- final String statusLabel = (recipeLabel == null || StringUtils.isEmpty(recipeLabel) ? key : recipeLabel)
- + " Status (" + recipe.getType() + ")";
+ if (key != null && !key.isEmpty()) {
+ final String name = recipe.getName();
+ final String recipeLabel = (name == null || name.isEmpty()) ? key : name;
+ final String nameLabel = recipeLabel + " Name (" + recipe.getType() + ")";
+ final String typeLabel = recipeLabel + " Type (" + recipe.getType() + ")";
+ final String enabledLabel = recipeLabel + " Enabled (" + recipe.getType() + ")";
+ final String statusLabel = recipeLabel + " Status (" + recipe.getType() + ")";
channels.add(ChannelBuilder
.create(UidUtils.createChannelUID(thingUid, NeeoConstants.ROOM_GROUP_RECIPE_ID,
import javax.servlet.ServletException;
import javax.ws.rs.client.ClientBuilder;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi;
}
/**
- * 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
* org.openhab.core.thing.binding.ThingHandler#handleCommand(org.openhab.core.thing.ChannelUID,
NeeoUtil.checkInterrupt();
final NeeoBrainConfig config = getBrainConfig();
+ logger.trace("Brain-UID {}: config is {}", thing.getUID(), config);
+
final String ipAddress = config.getIpAddress();
- if (ipAddress == null || StringUtils.isEmpty(ipAddress)) {
+ if (ipAddress == null || ipAddress.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Brain IP Address must be specified");
return;
addProperty(properties, "Last Change", String.valueOf(brain.getLastChange()));
updateProperties(properties);
- if (config.isEnableForwardActions()) {
+ String forwardChain = config.getForwardChain();
+ if (config.isEnableForwardActions() && forwardChain != null && !forwardChain.isEmpty()) {
NeeoUtil.checkInterrupt();
forwardActionServlet = new NeeoForwardActionsServlet(scheduler, json -> {
((NeeoRoomHandler) th).processAction(action);
}
}
- }, config.getForwardChain(), clientBuilder);
+ }, forwardChain, clientBuilder);
NeeoUtil.checkInterrupt();
try {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Exception occurred connecting to brain: " + e.getMessage());
} catch (InterruptedException e) {
- logger.debug("Initializtion was interrupted", e);
+ logger.debug("Initialization was interrupted", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR,
"Initialization was interrupted");
} finally {
* @param value a possibly null, possibly empty key
*/
private void addProperty(Map<String, String> properties, String key, @Nullable String value) {
- Objects.requireNonNull(properties, "properties cannot be null");
- NeeoUtil.requireNotEmpty(key, "key cannot be empty");
- if (value != null && StringUtils.isNotEmpty(value)) {
+ if (value != null && !value.isEmpty()) {
properties.put(key, value);
}
}
package org.openhab.binding.neeo.internal.handler;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
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.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi;
}
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 channelKey = channelIds.length > 1 ? channelIds[1] : "";
- if (StringUtils.isEmpty(groupId)) {
+ if (groupId.isEmpty()) {
logger.debug("GroupID for channel is null - ignoring command: {}", channelUID);
return;
}
final NeeoDeviceConfig config = getConfigAs(NeeoDeviceConfig.class);
final String roomKey = getRoomKey();
- if (roomKey == null || StringUtils.isEmpty(roomKey)) {
+ if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Room key (from the parent room bridge) was not found");
return;
}
final String deviceKey = config.getDeviceKey();
- if (deviceKey == null || StringUtils.isEmpty(deviceKey)) {
+ if (deviceKey == null || deviceKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Device key was not found or empty");
return;
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();
private void addProperty(Map<String, String> properties, String key, @Nullable String value) {
Objects.requireNonNull(properties, "properties cannot be null");
NeeoUtil.requireNotEmpty(key, "key cannot be empty");
- if (value != null && StringUtils.isNotEmpty(value)) {
+ if (value != null && !value.isEmpty()) {
properties.put(key, value);
}
}
package org.openhab.binding.neeo.internal.handler;
import java.io.IOException;
-import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.stream.Collectors;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.ClientBuilder;
-import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.http.HttpStatus;
private final Callback callback;
/** The forwarding chain */
- @Nullable
private final String forwardChain;
/** The {@link ClientBuilder} to use */
* @param callback a non-null {@link Callback}
* @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) {
super();
- Objects.requireNonNull(scheduler, "scheduler cannot be null");
- Objects.requireNonNull(callback, "callback cannot be null");
-
this.scheduler = scheduler;
this.callback = callback;
this.forwardChain = forwardChain;
}
/**
- * 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)
*
* @param req the non-null request
return;
}
- final String json = IOUtils.toString(req.getReader());
+ final String json = req.getReader().lines().collect(Collectors.joining("\n"));
logger.debug("handleForwardActions {}", json);
callback.post(json);
- final String fc = forwardChain;
- if (fc != null && !fc.isEmpty()) {
- scheduler.execute(() -> {
- try (final HttpRequest request = new HttpRequest(clientBuilder)) {
- for (final String forwardUrl : fc.split(",")) {
- if (forwardUrl != null && !forwardUrl.isEmpty()) {
- final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json);
- if (httpResponse.getHttpCode() != HttpStatus.OK_200) {
- logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl,
- httpResponse.getHttpCode());
- }
+ scheduler.execute(() -> {
+ try (final HttpRequest request = new HttpRequest(clientBuilder)) {
+ for (final String forwardUrl : forwardChain.split(",")) {
+ if (forwardUrl != null && !forwardUrl.isEmpty()) {
+ final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json);
+ if (httpResponse.getHttpCode() != HttpStatus.OK_200) {
+ logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl,
+ httpResponse.getHttpCode());
}
}
}
- });
- }
+ }
+ });
}
interface Callback {
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.neeo.internal.NeeoBrainApi;
}
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 channelKey = channelIds.length > 1 ? channelIds[1] : "";
final NeeoRoomConfig config = getConfigAs(NeeoRoomConfig.class);
final String roomKey = config.getRoomKey();
- if (roomKey == null || StringUtils.isEmpty(roomKey)) {
+ if (roomKey == null || roomKey.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Room key (from the parent room bridge) was not found");
return;
*/
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.Nullable;
@Override
public String toString() {
- return "NeeoDeviceDetails [sourceName=" + sourceName + ", adapterName=" + adapterName + ", type=" + type
- + ", manufacturer=" + manufacturer + ", name=" + name + ", timing=" + timing + ", deviceCapabilities="
- + StringUtils.join(deviceCapabilities, ',') + "]";
+ return "NeeoDeviceDetails{" + "sourceName='" + sourceName + '\'' + ", adapterName='" + adapterName + '\''
+ + ", type='" + type + '\'' + ", manufacturer='" + manufacturer + '\'' + ", name='" + name + '\''
+ + ", timing=" + timing + ", deviceCapabilities=" + Arrays.toString(deviceCapabilities) + '}';
}
}
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.Nullable;
@Nullable
public NeeoDevice getDevice(String key) {
for (NeeoDevice device : getDevices()) {
- if (StringUtils.equalsIgnoreCase(key, device.getKey())) {
+ if (key.equalsIgnoreCase(device.getKey())) {
return device;
}
}
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.Nullable;
@Nullable
public NeeoMacro getMacro(String key) {
for (NeeoMacro macro : getMacros()) {
- if (StringUtils.equalsIgnoreCase(key, macro.getKey())) {
+ if (key.equalsIgnoreCase(macro.getKey())) {
return macro;
}
}
package org.openhab.binding.neeo.internal.models;
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.Nullable;
public class NeeoRecipes {
/** The recipes. */
- private NeeoRecipe @Nullable [] recipes;
+ private NeeoRecipe[] recipes;
/**
* Creates the recipes from the given recipes
* @param recipes the recipes
*/
NeeoRecipes(NeeoRecipe[] recipes) {
- Objects.requireNonNull(recipes, "recipes cannot be null");
this.recipes = recipes;
}
* @return the recipes
*/
public NeeoRecipe[] getRecipes() {
- final NeeoRecipe[] localRecipes = recipes;
- return localRecipes == null ? new NeeoRecipe[0] : localRecipes;
+ return recipes;
}
/**
*/
@Nullable
public NeeoRecipe getRecipe(String key) {
- if (recipes == null || StringUtils.isEmpty(key)) {
+ if (key.isEmpty()) {
return null;
}
- for (NeeoRecipe recipe : getRecipes()) {
- if (StringUtils.equalsIgnoreCase(key, recipe.getKey())) {
+ for (NeeoRecipe recipe : recipes) {
+ if (key.equalsIgnoreCase(recipe.getKey())) {
return recipe;
}
}
*/
@Nullable
public NeeoRecipe getRecipeByScenarioKey(String key, String type) {
- if (recipes == null || StringUtils.isEmpty(key)) {
+ if (key.isEmpty()) {
return null;
}
- for (NeeoRecipe recipe : getRecipes()) {
- if (StringUtils.equalsIgnoreCase(key, recipe.getScenarioKey())
- && StringUtils.equalsIgnoreCase(type, recipe.getType())) {
+ for (NeeoRecipe recipe : recipes) {
+ if (key.equalsIgnoreCase(recipe.getScenarioKey()) && type.equalsIgnoreCase(recipe.getType())) {
return recipe;
}
}
*/
@Nullable
public NeeoRecipe getRecipeByName(String name) {
- if (recipes == null || StringUtils.isEmpty(name)) {
+ if (name.isEmpty()) {
return null;
}
- for (NeeoRecipe recipe : getRecipes()) {
- if (StringUtils.equalsIgnoreCase(name, recipe.getName())) {
+ for (NeeoRecipe recipe : recipes) {
+ if (name.equalsIgnoreCase(recipe.getName())) {
return recipe;
}
}
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.Nullable;
*/
NeeoRoom getRoom(String key) {
for (NeeoRoom room : getRooms()) {
- if (StringUtils.equalsIgnoreCase(key, room.getKey())) {
+ if (key.equalsIgnoreCase(room.getKey())) {
return room;
}
}
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.Nullable;
@Nullable
public NeeoScenario getScenario(String key) {
for (NeeoScenario scenario : getScenarios()) {
- if (StringUtils.equalsIgnoreCase(key, scenario.getKey())) {
+ if (key.equalsIgnoreCase(scenario.getKey())) {
return scenario;
}
}
import javax.ws.rs.core.Response;
-import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
if (response.hasEntity()) {
InputStream is = response.readEntity(InputStream.class);
- contents = IOUtils.toByteArray(is);
+ contents = is.readAllBytes();
} else {
contents = null;
}
<parameter name="forwardChain" type="text">
<label>Forward Chaining</label>
<description>Comma delimited list of URLs to forward NEEO brain actions to</description>
- <default>true</default>
<advanced>true</advanced>
</parameter>
<parameter name="checkStatusInterval" type="integer">