Skip to content

Commit

Permalink
Merge pull request openhab#18 from kaikreuzer/loc
Browse files Browse the repository at this point in the history
added location item support in config reader delegate
  • Loading branch information
kaikreuzer committed Feb 16, 2016
2 parents c7c6e29 + 6d04f2d commit ab2eebd
Showing 1 changed file with 59 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,70 +14,79 @@
/**
* This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
* namespace for the binding config readers. It wraps an instance with the old interface
* into a class with the new interface.
*
* into a class with the new interface.
*
* @author Kai Kreuzer - Initial contribution and API
*/
public class BindingConfigReaderDelegate implements BindingConfigReader {

private org.openhab.model.item.binding.BindingConfigReader reader;
private org.openhab.model.item.binding.BindingConfigReader reader;

public BindingConfigReaderDelegate(org.openhab.model.item.binding.BindingConfigReader reader) {
this.reader = reader;
}

@Override
public String getBindingType() {
return reader.getBindingType();
}

public BindingConfigReaderDelegate(
org.openhab.model.item.binding.BindingConfigReader reader) {
this.reader = reader;
}
@Override
public void validateItemType(String itemType, String bindingConfig) throws BindingConfigParseException {
try {
reader.validateItemType(getOpenHABItem(itemType), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}

@Override
public String getBindingType() {
return reader.getBindingType();
}
}

@Override
public void validateItemType(String itemType, String bindingConfig)
throws BindingConfigParseException {
try {
reader.validateItemType(getOpenHABItem(itemType), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}

}
@Override
public void processBindingConfiguration(String context, String itemType, String itemName, String bindingConfig)
throws BindingConfigParseException {
try {
reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}

@Override
public void processBindingConfiguration(String context, String itemType, String itemName,
String bindingConfig) throws BindingConfigParseException {
try {
reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}

}
}

private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException {
return getOpenHABItem(itemType, "itemName");
}
private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException {
return getOpenHABItem(itemType, "itemName");
}

private org.openhab.core.items.Item getOpenHABItem(String itemType,
String itemName) throws BindingConfigParseException {
private org.openhab.core.items.Item getOpenHABItem(String itemType, String itemName)
throws BindingConfigParseException {

switch(itemType) {
case "Switch" : return new org.openhab.core.library.items.SwitchItem(itemName);
case "Dimmer" : return new org.openhab.core.library.items.DimmerItem(itemName);
case "Color" : return new org.openhab.core.library.items.ColorItem(itemName);
case "String" : return new org.openhab.core.library.items.StringItem(itemName);
case "Number" : return new org.openhab.core.library.items.NumberItem(itemName);
case "Contact" : return new org.openhab.core.library.items.ContactItem(itemName);
case "Rollershutter" : return new org.openhab.core.library.items.RollershutterItem(itemName);
case "DateTime" : return new org.openhab.core.library.items.DateTimeItem(itemName);
case "Call" : return new org.openhab.library.tel.items.CallItem(itemName);
}
throw new BindingConfigParseException("cannot process unknown item type " + itemType);
}
switch (itemType) {
case "Switch":
return new org.openhab.core.library.items.SwitchItem(itemName);
case "Dimmer":
return new org.openhab.core.library.items.DimmerItem(itemName);
case "Color":
return new org.openhab.core.library.items.ColorItem(itemName);
case "String":
return new org.openhab.core.library.items.StringItem(itemName);
case "Number":
return new org.openhab.core.library.items.NumberItem(itemName);
case "Contact":
return new org.openhab.core.library.items.ContactItem(itemName);
case "Rollershutter":
return new org.openhab.core.library.items.RollershutterItem(itemName);
case "DateTime":
return new org.openhab.core.library.items.DateTimeItem(itemName);
case "Location":
return new org.openhab.core.library.items.LocationItem(itemName);
case "Call":
return new org.openhab.library.tel.items.CallItem(itemName);
}
throw new BindingConfigParseException("cannot process unknown item type " + itemType);
}

@Override
public void startConfigurationUpdate(String context) {
reader.removeConfigurations(context);
reader.removeConfigurations(context);
}

@Override
Expand Down

0 comments on commit ab2eebd

Please sign in to comment.