Search in sources :

Example 41 with StringType

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

the class OutputVisualize method visualizationHandleOutputStatus.

/** {@inheritDoc} */
@Override
public boolean visualizationHandleOutputStatus(ModStatusOutput pchkInput, Command cmd, Item item, EventPublisher eventPublisher) {
    if (pchkInput.getLogicalSourceAddr().equals(this.addr) && pchkInput.getOutputId() == this.outputId) {
        if (item.getAcceptedDataTypes().contains(StringType.class)) {
            String value = new DecimalFormat("0.#").format(pchkInput.getPercent());
            eventPublisher.postUpdate(item.getName(), new StringType(value));
            return true;
        } else if (item.getAcceptedDataTypes().contains(PercentType.class)) {
            eventPublisher.postUpdate(item.getName(), new PercentType((int) Math.round(pchkInput.getPercent())));
            return true;
        } else if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
            eventPublisher.postUpdate(item.getName(), new DecimalType(pchkInput.getPercent()));
            return true;
        } else if (item.getAcceptedDataTypes().contains(OnOffType.class)) {
            eventPublisher.postUpdate(item.getName(), pchkInput.getPercent() != 0 ? OnOffType.ON : OnOffType.OFF);
            return true;
        }
    }
    return false;
}
Also used : StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DecimalFormat(java.text.DecimalFormat) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType)

Example 42 with StringType

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

the class HeatPumpBinding method execute.

/**
     * @{inheritDoc
     */
