本文整理汇总了Java中org.openhab.core.library.types.StringType类的典型用法代码示例。如果您正苦于以下问题:Java StringType类的具体用法?Java StringType怎么用?Java StringType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringType类属于org.openhab.core.library.types包,在下文中一共展示了StringType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: createCommandFromString
import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
* Creates a {@link Command} out of the given <code>commandAsString</code>
* incorporating the {@link TypeParser}.
*
* @param item, or null if the Command has to be of the StringType type
* @param commandAsString
*
* @return an appropriate Command (see {@link TypeParser} for more
* information
*
* @throws BindingConfigParseException if the {@link TypeParser} couldn't
* create a command appropriately
*
* @see {@link TypeParser}
*/
private Command createCommandFromString(Item item, String commandAsString) throws BindingConfigParseException {
List<Class<? extends Command>> acceptedTypes = new ArrayList<Class<? extends Command>>();
if(item!=null) {
acceptedTypes = item.getAcceptedCommandTypes();
}
else {
acceptedTypes.add(StringType.class);
}
Command command = TypeParser.parseCommand(acceptedTypes, commandAsString);
if (command == null) {
throw new BindingConfigParseException("couldn't create Command from '" + commandAsString + "' ");
}
return command;
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:35,代码来源:SonosGenericBindingProvider.java
示例17: publishValue
import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
* Publishes the item with the value.
*/
private void publishValue(String itemName, Object value, WeatherBindingConfig bindingConfig) {
if (value == null) {
context.getEventPublisher().postUpdate(itemName, UnDefType.UNDEF);
} else if (value instanceof Calendar) {
Calendar calendar = (Calendar) value;
context.getEventPublisher().postUpdate(itemName, new DateTimeType(calendar));
} else if (value instanceof Number) {
context.getEventPublisher().postUpdate(itemName, new DecimalType(round(value.toString(), bindingConfig)));
} else if (value instanceof String || value instanceof Enum) {
if (value instanceof Enum) {
String enumValue = WordUtils.capitalizeFully(StringUtils.replace(value.toString(), "_", " "));
context.getEventPublisher().postUpdate(itemName, new StringType(enumValue));
} else {
context.getEventPublisher().postUpdate(itemName, new StringType(value.toString()));
}
} else {
logger.warn("Unsupported value type {}", value.getClass().getSimpleName());
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:WeatherPublisher.java
示例18: getState
import org.openhab.core.library.types.StringType; //导入依赖的package包/类
@Override
public State getState(LightwaveRfType type) {
switch (type) {
case HEATING_BATTERY:
return new DecimalType(getBatteryLevel());
case HEATING_SIGNAL:
return new DecimalType(getSignal());
case HEATING_CURRENT_TEMP:
return new DecimalType(getCurrentTemperature());
case HEATING_SET_TEMP:
return new DecimalType(getCurrentTargetTemperature());
case HEATING_MODE:
return new StringType(getState());
case HEATING_UPDATETIME:
Calendar cal = Calendar.getInstance();
// The date seems to be in a strange timezone so at the moment we
// use server date.
// cal.setTime(getTime());
return new DateTimeType(cal);
case VERSION:
return new StringType(getVersion());
default:
return null;
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:LightwaveRfHeatingInfoResponse.java
示例19: CallType
import org.openhab.core.library.types.StringType; //导入依赖的package包/类
public CallType(String value) {
this();
if (StringUtils.isNotBlank(value)) {
String[] elements = value.split(SEPARATOR);
if (elements.length == 2) {
callDetails.put(DEST_NUM, new StringType(elements[0]));
callDetails.put(ORIG_NUM, new StringType(elements[1]));
}
}
}
开发者ID:Neulinet,项目名称:Zoo,代码行数:11,代码来源:CallType.java
示例20: objectToState
import org.openhab.core.library.types.StringType; //导入依赖的package包/类
/**
* Converts a value to a {@link State} which is suitable for the given {@link Item}. This is
* needed for querying a {@link HistoricState}.
*
* @param value to be converted to a {@link State}
* @param itemName name of the {@link Item} to get the {@link State} for
* @return the state of the item represented by the itemName parameter,
* else the string value of the Object parameter
*/
private State objectToState(Object value, String itemName) {
String valueStr = String.valueOf(value);
if (itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof NumberItem) {
return new DecimalType(valueStr);
} else if (item instanceof ColorItem) {
return new HSBType(valueStr);
} else if (item instanceof DimmerItem) {
return new PercentType(valueStr);
} else if (item instanceof SwitchItem) {
return string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF)
? OnOffType.OFF
: OnOffType.ON;
} else if (item instanceof ContactItem) {
return (string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF))
? OpenClosedType.CLOSED
: OpenClosedType.OPEN;
} else if (item instanceof RollershutterItem) {
return new PercentType(valueStr);
} else if (item instanceof DateTimeItem) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(new BigDecimal(valueStr).longValue());
return new DateTimeType(calendar);
} else {
return new StringType(valueStr);
}
} catch (ItemNotFoundException e) {
logger.warn("Could not find item '{}' in registry", itemName);
}
}
// just return a StringType as a fallback
return new StringType(valueStr);
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:45,代码来源:InfluxDBPersistenceService.java
注:本文中的org.openhab.core.library.types.StringType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论