Search in sources :

Example 11 with StringType

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

the class Keypad method handleEvent.

/**
     * {@inheritDoc}
     */
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
    APIMessage apiMessage = null;
    int state;
    if (event != null) {
        apiMessage = event.getAPIMessage();
        logger.debug("handleEvent(): Keypad Item Name: {}", item.getName());
        if (config != null) {
            if (config.getDSCAlarmItemType() != null) {
                switch(config.getDSCAlarmItemType()) {
                    case KEYPAD_READY_LED:
                    case KEYPAD_ARMED_LED:
                    case KEYPAD_MEMORY_LED:
                    case KEYPAD_BYPASS_LED:
                    case KEYPAD_TROUBLE_LED:
                    case KEYPAD_PROGRAM_LED:
                    case KEYPAD_FIRE_LED:
                    case KEYPAD_BACKLIGHT_LED:
                    case KEYPAD_AC_LED:
                        state = Integer.parseInt(apiMessage.getAPIData().substring(1));
                        if (item instanceof NumberItem) {
                            publisher.postUpdate(item.getName(), new DecimalType(state));
                        }
                        if (item instanceof StringItem) {
                            publisher.postUpdate(item.getName(), new StringType(ledStates[state]));
                        }
                        break;
                    case KEYPAD_LCD_UPDATE:
                    case KEYPAD_LCD_CURSOR:
                        publisher.postUpdate(item.getName(), new StringType(apiMessage.getAPIData()));
                        break;
                    default:
                        logger.debug("handleEvent(): Keypad item not updated.");
                        break;
                }
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage) StringItem(org.openhab.core.library.items.StringItem)

Example 12 with StringType

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

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

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

the class Partition method handleEvent.

/**
     * {@inheritDoc}
     */
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
    int state = 0;
    int apiCode = -1;
    APIMessage apiMessage = null;
    String str = "";
    if (event != null) {
        apiMessage = event.getAPIMessage();
        apiCode = Integer.parseInt(apiMessage.getAPICode());
        str = apiMessage.getAPIName();
        logger.debug("handleEvent(): Partition Item Name: {}", item.getName());
        if (config != null) {
            if (config.getDSCAlarmItemType() != null) {
                switch(config.getDSCAlarmItemType()) {
                    case PARTITION_STATUS:
                        switch(apiCode) {
                            case 650:
                            case 653:
                            case 654:
                                state = 1;
                                break;
                            case 651:
                            case 672:
                            case 673:
                                state = 0;
                                break;
                            default:
                                break;
                        }
                        publisher.postUpdate(item.getName(), new StringType(str));
                        break;
                    case PARTITION_ARM_MODE:
                        if (apiCode == 652) {
                            state = Integer.parseInt(apiMessage.getMode()) + 1;
                        }
                        if (item instanceof NumberItem) {
                            publisher.postUpdate(item.getName(), new DecimalType(state));
                        }
                        if (item instanceof StringItem) {
                            publisher.postUpdate(item.getName(), new StringType(str));
                        }
                        break;
                    case PARTITION_OPENING_CLOSING_MODE:
                        switch(apiCode) {
                            case 700:
                                state = 1;
                                break;
                            case 701:
                                state = 2;
                                break;
                            case 702:
                                state = 3;
                                break;
                            case 750:
                                state = 4;
                                break;
                            case 751:
                                state = 5;
                                break;
                            default:
                                state = 0;
                                str = "";
                                break;
                        }
                        if (item instanceof NumberItem) {
                            publisher.postUpdate(item.getName(), new DecimalType(state));
                        }
                        if (item instanceof StringItem) {
                            publisher.postUpdate(item.getName(), new StringType(str));
                        }
                        break;
                    default:
                        logger.debug("handleEvent(): Partition item not updated.");
                        break;
                }
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage) StringItem(org.openhab.core.library.items.StringItem)

Example 15 with StringType

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

the class DenonConnector method processTitleCommand.

private void processTitleCommand(String command, String value) {
    if (DISPLAY_PATTERN.matcher(value).matches()) {
        Integer commandNo = Integer.valueOf(value.substring(1, 2));
        String titleValue = value.substring(2);
        if (commandNo == 0) {
            displayNowplaying = titleValue.contains("Now Playing");
        }
        State state = displayNowplaying ? new StringType(cleanupDisplayInfo(titleValue)) : UnDefType.UNDEF;
        switch(commandNo) {
            case 1:
                sendUpdate(DenonProperty.TRACK.getCode(), state);
                break;
            case 2:
                sendUpdate(DenonProperty.ARTIST.getCode(), state);
                break;
            case 4:
                sendUpdate(DenonProperty.ALBUM.getCode(), state);
                break;
        }
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State)

Aggregations

StringType (org.openhab.core.library.types.StringType)90 DecimalType (org.openhab.core.library.types.DecimalType)69 State (org.openhab.core.types.State)30 DateTimeType (org.openhab.core.library.types.DateTimeType)28 PercentType (org.openhab.core.library.types.PercentType)27 NumberItem (org.openhab.core.library.items.NumberItem)25 Calendar (java.util.Calendar)23 StringItem (org.openhab.core.library.items.StringItem)18 OnOffType (org.openhab.core.library.types.OnOffType)15 SwitchItem (org.openhab.core.library.items.SwitchItem)12 ContactItem (org.openhab.core.library.items.ContactItem)10 DimmerItem (org.openhab.core.library.items.DimmerItem)10 RollershutterItem (org.openhab.core.library.items.RollershutterItem)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)8 HSBType (org.openhab.core.library.types.HSBType)8 ConfigurationException (org.osgi.service.cm.ConfigurationException)8 IOException (java.io.IOException)7 BigDecimal (java.math.BigDecimal)7