use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class MqttMessageSubscriberTest method canParseCommand.
@Test
public void canParseCommand() throws Exception {
ColorItem colorItem = new ColorItem("ColorItem");
DimmerItem dimmerItem = new DimmerItem("DimmerItem");
LocationItem locationItem = new LocationItem("LocationItem");
NumberItem numberItem = new NumberItem("NumberItem");
RollershutterItem rollershutterItem = new RollershutterItem("SetpointItem");
StringItem stringItem = new StringItem("StringItem");
SwitchItem switchItem = new SwitchItem("SwitchItem");
MqttMessageSubscriber subscriber = new MqttMessageSubscriber("mybroker:/mytopic:command:default");
assertEquals(StringType.valueOf("test"), subscriber.getCommand("test", stringItem.getAcceptedCommandTypes()));
assertEquals(StringType.valueOf("{\"person\"{\"name\":\"me\"}}"), subscriber.getCommand("{\"person\"{\"name\":\"me\"}}", stringItem.getAcceptedCommandTypes()));
assertEquals(StringType.valueOf(""), subscriber.getCommand("", stringItem.getAcceptedCommandTypes()));
assertEquals(OnOffType.ON, subscriber.getCommand("ON", switchItem.getAcceptedCommandTypes()));
assertEquals(HSBType.valueOf("5,6,5"), subscriber.getCommand("5,6,5", colorItem.getAcceptedCommandTypes()));
assertEquals(DecimalType.ZERO, subscriber.getCommand(DecimalType.ZERO.toString(), numberItem.getAcceptedCommandTypes()));
assertEquals(PercentType.HUNDRED, subscriber.getCommand(PercentType.HUNDRED.toString(), dimmerItem.getAcceptedCommandTypes()));
assertEquals(PercentType.valueOf("80"), subscriber.getCommand(PercentType.valueOf("80").toString(), rollershutterItem.getAcceptedCommandTypes()));
assertEquals(PointType.valueOf("53.3239919,-6.5258807"), subscriber.getCommand(PointType.valueOf("53.3239919,-6.5258807").toString(), locationItem.getAcceptedCommandTypes()));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class ProtocolGenericBindingProvider method parseBindingConfig.
/**
* Parses the configuration string and update the provided config
*
* @param config - the Configuration that needs to be updated with the parsing results
* @param item - the Item that this configuration is intented for
* @param bindingConfig - the configuration string that will be parsed
* @throws BindingConfigParseException
*/
private void parseBindingConfig(ProtocolBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String direction = null;
Direction directionType = null;
String commandAsString = null;
String host = null;
String port = null;
String protocolCommand = null;
if (bindingConfig != null) {
Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if ((!actionMatcher.matches() && !statusMatcher.matches())) {
throw new BindingConfigParseException(getBindingType() + " binding configuration must consist of four [config=" + statusMatcher + "] or five parts [config=" + actionMatcher + "]");
} else {
if (actionMatcher.matches()) {
direction = actionMatcher.group(1);
commandAsString = actionMatcher.group(2);
host = actionMatcher.group(3);
port = actionMatcher.group(4);
protocolCommand = actionMatcher.group(5) != null ? actionMatcher.group(5) : actionMatcher.group(6);
} else if (statusMatcher.matches()) {
direction = statusMatcher.group(1);
commandAsString = null;
host = statusMatcher.group(2);
port = statusMatcher.group(3);
protocolCommand = statusMatcher.group(4) != null ? statusMatcher.group(4) : statusMatcher.group(5);
}
if (direction.equals(">")) {
directionType = Direction.OUT;
} else if (direction.equals("<")) {
directionType = Direction.IN;
}
ProtocolBindingConfigElement newElement = new ProtocolBindingConfigElement(host, port, directionType, protocolCommand, item.getAcceptedDataTypes());
Command command = null;
if (commandAsString == null) {
// for those configuration strings that are not really linked to a openHAB command we
// create a dummy Command to be able to store the configuration information
// I have choosen to do that with NumberItems
NumberItem dummy = new NumberItem(Integer.toString(counter));
command = createCommandFromString(dummy, Integer.toString(counter));
counter++;
} else {
command = createCommandFromString(item, commandAsString);
}
config.put(command, newElement);
}
} else {
return;
}
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testProcessBindingConfig_FileCount03.
@Test
public /* Verify a relative path file count configuration (Windows): "DirFiles:60000:..\resources\" */
void testProcessBindingConfig_FileCount03() throws BindingConfigParseException {
String simpleConfig = "DirFiles:60000:..\\resources\\";
NumberItem testItem = new NumberItem("DirFiles03");
provider.processBindingConfiguration("systeminfo", testItem, simpleConfig);
Assert.assertEquals("DirFiles", provider.getCommandType("DirFiles03").toString());
Assert.assertNull(provider.getItemType("DirFiles03"));
Assert.assertEquals(60000, provider.getRefreshInterval("DirFiles03"));
Assert.assertEquals("..\\resources\\", provider.getTarget("DirFiles03"));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testProcessBindingConfig_FileCount04.
/* Verify an absolute path file count configuration (*nix): "DirFiles:60000:/usr/bin/" */
public void testProcessBindingConfig_FileCount04() throws BindingConfigParseException {
String simpleConfig = "DirFiles:60000:/usr/bin/";
NumberItem testItem = new NumberItem("DirFiles04");
provider.processBindingConfiguration("systeminfo", testItem, simpleConfig);
Assert.assertEquals("DirFiles", provider.getCommandType("DirFiles04").toString());
Assert.assertNull(provider.getItemType("DirFiles04"));
Assert.assertEquals(60000, provider.getRefreshInterval("DirFiles04"));
Assert.assertEquals("/usr/bin/", provider.getTarget("DirFiles04"));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testProcessBindingConfig_FileCount05.
@Test
public /* Verify an absolute path file count configuration (Windows): "DirFiles:60000:c:\windows\" */
void testProcessBindingConfig_FileCount05() throws BindingConfigParseException {
String simpleConfig = "DirFiles:60000:c:\\temp\\";
NumberItem testItem = new NumberItem("DirFiles05");
provider.processBindingConfiguration("systeminfo", testItem, simpleConfig);
Assert.assertEquals("DirFiles", provider.getCommandType("DirFiles05").toString());
Assert.assertNull(provider.getItemType("DirFiles05"));
Assert.assertEquals(60000, provider.getRefreshInterval("DirFiles05"));
Assert.assertEquals("c:\\temp\\", provider.getTarget("DirFiles05"));
}
Aggregations