Skip to content

Commit

Permalink
Fix channel Number set using QuantityType
Browse files Browse the repository at this point in the history
  • Loading branch information
docbender committed Jan 11, 2021
1 parent 620795b commit 3060a53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.openhab.binding.simatic.internal.SimaticBindingConstants;
import org.openhab.binding.simatic.internal.libnodave.Nodave;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
Expand Down Expand Up @@ -51,12 +50,13 @@ public static SimaticWriteDataArea create(Command command, SimaticChannel channe
byte[] data = null;

if (channel.channelType.getId().equals(SimaticBindingConstants.CHANNEL_NUMBER)) {
if (!(command instanceof DecimalType)) {
throw new Exception(
String.format("Cannot create WriteDataArea. Command for ChannelType=%s must be DecimalType",
channel.channelType.getId()));
if (!(command instanceof Number)) {
throw new Exception(String.format(
"Cannot create WriteDataArea. Command for ChannelType=%s must be DecimalType. It is %s (%s)",
channel.channelType.getId(), command.getClass().getSimpleName(),
command.getClass().getGenericSuperclass().getTypeName()));
}
DecimalType cmd = (DecimalType) command;
Number cmd = (Number) command;
if (address.getSimaticDataType() == SimaticPLCDataTypes.BYTE
|| address.getSimaticDataType() == SimaticPLCDataTypes.BIT) {
data = new byte[] { cmd.byteValue() };
Expand Down Expand Up @@ -164,9 +164,25 @@ public static SimaticWriteDataArea create(Command command, SimaticChannel channe
}
} else if (channel.channelType.getId().equals(SimaticBindingConstants.CHANNEL_ROLLERSHUTTER)) {
if (command instanceof StopMoveType) {
data = new byte[] { (byte) (((StopMoveType) command).equals(StopMoveType.MOVE) ? 0x1 : 0x2) };
if (address.getSimaticDataType() == SimaticPLCDataTypes.WORD) {
data = new byte[] { (byte) (((StopMoveType) command).equals(StopMoveType.MOVE) ? 0x1 : 0x2), 0 };
} else {
data = new byte[] { (byte) (((StopMoveType) command).equals(StopMoveType.MOVE) ? 0x1 : 0x2) };
}
} else if (command instanceof UpDownType) {
data = new byte[] { (byte) (((UpDownType) command).equals(UpDownType.UP) ? 0x4 : 0x8) };
if (address.getSimaticDataType() == SimaticPLCDataTypes.WORD) {
data = new byte[] { (byte) (((UpDownType) command).equals(UpDownType.UP) ? 0x4 : 0x8), 0 };
} else {
data = new byte[] { (byte) (((UpDownType) command).equals(UpDownType.UP) ? 0x4 : 0x8) };
}
} else if (command instanceof PercentType) {
if (address.getSimaticDataType() == SimaticPLCDataTypes.WORD) {
data = new byte[] { 0x1, ((PercentType) command).byteValue() };
} else {
throw new Exception(String.format(
"Cannot create WriteDataArea. Command %s ChannelType=%s need for position set command address length of WORD.",
command.getClass(), channel.channelType.getId()));
}
} else {
throw new Exception(
String.format("Cannot create WriteDataArea. Command %s for ChannelType=%s not implemented",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@NonNullByDefault
public class SimaticBindingConstants {

public static final String VERSION = "3.0.2";
public static final String VERSION = "3.0.4";

private static final String BINDING_ID = "simatic";

Expand Down

0 comments on commit 3060a53

Please sign in to comment.