List of usage examples for org.apache.commons.lang ObjectUtils toString
public static String toString(Object obj)
Gets the toString
of an Object
returning an empty string ("") if null
input.
ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"
From source file:org.openhab.action.openwebif.internal.impl.model.adapter.BooleanTypeAdapter.java
/** * {@inheritDoc} */ @Override public String marshal(Boolean value) throws Exception { return ObjectUtils.toString(value); }
From source file:org.openhab.action.openwebif.internal.impl.model.adapter.TrimToNullStringAdapter.java
/** * {@inheritDoc} */ @Override public String marshal(String value) throws Exception { return ObjectUtils.toString(value); }
From source file:org.openhab.binding.gardena.internal.GardenaSmartImpl.java
/** * {@inheritDoc}//from w w w . j av a2 s. c o m */ @Override public void sendCommand(Device device, GardenaSmartCommandName commandName, Object value) throws GardenaException { Ability ability = null; Command command = null; switch (commandName) { case PARK_UNTIL_NEXT_TIMER: ability = device.getAbility(ABILITY_MOWER); command = new MowerParkUntilNextTimerCommand(); break; case PARK_UNTIL_FURTHER_NOTICE: ability = device.getAbility(ABILITY_MOWER); command = new MowerParkUntilFurtherNoticeCommand(); break; case START_RESUME_SCHEDULE: ability = device.getAbility(ABILITY_MOWER); command = new MowerStartResumeScheduleCommand(); break; case START_OVERRIDE_TIMER: ability = device.getAbility(ABILITY_MOWER); command = new MowerStartOverrideTimerCommand(mowerDuration); break; case DURATION_PROPERTY: if (value == null) { throw new GardenaException("Command '" + commandName + "' requires a value"); } mowerDuration = ObjectUtils.toString(value); return; case MEASURE_AMBIENT_TEMPERATURE: ability = device.getAbility(ABILITY_AMBIENT_TEMPERATURE); command = new SensorMeasureAmbientTemperatureCommand(); break; case MEASURE_LIGHT: ability = device.getAbility(ABILITY_LIGHT); command = new SensorMeasureLightCommand(); break; case MEASURE_SOIL_HUMIDITY: ability = device.getAbility(ABILITY_HUMIDITY); command = new SensorMeasureSoilHumidityCommand(); break; case MEASURE_SOIL_TEMPERATURE: ability = device.getAbility(ABILITY_SOIL_TEMPERATURE); command = new SensorMeasureSoilTemperatureCommand(); break; case OUTLET_MANUAL_OVERRIDE_TIME: if (value == null) { throw new GardenaException("Command '" + commandName + "' requires a value"); } SimpleProperties prop = new SimpleProperties(PROPERTY_BUTTON_MANUAL_OVERRIDE_TIME, ObjectUtils.toString(value)); String propertyUrl = String.format(URL_PROPERTY, device.getId(), ABILITY_OUTLET, PROPERTY_BUTTON_MANUAL_OVERRIDE_TIME, device.getLocation().getId()); executeRequest(HttpMethod.PUT, propertyUrl, new SimplePropertiesWrapper(prop), NoResult.class); break; case OUTLET_VALVE: ability = device.getAbility(ABILITY_OUTLET); if (value != null && value == Boolean.TRUE) { String wateringDuration = device.getAbility(ABILITY_OUTLET) .getProperty(PROPERTY_BUTTON_MANUAL_OVERRIDE_TIME).getValue(); command = new WateringManualOverrideCommand(wateringDuration); } else { command = new WateringCancelOverrideCommand(); } break; default: throw new GardenaException("Unknown command " + commandName); } if (command != null) { executeRequest(HttpMethod.POST, getCommandUrl(device, ability), command, NoResult.class); } scheduleIntermediateRefresh(); }
From source file:org.openhab.binding.gardena.internal.handler.GardenaThingHandler.java
/** * Updates the thing configuration from the Gardena device. *//* www . j a va2 s. co m*/ protected void updateSettings(Device device) throws GardenaException { if (GardenaSmartImpl.DEVICE_CATEGORY_PUMP.equals(device.getCategory())) { Configuration config = editConfiguration(); if (!equalsSetting(config, device, SETTING_LEAKAGE_DETECTION) || !equalsSetting(config, device, SETTING_OPERATION_MODE) || !equalsSetting(config, device, SETTING_TURN_ON_PRESSURE)) { config.put(SETTING_LEAKAGE_DETECTION, device.getSetting(SETTING_LEAKAGE_DETECTION).getValue()); config.put(SETTING_OPERATION_MODE, device.getSetting(SETTING_OPERATION_MODE).getValue()); config.put(SETTING_TURN_ON_PRESSURE, ObjectUtils.toString(device.getSetting(SETTING_TURN_ON_PRESSURE).getValue())); updateConfiguration(config); } } }
From source file:org.openhab.binding.gardena.internal.handler.GardenaThingHandler.java
private boolean equalsSetting(Configuration config, Device device, String key) throws GardenaException { return config.get(key) != null && config.get(key).equals(ObjectUtils.toString(device.getSetting(key).getValue())); }
From source file:org.openhab.binding.homematic.internal.communicator.CcuGateway.java
/** * {@inheritDoc}// w w w . jav a2 s . co m */ @Override protected void setVariable(HmDatapoint dp, Object value) throws IOException { String strValue = StringUtils.replace(ObjectUtils.toString(value), "\"", "\\\""); if (dp.isStringType()) { strValue = "\"" + strValue + "\""; } HmResult result = sendScriptByName("setVariable", HmResult.class, new String[] { "variable_name", "variable_state" }, new String[] { dp.getInfo(), strValue }); if (!result.isValid()) { throw new IOException("Unable to set CCU variable " + dp.getInfo()); } }
From source file:org.openhab.binding.homematic.internal.communicator.client.CcuClient.java
@Override public void setDatapointValue(HmDatapoint dp, String datapointName, Object value) throws HomematicClientException { HmInterface hmInterface = dp.getChannel().getDevice().getHmInterface(); if (hmInterface == HmInterface.VIRTUALDEVICES) { String groupName = HmInterface.VIRTUALDEVICES + "." + dp.getChannel().getAddress() + "." + datapointName;/* www . j av a2 s. c o m*/ if (dp.isIntegerValue() && value instanceof Double) { value = ((Number) value).intValue(); } String strValue = ObjectUtils.toString(value); if (dp.isStringValue()) { strValue = "\"" + strValue + "\""; } HmResult result = sendScriptByName("setVirtualGroup", HmResult.class, new String[] { "group_name", "group_state" }, new String[] { groupName, strValue }); if (!result.isValid()) { throw new HomematicClientException("Unable to set CCU group " + groupName); } } else { super.setDatapointValue(dp, datapointName, value); } }
From source file:org.openhab.binding.homematic.internal.communicator.client.CcuClient.java
/** * {@inheritDoc}/* w ww. ja va 2s. co m*/ */ @Override public void setVariable(HmValueItem hmValueItem, Object value) throws HomematicClientException { String strValue = ObjectUtils.toString(value); if (hmValueItem.isStringValue()) { strValue = "\"" + strValue + "\""; } logger.debug("Sending {} with value '{}' to CCU", hmValueItem.getName(), strValue); HmResult result = sendScriptByName("setVariable", HmResult.class, new String[] { "variable_name", "variable_state" }, new String[] { hmValueItem.getName(), strValue }); if (!result.isValid()) { throw new HomematicClientException("Unable to set CCU variable " + hmValueItem.getName()); } }
From source file:org.openhab.binding.homematic.internal.communicator.client.HomegearClient.java
/** * Parses the datapoint informations into the binding model. */// w w w.ja v a2 s. c o m private HmDatapoint parseDatapoint(HmChannel channel, String name, Map<String, ?> dpData) throws IllegalAccessException { HmDatapoint dp = new HmDatapoint(); dp.setName(name); FieldUtils.writeField(dp, "channel", channel, true); FieldUtils.writeField(dp, "writeable", dpData.get("WRITEABLE"), true); Object valueList = dpData.get("VALUE_LIST"); if (valueList != null && valueList instanceof Object[]) { Object[] vl = (Object[]) valueList; String[] stringArray = new String[vl.length]; for (int i = 0; i < vl.length; i++) { stringArray[i] = vl[i].toString(); } FieldUtils.writeField(dp, "valueList", stringArray, true); } Object value = dpData.get("VALUE"); String type = (String) dpData.get("TYPE"); boolean isString = StringUtils.equals("STRING", type); if (isString && value != null && !(value instanceof String)) { value = ObjectUtils.toString(value); } setValueType(dp, type, value); if (dp.isNumberValueType()) { FieldUtils.writeField(dp, "minValue", dpData.get("MIN"), true); FieldUtils.writeField(dp, "maxValue", dpData.get("MAX"), true); } dp.setValue(value); return dp; }
From source file:org.openhab.binding.homematic.internal.communicator.client.TclRegaScriptClient.java
/** * Set a variable on the CCU.// w ww .j av a 2 s . c o m */ public void setVariable(HmValueItem hmValueItem, Object value) throws CcuClientException { String strValue = ObjectUtils.toString(value); if (hmValueItem.isStringValue()) { strValue = "\"" + strValue + "\""; } logger.debug("Sending {} with value '{}' to CCU", hmValueItem.getName(), strValue); HmResult result = sendScriptByName("setVariable", HmResult.class, new String[] { "variable_name", "variable_state" }, new String[] { hmValueItem.getName(), strValue }); if (!result.isValid()) { throw new CcuClientException("Unable to set CCU variable " + hmValueItem.getName()); } }