*/
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;
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public class DmxBindingConstants {
-
public static final String BINDING_ID = "dmx";
// List of all Thing Type UIDs
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";
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;
*
* @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;
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());
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();
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);
}
}
}
// do action
- Integer channelCounter = 0;
+ int channelCounter = 0;
for (DmxChannel channel : channels) {
if (resumeAfter) {
channel.suspendAction();
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;
* @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);
*/
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;
*
* @author Jan N. Klug - Initial contribution
*/
-
+@NonNullByDefault
public abstract class DmxThingHandler extends BaseThingHandler {
protected ThingStatusDetail dmxHandlerStatus = ThingStatusDetail.HANDLER_CONFIGURATION_PENDING;
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;
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public class Util {
/**
* inRange checks if a value is between two other values
* @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;
}
/**
* @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);
* @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, "");
}
* @param max
* @return coerced value
*/
-
public static int coerceToRange(int value, int min, int max) {
return coerceToRange(value, min, max, null, "");
}
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;
/**
*
* @author Jan N. Klug - Initial contribution
*/
-
+@NonNullByDefault
public class ValueSet {
protected static final Pattern VALUESET_PATTERN = Pattern.compile("^(\\d*):([\\d,]*):([\\d-]*)$");
@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(" "));
}
}
*/
package org.openhab.binding.dmx.internal.action;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* The {@link ActionState} gives the state of an action
*
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public enum ActionState {
WAITING,
RUNNING,
*/
package org.openhab.binding.dmx.internal.action;
+import org.eclipse.jdt.annotation.NonNullByDefault;
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;
*/
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;
* @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;
private float stepDuration;
- private FadeDirection fadeDirection;
+ private FadeDirection fadeDirection = FadeDirection.DOWN;
/**
* Create new fading action.
@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";
}
}
*/
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
*/
package org.openhab.binding.dmx.internal.action;
+import org.eclipse.jdt.annotation.NonNullByDefault;
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
*
* @author Jan N. Klug - Initial contribution
*/
-
@NonNullByDefault
public class ColorThingHandlerConfiguration {
public String dmxid = "";
*/
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
* @author Jan N. Klug - Initial contribution
*
*/
+@NonNullByDefault
public class ArtnetNode extends IpNode {
public static final int DEFAULT_PORT = 6454;
*/
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;
*
* @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;
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;
*
* @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;
if (getThing().getStatus() != ThingStatus.ONLINE) {
try {
if (senderNode.getAddress() == null) {
+ DatagramSocket socket;
if (senderNode.getPort() == 0) {
socket = new DatagramSocket();
senderNode.setInetAddress(socket.getLocalAddress());
socket = new DatagramSocket(senderNode.getPort());
senderNode.setInetAddress(socket.getLocalAddress());
}
+ this.socket = socket;
} else {
socket = new DatagramSocket(senderNode.getPort(), senderNode.getAddress());
}
@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());
}
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(),
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());
*/
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
/**
* sets universe, calculates sender name and broadcast-address
*
- * @param universe
+ * @param universeId
*/
public abstract void setUniverse(int universeId);
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;
* @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
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);
*
* @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;
}
/**
*/
@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;
}
/**
*/
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
* @author Jan N. Klug - Initial contribution
*
*/
-
+@NonNullByDefault
public class SacnNode extends IpNode {
public static final int DEFAULT_PORT = 5568;
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;
*
* @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;
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;
*
* @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;
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();
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;
*
* @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);
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;
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);
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;
*
* @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);
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) {
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;
*
* @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;
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();
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;
*
* @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);
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;
*
* @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;
/**
* get DMX universe
*
- * @return an integer for the DMX universe
+ * @return a integer for the DMX universe
*/
public int getUniverseId() {
return universeId;
}
@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;
}
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)
*/
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;
* @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;
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);
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;
}
}
}
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:
}
}
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);
}
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;
*
* @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;
/**
* 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
*/
/**
* 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;
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;
*
* @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);
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();
@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);
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();
@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);
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();
@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();
@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();
@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();
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;
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public class UtilTest {
@Test
import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
/**
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public class ValueSetTest {
@Test
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;
*
* @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() {
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;
*
* @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() {
}
@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
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;
*
* @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() {
}
@Test
- public void testThingStatus_noBridge() {
+ public void testThingStatusNoBridge() {
// check that thing is offline if no bridge found
ColorThingHandler dimmerHandlerWithoutBridge = new ColorThingHandler(dimmerThing) {
@Override
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;
*
* @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() {
}
@Test
- public void testThingStatus_noBridge() {
+ public void testThingStatusNoBridge() {
// check that thing is offline if no bridge found
DimmerThingHandler dimmerHandlerWithoutBridge = new DimmerThingHandler(dimmerThing) {
@Override
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;
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
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() {
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;
*
* @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() {
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;
*
* @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() {
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;
*
* @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() {
}
@Test
- public void testThingStatus_noBridge() {
+ public void testThingStatusNoBridge() {
// check that thing is offline if no bridge found
TunableWhiteThingHandler dimmerHandlerWithoutBridge = new TunableWhiteThingHandler(dimmerThing) {
@Override
import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
/**
*
* @author Jan N. Klug - Initial contribution
*/
+@NonNullByDefault
public class BaseChannelTest {
@Test
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;
*
* @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() {
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;
* @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();
// 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());
*/
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;
*
* @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);
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);
}
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);
}
/**