use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class DSCAlarmActiveBinding method handleDSCAlarmEvent.
/**
* Handle incoming DSC Alarm events
*
* @param dscAlarmItemType
* @param dscAlarmEvent
* @param apiMessage
*/
private void handleDSCAlarmEvent(DSCAlarmItemType dscAlarmItemType, DSCAlarmEvent dscAlarmEvent, APIMessage apiMessage) {
logger.debug("handleDSCAlarmEvent(): Event received! Looking for item: {}", dscAlarmItemType);
DSCAlarmBindingConfig config = null;
APIMessage.APIMessageType apiMessageType = apiMessage.getAPIMessageType();
Item item = null;
String itemName = "";
int partitionId = apiMessage.getPartition();
int zoneId = apiMessage.getZone();
if (dscAlarmItemType != null) {
for (DSCAlarmBindingProvider prov : providers) {
for (String iName : prov.getItemNames()) {
config = prov.getDSCAlarmBindingConfig(iName);
if (config != null) {
switch(apiMessageType) {
case PANEL_EVENT:
if (dscAlarmItemType == config.getDSCAlarmItemType()) {
itemName = iName;
}
break;
case PARTITION_EVENT:
if (partitionId == config.getPartitionId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
itemName = iName;
}
break;
case ZONE_EVENT:
if (zoneId == config.getZoneId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
itemName = iName;
}
break;
case KEYPAD_EVENT:
if (dscAlarmItemType == config.getDSCAlarmItemType()) {
itemName = iName;
}
break;
default:
break;
}
}
if (StringUtils.isNotEmpty(itemName)) {
item = prov.getItem(itemName);
dscAlarmItemUpdate.updateDeviceItem(item, config, eventPublisher, dscAlarmEvent, 0, "");
pollTimeStart = 0;
return;
}
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class DSCAlarmActiveBinding method updateItem.
/**
* Update an item by item name
*
* @param itemName
*/
private void updateItem(String itemName, int state, String description) {
DSCAlarmBindingConfig config = null;
Item item = null;
for (DSCAlarmBindingProvider prov : providers) {
for (String iName : prov.getItemNames()) {
if (itemName == iName) {
config = prov.getDSCAlarmBindingConfig(iName);
if (config != null) {
item = prov.getItem(itemName);
dscAlarmItemUpdate.updateDeviceItem(item, config, eventPublisher, null, state, description);
break;
}
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class DSCAlarmActiveBinding method setTimeStampState.
/**
* Method to set the time stamp state
*
* @param timeStamp
*/
private void setTimeStampState(String timeStamp) {
logger.debug("setTimeStampState(): Time Stamp: {}", timeStamp);
int state = 0;
String itemName = "";
itemName = getItemName(DSCAlarmItemType.PANEL_TIME_STAMP, 0, 0);
if (StringUtils.isNotEmpty(itemName)) {
DSCAlarmBindingConfig config = getItemConfig(itemName);
if (config != null) {
Item item = getItem(itemName);
if (item != null) {
State onOffState = item.getState();
if (onOffState instanceof OnOffType) {
OnOffType value = (OnOffType) onOffState;
if ((StringUtils.isEmpty(timeStamp) && value.equals(OnOffType.OFF)) || (StringUtils.isNotEmpty(timeStamp) && value.equals(OnOffType.ON))) {
logger.debug("setTimeStampState(): Already Set!", timeStamp);
return;
} else if (StringUtils.isNotEmpty(timeStamp)) {
state = 1;
}
}
}
}
}
updateItemByItemType(DSCAlarmItemType.PANEL_TIME_STAMP, 0, 0, state);
logger.debug("setTimeStampState(): Changed state to '{}'.", state == 1 ? OnOffType.ON : OnOffType.OFF);
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class DiyOnXBeeBinding method internalReceiveCommand.
/**
*
* @return if the command was sent successfully
*/
private boolean internalReceiveCommand(DiyOnXBeeBindingProvider provider, String itemName, Command command) {
final String remote = provider.getRemote(itemName);
final int[] remoteAddress = FormatUtil.fromReadableAddress(remote);
Item item;
try {
item = itemRegistry.getItem(itemName);
} catch (ItemNotFoundException e1) {
logger.error("unable to get item {}", itemName, e1);
return false;
}
final String commandValue = createCommand(item, command);
if (commandValue == null) {
logger.warn("unable to create command {} for item {}", commandValue, itemName);
return false;
} else {
logger.debug("created command {} for item {}", commandValue, itemName);
}
final String commandString = new StringBuilder().append(provider.getId(itemName)).append('=').append(commandValue).append('\n').toString();
final ZNetTxRequest request = new ZNetTxRequest(new XBeeAddress64(remoteAddress), createPayload(commandString));
xbeeUsageLock.lock();
try {
if (xbee == null) {
logger.error("cannot send command to {} as the XBee module isn't initialized", itemName);
return false;
} else {
// TODO:
final XBeeResponse response = xbee.sendSynchronous(request);
// response?
return true;
}
} catch (XBeeTimeoutException e) {
logger.error("failed sending {} to {}", command, itemName, e);
} catch (XBeeException e) {
logger.error("failed sending {} to {}", command, itemName, e);
} finally {
xbeeUsageLock.unlock();
}
return false;
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class EventUtils method parseContent.
private static List<EventContent> parseContent(CalDavEvent event, ItemRegistry itemRegistry, Item itemIn, String expectedScope, String defaultItemOnBegin) {
final List<EventContent> outMap = new ArrayList<EventUtils.EventContent>();
// no content, nothing to parse
if (StringUtils.isEmpty(event.getContent())) {
return outMap;
}
try {
final BufferedReader reader = new BufferedReader(new StringReader(event.getContent()));
String line = null;
while ((line = reader.readLine()) != null) {
Item item = itemIn;
final EventLine eventLine = parseEventLine(line.trim(), event, defaultItemOnBegin);
if (eventLine == null) {
continue;
}
if (expectedScope != null && !expectedScope.equals(eventLine.scope)) {
continue;
}
if (item == null) {
if (itemRegistry == null) {
log.error("item is null, but itemRegistry as well");
continue;
}
try {
item = itemRegistry.getItem(eventLine.itemName);
} catch (ItemNotFoundException e) {
log.error("cannot find item: {}", eventLine.itemName);
continue;
}
}
if (!item.getName().equals(eventLine.itemName)) {
log.trace("name of item {} does not match itemName {}", item.getName(), eventLine.itemName);
continue;
}
final State state = TypeParser.parseState(item.getAcceptedDataTypes(), eventLine.stateString);
final Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), eventLine.stateString);
log.trace("add item {} to action list (scope={}, state={}, time={})", item, eventLine.scope, state, eventLine.time);
outMap.add(new EventContent(eventLine.scope, item, state, command, eventLine.time));
}
} catch (IOException e) {
log.error("cannot parse event content", e);
}
return outMap;
}
Aggregations