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

Java PercentType类代码示例

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

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



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

示例1: getStateAs

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public State getStateAs(Class<? extends State> typeClass) {
	if(typeClass==UpDownType.class) {
		if(state.equals(PercentType.ZERO)) {
			return UpDownType.UP;
		} else if(state.equals(PercentType.HUNDRED)) {
			return UpDownType.DOWN;
		} else {
			return UnDefType.UNDEF;
		}
	} else if(typeClass==DecimalType.class) {
		if(state instanceof PercentType) {
			return new DecimalType(((PercentType) state).toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
		}
	}
	return super.getStateAs(typeClass);
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:21,代码来源:RollershutterItem.java


示例2: increaseDecrease

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
private void increaseDecrease(TellstickDevice dev, IncreaseDecreaseType increaseDecreaseType)
		throws TellstickException {
	String strValue = dev.getData();
	double value = 0;
	if (strValue != null) {
		 value = Double.valueOf(strValue);
	}
	int percent = (int) Math.round((value / 255) * 100);
	if (IncreaseDecreaseType.INCREASE == increaseDecreaseType) {			
		percent = Math.min(percent + 10, 100);			
	} else if (IncreaseDecreaseType.DECREASE == increaseDecreaseType) {
		percent = Math.max(percent - 10, 0);				
	}
	
	dim(dev, new PercentType(percent));
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:TellstickController.java


示例3: createState

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


示例4: internalReceiveCommand

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * @{inheritDoc}
 */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
  HdlBindingConfig config = tryGetConfigFor(itemName);

  if (config == null)
    return;

  HdlDimmer dimmer = (HdlDimmer)(server.getDevice(config.address));
  if (dimmer != null) {
    try {
      if (command instanceof OnOffType) {
        dimmer.dimChannel(config.channel, command == OnOffType.ON ? 100 : 0);
      }
      else if (command instanceof PercentType) {
        dimmer.dimChannel(config.channel, ((PercentType)command).intValue());
      }
    }
    catch (IOException e) {
      logger.error("Failed to dim channel: {}", e.getMessage());
    }
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:HdlBinding.java


示例5: createState

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


示例6: getVolumeCommand

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
private String getVolumeCommand(PlexBindingConfig config, Command command) {
	int newVolume = 100;
	
	PlexSession session = getSessionByMachineId(config.getMachineIdentifier());
	if (session != null) 
		newVolume = session.getVolume();
	
	if (command.getClass().equals(PercentType.class)) {
		PercentType percentType = (PercentType)command;
		newVolume = percentType.intValue();
	}  else if (command.getClass().equals(IncreaseDecreaseType.class)) {
		if (command.equals(IncreaseDecreaseType.DECREASE)) 
			newVolume = Math.max(0, newVolume-VOLUME_STEP);
		else 
			newVolume = Math.min(100, newVolume+VOLUME_STEP);
	}
	
	if (session != null) {
		session.setVolume(newVolume);
		callback.updateReceived(session);
	}
	
	String url = String.format("playback/setParameters?volume=%d", newVolume);
	return url;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:PlexConnector.java


示例7: createState

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


示例8: handleMessage

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
@Override
public void handleMessage(int group, byte cmd1, Msg msg,
		DeviceFeature f, String fromPort) {
	if (isDuplicate(msg) || !isMybutton(msg, f)) {
		return;
	}
	InsteonAddress a = f.getDevice().getAddress();
	if (msg.isAckOfDirect()) {
		logger.error("{}: device {}: ignoring ack of direct.", nm(), a);
	} else {
		logger.info("{}: device {} was turned on. Sending poll request to get actual level", nm(), a);
		m_feature.publish(PercentType.HUNDRED, StateChangeType.ALWAYS);
		// need to poll to find out what level the dimmer is at now.
		// it may not be at 100% because dimmers can be configured
		// to switch to e.g. 75% when turned on.
		Msg m = f.makePollMsg();
		if (m != null)	f.getDevice().enqueueDelayedMessage(m, f, 1000);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:MessageHandler.java


示例9: createState

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


示例10: getState

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


示例11: decreasesWhenDecreaseCommandReceived

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


示例12: increasesWhenIncreaseCommandReceived

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
@Test
@Override
public void increasesWhenIncreaseCommandReceived()
		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.INCREASE);

	Mockito.verify(service, Mockito.times(1)).setChannelValue(3, 70);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(4, 140);
	Mockito.verify(service, Mockito.times(1)).setChannelValue(5, 106);

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


示例13: createUpdateCommand

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
private Action createUpdateCommand(Command command,	PilightBindingConfig config) {
	Action action = new Action(Action.ACTION_CONTROL);
	
	Code code = new Code();
	code.setDevice(config.getDevice());
	
	if (command instanceof OnOffType) {
		setOnOffValue((OnOffType)command, code);
	} else if (command instanceof PercentType){
		setDimmerValue((PercentType) command, code);
	} else {
		logger.error("Only OnOffType and PercentType can be changed by the pilight binding");
		return null;
	}
		
	action.setCode(code);
	return action;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:PilightBinding.java


示例14: canDetectSupportForStates

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
@Test
public void canDetectSupportForStates() throws BindingConfigParseException {
	testStateSupport("broker:/topic:state:OFF:0", OnOffType.OFF, true);
	testStateSupport("broker:/topic:state:OFF:0", OnOffType.ON, false);
	testStateSupport("broker:/topic:state:*:0", OnOffType.OFF, true);
	testStateSupport("broker:/topic:state:off:0", OnOffType.OFF, true);
	testStateSupport("broker:/topic:stAte:100:0",
			DecimalType.valueOf("100"), true);
	testStateSupport("broker:/topic:state:100:0",
			DecimalType.valueOf("99"), false);
	testStateSupport("broker:/topic:state:20:0", PercentType.HUNDRED, false);
	testStateSupport("broker:/topic:state:100:0", PercentType.HUNDRED, true);
	testStateSupport("broker:/topic:state:100:0", PercentType.ZERO, false);
	testStateSupport("broker:/topic:state:0:0", PercentType.ZERO, true);
	testStateSupport("broker:/topic:state:CLOSED:0", OpenClosedType.CLOSED,
			true);
	testStateSupport("broker:/topic:state:OPEN:0", OpenClosedType.CLOSED,
			false);
	testStateSupport("broker:/topic:command:*:0", OpenClosedType.CLOSED,
			false);
	testStateSupport("broker:/topic:command:CLOSED:0",
			OpenClosedType.CLOSED, false);
	testStateSupport("broker:/topic:state:240.0,100.0,100.0:0",
			HSBType.BLUE, true);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:MqttMessagePublisherTest.java


示例15: convertOpenHabCommandToDeviceCommand

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


示例16: setValue

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * 
 * @generated NOT
 */
public void setValue(PercentType percentValue, DeviceOptions opts)
{
  BigDecimal max = Tools.getBigDecimalOpt(ConfigOptsDimmable.MAX.toString(), opts);
  if (max == null) {
    logger.error("BrickDC dimmer option max is missing, items configuration has to be fixed!");
    return;
  } else {
    logger.debug("Brick DC max {}", max);
  }
  BigDecimal min = Tools.getBigDecimalOpt(ConfigOptsDimmable.MIN.toString(), opts);
  logger.debug("Brick DC min {}", min);
  if (min == null) {
    logger.error("BrickDC dimmer option min is missing, items configuration has to be fixed!");
    return;
  }
  setPercentValue(new PercentValue(percentValue.toBigDecimal()));
  BigDecimal abs = max.add(min.abs());
  Short newVelocity =
      abs.divide(new BigDecimal(100)).multiply(percentValue.toBigDecimal()).subtract(min.abs())
          .shortValue();
  setPoint(newVelocity, opts);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:28,代码来源:MBrickDCImpl.java


示例17: setState

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setState(State state) {
	// we map UP/DOWN values to the percent values 0 and 100
	if(state==UpDownType.UP) {
		super.setState(PercentType.ZERO);
	} else if(state==UpDownType.DOWN) {
		super.setState(PercentType.HUNDRED);
	} else {
		super.setState(state);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:15,代码来源:RollershutterItem.java


示例18: sendCooler

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
private PercentType sendCooler(int bulb, String bridgeId) {
	logger.debug("milight: sendCooler");
	int newPercent = getCurrentState(bulb, bridgeId, BindingType.brightness).intValue() - 10;
	if(newPercent < 0) {
		newPercent = 0;
	}
	PercentType newValue = new PercentType(newPercent);
	String messageBytes = "3F:00:55";
	sendMessage(messageBytes, bridgeId);
	setCurrentState(bulb, bridgeId, newValue, BindingType.brightness);
	return newValue;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:13,代码来源:MilightBinding.java


示例19: getStateAs

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public State getStateAs(Class<? extends State> typeClass) {
	if(typeClass==OnOffType.class) {
		// if it is not completely off, we consider the dimmer to be on
		return state.equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON;
	} else if(typeClass==DecimalType.class) {
		if(state instanceof PercentType) {
			return new DecimalType(((PercentType) state).toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
		}
	}
	return super.getStateAs(typeClass);
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:16,代码来源:DimmerItem.java


示例20: setState

import org.openhab.core.library.types.PercentType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setState(State state) {
	State currentState = this.state;
	
	if(currentState instanceof HSBType) {
		DecimalType hue = ((HSBType) currentState).getHue();
		PercentType saturation = ((HSBType) currentState).getSaturation();
		// we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed 
		if(state==OnOffType.OFF) {
			super.setState(new HSBType(hue, saturation, PercentType.ZERO));
		} else if(state==OnOffType.ON) {
			super.setState(new HSBType(hue, saturation, PercentType.HUNDRED));
		} else if(state instanceof PercentType && !(state instanceof HSBType)) {
			super.setState(new HSBType(hue, saturation, (PercentType) state));
		} else {
			super.setState(state);
		}
	} else {
		// we map ON/OFF values to black/white and percentage values to grey scale 
		if(state==OnOffType.OFF) {
			super.setState(HSBType.BLACK);
		} else if(state==OnOffType.ON) {
			super.setState(HSBType.WHITE);
		} else if(state instanceof PercentType && !(state instanceof HSBType)) {
			super.setState(new HSBType(DecimalType.ZERO, PercentType.ZERO, (PercentType) state));
		} else {
			super.setState(state);
		}
	}
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:34,代码来源:ColorItem.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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