Search in sources :

Example 6 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class Area method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int setting = 0;
    String str = "";
    switch(config.getObjectType()) {
        case AREA_ENTRY_TIMER:
            setting = properties.getEntryTimer();
            break;
        case AREA_EXIT_TIMER:
            setting = properties.getExitTimer();
            break;
        case AREA_STATUS_ENTRY_DELAY:
            setting = properties.getEntryDelay();
            break;
        case AREA_STATUS_EXIT_DELAY:
            setting = properties.getExitDelay();
            break;
        case AREA_STATUS_MODE:
            setting = properties.getMode();
            str = omni ? (setting < omniText.length ? omniText[setting] : "Unknown") : (setting < luminaText.length ? luminaText[setting] : "Unknown");
            break;
        case AREA_STATUS_ALARM:
            setting = properties.getAlarms();
            for (int i = 0; i < alarms.length; i++) {
                if (((setting >> i) & 1) > 0) {
                    if (str.length() > 0) {
                        str += " | ";
                    }
                    str += alarms[i];
                }
            }
            break;
        default:
            break;
    }
    logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof StringItem) {
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem)

Example 7 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class Thermostat method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int setting = 0;
    String mode = null;
    switch(config.getObjectType()) {
        case THERMO_COOL_POINT:
            setting = celsius ? MessageUtils.omniToC(properties.getCoolSetpoint()) : MessageUtils.omniToF(properties.getCoolSetpoint());
            break;
        case THERMO_TEMP:
            setting = celsius ? MessageUtils.omniToC(properties.getTemperature()) : MessageUtils.omniToF(properties.getTemperature());
            break;
        case THERMO_HEAT_POINT:
            setting = celsius ? MessageUtils.omniToC(properties.getHeatSetpoint()) : MessageUtils.omniToF(properties.getHeatSetpoint());
            break;
        case THERMO_FAN_MODE:
            setting = properties.isFan() ? 1 : 0;
            break;
        case THERMO_HOLD_MODE:
            setting = properties.isHold() ? 1 : 0;
            break;
        case THERMO_SYSTEM_MODE:
            setting = properties.getMode();
            if (setting < MODES.length) {
                mode = MODES[setting];
            }
            break;
        default:
            return;
    }
    logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof SwitchItem) {
        publisher.postUpdate(item.getName(), setting > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem && mode != null) {
        publisher.postUpdate(item.getName(), new StringType(mode));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 8 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class OneWireBindingConfigFactory method createOneWireDeviceProperty.

/**
     * @param pvItem
     * @param pvBindingConfig
     * @return a new BindingConfig, corresponding to the given
     *         <code><pvItem/code> and <code><pvBindingConfig/code>
     * @throws BindingConfigParseException
     */
public static OneWireBindingConfig createOneWireDeviceProperty(Item pvItem, String pvBindingConfig) throws BindingConfigParseException {
    logger.debug("createOneWireDeviceProperty: {} - bindingConfig:{}", pvItem.getName(), pvBindingConfig);
    OneWireBindingConfig lvNewBindingConfig = null;
    if (OneWireClearCacheControlBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireClearCacheControlBindingConfig(pvBindingConfig);
    } else if (OneWireDevicePropertyPushButtonBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireDevicePropertyPushButtonBindingConfig(pvBindingConfig);
    } else if (OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
        lvNewBindingConfig = new OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof NumberItem) {
        lvNewBindingConfig = new OneWireDevicePropertyNumberBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof ContactItem) {
        lvNewBindingConfig = new OneWireDevicePropertyContactBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof SwitchItem) {
        lvNewBindingConfig = new OneWireDevicePropertySwitchBindingConfig(pvBindingConfig);
    } else if (pvItem instanceof StringItem) {
        lvNewBindingConfig = new OneWireDevicePropertyStringBindingConfig(pvBindingConfig);
    } else {
        throw new UnsupportedOperationException("the item-type " + pvItem.getClass() + " cannot be a onewire device");
    }
    logger.debug("created newBindingConfig: {}", lvNewBindingConfig.toString());
    return lvNewBindingConfig;
}
Also used : OneWireDevicePropertyPushButtonBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyPushButtonBindingConfig) OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig) OneWireDevicePropertySwitchBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchBindingConfig) OneWireDevicePropertyStringBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyStringBindingConfig) ContactItem(org.openhab.core.library.items.ContactItem) OneWireClearCacheControlBindingConfig(org.openhab.binding.onewire.internal.control.OneWireClearCacheControlBindingConfig) StringItem(org.openhab.core.library.items.StringItem) OneWireDevicePropertyNumberBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyNumberBindingConfig) NumberItem(org.openhab.core.library.items.NumberItem) OneWireDevicePropertyContactBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyContactBindingConfig) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 9 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class WindowHandleTest method setUpDefaultDevice.

