• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DecimalType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setState

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * Set port state
 *
 * @param state
 */
public void setState(PortStates state) {

    // set state only if previous is different
    if (this.state != state) {
        this.prevState = this.state;
        this.state = state;
        this.changedSince = Calendar.getInstance();

        // update event bus
        if (itemState != null) {
            eventPublisher.postUpdate(itemState, new DecimalType(this.state.ordinal()));
        }
        if (itemPreviousState != null) {
            eventPublisher.postUpdate(itemPreviousState, new DecimalType(this.prevState.ordinal()));
        }
        if (itemStateChangeTime != null) {
            eventPublisher.postUpdate(itemStateChangeTime, new DateTimeType(this.changedSince));
        }
    }
}
 
开发者ID:docbender,项目名称:openHAB-Simatic,代码行数:26,代码来源:SimaticPortState.java


示例2: getQualifiedCommands

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public List<Command> getQualifiedCommands(String itemName,Command command){
	List<Command> commands = new ArrayList<Command>();
	ProtocolBindingConfig aConfig = (ProtocolBindingConfig) bindingConfigs.get(itemName);
	for(Command aCommand : aConfig.keySet()) {
		if(aCommand == command) {
			commands.add(aCommand);
		} else {
			if(aCommand instanceof DecimalType) {
				commands.add(aCommand);
			}				
		}
	}

	return commands;
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:19,代码来源:ProtocolGenericBindingProvider.java


示例3: stateToString

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * Converts {@link State} to a String suitable for influxdb queries.
 * 
 * @param state to be converted
 * @return {@link String} equivalent of the {@link State}
 */
private String stateToString(State state) {
  String value;
  if (state instanceof DecimalType) {
    value = ((DecimalType) state).toBigDecimal().toString();
  } else if (state instanceof OnOffType) {
    value = ((OnOffType) state) == OnOffType.ON ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;
  } else if (state instanceof OpenClosedType) {
    value = ((OpenClosedType) state) == OpenClosedType.OPEN ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;  
  } else if (state instanceof HSBType) {
    value = ((HSBType) state).toString();
  } else if (state instanceof DateTimeType) {
    value = String.valueOf(((DateTimeType) state).getCalendar().getTime().getTime());
  } else {
    value = state.toString();
  }
  return value;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:24,代码来源:InfluxDBPersistenceService.java


示例4: publish

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * Publish a persistence message for a given item.
 * 
 * Topic and template will be reformatted by String.format using the
 * following parameters:
 * 
 * <pre>
 * 	%1 item name 
 * 	%2 alias (as defined in mqtt.persist)
 * 	%3 item state 
 * 	%4 current timestamp
 * </pre>
 * 
 * @param item
 *            item which to persist the state of.
 * @param alias
 *            null or as defined in persistence configuration.
 * @throws Exception
 *             when no MQTT message could be sent.
 */
public void publish(Item item, String alias) throws Exception {

	Object state = item.getState().toString();
	
	if (item.getState() instanceof DecimalType) {
		state = ((DecimalType) item.getState()).toBigDecimal();
	} else if (item.getState() instanceof DateTimeType) {
		state = ((DateTimeType) item.getState()).getCalendar();
	} else if (item.getState() instanceof OnOffType) {
		state = item.getState().equals(OnOffType.ON) ? "1" : "0";
	} else if (item.getState() instanceof OpenClosedType) {
		state = item.getState().equals(OpenClosedType.OPEN) ? "1" : "0";
	} else if (item.getState() instanceof UpDownType) {
		state = item.getState().equals(UpDownType.UP) ? "1" : "0";
	}

	String message = format(messageTemplate, item.getName(), trimToEmpty(alias), state, currentTimeMillis());
	String destination = format(topic, item.getName(), trimToEmpty(alias), state, currentTimeMillis());
	
	channel.publish(destination, message.getBytes());
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:42,代码来源:MqttPersistencePublisher.java


示例5: mapToState

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
private State mapToState(double value, String itemName) {
	if(itemRegistry!=null) {
		try {
			Item item = itemRegistry.getItem(itemName);
			if(item instanceof SwitchItem && !(item instanceof DimmerItem)) {
				return value==0.0d ? OnOffType.OFF : OnOffType.ON;
			} else if(item instanceof ContactItem) {
				return value==0.0d ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
			}
		} catch (ItemNotFoundException e) {
			logger.debug("Could not find item '{}' in registry", itemName);
		}
	}
	// just return a DecimalType as a fallback
	return new DecimalType(value);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:RRD4jService.java


示例6: convertOpenHabCommandToDeviceCommand

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * Convert OpenHAB commmand to LGTV command.
 * 
 * @param command
 * @param cmdTemplate
 * 
 * @return
 */
private String convertOpenHabCommandToDeviceCommand(Command command, String cmdTemplate) {
	String deviceCmd = null;

	if (command instanceof OnOffType) {
		deviceCmd = String.format(cmdTemplate, command == OnOffType.ON ? 1 : 0);

	} else if (command instanceof StringType) {
		deviceCmd = String.format(cmdTemplate, command);

	} else if (command instanceof DecimalType) {
		deviceCmd = String.format(cmdTemplate, ((DecimalType) command).intValue());

	} else if (command instanceof PercentType) {
		deviceCmd = String.format(cmdTemplate, ((DecimalType) command).intValue());
	}

	return deviceCmd;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:LgtvBinding.java


示例7: createState

import org.openhab.core.library.types.DecimalType; //导入依赖的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,代码行数:30,代码来源:ExecBinding.java


示例8: testParseBindingConfigWithNumbers

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
@Test
public void testParseBindingConfigWithNumbers() throws BindingConfigParseException {
	
	String bindingConfig = ">[1:POST:http://www.domain.org:1234/home/lights/23871/?status=on&type=\"text\"] >[0:GET:http://www.domain.org:1234/home/lights/23871/?status=off]";
	Item testItem = new DecimalTestItem();
	
	// method under test
	HttpBindingConfig config = provider.parseBindingConfig(testItem, bindingConfig);
	
	// asserts
	Assert.assertEquals(true, config.containsKey(DecimalType.valueOf("1")));
	Assert.assertEquals("POST", config.get(DecimalType.valueOf("1")).httpMethod);
	Assert.assertEquals("http://www.domain.org:1234/home/lights/23871/?status=on&type=\"text\"", config.get(DecimalType.valueOf("1")).url);
	
	Assert.assertEquals(true, config.containsKey(DecimalType.valueOf("0")));
	Assert.assertEquals("GET", config.get(DecimalType.valueOf("0")).httpMethod);
	Assert.assertEquals("http://www.domain.org:1234/home/lights/23871/?status=off", config.get(DecimalType.valueOf("0")).url);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:HttpGenericBindingProviderTest.java


示例9: createState

import org.openhab.core.library.types.DecimalType; //导入依赖的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 if (itemType.isAssignableFrom(DateTimeItem.class)) {
			return DateTimeType.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,代码来源:HttpBinding.java


示例10: getQualifiedCommands

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public List<Command> getQualifiedCommands(String itemName,Command command){
	List<Command> commands = new ArrayList<Command>();
	IRtransBindingConfig aConfig = (IRtransBindingConfig) bindingConfigs.get(itemName);
	for(Command aCommand : aConfig.keySet()) {
		if(aCommand == command) {
			commands.add(aCommand);
		} else {
			if(aCommand instanceof DecimalType) {
				commands.add(aCommand);
			}				
		}
	}

	return commands;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:IRtransGenericBindingProvider.java


示例11: handleMessage

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
@Override
public void handleMessage(int group, byte cmd1, Msg msg,
		DeviceFeature f, String fromPort) {
	InsteonDevice dev = f.getDevice();
	try {
		int cmd1Msg = (int) (msg.getByte("command1") & 0xff);
		if (cmd1Msg != 0x6a) {
			logger.warn("{}: ignoring bad TEMPERATURE reply from {}", nm(), dev.getAddress());
			return;
		}
		int cmd2 = (int) (msg.getByte("command2") & 0xff);
		int level = cmd2/2;
		logger.info("{}: got TEMPERATURE from {} of value: {}", nm(), dev.getAddress(), level);
		logger.info("{}: set device {} to level {}", nm(), dev.getAddress(), level);
		f.publish(new DecimalType(level), StateChangeType.CHANGED);
	} catch (FieldException e) {
		logger.debug("{} no cmd2 found, dropping msg {}", nm(), msg);
		return;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:21,代码来源:MessageHandler.java


示例12: sumSince

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
/**
 * Gets the sum of the state of a given <code>item</code> since a certain point in time. 
 * The {@link PersistenceService} identified by the <code>serviceName</code> is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return the sum state value since the given point in time
 */

static public DecimalType sumSince(Item item, AbstractInstant timestamp, String serviceName) {
	Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
	Iterator<HistoricItem> it = result.iterator();
	
	double sum = 0;
	while(it.hasNext()) {
		State state = it.next().getState();
		if (state instanceof DecimalType) {
			sum += ((DecimalType) state).doubleValue();
		}
	}

	return new DecimalType(sum);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:PersistenceExtensions.java


示例13: canParseCommand

import org.openhab.core.library.types.DecimalType; //导入依赖的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


示例14: convertData

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
double convertData(org.openhab.core.types.State state) {
	if (state instanceof DecimalType) {
		return ((DecimalType) state).doubleValue();				
	}
	else if(state instanceof OnOffType) {
		if(state == OnOffType.OFF)
			return 0;
		else
			return 1;
	}
	else if(state instanceof OpenClosedType) {
		if(state == OpenClosedType.CLOSED)
			return 0;
		else
			return 1;
	}
	else {
		logger.debug("Unsupported item type in chart: {}", state.getClass().toString());
		return 0;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:22,代码来源:DefaultChartProvider.java


示例15: decreasesWhenDecreaseCommandReceived

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
@Test
@Override
public void decreasesWhenDecreaseCommandReceived()
		throws BindingConfigParseException {

	DmxItem item = getValidInstance();
	DmxService service = Mockito.mock(DmxService.class);

	HSBType hsb = new HSBType(new DecimalType(150), new PercentType(50),
			new PercentType(50));
	item.processCommand(service, hsb);

	Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 65);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 129);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 97);

	item.processCommand(service, IncreaseDecreaseType.DECREASE);

	Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 57);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 116);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 87);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:DmxColorItemTest.java


示例16: getState

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
private StateTransformable getState(Item item) {
    StateTransformable state = null;
    if (item.getState() instanceof HSBType) {
        HSBType hsb = (HSBType) item.getState();
        state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue());
    } else if (item.getState() instanceof DateTimeType) {
        DateTimeType dt = (DateTimeType) item.getState();
        DateTimeDataType data = new DateTimeDataType(dt.toString());
        state = new DateTimeData(data);
    } else if (item.getState() instanceof DecimalType) {

    } else if (item.getState() instanceof OnOffType) {

    } else if (item.getState() instanceof OpenClosedType) {

    } else if (item.getState() instanceof PercentType) {

    } else if (item.getState() instanceof UpDownType) {

    }
    return state;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:ItemStateRequestProcessor.java


示例17: mapResponseToState

import org.openhab.core.library.types.DecimalType; //导入依赖的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


示例18: postUpdate

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
private void postUpdate(EHealthDatagram datagram) {
	for (EHealthBindingProvider provider : providers) {
		for (String itemName : provider.getItemNames()) {
			EHealthSensorPropertyName propertyName = provider.getSensorPropertyName(itemName);
			
			// do only publish a new state if it has changed ...
			if (datagram.hasChanged(previousDatagram, propertyName)) {
				Number sensorValue = datagram.getRawData().get(propertyName);
				State newState = new DecimalType(sensorValue.toString());
				eventPublisher.postUpdate(itemName, newState);
			}
		}
	}
	
	this.previousDatagram = datagram;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:EHealthBinding.java


示例19: updateItemState

import org.openhab.core.library.types.DecimalType; //导入依赖的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


示例20: convertReadValueToType

import org.openhab.core.library.types.DecimalType; //导入依赖的package包/类
@Override
public Type convertReadValueToType(String pvReadValue) {
	Type lvType = super.convertReadValueToType(pvReadValue);

	// Must be Number Tyoe
	DecimalType lvDecimalType = (DecimalType) lvType;

	// Check if readValue greater then MaxWarningValue or less then
	// MinWarningValue
	if (ivMaxWarningValue != null && lvDecimalType.toBigDecimal().compareTo(ivMaxWarningValue) == 1) {
		return OnOffType.ON;
	} else if (ivMinWarningValue != null && lvDecimalType.toBigDecimal().compareTo(ivMinWarningValue) == -1) {
		return OnOffType.ON;
	} else {
		return OnOffType.OFF;
	}

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Trace类代码示例发布时间:2022-05-22
下一篇:
Java NormalAnnotation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap