Skip to content

Commit

Permalink
mapping 9.007 to PercentType, sync for KNX2 PR openhab#3410
Browse files Browse the repository at this point in the history
Signed-off-by: lewie <helmut.lehmeyer@gmail.com>
  • Loading branch information
lewie committed Mar 29, 2018
1 parent 064d59b commit 2f6ca5b
Show file tree
Hide file tree
Showing 3 changed files with 522 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.openhab.core.types.Type;

import com.sun.istack.internal.Nullable;

import tuwien.auto.calimero.datapoint.Datapoint;
import tuwien.auto.calimero.process.ProcessEvent;

Expand All @@ -27,7 +29,7 @@ public interface KNXTypeMapper {

/**
* maps an openHAB command/state to a string value which correspond to its datapoint in KNX
*
*
* @param type a command or state
* @param dpt the corresponding datapoint type
* @return datapoint value as a string
Expand All @@ -36,11 +38,14 @@ public interface KNXTypeMapper {

/**
* maps a datapoint value to an openHAB command or state
*
*
* @param datapoint the source datapoint
* @param data the datapoint value as an ASDU byte array (see <code>{@link ProcessEvent}.getASDU()</code>)
* @return a command or state of openHAB
*/
public Type toType(Datapoint datapoint, byte[] data);

@Nullable
public Class<? extends Type> toTypeClass(@Nullable String dpt);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.NoSuchElementException;

import org.openhab.binding.knx.config.KNXBindingProvider;
import org.openhab.binding.knx.config.KNXTypeMapper;
import org.openhab.binding.knx.internal.dpt.KNXCoreTypeMapper;
import org.openhab.core.autoupdate.AutoUpdateBindingProvider;
import org.openhab.core.binding.BindingConfig;
Expand Down Expand Up @@ -94,6 +95,8 @@
public class KNXGenericBindingProvider extends AbstractGenericBindingProvider
implements KNXBindingProvider, AutoUpdateBindingProvider {

private final KNXTypeMapper typeHelper = new KNXCoreTypeMapper();

/** the binding type to register for as a binding config reader */
public static final String KNX_BINDING_TYPE = "knx";

Expand Down Expand Up @@ -187,7 +190,7 @@ public boolean apply(KNXBindingConfigItem input) {
return false;
}
if (input.itemName.equals(itemName) && input.mainDataPoint != null) {
Class<?> dptTypeClass = KNXCoreTypeMapper.toTypeClass(input.mainDataPoint.getDPT());
Class<?> dptTypeClass = typeHelper.toTypeClass(input.mainDataPoint.getDPT());
return dptTypeClass != null && dptTypeClass.equals(typeClass);
}
return false;
Expand Down Expand Up @@ -453,7 +456,7 @@ protected KNXBindingConfig parseBindingConfigString(Item item, String bindingCon
"No DPT could be determined for the type '" + typeClass.getSimpleName() + "'.");
}
// check if this DPT is supported
if (KNXCoreTypeMapper.toTypeClass(dptID) == null) {
if (typeHelper.toTypeClass(dptID) == null) {
throw new BindingConfigParseException("DPT " + dptID + " is not supported by the KNX binding.");
}

Expand Down Expand Up @@ -513,7 +516,7 @@ protected KNXBindingConfig parseBindingConfigString(Item item, String bindingCon
* @return the default datapoint type id
*/
private String getDefaultDPTId(Class<? extends Type> typeClass) {
return KNXCoreTypeMapper.toDPTid(typeClass);
return ((KNXCoreTypeMapper) typeHelper).toDPTid(typeClass);
}

/**
Expand Down

0 comments on commit 2f6ca5b

Please sign in to comment.