Search in sources :

Example 11 with Item

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;
                }
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 12 with Item

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;
                }
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 13 with Item

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);
}
Also used : Item(org.openhab.core.items.Item) OnOffType(org.openhab.core.library.types.OnOffType) State(org.openhab.core.types.State) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 14 with Item

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;
}
Also used : Item(org.openhab.core.items.Item) ZNetTxRequest(com.rapplogic.xbee.api.zigbee.ZNetTxRequest) XBeeAddress64(com.rapplogic.xbee.api.XBeeAddress64) XBeeException(com.rapplogic.xbee.api.XBeeException) XBeeResponse(com.rapplogic.xbee.api.XBeeResponse) XBeeTimeoutException(com.rapplogic.xbee.api.XBeeTimeoutException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 15 with Item

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Item(org.openhab.core.items.Item) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

Item (org.openhab.core.items.Item)59 SwitchItem (org.openhab.core.library.items.SwitchItem)23 NumberItem (org.openhab.core.library.items.NumberItem)20 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)16 State (org.openhab.core.types.State)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ContactItem (org.openhab.core.library.items.ContactItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)14 DecimalType (org.openhab.core.library.types.DecimalType)9 HistoricItem (org.openhab.core.persistence.HistoricItem)9 ArrayList (java.util.ArrayList)7 ColorItem (org.openhab.core.library.items.ColorItem)7 StringItem (org.openhab.core.library.items.StringItem)7 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6 Test (org.junit.Test)5 GenericItem (org.openhab.core.items.GenericItem)5 GroupItem (org.openhab.core.items.GroupItem)5 ItemRegistry (org.openhab.core.items.ItemRegistry)5 Calendar (java.util.Calendar)3