@Override
public void execute() {
    if (!bindingsExist()) {
        logger.debug("There is no existing Heatpump binding configuration => refresh cycle aborted!");
        return;
    }
    HeatpumpConnector connector = new HeatpumpConnector(ip, port);
    try {
        connector.connect();
        // read all available values
        int[] heatpumpValues = connector.getValues();
        // all temperatures are 0.2 degree Celsius exact
        // but use int to save values
        // example 124 is 12.4 degree Celsius
        handleEventType(new DecimalType((double) heatpumpValues[10] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_SUPPLAY);
        handleEventType(new DecimalType((double) heatpumpValues[11] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_RETURN);
        handleEventType(new DecimalType((double) heatpumpValues[12] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_REFERENCE_RETURN);
        handleEventType(new DecimalType((double) heatpumpValues[13] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_OUT_EXTERNAL);
        handleEventType(new DecimalType((double) heatpumpValues[14] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_HOT_GAS);
        handleEventType(new DecimalType((double) heatpumpValues[15] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_OUTSIDE);
        handleEventType(new DecimalType((double) heatpumpValues[16] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_OUTSIDE_AVG);
        handleEventType(new DecimalType((double) heatpumpValues[17] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_SERVICEWATER);
        handleEventType(new DecimalType((double) heatpumpValues[18] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_SERVICEWATER_REFERENCE);
        handleEventType(new DecimalType((double) heatpumpValues[19] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_PROBE_IN);
        handleEventType(new DecimalType((double) heatpumpValues[20] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_PROBE_OUT);
        handleEventType(new DecimalType((double) heatpumpValues[21] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_MK1);
        handleEventType(new DecimalType((double) heatpumpValues[22] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_MK1_REFERENCE);
        handleEventType(new DecimalType((double) heatpumpValues[24] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_MK2);
        handleEventType(new DecimalType((double) heatpumpValues[25] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_MK2_REFERENCE);
        handleEventType(new DecimalType((double) heatpumpValues[26] / 10), HeatpumpCommandType.TYPE_HEATPUMP_SOLAR_COLLECTOR);
        handleEventType(new DecimalType((double) heatpumpValues[27] / 10), HeatpumpCommandType.TYPE_HEATPUMP_SOLAR_STORAGE);
        handleEventType(new DecimalType((double) heatpumpValues[28] / 10), HeatpumpCommandType.TYPE_TEMPERATURE_EXTERNAL_SOURCE);
        handleEventType(new StringType(formatHours(heatpumpValues[56])), HeatpumpCommandType.TYPE_HOURS_COMPRESSOR1);
        handleEventType(new DecimalType((double) heatpumpValues[57]), HeatpumpCommandType.TYPE_STARTS_COMPRESSOR1);
        handleEventType(new StringType(formatHours(heatpumpValues[58])), HeatpumpCommandType.TYPE_HOURS_COMPRESSOR2);
        handleEventType(new DecimalType((double) heatpumpValues[59]), HeatpumpCommandType.TYPE_STARTS_COMPRESSOR2);
        handleEventType(new StringType(formatHours(heatpumpValues[60])), HeatpumpCommandType.TYPE_HOURS_ZWE1);
        handleEventType(new StringType(formatHours(heatpumpValues[61])), HeatpumpCommandType.TYPE_HOURS_ZWE2);
        handleEventType(new StringType(formatHours(heatpumpValues[62])), HeatpumpCommandType.TYPE_HOURS_ZWE3);
        handleEventType(new StringType(formatHours(heatpumpValues[63])), HeatpumpCommandType.TYPE_HOURS_HETPUMP);
        handleEventType(new StringType(formatHours(heatpumpValues[64])), HeatpumpCommandType.TYPE_HOURS_HEATING);
        handleEventType(new StringType(formatHours(heatpumpValues[65])), HeatpumpCommandType.TYPE_HOURS_WARMWATER);
        handleEventType(new StringType(formatHours(heatpumpValues[66])), HeatpumpCommandType.TYPE_HOURS_COOLING);
        handleEventType(new DecimalType((double) heatpumpValues[151] / 10), HeatpumpCommandType.TYPE_THERMALENERGY_HEATING);
        handleEventType(new DecimalType((double) heatpumpValues[152] / 10), HeatpumpCommandType.TYPE_THERMALENERGY_WARMWATER);
        handleEventType(new DecimalType((double) heatpumpValues[153] / 10), HeatpumpCommandType.TYPE_THERMALENERGY_POOL);
        handleEventType(new DecimalType((double) heatpumpValues[154] / 10), HeatpumpCommandType.TYPE_THERMALENERGY_TOTAL);
        handleEventType(new DecimalType((double) heatpumpValues[155]), HeatpumpCommandType.TYPE_MASSFLOW);
        //$NON-NLS-1$
        String heatpumpState = getStateString(heatpumpValues) + ": " + getStateTime(heatpumpValues);
        handleEventType(new StringType(heatpumpState), HeatpumpCommandType.TYPE_HEATPUMP_STATE);
        String heatpumpExtendedState = //$NON-NLS-1$
        getExtendeStateString(heatpumpValues) + ": " + formatHours(heatpumpValues[120]);
        handleEventType(new StringType(heatpumpExtendedState), HeatpumpCommandType.TYPE_HEATPUMP_EXTENDED_STATE);
        // read all parameters
        int[] heatpumpParams = connector.getParams();
        handleEventType(new DecimalType(heatpumpParams[PARAM_HEATING_TEMPERATURE] / 10.), HeatpumpCommandType.TYPE_HEATING_TEMPERATURE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_HEATING_OPERATION_MODE]), HeatpumpCommandType.TYPE_HEATING_OPERATION_MODE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_WARMWATER_TEMPERATURE] / 10.), HeatpumpCommandType.TYPE_WARMWATER_TEMPERATURE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_WARMWATER_OPERATION_MODE]), HeatpumpCommandType.TYPE_WARMWATER_OPERATION_MODE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_COOLING_OPERATION_MODE]), HeatpumpCommandType.TYPE_COOLING_OPERATION_MODE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_COOLING_RELEASE_TEMP] / 10.), HeatpumpCommandType.TYPE_COOLING_RELEASE_TEMPERATURE);
        handleEventType(new DecimalType(heatpumpParams[PARAM_COOLING_INLET_TEMP] / 10.), HeatpumpCommandType.TYPE_COOLING_INLET_TEMP);
        handleEventType(new DecimalType(heatpumpParams[PARAM_COOLING_START] / 10.), HeatpumpCommandType.TYPE_COOLING_START_AFTER_HOURS);
        handleEventType(new DecimalType(heatpumpParams[PARAM_COOLING_STOP] / 10.), HeatpumpCommandType.TYPE_COOLING_STOP_AFTER_HOURS);
    } catch (UnknownHostException e) {
        logger.warn("the given hostname '{}' of the Novelan heatpump is unknown", ip);
    } catch (IOException e) {
        logger.warn("couldn't establish network connection [host '{}']", ip);
    } finally {
        if (connector != null) {
            connector.disconnect();
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) IOException(java.io.IOException)

Example 43 with StringType

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

the class AudioZone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int num = 0;
    String str = "";
    int source = new Integer(properties.getSource());
    switch(config.getObjectType()) {
        case AUDIOZONE_MUTE:
            num = properties.isMute() ? 1 : 0;
            break;
        case AUDIOZONE_POWER:
            num = properties.isOn() ? 1 : 0;
            break;
        case AUDIOZONE_SOURCE:
            num = properties.getSource();
            break;
        case AUDIOZONE_VOLUME:
            num = properties.getVolume();
            break;
        case AUDIOZONE_TEXT:
            if (sourceValid(source)) {
                str = audioSources.get(source).formatAudioText();
            }
            break;
        case AUDIOZONE_TEXT_FIELD1:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(0);
            }
            break;
        case AUDIOZONE_TEXT_FIELD2:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(1);
            }
            break;
        case AUDIOZONE_TEXT_FIELD3:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(2);
            }
            break;
        case AUDIOZONE_KEY:
            num = -1;
            break;
        default:
            return;
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", num);
        publisher.postUpdate(item.getName(), new PercentType(num));
    } else if (item instanceof NumberItem) {
        logger.debug("updating number type {}", num);
        publisher.postUpdate(item.getName(), new DecimalType(num));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", num > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), num > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", str);
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 44 with StringType

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

the class PowerMaxBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.
    logger.debug("internalReceiveCommand({},{}) is called", itemName, command);
    if (!isProperlyConfigured() || !connected) {
        logger.warn("PowerMax alarm binding is not properly configured. Command is ignored.");
        return;
    }
    String armMode = null;
    String actionPGMX10 = null;
    Byte devicePGMX10 = null;
    Boolean bypass = null;
    byte zoneNr = 0;
    String commandStr = null;
    PowerMaxPanelSettings settings = PowerMaxPanelSettings.getThePanelSettings();
    PowerMaxCommDriver comm = PowerMaxCommDriver.getTheCommDriver();
    for (PowerMaxBindingProvider provider : providers) {
        PowerMaxBindingConfig config = provider.getConfig(itemName);
        if (config == null) {
            continue;
        }
        switch(config.getSelectorType()) {
            case PARTITION_ARM_MODE:
                if (command instanceof StringType) {
                    armMode = command.toString();
                }
                break;
            case PARTITION_ARMED:
                if (command instanceof OnOffType) {
                    armMode = command.equals(OnOffType.ON) ? "Armed" : "Disarmed";
                }
                break;
            case PGM_STATUS:
                if (command instanceof OnOffType) {
                    actionPGMX10 = command.toString();
                }
                break;
            case X10_STATUS:
                if (command instanceof OnOffType || command instanceof StringType) {
                    actionPGMX10 = command.toString();
                }
                try {
                    devicePGMX10 = Byte.parseByte(config.getSelectorParam());
                } catch (NumberFormatException e) {
                    logger.warn("PowerMax alarm binding: invalid X10 device id: {}", config.getSelectorParam());
                    actionPGMX10 = null;
                }
                break;
            case ZONE_BYPASSED:
                if (command instanceof OnOffType) {
                    bypass = command.equals(OnOffType.ON) ? Boolean.TRUE : Boolean.FALSE;
                }
                try {
                    zoneNr = Byte.parseByte(config.getSelectorParam());
                } catch (NumberFormatException e) {
                    logger.warn("PowerMax alarm binding: invalid zone number: {}", config.getSelectorParam());
                    bypass = null;
                }
                break;
            case COMMAND:
                if (command instanceof StringType) {
                    commandStr = command.toString();
                    eventPublisher.postUpdate(itemName, new StringType(commandStr));
                }
                break;
            default:
                break;
        }
        if (armMode != null) {
            HashMap<String, Boolean> allowedModes = new HashMap<String, Boolean>();
            allowedModes.put("Disarmed", allowDisarming);
            allowedModes.put("Stay", allowArming);
            allowedModes.put("Armed", allowArming);
            allowedModes.put("StayInstant", allowArming);
            allowedModes.put("ArmedInstant", allowArming);
            allowedModes.put("Night", allowArming);
            allowedModes.put("NightInstant", allowArming);
            Boolean allowed = allowedModes.get(armMode);
            if ((allowed == null) || !allowed) {
                logger.warn("PowerMax alarm binding: rejected command {}", armMode);
            } else {
                comm.requestArmMode(armMode, currentState.isPowerlinkMode() ? PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode() : pinCode);
            }
            break;
        } else if (actionPGMX10 != null) {
            comm.sendPGMX10(actionPGMX10, devicePGMX10);
            break;
        } else if (bypass != null) {
            if ((currentState.isPowerlinkMode() == null) || currentState.isPowerlinkMode().equals(Boolean.FALSE)) {
                logger.warn("PowerMax alarm binding: Bypass option only supported in Powerlink mode");
            } else if (!PowerMaxPanelSettings.getThePanelSettings().isBypassEnabled()) {
                logger.warn("PowerMax alarm binding: Bypass option not enabled in panel settings");
            } else {
                comm.sendZoneBypass(bypass.booleanValue(), zoneNr, PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode());
            }
            break;
        } else if (commandStr != null) {
            if (commandStr.equalsIgnoreCase("get_event_log")) {
                comm.requestEventLog(currentState.isPowerlinkMode() ? PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode() : pinCode);
            } else if (commandStr.equalsIgnoreCase("download_setup")) {
                if ((currentState.isPowerlinkMode() == null) || currentState.isPowerlinkMode().equals(Boolean.FALSE)) {
                    logger.warn("PowerMax alarm binding: download setup only supported in Powerlink mode");
                } else {
                    comm.startDownload();
                    if (currentState.getLastKeepAlive() != null) {
                        currentState.setLastKeepAlive(System.currentTimeMillis());
                    }
                }
            } else if (commandStr.equalsIgnoreCase("log_setup")) {
                settings.log();
            } else if (commandStr.equalsIgnoreCase("help_items")) {
                settings.helpItems();
            } else {
                logger.warn("PowerMax alarm binding: rejected command {}", commandStr);
            }
            break;
        }
    }
}
Also used : PowerMaxBindingConfig(org.openhab.binding.powermax.PowerMaxBindingConfig) StringType(org.openhab.core.library.types.StringType) HashMap(java.util.HashMap) PowerMaxCommDriver(org.openhab.binding.powermax.internal.message.PowerMaxCommDriver) OnOffType(org.openhab.core.library.types.OnOffType) PowerMaxPanelSettings(org.openhab.binding.powermax.internal.state.PowerMaxPanelSettings) PowerMaxBindingProvider(org.openhab.binding.powermax.PowerMaxBindingProvider)

Example 45 with StringType

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

the class PrimareSPA20Response method openHabState.

/**
     * Convert received response message containing a Primare device variable value
     * to suitable OpenHAB state for the given itemType
     * 
     * @param itemType
     * 
     * @return openHAB state
     */
@Override
public State openHabState(Class<? extends Item> itemType) {
    State state = UnDefType.UNDEF;
    try {
        int index;
        String s;
        if (itemType == SwitchItem.class) {
            index = message[2];
            // observed with SPA20, software version 1.50 Nov 2 2003
            if (message[1] == 9) {
                logger.trace("MUTE (variable 9) converted opposite to documentation");
                state = index == 0 ? OnOffType.ON : OnOffType.OFF;
            } else {
                state = index == 0 ? OnOffType.OFF : OnOffType.ON;
            }
        } else if (itemType == NumberItem.class) {
            index = message[2];
            state = new DecimalType(index);
        } else if (itemType == DimmerItem.class) {
            index = message[2];
            state = new PercentType(index);
        } else if (itemType == RollershutterItem.class) {
            index = message[2];
            state = new PercentType(index);
        } else if (itemType == StringItem.class) {
            s = new String(Arrays.copyOfRange(message, 2, message.length - 2));
            state = new StringType(s);
        }
    } catch (Exception e) {
        logger.debug("Cannot convert value '{}' to data type {}", message[1], itemType);
    }
    return state;
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType)

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