本文整理汇总了Java中org.openhab.core.library.types.DecimalType类的典型用法代码示例。如果您正苦于以下问题:Java DecimalType类的具体用法?Java DecimalType怎么用?Java DecimalType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DecimalType类属于org.openhab.core.library.types包,在下文中一共展示了DecimalType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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()));
}
示例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;
}
}
示例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);
}