use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class JdbcBaseDAO method getItemType.
public String getItemType(Item i) {
Item item = i;
String def = "STRINGITEM";
if (i instanceof GroupItem) {
item = ((GroupItem) i).getBaseItem();
if (item == null) {
// if GroupItem:<ItemType> is not defined in
// *.items using StringType
// logger.debug("JDBC: BaseItem GroupItem:<ItemType> is not
// defined in *.items searching for first Member and try to use
// as ItemType");
logger.debug("JDBC::getItemType: Cannot detect ItemType for {} because the GroupItems' base type isn't set in *.items File.", i.getName());
item = ((GroupItem) i).getMembers().get(0);
if (item == null) {
logger.debug("JDBC::getItemType: No ItemType found for first Child-Member of GroupItem {}, use ItemType for STRINGITEM as Fallback", i.getName());
return def;
}
}
}
String itemType = item.getClass().getSimpleName().toUpperCase();
logger.debug("JDBC::getItemType: Try to use ItemType {} for Item {}", itemType, i.getName());
if (sqlTypes.get(itemType) == null) {
logger.warn("JDBC::getItemType: No sqlType found for ItemType {}, use ItemType for STRINGITEM as Fallback for {}", itemType, i.getName());
return def;
}
return itemType;
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class LightwaveRfBindingFunctionalTest method testWifiLinkStatusReceived.
@Test
public void testWifiLinkStatusReceived() throws Exception {
String message = "*!{\"trans\":452,\"mac\":\"ab:cd:ef\",\"time\":1447712274,\"type\":\"hub\",\"prod\":\"wfl\",\"fw\":\"U2.91Y\"," + "\"uptime\":1386309,\"timeZone\":0,\"lat\":52.48,\"long\":-87.89,\"duskTime\":1447690400," + "\"dawnTime\":1447659083,\"tmrs\":0,\"evns\":1,\"run\":0,\"macs\":8,\"ip\":\"192.168.0.1\",\"devs\":0}";
List<ItemConfigAndExpectedState> itemConfigAndExpectedStates = new LinkedList<ItemConfigAndExpectedState>();
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_IP"), "serial=wifilink,type=WIFILINK_IP", new StringType("192.168.0.1")));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_FIRMWARE"), "serial=wifilink,type=WIFILINK_FIRMWARE", new StringType("U2.91Y")));
Calendar duskCal = Calendar.getInstance();
duskCal.setTime(new Date(1447690400000L));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DUSK_TIME"), "serial=wifilink,type=WIFILINK_DUSK_TIME", new DateTimeType(duskCal)));
Calendar dawnCal = Calendar.getInstance();
dawnCal.setTime(new Date(1447659083000L));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DAWN_TIME"), "serial=wifilink,type=WIFILINK_DAWN_TIME", new DateTimeType(dawnCal)));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("WIFILINK_UPTIME"), "serial=wifilink,type=WIFILINK_UPTIME", new DecimalType("1386309")));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LONGITUDE"), "serial=wifilink,type=WIFILINK_LONGITUDE", new StringType("-87.89")));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LATITUDE"), "serial=wifilink,type=WIFILINK_LATITUDE", new StringType("52.48")));
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(1447712274000L));
itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("TIME"), "serial=wifilink,type=UPDATETIME", new DateTimeType(cal)));
testReceivingACommandAndVerify(itemConfigAndExpectedStates, message);
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class LcnGenericBindingProvider method processBindingConfiguration.
/**
* Item processing for the LCN bindings.
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
Matcher matcher = PATTERN_BINDING_GENERAL.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException(bindingConfig + "' contains no valid binding!");
}
matcher.reset();
LcnBindingConfig bc = new LcnBindingConfig(item);
while (matcher.find()) {
String binding = matcher.group(1);
if (binding != null && !binding.trim().isEmpty()) {
String openHabCmd = null;
String connId, lcnTarget;
Matcher openHabMatcher = PATTERN_BINDING_WITH_OPENHAB.matcher(binding);
Matcher pureMatcher = PATTERN_BINDING_PURE.matcher(binding);
if (openHabMatcher.matches()) {
openHabCmd = openHabMatcher.group(1);
connId = openHabMatcher.group(2);
lcnTarget = openHabMatcher.group(3);
} else if (pureMatcher.matches()) {
connId = pureMatcher.group(1);
lcnTarget = pureMatcher.group(2);
} else {
throw new BindingConfigParseException("Invalid binding configuration for " + binding + "!");
}
String lcnShort = resolveMappings(lcnTarget, openHabCmd);
if (lcnShort == null || lcnShort.equals(openHabCmd)) {
lcnShort = lcnTarget;
}
Command cmd = openHabCmd == null ? TypeParser.parseCommand(new StringItem("").getAcceptedCommandTypes(), "") : openHabCmd.equals("%i") ? new StringType("%i") : TypeParser.parseCommand(item.getAcceptedCommandTypes(), openHabCmd);
bc.add(new LcnBindingConfig.Mapping(cmd, connId, lcnShort));
}
}
// Finished
this.addBindingConfig(item, bc);
for (LcnAddrMod addr : bc.getRelatedModules()) {
HashSet<String> l = this.itemNamesByModulCache.get(addr);
if (l == null) {
l = new HashSet<String>();
this.itemNamesByModulCache.put(addr, l);
}
l.add(item.getName());
}
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class AudioZone method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int num = 0;
String str = "";
int source = new Integer(properties.getSource());
switch(config.getObjectType()) {
case AUDIOZONE_MUTE:
num = properties.isMute() ? 1 : 0;
break;
case AUDIOZONE_POWER:
num = properties.isOn() ? 1 : 0;
break;
case AUDIOZONE_SOURCE:
num = properties.getSource();
break;
case AUDIOZONE_VOLUME:
num = properties.getVolume();
break;
case AUDIOZONE_TEXT:
if (sourceValid(source)) {
str = audioSources.get(source).formatAudioText();
}
break;
case AUDIOZONE_TEXT_FIELD1:
if (sourceValid(source)) {
str = audioSources.get(source).getAudioText(0);
}
break;
case AUDIOZONE_TEXT_FIELD2:
if (sourceValid(source)) {
str = audioSources.get(source).getAudioText(1);
}
break;
case AUDIOZONE_TEXT_FIELD3:
if (sourceValid(source)) {
str = audioSources.get(source).getAudioText(2);
}
break;
case AUDIOZONE_KEY:
num = -1;
break;
default:
return;
}
if (item instanceof DimmerItem) {
logger.debug("updating percent type {}", num);
publisher.postUpdate(item.getName(), new PercentType(num));
} else if (item instanceof NumberItem) {
logger.debug("updating number type {}", num);
publisher.postUpdate(item.getName(), new DecimalType(num));
} else if (item instanceof SwitchItem) {
logger.debug("updating switch type {}", num > 0 ? OnOffType.ON : OnOffType.OFF);
publisher.postUpdate(item.getName(), num > 0 ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof StringItem) {
logger.debug("updating string type {}", str);
publisher.postUpdate(item.getName(), new StringType(str));
}
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class PulseaudioGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
PulseaudioBindingConfig config = new PulseaudioBindingConfig();
String[] configParts = bindingConfig.split(":");
if (item instanceof StringItem) {
if (configParts.length != 1 && configParts.length != 3) {
throw new BindingConfigParseException("Pulseaudio binding configuration for StringItems must consist of one or three part [config=" + configParts + "]");
}
config.serverId = StringUtils.trim(configParts[0]);
config.itemType = item.getClass();
addBindingConfig(item, config);
return;
} else if (configParts.length < 2 || configParts.length > 3) {
throw new BindingConfigParseException("Pulseaudio binding configuration must consist of two or three parts [config=" + configParts + "]");
}
config.serverId = StringUtils.trim(configParts[0]);
config.itemName = StringUtils.trim(configParts[1]);
if (configParts.length == 3) {
config.command = StringUtils.trim(configParts[2]);
}
config.itemType = item.getClass();
addBindingConfig(item, config);
}
Aggregations