Search in sources :

Example 16 with OnOffType

use of org.openhab.core.library.types.OnOffType 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 17 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class Panel method refreshItem.

/**
     * {@inheritDoc}
     */
@Override
public void refreshItem(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, int state, String description) {
    logger.debug("refreshItem(): Panel Item Name: {}", item.getName());
    String str = "";
    OnOffType onOffType;
    if (config != null) {
        if (config.getDSCAlarmItemType() != null) {
            switch(config.getDSCAlarmItemType()) {
                case PANEL_CONNECTION:
                    publisher.postUpdate(item.getName(), new DecimalType(state));
                    break;
                case PANEL_MESSAGE:
                    publisher.postUpdate(item.getName(), new StringType(description));
                    break;
                case PANEL_SYSTEM_ERROR:
                    str = String.format("%03d: %s", state, ((state == 0) ? "No Error" : description));
                    publisher.postUpdate(item.getName(), new StringType(str));
                    break;
                case PANEL_TIME:
                    str = getFormattedPanelTime(description);
                    publisher.postUpdate(item.getName(), new DateTimeType(str));
                    break;
                case PANEL_TIME_STAMP:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TIME_BROADCAST:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_COMMAND:
                    publisher.postUpdate(item.getName(), new DecimalType(state));
                    break;
                case PANEL_TROUBLE_MESSAGE:
                    publisher.postUpdate(item.getName(), new StringType(description));
                    break;
                case PANEL_TROUBLE_LED:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_SERVICE_REQUIRED:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AC_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TELEPHONE_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_FTC_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_FAULT:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_TAMPER:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_LOW_BATTERY:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TIME_LOSS:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_FIRE_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_PANIC_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AUX_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AUX_INPUT_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                default:
                    logger.debug("refreshItem(): Panel item not updated.");
                    break;
            }
        }
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 18 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class Panel method handleEvent.

/**
     * {@inheritDoc}
     */
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
    APIMessage apiMessage = null;
    int apiCode = -1;
    boolean boolState;
    int state = 0;
    OnOffType onOffType;
    if (event != null) {
        apiMessage = event.getAPIMessage();
        apiCode = Integer.parseInt(apiMessage.getAPICode());
        String str = "";
        logger.debug("handleEvent(): Panel Item Name: {}", item.getName());
        if (config != null) {
            if (config.getDSCAlarmItemType() != null) {
                switch(config.getDSCAlarmItemType()) {
                    case PANEL_CONNECTION:
                        publisher.postUpdate(item.getName(), new DecimalType(state));
                        break;
                    case PANEL_MESSAGE:
                        if (apiMessage != null) {
                            str = apiMessage.getAPIDescription();
                        }
                        publisher.postUpdate(item.getName(), new StringType(str));
                        break;
                    case PANEL_SYSTEM_ERROR:
                        int systemErrorCode = 0;
                        if (apiMessage != null) {
                            systemErrorCode = Integer.parseInt(apiMessage.getAPIData());
                            str = String.format("%03d: %s", systemErrorCode, apiMessage.getError());
                            publisher.postUpdate(item.getName(), new StringType(str));
                        }
                        break;
                    case PANEL_TROUBLE_MESSAGE:
                        if (apiMessage != null) {
                            str = apiMessage.getAPIDescription();
                        }
                        publisher.postUpdate(item.getName(), new StringType(str));
                        break;
                    case PANEL_TROUBLE_LED:
                        if (apiMessage != null) {
                            boolState = (apiCode == 840) ? true : false;
                            onOffType = boolState ? OnOffType.ON : OnOffType.OFF;
                            publisher.postUpdate(item.getName(), onOffType);
                        }
                        break;
                    case PANEL_TIME:
                        if (apiMessage != null) {
                            str = getFormattedPanelTime(apiMessage.getAPIData());
                            publisher.postUpdate(item.getName(), new DateTimeType(str));
                        }
                        break;
                    default:
                        logger.debug("handleEvent(): Panel item not updated.");
                        break;
                }
            }
        }
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 19 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class DmxSwitchItem method processCommand.

/**
     * {@inheritDoc}
     */
@Override
public void processCommand(DmxService service, Command command) {
    // process regular on/off switch
    if (command instanceof OnOffType && !isRedefinedByCustomCommand(command)) {
        if (OnOffType.ON.equals(command)) {
            boolean hasValue = false;
            for (int channelId : channels) {
                service.enableChannel(channelId);
                if (service.getChannelValue(channelId) > 0) {
                    hasValue = true;
                }
            }
            if (!hasValue) {
                // switch to max value if there is no light..
                for (int channelId : channels) {
                    service.setChannelValue(channelId, DmxChannel.DMX_MAX_VALUE);
                }
            }
        } else {
            for (int channelId : channels) {
                service.disableChannel(channelId);
            }
        }
        return;
    }
    // process custom commands if they are available
    if (isRedefinedByCustomCommand(command)) {
        DmxCommand dmxCommand = customCommands.get(command.toString());
        dmxCommand.execute(service);
        return;
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) DmxCommand(org.openhab.binding.dmx.internal.cmd.DmxCommand)

Example 20 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class MaxCulBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(final String itemName, Command command) {
    Timer pairModeTimer = null;
    MaxCulBindingConfig bindingConfig = null;
    for (MaxCulBindingProvider provider : super.providers) {
        bindingConfig = provider.getConfigForItemName(itemName);
        if (bindingConfig != null) {
            break;
        }
    }
    logger.debug("Received command " + command.toString() + " for item " + itemName);
    if (bindingConfig != null) {
        logger.debug("Found config for " + itemName);
        switch(bindingConfig.getDeviceType()) {
            case PAIR_MODE:
                if ((command instanceof OnOffType)) {
                    switch((OnOffType) command) {
                        case ON:
                            /*
                                 * turn on pair mode and schedule disabling of pairing
                                 * mode
                                 */
                            pairMode = true;
                            TimerTask task = new TimerTask() {

                                @Override
                                public void run() {
                                    logger.debug(itemName + " pairMode timeout executed");
                                    pairMode = false;
                                    eventPublisher.postUpdate(itemName, OnOffType.OFF);
                                }
                            };
                            pairModeTimer = timers.get(itemName);
                            if (pairModeTimer != null) {
                                pairModeTimer.cancel();
                                timers.remove(itemName);
                            }
                            pairModeTimer = new Timer();
                            timers.put(itemName, pairModeTimer);
                            pairModeTimer.schedule(task, pairModeTimeout);
                            logger.debug(itemName + " pairMode enabled & timeout scheduled");
                            break;
                        case OFF:
                            /*
                                 * we are manually disabling, so clear the timer and the
                                 * flag
                                 */
                            pairMode = false;
                            pairModeTimer = timers.get(itemName);
                            if (pairModeTimer != null) {
                                logger.debug(itemName + " pairMode timer cancelled");
                                pairModeTimer.cancel();
                                timers.remove(itemName);
                            }
                            logger.debug(itemName + " pairMode cleared");
                            break;
                    }
                } else {
                    logger.warn("Command not handled for " + bindingConfig.getDeviceType() + " that is not OnOffType");
                }
                break;
            case LISTEN_MODE:
                if (command instanceof OnOffType) {
                    this.messageHandler.setListenMode(((OnOffType) command == OnOffType.ON));
                } else {
                    logger.warn("Command not handled for " + bindingConfig.getDeviceType() + " that is not OnOffType");
                }
                break;
            case LED_MODE:
                if (command instanceof OnOffType) {
                    this.messageHandler.setLedMode(((OnOffType) command == OnOffType.ON));
                } else {
                    logger.warn("Command not handled for " + bindingConfig.getDeviceType() + " that is not OnOffType");
                }
                break;
            case RADIATOR_THERMOSTAT:
            case RADIATOR_THERMOSTAT_PLUS:
            case WALL_THERMOSTAT:
                if (bindingConfig.getFeature() == MaxCulFeature.THERMOSTAT) {
                    /* clear out old pacing timer */
                    if (pacedBindingTransmitTimers.containsKey(bindingConfig)) {
                        pacedBindingTransmitTimers.get(bindingConfig).cancel();
                        pacedBindingTransmitTimers.remove(bindingConfig);
                    }
                    /* schedule new timer */
                    Timer pacingTimer = new Timer();
                    pacedBindingTransmitTimers.put(bindingConfig, pacingTimer);
                    pacingTimer.schedule(new MaxCulPacedThermostatTransmitTask(command, bindingConfig, messageHandler, super.providers), PACED_TRANSMIT_TIME);
                } else if (bindingConfig.getFeature() == MaxCulFeature.DISPLAYSETTING) {
                    messageHandler.sendSetDisplayActualTemp(bindingConfig.getDevAddr(), ((OnOffType) command == OnOffType.ON));
                } else if (bindingConfig.getFeature() == MaxCulFeature.RESET) {
                    messageHandler.sendReset(bindingConfig.getDevAddr());
                } else {
                    logger.warn("Command not handled for " + bindingConfig.getDeviceType() + " that is not OnOffType or DecimalType");
                }
                break;
            case SHUTTER_CONTACT:
                if (bindingConfig.getFeature() == MaxCulFeature.RESET) {
                    messageHandler.sendReset(bindingConfig.getDevAddr());
                }
                break;
            default:
                logger.warn("Command not handled for " + bindingConfig.getDeviceType());
                break;
        }
    }
    updateCreditMonitors();
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) OnOffType(org.openhab.core.library.types.OnOffType) MaxCulBindingProvider(org.openhab.binding.maxcul.MaxCulBindingProvider)

Aggregations

OnOffType (org.openhab.core.library.types.OnOffType)50 DecimalType (org.openhab.core.library.types.DecimalType)22 PercentType (org.openhab.core.library.types.PercentType)15 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)12 OpenClosedType (org.openhab.core.library.types.OpenClosedType)11 StringType (org.openhab.core.library.types.StringType)11 UpDownType (org.openhab.core.library.types.UpDownType)9 IOException (java.io.IOException)8 State (org.openhab.core.types.State)7 StopMoveType (org.openhab.core.library.types.StopMoveType)6 DateTimeType (org.openhab.core.library.types.DateTimeType)5 HSBType (org.openhab.core.library.types.HSBType)5 UnknownHostException (java.net.UnknownHostException)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 RFXComException (org.openhab.binding.rfxcom.internal.RFXComException)3 Item (org.openhab.core.items.Item)3 SwitchItem (org.openhab.core.library.items.SwitchItem)3 Color (java.awt.Color)2 DatagramPacket (java.net.DatagramPacket)2 SocketTimeoutException (java.net.SocketTimeoutException)2