use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.
the class AlarmDecoderBinding method parseKeypadMessage.
private void parseKeypadMessage(String msg) throws MessageParseException {
List<String> parts = splitMsg(msg);
if (parts.size() != 4) {
throw new MessageParseException("got invalid keypad msg");
}
if (parts.get(0).length() != 22) {
throw new MessageParseException("bad keypad status length : " + parts.get(0).length());
}
try {
int numeric = 0;
try {
numeric = Integer.parseInt(parts.get(1));
} catch (NumberFormatException e) {
numeric = Integer.parseInt(parts.get(1), 16);
}
int upper = Integer.parseInt(parts.get(0).substring(1, 6), 2);
int nbeeps = Integer.parseInt(parts.get(0).substring(6, 7));
int lower = Integer.parseInt(parts.get(0).substring(7, 17), 2);
int status = ((upper & 0x1F) << 13) | ((nbeeps & 0x3) << 10) | lower;
ArrayList<AlarmDecoderBindingConfig> bcl = getItems(ADMsgType.KPM, null, null);
for (AlarmDecoderBindingConfig c : bcl) {
if (c.hasFeature("zone")) {
updateItem(c, new DecimalType(numeric));
} else if (c.hasFeature("text")) {
updateItem(c, new StringType(parts.get(3)));
} else if (c.hasFeature("beeps")) {
updateItem(c, new DecimalType(nbeeps));
} else if (c.hasFeature("status")) {
int bit = c.getIntParameter("bit", 0, 17, -1);
if (bit >= 0) {
// only pick a single bit
int v = (status >> bit) & 0x1;
updateItem(c, new DecimalType(v));
} else {
// pick all bits
updateItem(c, new DecimalType(status));
}
} else if (c.hasFeature("contact")) {
int bit = c.getIntParameter("bit", 0, 17, -1);
if (bit >= 0) {
// only pick a single bit
int v = (status >> bit) & 0x1;
updateItem(c, (v == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
} else {
// pick all bits
logger.warn("ignoring item {}: it has contact without bit field", c.getItemName());
}
}
}
if ((status & (1 << 17)) != 0) {
// the panel is clear, so we can assume that all contacts that we
// have not heard from are open
setUnupdatedItemsToDefault();
}
} catch (NumberFormatException e) {
throw new MessageParseException("keypad msg contains invalid number: " + e.getMessage());
}
}
use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.
the class AlarmDecoderBinding method parseLRRMessage.
private void parseLRRMessage(String msg) throws MessageParseException {
String[] parts = splitMessage(msg);
if (parts.length != 3) {
throw new MessageParseException("need 3 comma separated fields in msg");
}
ArrayList<AlarmDecoderBindingConfig> bcl = getItems(ADMsgType.LRR, null, null);
for (AlarmDecoderBindingConfig c : bcl) {
updateItem(c, new StringType(String.join(",", parts)));
}
}
use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.
the class Iec6205621MeterBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
// the frequently executed code (polling) goes here ...
Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
for (Iec6205621MeterBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
Meter reader = entry.getValue();
String meterName = provider.getMeterName(itemName);
if (meterName != null && meterName.equals(entry.getKey())) {
Map<String, DataSet> dataSets;
if ((dataSets = cache.get(meterName)) == null) {
if (logger.isDebugEnabled()) {
logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
}
dataSets = reader.read();
cache.put(meterName, dataSets);
}
String obis = provider.getObis(itemName);
if (obis != null && dataSets.containsKey(obis)) {
DataSet dataSet = dataSets.get(obis);
if (logger.isDebugEnabled()) {
logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
}
Class<? extends Item> itemType = provider.getItemType(itemName);
if (itemType.isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
}
if (itemType.isAssignableFrom(StringItem.class)) {
String value = dataSet.getValue();
eventPublisher.postUpdate(itemName, new StringType(value));
}
}
}
}
}
}
}
use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.
the class Area method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String str = "";
switch(config.getObjectType()) {
case AREA_ENTRY_TIMER:
setting = properties.getEntryTimer();
break;
case AREA_EXIT_TIMER:
setting = properties.getExitTimer();
break;
case AREA_STATUS_ENTRY_DELAY:
setting = properties.getEntryDelay();
break;
case AREA_STATUS_EXIT_DELAY:
setting = properties.getExitDelay();
break;
case AREA_STATUS_MODE:
setting = properties.getMode();
str = omni ? (setting < omniText.length ? omniText[setting] : "Unknown") : (setting < luminaText.length ? luminaText[setting] : "Unknown");
break;
case AREA_STATUS_ALARM:
setting = properties.getAlarms();
for (int i = 0; i < alarms.length; i++) {
if (((setting >> i) & 1) > 0) {
if (str.length() > 0) {
str += " | ";
}
str += alarms[i];
}
}
break;
default:
break;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(str));
}
}
use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.
the class Thermostat method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String mode = null;
switch(config.getObjectType()) {
case THERMO_COOL_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getCoolSetpoint()) : MessageUtils.omniToF(properties.getCoolSetpoint());
break;
case THERMO_TEMP:
setting = celsius ? MessageUtils.omniToC(properties.getTemperature()) : MessageUtils.omniToF(properties.getTemperature());
break;
case THERMO_HEAT_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getHeatSetpoint()) : MessageUtils.omniToF(properties.getHeatSetpoint());
break;
case THERMO_FAN_MODE:
setting = properties.isFan() ? 1 : 0;
break;
case THERMO_HOLD_MODE:
setting = properties.isHold() ? 1 : 0;
break;
case THERMO_SYSTEM_MODE:
setting = properties.getMode();
if (setting < MODES.length) {
mode = MODES[setting];
}
break;
default:
return;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof SwitchItem) {
publisher.postUpdate(item.getName(), setting > 0 ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof StringItem && mode != null) {
publisher.postUpdate(item.getName(), new StringType(mode));
}
}
Aggregations