[dmx] Refactor and improve code (#14327)
Also adds null-annotations Signed-off-by: Jan N. Klug <github@klug.nrw> (cherry picked from commit 8153032ce07f5bcd7c5b31316ac0d4565126fe72)
This commit is contained in:
@@ -12,11 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||
|
||||
@@ -26,8 +22,8 @@ import org.openhab.core.thing.type.ChannelTypeUID;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DmxBindingConstants {
|
||||
|
||||
public static final String BINDING_ID = "dmx";
|
||||
|
||||
// List of all Thing Type UIDs
|
||||
@@ -39,10 +35,6 @@ public class DmxBindingConstants {
|
||||
public static final ThingTypeUID THING_TYPE_LIB485_BRIDGE = new ThingTypeUID(BINDING_ID, "lib485-bridge");
|
||||
public static final ThingTypeUID THING_TYPE_SACN_BRIDGE = new ThingTypeUID(BINDING_ID, "sacn-bridge");
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.unmodifiableSet(
|
||||
Stream.of(THING_TYPE_ARTNET_BRIDGE, THING_TYPE_LIB485_BRIDGE, THING_TYPE_SACN_BRIDGE, THING_TYPE_CHASER,
|
||||
THING_TYPE_COLOR, THING_TYPE_DIMMER, THING_TYPE_TUNABLEWHITE).collect(Collectors.toSet()));
|
||||
|
||||
// List of all config options
|
||||
public static final String CONFIG_UNIVERSE = "universe";
|
||||
public static final String CONFIG_DMX_ID = "dmxid";
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.action.DmxActions;
|
||||
import org.openhab.binding.dmx.internal.action.FadeAction;
|
||||
import org.openhab.binding.dmx.internal.action.ResumeAction;
|
||||
@@ -47,15 +49,15 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public abstract class DmxBridgeHandler extends BaseBridgeHandler {
|
||||
public static final int DEFAULT_REFRESH_RATE = 20;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DmxBridgeHandler.class);
|
||||
|
||||
protected Universe universe;
|
||||
protected Universe universe = new Universe(0); // default universe
|
||||
|
||||
private ScheduledFuture<?> senderJob;
|
||||
private @Nullable ScheduledFuture<?> senderJob;
|
||||
private boolean isMuted = false;
|
||||
private int refreshTime = 1000 / DEFAULT_REFRESH_RATE;
|
||||
|
||||
@@ -68,7 +70,7 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
|
||||
switch (channelUID.getId()) {
|
||||
case CHANNEL_MUTE:
|
||||
if (command instanceof OnOffType) {
|
||||
isMuted = ((OnOffType) command).equals(OnOffType.ON);
|
||||
isMuted = command.equals(OnOffType.ON);
|
||||
} else {
|
||||
logger.debug("command {} not supported in channel {}:mute", command.getClass(),
|
||||
this.thing.getUID());
|
||||
@@ -108,15 +110,6 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
|
||||
return universe.getUniverseId();
|
||||
}
|
||||
|
||||
/**
|
||||
* rename the universe associated with this bridge
|
||||
*
|
||||
* @param universeId the new DMX universe id
|
||||
*/
|
||||
protected void renameUniverse(int universeId) {
|
||||
universe.rename(universeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void thingUpdated(Thing thing) {
|
||||
updateConfiguration();
|
||||
@@ -228,9 +221,7 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
|
||||
int universeId = minUniverseId;
|
||||
universeId = Util.coerceToRange(universeConfig, minUniverseId, maxUniverseId, logger, "universeId");
|
||||
|
||||
if (universe == null) {
|
||||
universe = new Universe(universeId);
|
||||
} else if (universe.getUniverseId() != universeId) {
|
||||
if (universe.getUniverseId() != universeId) {
|
||||
universe.rename(universeId);
|
||||
}
|
||||
}
|
||||
@@ -264,7 +255,7 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
|
||||
}
|
||||
|
||||
// do action
|
||||
Integer channelCounter = 0;
|
||||
int channelCounter = 0;
|
||||
for (DmxChannel channel : channels) {
|
||||
if (resumeAfter) {
|
||||
channel.suspendAction();
|
||||
|
||||
@@ -14,6 +14,12 @@ package org.openhab.binding.dmx.internal;
|
||||
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.handler.ArtnetBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.handler.ChaserThingHandler;
|
||||
import org.openhab.binding.dmx.internal.handler.ColorThingHandler;
|
||||
@@ -36,15 +42,22 @@ import org.osgi.service.component.annotations.Component;
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.dmx")
|
||||
@NonNullByDefault
|
||||
public class DmxHandlerFactory extends BaseThingHandlerFactory {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
|
||||
.of(ArtnetBridgeHandler.SUPPORTED_THING_TYPES, Lib485BridgeHandler.SUPPORTED_THING_TYPES,
|
||||
SacnBridgeHandler.SUPPORTED_THING_TYPES, ChaserThingHandler.SUPPORTED_THING_TYPES,
|
||||
ColorThingHandler.SUPPORTED_THING_TYPES, DimmerThingHandler.SUPPORTED_THING_TYPES,
|
||||
TunableWhiteThingHandler.SUPPORTED_THING_TYPES)
|
||||
.flatMap(Set::stream).collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
return DmxBindingConstants.SUPPORTED_THING_TYPES.contains(thingTypeUID);
|
||||
return SUPPORTED_THING_TYPES.contains(thingTypeUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThingHandler createHandler(Thing thing) {
|
||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
if (thingTypeUID.equals(THING_TYPE_ARTNET_BRIDGE)) {
|
||||
ArtnetBridgeHandler handler = new ArtnetBridgeHandler((Bridge) thing);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
@@ -26,7 +27,7 @@ import org.openhab.core.types.State;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public abstract class DmxThingHandler extends BaseThingHandler {
|
||||
|
||||
protected ThingStatusDetail dmxHandlerStatus = ThingStatusDetail.HANDLER_CONFIGURATION_PENDING;
|
||||
|
||||
@@ -14,6 +14,8 @@ package org.openhab.binding.dmx.internal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
import org.slf4j.Logger;
|
||||
@@ -23,6 +25,7 @@ import org.slf4j.Logger;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Util {
|
||||
/**
|
||||
* inRange checks if a value is between two other values
|
||||
@@ -33,7 +36,10 @@ public class Util {
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean inRange(int value, int min, int max) {
|
||||
return value >= min && value <= max;
|
||||
if (value < min) {
|
||||
return false;
|
||||
}
|
||||
return value <= max;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +52,7 @@ public class Util {
|
||||
* @param var name of the variable (used for logging)
|
||||
* @return coerced value
|
||||
*/
|
||||
public static int coerceToRange(int value, int min, int max, Logger logger, String var) {
|
||||
public static int coerceToRange(int value, int min, int max, @Nullable Logger logger, String var) {
|
||||
if (value < min) {
|
||||
if (logger != null) {
|
||||
logger.warn("coerced {} {} to allowed range {}-{}", var, value, min, max);
|
||||
@@ -71,8 +77,7 @@ public class Util {
|
||||
* @param logger logger that shall be used
|
||||
* @return coerced value
|
||||
*/
|
||||
|
||||
public static int coerceToRange(int value, int min, int max, Logger logger) {
|
||||
public static int coerceToRange(int value, int min, int max, @Nullable Logger logger) {
|
||||
return coerceToRange(value, min, max, logger, "");
|
||||
}
|
||||
|
||||
@@ -84,7 +89,6 @@ public class Util {
|
||||
* @param max
|
||||
* @return coerced value
|
||||
*/
|
||||
|
||||
public static int coerceToRange(int value, int min, int max) {
|
||||
return coerceToRange(value, min, max, null, "");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
|
||||
/**
|
||||
@@ -24,7 +26,7 @@ import org.openhab.core.library.types.PercentType;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class ValueSet {
|
||||
protected static final Pattern VALUESET_PATTERN = Pattern.compile("^(\\d*):([\\d,]*):([\\d-]*)$");
|
||||
|
||||
@@ -189,10 +191,7 @@ public class ValueSet {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = "fade/hold:" + String.valueOf(fadeTime) + "/" + String.valueOf(holdTime) + ": ";
|
||||
for (Integer value : values) {
|
||||
str += String.valueOf(value) + " ";
|
||||
}
|
||||
return str;
|
||||
return "fade/hold:" + fadeTime + "/" + holdTime + ": "
|
||||
+ values.stream().map(String::valueOf).collect(Collectors.joining(" "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.action;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link ActionState} gives the state of an action
|
||||
*
|
||||
@@ -22,6 +24,7 @@ package org.openhab.binding.dmx.internal.action;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public enum ActionState {
|
||||
WAITING,
|
||||
RUNNING,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.action;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,7 @@ import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
* @author Davy Vanherbergen - Initial contribution
|
||||
* @author Jan N. Klug - Refactoring for ESH
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class BaseAction {
|
||||
|
||||
protected ActionState state = ActionState.WAITING;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.action;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.Util;
|
||||
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
@@ -24,6 +25,7 @@ import org.openhab.core.library.types.PercentType;
|
||||
* @author Davy Vanherbergen - Initial contribution
|
||||
* @author Jan N. Klug - Refactoring for ESH
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class FadeAction extends BaseAction {
|
||||
/** Time in ms to hold the target value. -1 is indefinite */
|
||||
private long holdTime;
|
||||
@@ -39,7 +41,7 @@ public class FadeAction extends BaseAction {
|
||||
|
||||
private float stepDuration;
|
||||
|
||||
private FadeDirection fadeDirection;
|
||||
private FadeDirection fadeDirection = FadeDirection.DOWN;
|
||||
|
||||
/**
|
||||
* Create new fading action.
|
||||
@@ -139,7 +141,6 @@ public class FadeAction extends BaseAction {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FadeAction: " + String.valueOf(targetValue) + ", fade time " + String.valueOf(fadeTime)
|
||||
+ "ms, hold time " + String.valueOf(holdTime) + "ms";
|
||||
return "FadeAction: " + targetValue + ", fade time " + fadeTime + "ms, hold time " + holdTime + "ms";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,14 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.action;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link FadeDirection} gives the direction for fading
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
enum FadeDirection {
|
||||
UP,
|
||||
DOWN
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.action;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,7 @@ import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
* @author Davy Vanherbergen - Initial contribution
|
||||
* @author Jan N. Klug - Refactoring for ESH
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ResumeAction extends BaseAction {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class ColorThingHandlerConfiguration {
|
||||
public String dmxid = "";
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link ArtnetNode} represents a sending or receiving node with address and port
|
||||
* default address is set to 6454 for ArtNet
|
||||
@@ -19,6 +21,7 @@ package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ArtnetNode extends IpNode {
|
||||
public static final int DEFAULT_PORT = 6454;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.multiverse.Universe;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -21,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ArtnetPacket extends DmxOverEthernetPacket {
|
||||
public static final int ARTNET_MAX_PACKET_LEN = 530;
|
||||
public static final int ARTNET_MAX_PAYLOAD_SIZE = 512;
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
@@ -32,17 +34,17 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
private final Logger logger = LoggerFactory.getLogger(DmxOverEthernetHandler.class);
|
||||
|
||||
protected DmxOverEthernetPacket packetTemplate;
|
||||
protected @Nullable DmxOverEthernetPacket packetTemplate;
|
||||
protected IpNode senderNode = new IpNode();
|
||||
protected List<IpNode> receiverNodes = new ArrayList<>();
|
||||
|
||||
protected boolean refreshAlways = false;
|
||||
|
||||
DatagramSocket socket = null;
|
||||
protected @Nullable DatagramSocket socket = null;
|
||||
private long lastSend = 0;
|
||||
private int repeatCounter = 0;
|
||||
private int sequenceNo = 0;
|
||||
@@ -52,6 +54,7 @@ public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
if (getThing().getStatus() != ThingStatus.ONLINE) {
|
||||
try {
|
||||
if (senderNode.getAddress() == null) {
|
||||
DatagramSocket socket;
|
||||
if (senderNode.getPort() == 0) {
|
||||
socket = new DatagramSocket();
|
||||
senderNode.setInetAddress(socket.getLocalAddress());
|
||||
@@ -60,6 +63,7 @@ public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
socket = new DatagramSocket(senderNode.getPort());
|
||||
senderNode.setInetAddress(socket.getLocalAddress());
|
||||
}
|
||||
this.socket = socket;
|
||||
} else {
|
||||
socket = new DatagramSocket(senderNode.getPort(), senderNode.getAddress());
|
||||
}
|
||||
@@ -75,10 +79,11 @@ public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
|
||||
@Override
|
||||
protected void closeConnection() {
|
||||
DatagramSocket socket = this.socket;
|
||||
if (socket != null) {
|
||||
logger.debug("closing socket {} in bridge {}", senderNode, this.thing.getUID());
|
||||
socket.close();
|
||||
socket = null;
|
||||
this.socket = null;
|
||||
} else {
|
||||
logger.debug("socket was already closed when calling closeConnection in bridge {}", this.thing.getUID());
|
||||
}
|
||||
@@ -101,6 +106,12 @@ public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
repeatCounter++;
|
||||
}
|
||||
if (needsSending) {
|
||||
DmxOverEthernetPacket packetTemplate = this.packetTemplate;
|
||||
if (packetTemplate == null) {
|
||||
logger.warn("Packet template missing when trying to send data for '{}'. This is a bug.",
|
||||
thing.getUID());
|
||||
return;
|
||||
}
|
||||
packetTemplate.setPayload(universe.getBuffer(), universe.getBufferSize());
|
||||
packetTemplate.setSequence(sequenceNo);
|
||||
DatagramPacket sendPacket = new DatagramPacket(packetTemplate.getRawPacket(),
|
||||
@@ -111,7 +122,12 @@ public abstract class DmxOverEthernetHandler extends DmxBridgeHandler {
|
||||
logger.trace("sending packet with length {} to {}", packetTemplate.getPacketLength(),
|
||||
receiverNode.toString());
|
||||
try {
|
||||
socket.send(sendPacket);
|
||||
DatagramSocket socket = this.socket;
|
||||
if (socket != null) {
|
||||
socket.send(sendPacket);
|
||||
} else {
|
||||
throw new IOException("Socket for sending not set.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.debug("Could not send to {} in {}: {}", receiverNode, this.thing.getUID(),
|
||||
e.getMessage());
|
||||
|
||||
@@ -12,17 +12,19 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link DmxOverEthernetPacket} is an abstract class for
|
||||
* DMX over Ethernet packets (ArtNet, sACN)
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class DmxOverEthernetPacket {
|
||||
|
||||
protected int universeId;
|
||||
protected int payloadSize;
|
||||
protected byte[] rawPacket;
|
||||
protected byte[] rawPacket = new byte[0];
|
||||
|
||||
/**
|
||||
* set payload size
|
||||
@@ -34,7 +36,7 @@ public abstract class DmxOverEthernetPacket {
|
||||
/**
|
||||
* sets universe, calculates sender name and broadcast-address
|
||||
*
|
||||
* @param universe
|
||||
* @param universeId
|
||||
*/
|
||||
public abstract void setUniverse(int universeId);
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -28,13 +30,14 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class IpNode {
|
||||
protected static final Pattern ADDR_PATTERN = Pattern.compile("([\\w.-]+):?(\\d*)");
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(IpNode.class);
|
||||
|
||||
protected int port = 0;
|
||||
protected InetAddress address = null;
|
||||
protected @Nullable InetAddress address = null;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
@@ -52,7 +55,7 @@ public class IpNode {
|
||||
if (addrMatcher.matches()) {
|
||||
setInetAddress(addrMatcher.group(1));
|
||||
if (!addrMatcher.group(2).isEmpty()) {
|
||||
setPort(Integer.valueOf(addrMatcher.group(2)));
|
||||
setPort(Integer.parseInt(addrMatcher.group(2)));
|
||||
}
|
||||
} else {
|
||||
logger.warn("invalid format {}, returning empty UdpNode", addrString);
|
||||
@@ -116,13 +119,13 @@ public class IpNode {
|
||||
*
|
||||
* @return address as InetAddress
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
public @Nullable InetAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getAddressString() {
|
||||
String addrString = address.getHostAddress();
|
||||
return addrString;
|
||||
public @Nullable String getAddressString() {
|
||||
InetAddress address = this.address;
|
||||
return address != null ? address.getHostAddress() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,10 +135,8 @@ public class IpNode {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.address == null) {
|
||||
return "(null):" + String.valueOf(this.port);
|
||||
}
|
||||
return this.address.toString() + ":" + String.valueOf(this.port);
|
||||
InetAddress address = this.address;
|
||||
return address != null ? address.toString() + ":" + this.port : "(null):" + this.port;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link ArtnetNode} represents a sending or receiving node with address and port
|
||||
* default address is set to 5568 for sACN/E1.31
|
||||
@@ -19,7 +21,7 @@ package org.openhab.binding.dmx.internal.dmxoverethernet;
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class SacnNode extends IpNode {
|
||||
public static final int DEFAULT_PORT = 5568;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.Util;
|
||||
import org.openhab.binding.dmx.internal.multiverse.Universe;
|
||||
import org.slf4j.Logger;
|
||||
@@ -27,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SacnPacket extends DmxOverEthernetPacket {
|
||||
public static final int SACN_MAX_PACKET_LEN = 638;
|
||||
public static final int SACN_MAX_PAYLOAD_SIZE = 512;
|
||||
|
||||
@@ -14,13 +14,14 @@ package org.openhab.binding.dmx.internal.handler;
|
||||
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.THING_TYPE_ARTNET_BRIDGE;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.config.ArtnetBridgeHandlerConfiguration;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.ArtnetNode;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.ArtnetPacket;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetHandler;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetPacket;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
@@ -35,8 +36,9 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ArtnetBridgeHandler extends DmxOverEthernetHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ARTNET_BRIDGE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ARTNET_BRIDGE);
|
||||
public static final int MIN_UNIVERSE_ID = 0;
|
||||
public static final int MAX_UNIVERSE_ID = 32767;
|
||||
|
||||
@@ -51,6 +53,11 @@ public class ArtnetBridgeHandler extends DmxOverEthernetHandler {
|
||||
ArtnetBridgeHandlerConfiguration configuration = getConfig().as(ArtnetBridgeHandlerConfiguration.class);
|
||||
|
||||
setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
|
||||
DmxOverEthernetPacket packetTemplate = this.packetTemplate;
|
||||
if (packetTemplate == null) {
|
||||
packetTemplate = new ArtnetPacket();
|
||||
this.packetTemplate = packetTemplate;
|
||||
}
|
||||
packetTemplate.setUniverse(universe.getUniverseId());
|
||||
|
||||
receiverNodes.clear();
|
||||
|
||||
@@ -15,10 +15,10 @@ package org.openhab.binding.dmx.internal.handler;
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.DmxBindingConstants.ListenerType;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.DmxThingHandler;
|
||||
@@ -48,9 +48,9 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class ChaserThingHandler extends DmxThingHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_CHASER);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_CHASER);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ChaserThingHandler.class);
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ package org.openhab.binding.dmx.internal.handler;
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.DmxBindingConstants.ListenerType;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.DmxThingHandler;
|
||||
@@ -46,14 +46,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The {@link ColorThingHandler} is responsible for handling commands, which are
|
||||
* The {@link DimmerThingHandler} is responsible for handling commands, which are
|
||||
* sent to the dimmer.
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class ColorThingHandler extends DmxThingHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_COLOR);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_COLOR);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ColorThingHandler.class);
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.THING_TYPE_LI
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.config.Lib485BridgeHandlerConfiguration;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
|
||||
@@ -38,15 +39,15 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class Lib485BridgeHandler extends DmxBridgeHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_LIB485_BRIDGE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_LIB485_BRIDGE);
|
||||
public static final int MIN_UNIVERSE_ID = 0;
|
||||
public static final int MAX_UNIVERSE_ID = 0;
|
||||
public static final int DEFAULT_PORT = 9020;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(Lib485BridgeHandler.class);
|
||||
private final Map<IpNode, Socket> receiverNodes = new HashMap<>();
|
||||
private final Map<IpNode, @Nullable Socket> receiverNodes = new HashMap<>();
|
||||
|
||||
public Lib485BridgeHandler(Bridge lib485Bridge) {
|
||||
super(lib485Bridge);
|
||||
@@ -104,7 +105,7 @@ public class Lib485BridgeHandler extends DmxBridgeHandler {
|
||||
universe.calculateBuffer(now);
|
||||
for (IpNode receiverNode : receiverNodes.keySet()) {
|
||||
Socket socket = receiverNodes.get(receiverNode);
|
||||
if (socket.isConnected()) {
|
||||
if (socket != null && socket.isConnected()) {
|
||||
try {
|
||||
socket.getOutputStream().write(universe.getBuffer());
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -15,12 +15,13 @@ package org.openhab.binding.dmx.internal.handler;
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.THING_TYPE_SACN_BRIDGE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.config.SacnBridgeHandlerConfiguration;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetHandler;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetPacket;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.SacnNode;
|
||||
import org.openhab.binding.dmx.internal.dmxoverethernet.SacnPacket;
|
||||
@@ -37,8 +38,9 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SacnBridgeHandler extends DmxOverEthernetHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_SACN_BRIDGE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_SACN_BRIDGE);
|
||||
public static final int MIN_UNIVERSE_ID = 1;
|
||||
public static final int MAX_UNIVERSE_ID = 63999;
|
||||
|
||||
@@ -55,6 +57,11 @@ public class SacnBridgeHandler extends DmxOverEthernetHandler {
|
||||
SacnBridgeHandlerConfiguration configuration = getConfig().as(SacnBridgeHandlerConfiguration.class);
|
||||
|
||||
setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
|
||||
DmxOverEthernetPacket packetTemplate = this.packetTemplate;
|
||||
if (packetTemplate == null) {
|
||||
packetTemplate = new SacnPacket(senderUUID);
|
||||
this.packetTemplate = packetTemplate;
|
||||
}
|
||||
packetTemplate.setUniverse(universe.getUniverseId());
|
||||
|
||||
receiverNodes.clear();
|
||||
|
||||
@@ -15,11 +15,11 @@ package org.openhab.binding.dmx.internal.handler;
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.DmxBindingConstants.ListenerType;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.DmxThingHandler;
|
||||
@@ -50,9 +50,9 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class TunableWhiteThingHandler extends DmxThingHandler {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_TUNABLEWHITE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_TUNABLEWHITE);
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(TunableWhiteThingHandler.class);
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -28,7 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class BaseDmxChannel implements Comparable<BaseDmxChannel> {
|
||||
public static final int MIN_CHANNEL_ID = 1;
|
||||
public static final int MAX_CHANNEL_ID = 512;
|
||||
@@ -75,7 +77,7 @@ public class BaseDmxChannel implements Comparable<BaseDmxChannel> {
|
||||
/**
|
||||
* get DMX universe
|
||||
*
|
||||
* @return an integer for the DMX universe
|
||||
* @return a integer for the DMX universe
|
||||
*/
|
||||
public int getUniverseId() {
|
||||
return universeId;
|
||||
@@ -91,14 +93,13 @@ public class BaseDmxChannel implements Comparable<BaseDmxChannel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(BaseDmxChannel otherDmxChannel) {
|
||||
public int compareTo(@Nullable BaseDmxChannel otherDmxChannel) {
|
||||
if (otherDmxChannel == null) {
|
||||
return -1;
|
||||
}
|
||||
int universeCompare = Integer.valueOf(getUniverseId())
|
||||
.compareTo(Integer.valueOf(otherDmxChannel.getUniverseId()));
|
||||
int universeCompare = Integer.valueOf(getUniverseId()).compareTo(otherDmxChannel.getUniverseId());
|
||||
if (universeCompare == 0) {
|
||||
return Integer.valueOf(getChannelId()).compareTo(Integer.valueOf(otherDmxChannel.getChannelId()));
|
||||
return Integer.compare(getChannelId(), otherDmxChannel.getChannelId());
|
||||
} else {
|
||||
return universeCompare;
|
||||
}
|
||||
@@ -125,9 +126,9 @@ public class BaseDmxChannel implements Comparable<BaseDmxChannel> {
|
||||
Matcher channelMatch = CHANNEL_PATTERN.matcher(singleDmxChannelString);
|
||||
if (channelMatch.matches()) {
|
||||
final int universeId = (channelMatch.group(1) == null) ? defaultUniverseId
|
||||
: Integer.valueOf(channelMatch.group(1));
|
||||
dmxChannelWidth = channelMatch.group(3).equals("") ? 1 : Integer.valueOf(channelMatch.group(3));
|
||||
dmxChannelId = Integer.valueOf(channelMatch.group(2));
|
||||
: Integer.parseInt(channelMatch.group(1));
|
||||
dmxChannelWidth = channelMatch.group(3).equals("") ? 1 : Integer.parseInt(channelMatch.group(3));
|
||||
dmxChannelId = Integer.parseInt(channelMatch.group(2));
|
||||
LOGGER.trace("parsed channel string {} to universe {}, id {}, width {}", singleDmxChannelString,
|
||||
universeId, dmxChannelId, dmxChannelWidth);
|
||||
IntStream.range(dmxChannelId, dmxChannelId + dmxChannelWidth)
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.internal.multiverse;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.dmx.internal.DmxBindingConstants.ListenerType;
|
||||
import org.openhab.binding.dmx.internal.DmxThingHandler;
|
||||
import org.openhab.binding.dmx.internal.Util;
|
||||
@@ -38,6 +39,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
* @author Davy Vanherbergen - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DmxChannel extends BaseDmxChannel {
|
||||
public static final int MIN_VALUE = 0;
|
||||
public static final int MAX_VALUE = 255;
|
||||
@@ -58,7 +60,7 @@ public class DmxChannel extends BaseDmxChannel {
|
||||
|
||||
private final Map<ChannelUID, DmxThingHandler> onOffListeners = new HashMap<>();
|
||||
private final Map<ChannelUID, DmxThingHandler> valueListeners = new HashMap<>();
|
||||
private Entry<ChannelUID, DmxThingHandler> actionListener = null;
|
||||
private @Nullable Entry<ChannelUID, DmxThingHandler> actionListener = null;
|
||||
|
||||
public DmxChannel(int universeId, int dmxChannelId, int refreshTime) {
|
||||
super(universeId, dmxChannelId);
|
||||
@@ -196,9 +198,10 @@ public class DmxChannel extends BaseDmxChannel {
|
||||
logger.trace("clearing all actions for DMX channel {}", this);
|
||||
actions.clear();
|
||||
// remove action listener
|
||||
Map.Entry<ChannelUID, DmxThingHandler> actionListener = this.actionListener;
|
||||
if (actionListener != null) {
|
||||
actionListener.getValue().updateSwitchState(actionListener.getKey(), OnOffType.OFF);
|
||||
actionListener = null;
|
||||
this.actionListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,13 +322,14 @@ public class DmxChannel extends BaseDmxChannel {
|
||||
}
|
||||
break;
|
||||
case ACTION:
|
||||
Map.Entry<ChannelUID, DmxThingHandler> actionListener = this.actionListener;
|
||||
if (actionListener != null) {
|
||||
logger.info("replacing ACTION listener {} with {} in channel {}", actionListener.getValue(),
|
||||
listener, this);
|
||||
} else {
|
||||
logger.debug("adding ACTION listener {} in channel {}", listener, this);
|
||||
}
|
||||
actionListener = new AbstractMap.SimpleEntry<>(thingChannel, listener);
|
||||
this.actionListener = Map.entry(thingChannel, listener);
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -347,8 +351,9 @@ public class DmxChannel extends BaseDmxChannel {
|
||||
foundListener = true;
|
||||
logger.debug("removing VALUE listener {} from DMX channel {}", thingChannel, this);
|
||||
}
|
||||
Map.Entry<ChannelUID, DmxThingHandler> actionListener = this.actionListener;
|
||||
if (actionListener != null && actionListener.getKey().equals(thingChannel)) {
|
||||
actionListener = null;
|
||||
this.actionListener = null;
|
||||
foundListener = true;
|
||||
logger.debug("removing ACTION listener {} from DMX channel {}", thingChannel, this);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -27,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Universe {
|
||||
public static final int MIN_UNIVERSE_SIZE = 32;
|
||||
public static final int MAX_UNIVERSE_SIZE = 512;
|
||||
@@ -67,7 +69,7 @@ public class Universe {
|
||||
/**
|
||||
* register a channel in the universe, create if not existing
|
||||
*
|
||||
* @param channel the channel represented by a {@link BaseDmxChannel} object
|
||||
* @param baseChannel the channel represented by a {@link BaseDmxChannel} object
|
||||
* @param thing the thing to register this channel to
|
||||
* @return a full featured channel
|
||||
*/
|
||||
@@ -143,7 +145,7 @@ public class Universe {
|
||||
/**
|
||||
* get size of the buffer
|
||||
*
|
||||
* @return value between {@link MIN_UNIVERSE_SIZE} and 512
|
||||
* @return value between {@link #MIN_UNIVERSE_SIZE} and 512
|
||||
*/
|
||||
public int getBufferSize() {
|
||||
return bufferSize;
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.openhab.binding.dmx.internal;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.dmx.internal.action.ActionState;
|
||||
import org.openhab.binding.dmx.internal.action.FadeAction;
|
||||
@@ -25,15 +26,15 @@ import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class FadeActionTest {
|
||||
|
||||
private static final int testValue = 200;
|
||||
private static final int testFadeTime = 1000;
|
||||
private static final int testHoldTime = 1000;
|
||||
private static final int TEST_VALUE = 200;
|
||||
private static final int TEST_FADE_TIME = 1000;
|
||||
private static final int TEST_HOLD_TIME = 1000;
|
||||
|
||||
@Test
|
||||
public void checkWithFadingWithoutHold() {
|
||||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, 0);
|
||||
FadeAction fadeAction = new FadeAction(TEST_FADE_TIME, TEST_VALUE, 0);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
@@ -42,8 +43,8 @@ public class FadeActionTest {
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + 1000), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME / 2), is(256 * TEST_VALUE / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + 1000), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
|
||||
|
||||
fadeAction.reset();
|
||||
@@ -52,7 +53,7 @@ public class FadeActionTest {
|
||||
|
||||
@Test
|
||||
public void checkWithFadingWithHold() {
|
||||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, testHoldTime);
|
||||
FadeAction fadeAction = new FadeAction(TEST_FADE_TIME, TEST_VALUE, TEST_HOLD_TIME);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
@@ -61,13 +62,14 @@ public class FadeActionTest {
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME / 2), is(256 * TEST_VALUE / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime + testHoldTime / 2),
|
||||
is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME + TEST_HOLD_TIME / 2),
|
||||
is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime + testHoldTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME + TEST_HOLD_TIME),
|
||||
is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
|
||||
|
||||
fadeAction.reset();
|
||||
@@ -76,7 +78,7 @@ public class FadeActionTest {
|
||||
|
||||
@Test
|
||||
public void checkWithFadingWithInfiniteHold() {
|
||||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, -1);
|
||||
FadeAction fadeAction = new FadeAction(TEST_FADE_TIME, TEST_VALUE, -1);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
@@ -85,8 +87,8 @@ public class FadeActionTest {
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME / 2), is(256 * TEST_VALUE / 2));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_FADE_TIME), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL));
|
||||
|
||||
fadeAction.reset();
|
||||
@@ -95,18 +97,18 @@ public class FadeActionTest {
|
||||
|
||||
@Test
|
||||
public void checkWithoutFadingWithHold() {
|
||||
FadeAction fadeAction = new FadeAction(0, testValue, testHoldTime);
|
||||
FadeAction fadeAction = new FadeAction(0, TEST_VALUE, TEST_HOLD_TIME);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testHoldTime / 2), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_HOLD_TIME / 2), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.RUNNING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + testHoldTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime + TEST_HOLD_TIME), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
|
||||
|
||||
fadeAction.reset();
|
||||
@@ -115,14 +117,14 @@ public class FadeActionTest {
|
||||
|
||||
@Test
|
||||
public void checkWithoutFadingWithoutHold() {
|
||||
FadeAction fadeAction = new FadeAction(0, testValue, 0);
|
||||
FadeAction fadeAction = new FadeAction(0, TEST_VALUE, 0);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED));
|
||||
|
||||
fadeAction.reset();
|
||||
@@ -131,14 +133,14 @@ public class FadeActionTest {
|
||||
|
||||
@Test
|
||||
public void checkWithoutFadingWithInfiniteHold() {
|
||||
FadeAction fadeAction = new FadeAction(0, testValue, -1);
|
||||
FadeAction fadeAction = new FadeAction(0, TEST_VALUE, -1);
|
||||
DmxChannel testChannel = new DmxChannel(0, 1, 0);
|
||||
testChannel.setValue(0);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
assertThat(fadeAction.getState(), is(ActionState.WAITING));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue));
|
||||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * TEST_VALUE));
|
||||
assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL));
|
||||
|
||||
fadeAction.reset();
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.openhab.binding.dmx.internal;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
@@ -24,6 +25,7 @@ import org.openhab.core.library.types.PercentType;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class UtilTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,6 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ValueSetTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -41,18 +42,16 @@ import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ArtnetBridgeHandlerTest extends JavaTest {
|
||||
|
||||
private static final String TEST_ADDRESS = "localhost";
|
||||
private static final int TEST_UNIVERSE = 1;
|
||||
private static final ThingUID BRIDGE_UID_ARTNET = new ThingUID(THING_TYPE_ARTNET_BRIDGE, "artnetbridge");
|
||||
private static final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_ARTNET, CHANNEL_MUTE);
|
||||
|
||||
private final ThingUID BRIDGE_UID_ARTNET = new ThingUID(THING_TYPE_ARTNET_BRIDGE, "artnetbridge");
|
||||
private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_ARTNET, CHANNEL_MUTE);
|
||||
|
||||
Map<String, Object> bridgeProperties;
|
||||
|
||||
private Bridge bridge;
|
||||
private ArtnetBridgeHandler bridgeHandler;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Bridge bridge;
|
||||
private @NonNullByDefault({}) ArtnetBridgeHandler bridgeHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.openhab.binding.dmx.test.TestBridgeHandler.THING_TYPE_TEST_BRI
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -44,22 +45,20 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ChaserThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
|
||||
private static final String TEST_CHANNEL = "100";
|
||||
private static final String TEST_STEPS_INFINITE = "1000:100:1000|1000:200:-1";
|
||||
private static final String TEST_STEPS_REPEAT = "1000:115:1000|1000:210:1000";
|
||||
private static final ThingUID THING_UID_CHASER = new ThingUID(THING_TYPE_CHASER, "testchaser");
|
||||
private static final ChannelUID CHANNEL_UID_SWITCH = new ChannelUID(THING_UID_CHASER, CHANNEL_SWITCH);
|
||||
|
||||
private final ThingUID THING_UID_CHASER = new ThingUID(THING_TYPE_CHASER, "testchaser");
|
||||
private final ChannelUID CHANNEL_UID_SWITCH = new ChannelUID(THING_UID_CHASER, CHANNEL_SWITCH);
|
||||
|
||||
Map<String, Object> bridgeProperties;
|
||||
Map<String, Object> thingProperties;
|
||||
|
||||
private Thing chaserThing;
|
||||
|
||||
private TestBridgeHandler dmxBridgeHandler;
|
||||
private ChaserThingHandler chaserThingHandler;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Map<String, Object> thingProperties;
|
||||
private @NonNullByDefault({}) Thing chaserThing;
|
||||
private @NonNullByDefault({}) TestBridgeHandler dmxBridgeHandler;
|
||||
private @NonNullByDefault({}) ChaserThingHandler chaserThingHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -77,7 +76,7 @@ public class ChaserThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThingStatus_noBridge() {
|
||||
public void testThingStatusNoBridge() {
|
||||
thingProperties.put(CONFIG_CHASER_STEPS, TEST_STEPS_INFINITE);
|
||||
initialize();
|
||||
// check that thing is offline if no bridge found
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -42,22 +43,21 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ColorThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
|
||||
private static final String TEST_CHANNEL_CONFIG = "100/3";
|
||||
private static final int TEST_FADE_TIME = 1500;
|
||||
private static final HSBType TEST_COLOR = new HSBType(new DecimalType(280), new PercentType(100),
|
||||
new PercentType(100));
|
||||
private static final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_COLOR, "testdimmer");
|
||||
private static final ChannelUID CHANNEL_UID_COLOR = new ChannelUID(THING_UID_DIMMER, CHANNEL_COLOR);
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS_R = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_R);
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS_G = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_G);
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS_B = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_B);
|
||||
|
||||
private Map<String, Object> thingProperties;
|
||||
private Thing dimmerThing;
|
||||
private ColorThingHandler dimmerThingHandler;
|
||||
|
||||
private final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_COLOR, "testdimmer");
|
||||
private final ChannelUID CHANNEL_UID_COLOR = new ChannelUID(THING_UID_DIMMER, CHANNEL_COLOR);
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS_R = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_R);
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS_G = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_G);
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS_B = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_B);
|
||||
private @NonNullByDefault({}) Map<String, Object> thingProperties;
|
||||
private @NonNullByDefault({}) Thing dimmerThing;
|
||||
private @NonNullByDefault({}) ColorThingHandler dimmerThingHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -92,7 +92,7 @@ public class ColorThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThingStatus_noBridge() {
|
||||
public void testThingStatusNoBridge() {
|
||||
// check that thing is offline if no bridge found
|
||||
ColorThingHandler dimmerHandlerWithoutBridge = new ColorThingHandler(dimmerThing) {
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -41,16 +42,16 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DimmerThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
private static final String TEST_CHANNEL_CONFIG = "100";
|
||||
private static final int TEST_FADE_TIME = 1500;
|
||||
private static final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_DIMMER, "testdimmer");
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS);
|
||||
|
||||
private Map<String, Object> thingProperties;
|
||||
private Thing dimmerThing;
|
||||
private DimmerThingHandler dimmerThingHandler;
|
||||
|
||||
private final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_DIMMER, "testdimmer");
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS);
|
||||
private @NonNullByDefault({}) Map<String, Object> thingProperties;
|
||||
private @NonNullByDefault({}) Thing dimmerThing;
|
||||
private @NonNullByDefault({}) DimmerThingHandler dimmerThingHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -82,7 +83,7 @@ public class DimmerThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThingStatus_noBridge() {
|
||||
public void testThingStatusNoBridge() {
|
||||
// check that thing is offline if no bridge found
|
||||
DimmerThingHandler dimmerHandlerWithoutBridge = new DimmerThingHandler(dimmerThing) {
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@@ -49,6 +50,7 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DmxBridgeHandlerTest extends JavaTest {
|
||||
|
||||
/**
|
||||
@@ -85,14 +87,13 @@ public class DmxBridgeHandlerTest extends JavaTest {
|
||||
private static final int TEST_UNIVERSE = 1;
|
||||
private static final int TEST_CHANNEL = 100;
|
||||
|
||||
private final ThingTypeUID THING_TYPE_TEST_BRIDGE = new ThingTypeUID(BINDING_ID, "testbridge");
|
||||
private final ThingUID BRIDGE_UID_TEST = new ThingUID(THING_TYPE_TEST_BRIDGE, "testbridge");
|
||||
private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_TEST, CHANNEL_MUTE);
|
||||
private static final ThingTypeUID THING_TYPE_TEST_BRIDGE = new ThingTypeUID(BINDING_ID, "testbridge");
|
||||
private static final ThingUID BRIDGE_UID_TEST = new ThingUID(THING_TYPE_TEST_BRIDGE, "testbridge");
|
||||
private static final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_TEST, CHANNEL_MUTE);
|
||||
|
||||
Map<String, Object> bridgeProperties;
|
||||
|
||||
private Bridge bridge;
|
||||
private DmxBridgeHandlerImpl bridgeHandler;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Bridge bridge;
|
||||
private @NonNullByDefault({}) DmxBridgeHandlerImpl bridgeHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -39,17 +40,15 @@ import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Lib485BridgeHandlerTest extends JavaTest {
|
||||
|
||||
private static final String TEST_ADDRESS = "localhost";
|
||||
private static final ThingUID BRIDGE_UID_LIB485 = new ThingUID(THING_TYPE_LIB485_BRIDGE, "lib485bridge");
|
||||
private static final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_LIB485, CHANNEL_MUTE);
|
||||
|
||||
private final ThingUID BRIDGE_UID_LIB485 = new ThingUID(THING_TYPE_LIB485_BRIDGE, "lib485bridge");
|
||||
private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_LIB485, CHANNEL_MUTE);
|
||||
|
||||
Map<String, Object> bridgeProperties;
|
||||
|
||||
private Bridge bridge;
|
||||
private Lib485BridgeHandler bridgeHandler;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Bridge bridge;
|
||||
private @NonNullByDefault({}) Lib485BridgeHandler bridgeHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -41,17 +42,16 @@ import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SacnBridgeHandlerTest extends JavaTest {
|
||||
private static final String TEST_ADDRESS = "localhost";
|
||||
private static final int TEST_UNIVERSE = 1;
|
||||
private static final ThingUID BRIDGE_UID_SACN = new ThingUID(THING_TYPE_SACN_BRIDGE, "sacnbridge");
|
||||
private static final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_SACN, CHANNEL_MUTE);
|
||||
|
||||
private final ThingUID BRIDGE_UID_SACN = new ThingUID(THING_TYPE_SACN_BRIDGE, "sacnbridge");
|
||||
private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_SACN, CHANNEL_MUTE);
|
||||
|
||||
Map<String, Object> bridgeProperties;
|
||||
|
||||
private Bridge bridge;
|
||||
private SacnBridgeHandler bridgeHandler;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Bridge bridge;
|
||||
private @NonNullByDefault({}) SacnBridgeHandler bridgeHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -40,20 +41,20 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TunableWhiteThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
|
||||
private static final String TEST_CHANNEL_CONFIG = "100/2";
|
||||
private static final int TEST_FADE_TIME = 1500;
|
||||
private static final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_TUNABLEWHITE, "testdimmer");
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS);
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS_CW = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_CW);
|
||||
private static final ChannelUID CHANNEL_UID_BRIGHTNESS_WW = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_WW);
|
||||
private static final ChannelUID CHANNEL_UID_COLOR_TEMP = new ChannelUID(THING_UID_DIMMER,
|
||||
CHANNEL_COLOR_TEMPERATURE);
|
||||
|
||||
private Map<String, Object> thingProperties;
|
||||
private Thing dimmerThing;
|
||||
private TunableWhiteThingHandler dimmerThingHandler;
|
||||
|
||||
private final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_TUNABLEWHITE, "testdimmer");
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS);
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS_CW = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_CW);
|
||||
private final ChannelUID CHANNEL_UID_BRIGHTNESS_WW = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_WW);
|
||||
private final ChannelUID CHANNEL_UID_COLOR_TEMP = new ChannelUID(THING_UID_DIMMER, CHANNEL_COLOR_TEMPERATURE);
|
||||
private @NonNullByDefault({}) Map<String, Object> thingProperties;
|
||||
private @NonNullByDefault({}) Thing dimmerThing;
|
||||
private @NonNullByDefault({}) TunableWhiteThingHandler dimmerThingHandler;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -90,7 +91,7 @@ public class TunableWhiteThingHandlerTest extends AbstractDmxThingTestParent {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThingStatus_noBridge() {
|
||||
public void testThingStatusNoBridge() {
|
||||
// check that thing is offline if no bridge found
|
||||
TunableWhiteThingHandler dimmerHandlerWithoutBridge = new TunableWhiteThingHandler(dimmerThing) {
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BaseChannelTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.openhab.binding.dmx.internal.multiverse;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -29,13 +30,13 @@ import org.openhab.core.thing.ChannelUID;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DmxChannelTest {
|
||||
|
||||
private final ChannelUID valueChannelUID = new ChannelUID("dmx:testBridge:testThing:valueChannel");
|
||||
|
||||
DmxChannel dmxChannel;
|
||||
DimmerThingHandler dimmerThingHandler;
|
||||
long currentTime;
|
||||
private @NonNullByDefault({}) DmxChannel dmxChannel;
|
||||
private @NonNullByDefault({}) DimmerThingHandler dimmerThingHandler;
|
||||
private long currentTime;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
@@ -22,8 +22,10 @@ import static org.openhab.binding.dmx.test.TestBridgeHandler.THING_TYPE_TEST_BRI
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@@ -46,13 +48,14 @@ import org.openhab.core.types.State;
|
||||
* @author Simon Kaufmann - initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AbstractDmxThingTestParent extends JavaTest {
|
||||
|
||||
private Map<String, Object> bridgeProperties;
|
||||
private @NonNullByDefault({}) Map<String, Object> bridgeProperties;
|
||||
|
||||
protected Bridge bridge;
|
||||
protected TestBridgeHandler dmxBridgeHandler;
|
||||
protected ThingHandlerCallback mockCallback;
|
||||
protected @NonNullByDefault({}) Bridge bridge;
|
||||
protected @NonNullByDefault({}) TestBridgeHandler dmxBridgeHandler;
|
||||
protected @NonNullByDefault({}) ThingHandlerCallback mockCallback;
|
||||
|
||||
protected void setup() {
|
||||
initializeBridge();
|
||||
@@ -92,6 +95,7 @@ public class AbstractDmxThingTestParent extends JavaTest {
|
||||
// check that thing properly follows bridge status
|
||||
ThingHandler handler = thing.getHandler();
|
||||
assertNotNull(handler);
|
||||
Objects.requireNonNull(handler);
|
||||
handler.bridgeStatusChanged(ThingStatusInfoBuilder.create(ThingStatus.OFFLINE).build());
|
||||
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, thing.getStatusInfo().getStatus()));
|
||||
handler.bridgeStatusChanged(ThingStatusInfoBuilder.create(ThingStatus.ONLINE).build());
|
||||
|
||||
@@ -12,18 +12,21 @@
|
||||
*/
|
||||
package org.openhab.binding.dmx.test;
|
||||
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.BINDING_ID;
|
||||
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
|
||||
import org.openhab.binding.dmx.internal.multiverse.BaseDmxChannel;
|
||||
import org.openhab.binding.dmx.internal.multiverse.Universe;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
import org.openhab.core.thing.ThingStatusDetail;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -32,7 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
|
||||
@NonNullByDefault
|
||||
public class TestBridgeHandler extends DmxBridgeHandler {
|
||||
public static final ThingTypeUID THING_TYPE_TEST_BRIDGE = new ThingTypeUID(BINDING_ID, "test-bridge");
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_TEST_BRIDGE);
|
||||
@@ -40,6 +43,7 @@ public class TestBridgeHandler extends DmxBridgeHandler {
|
||||
public static final int MAX_UNIVERSE_ID = 0;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(TestBridgeHandler.class);
|
||||
private Thing dummyThing = ThingBuilder.create(THING_TYPE_DIMMER, "dummy").build();
|
||||
|
||||
public TestBridgeHandler(Bridge testBridge) {
|
||||
super(testBridge);
|
||||
@@ -101,7 +105,7 @@ public class TestBridgeHandler extends DmxBridgeHandler {
|
||||
}
|
||||
|
||||
public void setDmxChannelValue(int dmxChannel, int value) {
|
||||
this.getDmxChannel(new BaseDmxChannel(MIN_UNIVERSE_ID, dmxChannel), null).setValue(value);
|
||||
this.getDmxChannel(new BaseDmxChannel(MIN_UNIVERSE_ID, dmxChannel), dummyThing).setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user