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