@Before
public void setUpDefaultDevice() {
    parameterAddress = new EnoceanParameterAddress(EnoceanId.fromString(EnoceanBindingProviderMock.DEVICE_ID));
    provider.setParameterAddress(parameterAddress);
    provider.setItem(new StringItem("dummie"));
    provider.setEep(EEPId.EEP_F6_10_00);
    binding.addBindingProvider(provider);
}
Also used : EnoceanParameterAddress(org.opencean.core.address.EnoceanParameterAddress) StringItem(org.openhab.core.library.items.StringItem) Before(org.junit.Before)

Example 10 with StringItem

use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.

the class KM200Comm method sendProvidersState.

/**
     * This function sets the state of a service on the device
     *
     */
public byte[] sendProvidersState(KM200BindingProvider provider, String item, Command command) {
    synchronized (device) {
        String type = null;
        String dataToSend = null;
        KM200CommObject object = null;
        Class<? extends Item> itemType = provider.getItemType(item);
        String service = checkParameterReplacement(provider, item);
        logger.debug("Prepare item for send: {} type: {} item: {}", service, type, itemType.getName());
        if (device.blacklistMap.contains(service)) {
            logger.debug("Service on blacklist: {}", service);
            return null;
        }
        if (device.serviceMap.containsKey(service)) {
            if (device.serviceMap.get(service).getWriteable() == 0) {
                logger.error("Service is listed as read-only: {}", service);
                return null;
            }
            object = device.serviceMap.get(service);
            type = object.getServiceType();
        } else {
            logger.error("Service is not in the determined device service list: {}", service);
            return null;
        }
        /* The service is availible, set now the values depeding on the item and binding type */
        logger.debug("state of: {} type: {}", command, type);
        /* Binding is a NumberItem */
        if (itemType.isAssignableFrom(NumberItem.class)) {
            BigDecimal bdVal = ((DecimalType) command).toBigDecimal();
            /* Check the capabilities of this service */
            if (object.getValueParameter() != null) {
                @SuppressWarnings("unchecked") List<BigDecimal> valParas = (List<BigDecimal>) object.getValueParameter();
                BigDecimal minVal = valParas.get(0);
                BigDecimal maxVal = valParas.get(1);
                if (bdVal.compareTo(minVal) < 0) {
                    bdVal = minVal;
                }
                if (bdVal.compareTo(maxVal) > 0) {
                    bdVal = maxVal;
                }
            }
            if (type.equals("floatValue")) {
                dataToSend = new JSONObject().put("value", bdVal).toString();
            } else if (type.equals("stringValue")) {
                dataToSend = new JSONObject().put("value", bdVal.toString()).toString();
            } else if (type.equals("switchProgram") && object.getVirtual() == 1) {
                /* A switchProgram as NumberItem is always virtual */
                dataToSend = sendVirtualState(object, itemType, service, command);
            } else if (type.equals("errorList") && object.getVirtual() == 1) {
                /* A errorList as NumberItem is always virtual */
                dataToSend = sendVirtualState(object, itemType, service, command);
            } else {
                logger.warn("Not supported type for numberItem: {}", type);
            }
        /* Binding is a StringItem */
        } else if (itemType.isAssignableFrom(StringItem.class)) {
            String val = ((StringType) command).toString();
            /* Check the capabilities of this service */
            if (object.getValueParameter() != null) {
                @SuppressWarnings("unchecked") List<String> valParas = (List<String>) object.getValueParameter();
                if (!valParas.contains(val)) {
                    logger.warn("Parameter is not in the service parameterlist: {}", val);
                    return null;
                }
            }
            if (type.equals("stringValue")) {
                dataToSend = new JSONObject().put("value", val).toString();
            } else if (type.equals("floatValue")) {
                dataToSend = new JSONObject().put("value", Float.parseFloat(val)).toString();
            } else if (type.equals("switchProgram")) {
                if (object.getVirtual() == 1) {
                    dataToSend = sendVirtualState(object, itemType, service, command);
                } else {
                    /* The JSONArray of switch items can be sended directly */
                    try {
                        /* Check whether ths input string is a valid JSONArray */
                        JSONArray userArray = new JSONArray(val);
                        dataToSend = userArray.toString();
                    } catch (Exception e) {
                        logger.warn("The input for the switchProgram is not a valid JSONArray : {}", e.getMessage());
                        return null;
                    }
                }
            } else {
                logger.warn("Not supported type for stringItem: {}", type);
            }
        /* Binding is a DateTimeItem */
        } else if (itemType.isAssignableFrom(DateTimeItem.class)) {
            String val = ((DateTimeType) command).toString();
            if (type.equals("stringValue")) {
                dataToSend = new JSONObject().put("value", val).toString();
            } else if (type.equals("switchProgram")) {
                dataToSend = sendVirtualState(object, itemType, service, command);
            } else {
                logger.warn("Not supported type for dateTimeItem: {}", type);
            }
        /* Binding is a SwitchItem */
        } else if (itemType.isAssignableFrom(SwitchItem.class)) {
            String val = null;
            if (provider.getParameter(item).containsKey("on")) {
                if (command == OnOffType.OFF) {
                    val = provider.getParameter(item).get("off");
                } else if (command == OnOffType.ON) {
                    val = provider.getParameter(item).get("on");
                }
            } else {
                logger.warn("Switch-Item only on configured on/off string values {}", command);
                return null;
            }
            if (type.equals("stringValue")) {
                dataToSend = new JSONObject().put("value", val).toString();
            } else {
                logger.warn("Not supported type for SwitchItem:{}", type);
            }
        } else {
            logger.warn("Bindingtype not supported: {}", itemType.getClass());
            return null;
        }
        /* If some data is availible then we have to send it to device */
        if (dataToSend != null) {
            /* base64 + encoding */
            logger.debug("Encoding: {}", dataToSend);
            byte[] encData = encodeMessage(dataToSend);
            if (encData == null) {
                logger.error("Couldn't encrypt data");
                return null;
            }
            return encData;
        } else {
            return null;
        }
    }
}
Also used : JSONArray(org.json.JSONArray) StringItem(org.openhab.core.library.items.StringItem) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateTimeType(org.openhab.core.library.types.DateTimeType) JSONObject(org.json.JSONObject) DecimalType(org.openhab.core.library.types.DecimalType) ArrayList(java.util.ArrayList) List(java.util.List) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

StringItem (org.openhab.core.library.items.StringItem)27 NumberItem (org.openhab.core.library.items.NumberItem)16 StringType (org.openhab.core.library.types.StringType)16 DecimalType (org.openhab.core.library.types.DecimalType)14 SwitchItem (org.openhab.core.library.items.SwitchItem)12 DimmerItem (org.openhab.core.library.items.DimmerItem)8 DateTimeType (org.openhab.core.library.types.DateTimeType)8 Test (org.junit.Test)7 ContactItem (org.openhab.core.library.items.ContactItem)7 Calendar (java.util.Calendar)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)5 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 PercentType (org.openhab.core.library.types.PercentType)5 BigDecimal (java.math.BigDecimal)4 ColorItem (org.openhab.core.library.items.ColorItem)4 Date (java.util.Date)3 Item (org.openhab.core.items.Item)3 State (org.openhab.core.types.State)3 LinkedList (java.util.LinkedList)2 JSONException (org.json.JSONException)2