本文整理汇总了Java中org.openhab.model.item.binding.BindingConfigParseException类的典型用法代码示例。如果您正苦于以下问题:Java BindingConfigParseException类的具体用法?Java BindingConfigParseException怎么用?Java BindingConfigParseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingConfigParseException类属于org.openhab.model.item.binding包,在下文中一共展示了BindingConfigParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processBindingConfiguration
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item,
String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
// parse configuration
Map<String, String> props = parseProperties(bindingConfig);
String id = props.get(YamahaReceiverBindingConfig.KEY_DEVICE_UID);
String zone = props.get(YamahaReceiverBindingConfig.KEY_ZONE);
String bindingType = props
.get(YamahaReceiverBindingConfig.KEY_BINDING_TYPE);
// create configuration
YamahaReceiverBindingConfig config = new YamahaReceiverBindingConfig(
id, zone, bindingType, item.getName());
// add binding configuration
addBindingConfig(item, config);
}
}
示例2: canParseValidButtonConfigWithRefresh
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
@Test
public void canParseValidButtonConfigWithRefresh()
throws BindingConfigParseException {
// test parsing of regular buttons
parseButtonWithRefresh("btn-cfg1", "#NA0914D[1973-1,1824-2]",
Button.PressType.SHORT, "#NA0914D", new String[] { "1973-1",
"1824-2" });
parseButtonWithRefresh("btn-cfg1",
"#NA0914D[1973-1,1824-2,55DC-2,884E-1]",
Button.PressType.SHORT, "#NA0914D", new String[] { "1973-1",
"1824-2", "55DC-2", "884E-1" });
parseButtonWithRefresh("btn-cfg1", "#NA0914D[1973-1]",
Button.PressType.SHORT, "#NA0914D", new String[] { "1973-1" });
parseButtonWithRefresh("btn-cfg2", "#N003334:SHORT[1233-1]",
Button.PressType.SHORT, "#N003334", new String[] { "1233-1" });
parseButtonWithRefresh("btn-cfg3", "#N003335:LONG[1973-1,1824-2]",
Button.PressType.LONG, "#N003335", new String[] { "1973-1",
"1824-2" });
parseButtonWithRefresh("btn-cfg4", "#N003333[1973-1,1824-2]",
Button.PressType.SHORT, "#N003333", new String[] { "1973-1",
"1824-2" });
}
示例3: processBindingConfiguration
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length > 2) {
throw new BindingConfigParseException("NTP binding configuration must not contain more than two parts");
}
NTPBindingConfig config = new NTPBindingConfig();
config.timeZone = configParts.length > 0 ? TimeZone.getTimeZone(configParts[0]) : TimeZone.getDefault();
config.locale = configParts.length > 1 ? new Locale(configParts[1]) : Locale.getDefault();
addBindingConfig(item, config);
}
示例4: processBindingConfiguration
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item,
String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
// parse binding configuration
InsteonHubBindingConfig config = InsteonHubBindingConfig.parse(
item.getName(), bindingConfig);
// add binding configuration
addBindingConfig(item, config);
// add to hubid+device map
Set<String> deviceItems = getOrCreateDeviceItems(config
.getDeviceInfo());
deviceItems.add(config.getItemName());
}
}
示例5: testParseBindingConfig_Roland
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
@Test
public void testParseBindingConfig_Roland() throws BindingConfigParseException {
String bindingConfig = "<[http://localhost:42111/valueget.html?q=4-SWITCHMULTILEVEL-user-byte-1-0:60000:XSLT(value.xsl)] >[CHANGED:POST:http://localhost:42111/valuepost.html?id=4-SWITCHMULTILEVEL-user-byte-1-0&v=39]";
testItem = new DimmerTestItem();
// method under test
HttpBindingConfig config = provider.parseBindingConfig(testItem, bindingConfig);
// asserts
Assert.assertEquals(true, config.containsKey(HttpGenericBindingProvider.IN_BINDING_KEY));
Assert.assertEquals(null, config.get(HttpGenericBindingProvider.IN_BINDING_KEY).httpMethod);
Assert.assertEquals("http://localhost:42111/valueget.html?q=4-SWITCHMULTILEVEL-user-byte-1-0", config.get(HttpGenericBindingProvider.IN_BINDING_KEY).url);
Assert.assertEquals(60000, config.get(HttpGenericBindingProvider.IN_BINDING_KEY).refreshInterval);
Assert.assertEquals("XSLT(value.xsl)", config.get(HttpGenericBindingProvider.IN_BINDING_KEY).transformation);
Assert.assertEquals(true, config.containsKey(HttpGenericBindingProvider.CHANGED_COMMAND_KEY));
Assert.assertEquals("POST", config.get(HttpGenericBindingProvider.CHANGED_COMMAND_KEY).httpMethod);
Assert.assertEquals("http://localhost:42111/valuepost.html?id=4-SWITCHMULTILEVEL-user-byte-1-0&v=39", config.get(HttpGenericBindingProvider.CHANGED_COMMAND_KEY).url);
}
示例6: create
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* Static constructor-method.
*
* @return an initialized MiOS System Binding Configuration object.
*/
public static final MiosBindingConfig create(String context, String itemName, String unitName, String stuff,
Class<? extends Item> itemType, String inTransform, String outTransform) throws BindingConfigParseException {
ParameterDefaults pd = paramDefaults.get(stuff);
if (pd != null) {
logger.trace("System ParameterDefaults FOUND '{}' for '{}', '{}'", itemName, stuff, pd);
if (inTransform == null) {
inTransform = pd.getInTransform();
logger.trace("System ParameterDefaults '{}' defaulted in: to '{}'", itemName, inTransform);
}
if (outTransform == null) {
outTransform = pd.getOutTransform();
logger.trace("System ParameterDefaults '{}' defaulted out: to '{}'", itemName, outTransform);
}
} else {
logger.trace("System ParameterDefaults NOT FOUND '{}' for '{}'", itemName, stuff);
}
MiosBindingConfig c = new SystemBindingConfig(context, itemName, unitName, stuff, itemType, inTransform,
outTransform);
c.initialize();
return c;
}
示例7: parseBindingConfig
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
protected void parseBindingConfig(String bindingConfigs,
PrimareBindingConfig config) throws BindingConfigParseException {
String bindingConfig = StringUtils.substringBefore(bindingConfigs, ",");
String bindingConfigTail = StringUtils.substringAfter(bindingConfigs, ",");
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length != 3) {
throw new BindingConfigParseException(
"Primare binding must contain three parts separated by ':'");
}
String command = StringUtils.trim(configParts[0]);
String deviceId = StringUtils.trim(configParts[1]);
String deviceCommand = StringUtils.trim(configParts[2]);
// if there are more commands to parse do that recursively ...
if (StringUtils.isNotBlank(bindingConfigTail)) {
parseBindingConfig(bindingConfigTail, config);
}
logger.trace("Append config {} = {}", command, deviceId + ":" + deviceCommand);
config.put(command, deviceId + ":" + deviceCommand);
}
示例8: testParseBindingConfigIn
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
@Test
public void testParseBindingConfigIn() throws BindingConfigParseException {
String cmdLine = "/usr/bin/uptime";
String itemName = "Switch";
SwitchItem item = new SwitchItem(itemName);
String bindingConfig = "<[" + cmdLine + ":60000:]";
provider.processBindingConfiguration("New", item, bindingConfig);
Assert.assertTrue(provider.providesBinding());
Assert.assertTrue(provider.providesBindingFor(itemName));
Assert.assertEquals(cmdLine, provider.getCommandLine(itemName));
Assert.assertEquals(60000, provider.getRefreshInterval(itemName));
Assert.assertEquals("", provider.getTransformation(itemName));
List<String> itemNames = provider.getInBindingItemNames();
Assert.assertEquals(itemName, itemNames.get(0));
}
示例9: getMacBytes
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
private static byte[] getMacBytes(String macStr) throws BindingConfigParseException {
byte[] bytes = new byte[6];
String[] hex = macStr.split("(\\:|\\-)");
if (hex.length != 6) {
throw new BindingConfigParseException("Invalid MAC address [macStr=" + macStr + "]");
}
int hexIndex = 0;
try {
for (hexIndex = 0; hexIndex < 6; hexIndex++) {
bytes[hexIndex] = (byte) Integer.parseInt(hex[hexIndex], 16);
}
}
catch (NumberFormatException e) {
throw new BindingConfigParseException("Invalid hex digit in MAC address [digit=" + hex[hexIndex]);
}
return bytes;
}
示例10: parseConfigTemp
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
private static void parseConfigTemp(String configPart,
MaxCulBindingConfig cfg) throws BindingConfigParseException {
String[] configKeyValueSplit = configPart.split("=");
if (configKeyValueSplit.length == 2) {
String[] configParts = configKeyValueSplit[1].split("/");
if (configParts.length == 7) {
// <comfortTemp>/<ecoTemp>/<maxTemp>/<minTemp>/<windowOpenTemperature>/<windowOpenDuration>/<measurementOffset>
cfg.setComfortTemp(Double.parseDouble(configParts[0]));
cfg.setEcoTemp(Double.parseDouble(configParts[1]));
cfg.setMaxTemp(Double.parseDouble(configParts[2]));
cfg.setMinTemp(Double.parseDouble(configParts[3]));
cfg.setWindowOpenTemperature(Double.parseDouble(configParts[4]));
cfg.setWindowOpenDuration(Double.parseDouble(configParts[5]));
cfg.setMeasurementOffset(Double.parseDouble(configParts[6]));
cfg.setTemperatureConfigSet(true);
} else
throw new BindingConfigParseException(
"Temperature configuration should be of form 'configTemp=<comfortTemp>/<ecoTemp>/<maxTemp>/<minTemp>/<windowOpenTemperature>/<windowOpenDuration>/<measurementOffset>'");
} else
throw new BindingConfigParseException(
"Temperature configuration should be of form 'configTemp=<comfortTemp>/<ecoTemp>/<maxTemp>/<minTemp>/<windowOpenTemperature>/<windowOpenDuration>/<measurementOffset>'");
}
示例11: createCommandFromString
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* Creates a {@link Command} out of the given <code>commandAsString</code>
* taking the special Commands "CHANGED" and "*" into account and incorporating
* the {@link TypeParser}.
*
* @param item
* @param commandAsString
*
* @return an appropriate Command (see {@link TypeParser} for more
* information
*
* @throws BindingConfigParseException if the {@link TypeParser} couldn't
* create a command appropriately
*
* @see {@link TypeParser}
*/
private Command createCommandFromString(Item item, String commandAsString) throws BindingConfigParseException {
if (CHANGED_COMMAND_KEY.equals(commandAsString)) {
return CHANGED_COMMAND_KEY;
}
else if (WILDCARD_COMMAND_KEY.equals(commandAsString)) {
return WILDCARD_COMMAND_KEY;
} else {
Command command = TypeParser.parseCommand(
item.getAcceptedCommandTypes(), commandAsString);
if (command == null) {
throw new BindingConfigParseException("couldn't create Command from '" + commandAsString + "' ");
}
return command;
}
}
示例12: processBindingConfiguration
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* Inherited from AbstractGenericBindingProvider.
* Processes InsteonPLM binding configuration string.
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] parts = parseConfigString(bindingConfig);
if (parts.length != 3) throw new
BindingConfigParseException("item config must have addr:prodKey#feature format");
InsteonAddress addr = new InsteonAddress(parts[0]);
String [] params = parts[2].split(",");
String feature = params[0];
HashMap<String, String> args = new HashMap<String, String>();
for (int i = 1; i < params.length; i++) {
String [] kv = params[i].split("=");
if (kv.length == 2) {
args.put(kv[0], kv[1]);
} else {
logger.error("parameter {} does not have format a=b", params[i]);
}
}
InsteonPLMBindingConfig config = new InsteonPLMBindingConfig(item.getName(), addr, feature, parts[1], args);
addBindingConfig(item, config);
logger.trace("processing item \"{}\" read from .items file with cfg string {}",
item.getName(), bindingConfig);
items.put(item.getName(), item);
}
示例13: parseConfigString
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* Parses binding configuration string. The config string has the format:
*
* xx.xxx.xxx:productKey#feature,param1=yyy,param2=zzz
*
* @param bindingConfig string with binding parameters
* @return String array with split arguments: [address,prodKey,features+params]
* @throws BindingConfigParseException if parameters are invalid
*/
private String[] parseConfigString(String bindingConfig) throws BindingConfigParseException {
// the config string has the format
//
// xx.xx.xx:productKey#feature
//
String shouldBe = "should be address:prodKey#feature, e.g. 28.c3.91:F00.00.01#switch,param=xxx";
String[] segments = bindingConfig.split("#");
if (segments.length != 2)
throw new BindingConfigParseException("invalid item format: " + bindingConfig + ", " + shouldBe);
String[] dev = segments[0].split(":");
if (dev.length != 2) {
throw new BindingConfigParseException("missing colon in item format: "
+ bindingConfig + ", " + shouldBe);
}
String addr = dev[0];
String [] retval = {addr, dev[1], segments[1]};
if (!InsteonAddress.s_isValid(addr)) {
String errstr = "invalid insteon or X10 device address: " + addr +
" in items file. Must have format AB.CD.EF or (for X10): H.U";
logger.error(errstr);
throw new BindingConfigParseException(errstr);
}
return retval;
}
示例14: validateItemType
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
@Override
public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
// if (!(item instanceof SwitchItem || item instanceof DimmerItem)) {
// throw new BindingConfigParseException("item '" + item.getName()
// + "' is of type '" + item.getClass().getSimpleName()
// + "', only Switch- and DimmerItems are allowed - please check your *.items configuration");
// }
}
示例15: resolveConfigDataLength
import org.openhab.model.item.binding.BindingConfigParseException; //导入依赖的package包/类
int resolveConfigDataLength(String configParameters, Item item) throws BindingConfigParseException {
String[] optionalConfigs = configParameters.substring(1).split(":");
for (int i = 0; i < optionalConfigs.length; i++) {
String param = optionalConfigs[i].toLowerCase();
// is datatype?
if (!(param.equals("i") || param.equals("o") || param.equals("io"))) {
Matcher matcher = Pattern.compile("^array\\[(\\d+)\\]$").matcher(param);
if (matcher.matches()) {
if (item.getClass().isAssignableFrom(StringItem.class)) {
if (!param.startsWith("array")) {
logger.warn(
"Item %s support datatype array only. Type %s is ignored. Setted to ARRAY with length 32.",
item.getName(), param);
return 32;
} else {
return Integer.valueOf(matcher.group(1)).intValue();
}
}
}
}
}
return 1;
}