当前位置: 首页>>代码示例>>Java>>正文


Java StringType类代码示例

本文整理汇总了Java中org.openhab.core.library.types.StringType的典型用法代码示例。如果您正苦于以下问题:Java StringType类的具体用法?Java StringType怎么用?Java StringType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringType类属于org.openhab.core.library.types包,在下文中一共展示了StringType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Creates an openHAB {@link State} in accordance to the class of the given {@code propertyValue}. Currently
 * {@link Date}, {@link BigDecimal}, {@link Temperature} and {@link Boolean} are handled explicitly. All other
 * {@code dataTypes} are mapped to {@link StringType}.
 * <p>
 * If {@code propertyValue} is {@code null}, {@link UnDefType#NULL} will be returned.
 * 
 * Copied/adapted from the Koubachi binding.
 * 
 * @param propertyValue
 * 
 * @return the new {@link State} in accordance with {@code dataType}. Will never be {@code null}.
 */
private State createState(Object propertyValue) {
	if (propertyValue == null) {
		return UnDefType.NULL;
	}

	Class<?> dataType = propertyValue.getClass();

	if (Date.class.isAssignableFrom(dataType)) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime((Date) propertyValue);
		return new DateTimeType(calendar);
	} else if (Integer.class.isAssignableFrom(dataType)) {
		return new DecimalType((Integer) propertyValue);
	} else if (BigDecimal.class.isAssignableFrom(dataType)) {
		return new DecimalType((BigDecimal) propertyValue);
	} else if (Boolean.class.isAssignableFrom(dataType)) {
		if ((Boolean) propertyValue) {
			return OnOffType.ON;
		} else {
			return OnOffType.OFF;
		}
	} else {
		return new StringType(propertyValue.toString());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:39,代码来源:NestBinding.java

示例2: getState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Convert a string representation of a state to an openHAB State.
 * 
 * @param value
 *            string representation of State
 * @return State
 */
protected State getState(String value) {

	List<Class<? extends State>> stateList = new ArrayList<Class<? extends State>>();

	// Not sure if the sequence below is the best one..
	stateList.add(OnOffType.class);
	stateList.add(OpenClosedType.class);
	stateList.add(UpDownType.class);
	stateList.add(HSBType.class);
	stateList.add(PercentType.class);
	stateList.add(DecimalType.class);
	stateList.add(DateTimeType.class);
	stateList.add(StringType.class);

	return TypeParser.parseState(stateList, value);

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:MqttMessageSubscriber.java

示例3: createState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
private State createState(Class<? extends Item> itemType,
		String transformedResponse) {
	try {
		if (itemType.isAssignableFrom(NumberItem.class)) {
			return DecimalType.valueOf(transformedResponse);
		} else if (itemType.isAssignableFrom(SwitchItem.class)) {
			return OnOffType.valueOf(transformedResponse);
		} else if (itemType.isAssignableFrom(DimmerItem.class)) {
			return PercentType.valueOf(transformedResponse);
		} else {
			return StringType.valueOf(transformedResponse);
		}
	} catch (Exception e) {
		logger.debug("Couldn't create state of type '{}' for value '{}'",
				itemType, transformedResponse);
		return StringType.valueOf(transformedResponse);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:Enigma2Binding.java

示例4: convertToState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Converts a value to a openhab state
 * @param value A value to converrt
 * @return A converted state or null
 */
public static State convertToState(Object value) {

	if(value instanceof BigDecimal) {
		return new DecimalType((BigDecimal)value);
		
	} else if(value instanceof Boolean) {
		return (Boolean)value ? OnOffType.ON : OnOffType.OFF;
		
	} else if(value instanceof String) {
		return  new StringType((String)value);
		
	} else if(value == null) {
		return null;
		
	} else {
		logger.error("Unknown data type!");
		return null;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:StateUtils.java

示例5: internalReceiveCommand

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * @{inheritDoc}
 */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
	logger.trace("Received command for item '{}' with command '{}'",itemName, command);

	for (FreeswitchBindingProvider provider : providers) {
		FreeswitchBindingConfig config = provider.getFreeswitchBindingConfig(itemName);
		switch(config.getType()){
		case CMD_API:{
			if (!(command instanceof StringType)){
				logger.warn("could not process command '{}' for item '{}': command is not a StringType", command, itemName);
				return;
			}

			String str = ((StringType) command).toString().toLowerCase();
			String response = executeApiCommand(str);
			eventPublisher.postUpdate(itemName, new StringType(response));
		}
			break;
		default:
			break;
		}
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:FreeswitchBinding.java

示例6: newCallItemUpdate

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Update items for new calls
 * @param config
 * @param channel
 */
private void newCallItemUpdate(FreeswitchBindingConfig config, Channel channel){

	if (config.getItemType().isAssignableFrom(SwitchItem.class)) {

		eventPublisher.postUpdate(config.getItemName(), OnOffType.ON);
	}
	else if (config.getItemType().isAssignableFrom(CallItem.class)) {

		eventPublisher.postUpdate(config.getItemName(), channel.getCall());
	}
	else if (config.getItemType().isAssignableFrom(StringItem.class)) {

		eventPublisher.postUpdate(config.getItemName(), 
				new StringType(String.format("%s : %s",
						channel.getEventHeader(CID_NAME),
						channel.getEventHeader(CID_NUMBER))));
	}
	else {
		logger.warn("handleHangupCall - postUpdate for itemType '{}' is undefined", config.getItemName());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:FreeswitchBinding.java

示例7: processTitleCommand

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
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;
		}
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:DenonConnector.java

示例8: createState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Returns a {@link State} which is inherited from the {@link Item}s
 * accepted DataTypes. The call is delegated to the {@link TypeParser}. If
 * <code>item</code> is <code>null</code> the {@link StringType} is used.
 * 
 * @param itemType
 * @param transformedResponse
 * 
 * @return a {@link State} which type is inherited by the {@link TypeParser}
 *         or a {@link StringType} if <code>item</code> is <code>null</code>
 */
private State createState(Class<? extends Item> itemType,
		String transformedResponse) {
	try {
		if (itemType.isAssignableFrom(NumberItem.class)) {
			return DecimalType.valueOf(transformedResponse);
		} else if (itemType.isAssignableFrom(ContactItem.class)) {
			return OpenClosedType.valueOf(transformedResponse);
		} else if (itemType.isAssignableFrom(SwitchItem.class)) {
			return OnOffType.valueOf(transformedResponse);
		} else if (itemType.isAssignableFrom(RollershutterItem.class)) {
			return PercentType.valueOf(transformedResponse);
		} else {
			return StringType.valueOf(transformedResponse);
		}
	} catch (Exception e) {
		logger.debug("Couldn't create state of type '{}' for value '{}'",
				itemType, transformedResponse);
		return StringType.valueOf(transformedResponse);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:32,代码来源:OWServerBinding.java

示例9: testImage

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
@Test
public void testImage() throws Exception {
	addBindingConfig(new StringItem("Ulux_Image"), "{switchId=1, type='IMAGE'}");

	receiveCommand("Ulux_Image", new StringType("http://www.openhab.org/images/openhab-logo-square.png"));

	byte[] actual = toBytes(datagramList.poll());
	byte[] expected = toBytes("0C:A2:00:00:00:00:00:00:01:00:00:00");

	assertThat(actual, equalTo(expected));

	assertThat(datagramList.size(), equalTo(46));

	for (int i = 1; !datagramList.isEmpty(); i++) {
		final UluxDatagram datagram = datagramList.poll();

		assertThat(datagram, isVideoDatagram());

		if (i % 10 == 0) {
			actual = toBytes(datagram);
			expected = toBytes(new File("src/test/resources/VideoStreamMessageTest-" + i + ".txt"));

			assertThat(actual, equalTo(expected));
		}
	}
}
 
开发者ID:abrenk,项目名称:openhab-ulux-binding,代码行数:27,代码来源:VideoStreamMessageTest.java

示例10: mapResponseToState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
private State mapResponseToState(final InfoResponse infoResponse,
		final String deviceName, final NeoStatProperty property) {
	final Device deviceInfo = infoResponse.getDevice(deviceName);
	switch (property) {
	case CurrentTemperature:
		return new DecimalType(deviceInfo.getCurrentTemperature());
	case CurrentFloorTemperature:
		return new DecimalType(deviceInfo.getCurrentFloorTemperature());
	case CurrentSetTemperature:
		return new DecimalType(deviceInfo.getCurrentSetTemperature());
	case DeviceName:
		return new StringType(deviceInfo.getDeviceName());
	case Away:
		return deviceInfo.isAway() ? OnOffType.ON : OnOffType.OFF;
	case Standby:
		return deviceInfo.isStandby() ? OnOffType.ON : OnOffType.OFF;
	case Heating:
		return deviceInfo.isHeating() ? OnOffType.ON : OnOffType.OFF;
	default:
		throw new IllegalStateException(
				String.format(
						"No result mapping configured for this neo stat property: %s",
						property));
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:NeoHubBinding.java

示例11: updateItemState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Polls the TV for the values specified in @see tvCommand and posts state
 * update for @see itemName Currently only the following commands are
 * available - "ambilight[...]" returning a HSBType state for the given
 * ambilight pixel specified in [...] - "volume" returning a DecimalType -
 * "volume.mute" returning 'On' or 'Off' - "source" returning a String with
 * selected source (e.g. "hdmi1", "tv", etc)
 * 
 * @param itemName
 * @param tvCommand
 */
private void updateItemState(String itemName, String tvCommand) {
	if (tvCommand.contains("ambilight")) {
		String[] layer = command2LayerString(tvCommand);
		HSBType state = new HSBType(getAmbilightColor(ip + ":" + port, layer));
		eventPublisher.postUpdate(itemName, state);
	} else if (tvCommand.contains("volume")) {
		if (tvCommand.contains("mute")) {
			eventPublisher.postUpdate(itemName, getTVVolume(ip + ":" + port).mute ? OnOffType.ON : OnOffType.OFF);
		} else {
			eventPublisher.postUpdate(itemName, new DecimalType(getTVVolume(ip + ":" + port).volume));
		}
	} else if (tvCommand.contains("source")) {
		eventPublisher.postUpdate(itemName, new StringType(getSource(ip + ":" + port)));
	} else {
		logger.error("Could not parse item state\"" + tvCommand + "\" for polling");
		return;
	}

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:31,代码来源:JointSpaceBinding.java

示例12: createState

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Creates an openHAB {@link State} in accordance to the class of the given
 * {@code propertyValue}. Currently {@link Date}, {@link BigDecimal} and
 * {@link Boolean} are handled explicitly. All other {@code dataTypes} are
 * mapped to {@link StringType}.
 * <p>
 * If {@code propertyValue} is {@code null}, {@link UnDefType#NULL} will be
 * returned.
 * 
 * @param propertyValue
 * 
 * @return the new {@link State} in accordance to {@code dataType}. Will
 *         never be {@code null}.
 */
private State createState(Object propertyValue) {
	if(propertyValue == null) {
		return UnDefType.NULL;
	}

	Class<?> dataType = propertyValue.getClass();

	if (Date.class.isAssignableFrom(dataType)) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime((Date) propertyValue);
		return new DateTimeType(calendar);
	} else if (BigDecimal.class.isAssignableFrom(dataType)) {
		return new DecimalType((BigDecimal) propertyValue);
	} else if (Boolean.class.isAssignableFrom(dataType)) {
		if((Boolean) propertyValue) {
			return OnOffType.ON;
		} else {
			return OnOffType.OFF;
		}
	} else {
		return new StringType(propertyValue.toString());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:38,代码来源:KoubachiBinding.java

示例13: updateConfigFromSession

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Maps properties from {@code session} to openHAB item {@code config}. Mapping is specified by {@link ItemMapping} annotations. 
 * 
 * @param config Binding config
 * @param session Plex session
 */
private void updateConfigFromSession(PlexBindingConfig config, PlexSession session) {
	String property = config.getProperty();
	String itemName = config.getItemName();
	PlexPlayerState state = session.getState();
	
	for(Field field : session.getClass().getDeclaredFields()){
		ItemMapping itemMapping = field.getAnnotation(ItemMapping.class);
		if (itemMapping != null) {
			if (itemMapping.property().equals(property)) {
				if (itemMapping.type().equals(StringType.class)) {
					eventPublisher.postUpdate(itemName, new StringType(getStringProperty(field, session)));
				} else if (itemMapping.type().equals(PercentType.class)) {
					eventPublisher.postUpdate(itemName, new PercentType(getStringProperty(field, session)));
				} 
			}
			for (ItemPlayerStateMapping stateMapping : itemMapping.stateMappings()) {
				if (stateMapping.property().equals(property)) {
					eventPublisher.postUpdate(itemName, state.equals(stateMapping.state()) ? OnOffType.ON : OnOffType.OFF);
				}
			}
		}
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:30,代码来源:PlexBinding.java

示例14: getCommand

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
 * Convert a string representation of a command to an openHAB command.
 * 
 * @param value
 *            string representation of command
 * @return Command
 */
protected Command getCommand(String value) {

	List<Class<? extends Command>> commandList = new ArrayList<Class<? extends Command>>();

	commandList.add(OnOffType.class);
	commandList.add(OpenClosedType.class);
	commandList.add(UpDownType.class);
	commandList.add(IncreaseDecreaseType.class);
	commandList.add(StopMoveType.class);
	commandList.add(HSBType.class);
	commandList.add(PercentType.class);
	commandList.add(DecimalType.class);
	commandList.add(StringType.class);

	return TypeParser.parseCommand(commandList, value);

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:MqttMessageSubscriber.java

示例15: canParseCommand

import org.openhab.core.library.types.StringType; //导入依赖的package包/类
@Test
public void canParseCommand() throws Exception {

	MqttMessageSubscriber subscriber = new MqttMessageSubscriber(
			"mybroker:/mytopic:command:default");
	assertEquals(StringType.valueOf("test"), subscriber.getCommand("test"));
	assertEquals(StringType.valueOf("{\"person\"{\"name\":\"me\"}}"),
			subscriber.getCommand("{\"person\"{\"name\":\"me\"}}"));
	assertEquals(StringType.valueOf(""), subscriber.getCommand(""));
	assertEquals(OnOffType.ON, subscriber.getCommand("ON"));
	assertEquals(HSBType.valueOf("5,6,5"), subscriber.getCommand("5,6,5"));
	assertEquals(DecimalType.ZERO,
			subscriber.getCommand(DecimalType.ZERO.toString()));
	assertEquals(PercentType.HUNDRED,
			subscriber.getCommand(PercentType.HUNDRED.toString()));
	assertEquals(PercentType.valueOf("80"),
			subscriber.getCommand(PercentType.valueOf("80").toString()));

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:MqttMessageSubscriberTest.java


注:本文中的org.openhab.core.library.types.StringType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。