本文整理汇总了Java中org.openhab.core.library.types.OnOffType类的典型用法代码示例。如果您正苦于以下问题:Java OnOffType类的具体用法?Java OnOffType怎么用?Java OnOffType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OnOffType类属于org.openhab.core.library.types包,在下文中一共展示了OnOffType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createState
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例2: convertOpenHabCommandToDeviceCommand
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
/**
* Convert OpenHAB commmand to onkyo receiver 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,代码来源:OnkyoBinding.java
示例3: createState
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例4: execute
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
@Override
protected void execute() {
logger.debug("VDRMonitor execute called");
if (vdrBinding != null) {
for (VDRConfig vdrConfig : vdrBinding.vdrConfigCache.values()) {
Boolean recording = checkRecording(vdrConfig);
if (recording != null) {
if (eventPublisher != null) {
VDRBindingProvider bindingProvider = vdrBinding
.findFirstMatchingBindingProviderByVDRId(vdrConfig.vdrId);
if (bindingProvider != null) {
String itemName = bindingProvider
.getBindingItemName(vdrConfig.vdrId,
VDRCommandType.RECORDING);
State newState = recording.booleanValue() ? OnOffType.ON
: OnOffType.OFF;
eventPublisher.postUpdate(itemName, newState);
}
}
}
}
} else {
logger.info("VDRBinding not available");
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:VDRMonitor.java
示例5: updateItemState
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
private void updateItemState(String itemName, int value) {
Class<? extends Item> itemType = getItemType(itemName);
if (itemType.equals(SwitchItem.class)) {
if (value == 0) {
eventPublisher.postUpdate(itemName, OnOffType.OFF);
} else if (value == 1) {
eventPublisher.postUpdate(itemName, OnOffType.ON);
}
}
if (itemType.equals(ContactItem.class)) {
if (value == 0) {
eventPublisher.postUpdate(itemName, OpenClosedType.OPEN);
} else if (value == 1) {
eventPublisher.postUpdate(itemName, OpenClosedType.CLOSED);
}
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:PifaceBinding.java
示例6: handleNewCall
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
private void handleNewCall(String itemName, Class<? extends Item> itemType, NewChannelEvent event) {
if (event.getCallerIdNum() == null || event.getExten() == null) {
logger.debug("calleridnum or exten is null -> handle new call aborted!");
return;
}
CallType call = new CallType(
new StringType(event.getCallerIdNum()),
new StringType(event.getExten()));
eventCache.put(event.getUniqueId(), call);
if (itemType.isAssignableFrom(SwitchItem.class)) {
eventPublisher.postUpdate(itemName, OnOffType.ON);
}
else if (itemType.isAssignableFrom(CallItem.class)) {
eventPublisher.postUpdate(itemName, call);
}
else {
logger.warn("handle call for item type '{}' is undefined", itemName);
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:22,代码来源:AsteriskBinding.java
示例7: updateConfigFromSession
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例8: mapCommandToItemType
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
private Class<? extends Item> mapCommandToItemType(Command command) {
if (command instanceof IncreaseDecreaseType) {
return DimmerItem.class;
} else if (command instanceof PercentType) {
return DimmerItem.class;
} else if (command instanceof DecimalType) {
return NumberItem.class;
} else if (command instanceof OnOffType) {
return SwitchItem.class;
} else if (command instanceof StringType) {
return StringItem.class;
} else {
logger.warn(
"No explicit mapping found for command type '{}' - return StringItem.class instead",
command.getClass().getSimpleName());
return StringItem.class;
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:PulseaudioBinding.java
示例9: getCommand
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例10: getState
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
/**
* Returns the current state of the thermostat
* This is a consolidated status that brings together a number of
* status registers within the thermostat.
* @param itemType
* @return
*/
public State getState(Class<? extends Item> itemType) {
// If this is a switch, then just treat this like the getOnOffState() function
if (itemType == SwitchItem.class)
return dcbState == 1 ? OnOffType.ON : OnOffType.OFF;
// Default to a string
if(dcbState == 0)
return StringType.valueOf(States.OFF.toString());
if(dcbHolidayTime != 0)
return StringType.valueOf(States.HOLIDAY.toString());
if(dcbHoldTime != 0)
return StringType.valueOf(States.HOLD.toString());
return StringType.valueOf(States.ON.toString());
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:HeatmiserThermostat.java
示例11: mapResponseToState
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例12: canParseCommand
import org.openhab.core.library.types.OnOffType; //导入依赖的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
示例13: updateMessageWaitingItem
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
/**
* update items for message waiting types
* @param itemName
* @param config
*/
private void updateMessageWaitingItem(FreeswitchBindingConfig config) {
MWIModel model = mwiCache.get(config.getArgument());
/*
* see if this is for us
*/
if(model == null)
return;
if (config.getItemType().isAssignableFrom(SwitchItem.class)) {
eventPublisher.postUpdate(config.getItemName(), model.mwi ? OnOffType.ON : OnOffType.OFF);
}
else if (config.getItemType().isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(config.getItemName(), new DecimalType(model.messages));
}
else {
logger.warn("handle call for item type '{}' is undefined", config.getItemName());
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:25,代码来源:FreeswitchBinding.java
示例14: sendCommand
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
/**
* Send a command for a certain property
*
* @param config The property
* @param command The command
*/
public void sendCommand(DenonBindingConfig config, Command command) {
String commandToSend = null;
Class<? extends Command> commandClass = command.getClass();
if (commandClass.equals(OnOffType.class)) {
commandToSend = getCommandFor(config, (OnOffType)command);
} else if (commandClass.equals(IncreaseDecreaseType.class)) {
commandToSend = getCommandFor(config, (IncreaseDecreaseType)command);
} else if (commandClass.equals(PercentType.class)) {
commandToSend = getCommandFor(config, (PercentType)command);
} else if (commandClass.equals(StringType.class)) {
commandToSend = getCommandFor(config, (StringType)command);
}
internalSendCommand(commandToSend);
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:DenonConnector.java
示例15: getCommandFor
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
private String getCommandFor(DenonBindingConfig config, OnOffType onOff) {
String commandToSend = null;
String property = config.getActualProperty();
if (config.isOnOffProperty()) {
if (property.equals(DenonProperty.POWER.getCode())) {
if (OnOffType.ON.equals(onOff)) {
commandToSend = "PWON";
} else {
commandToSend = "PWSTANDBY";
}
} else {
commandToSend = property + onOff.name();
}
} else {
if (onOff.equals(OnOffType.ON)) {
commandToSend = property;
}
}
return commandToSend;
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:DenonConnector.java
示例16: createEditValueMessage
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
public EditValueMessage createEditValueMessage(UluxBindingConfig config, OnOffType onOff) {
final short value;
switch (onOff) {
case ON:
value = EditValueMessage.ON;
break;
case OFF:
value = EditValueMessage.OFF;
break;
default:
LOG.warn("Unknown OnOffType '{}'!", onOff);
value = EditValueMessage.OFF;
}
return new EditValueMessage(config.getActorId(), value);
}
开发者ID:abrenk,项目名称:openhab-ulux-binding,代码行数:18,代码来源:UluxMessageFactory.java
示例17: convertFromState
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
@Override
public void convertFromState(RFXComValueSelector valueSelector, String id,
Object subType, Type type, byte seqNumber) throws RFXComException {
this.subType = ((SubType) subType);
seqNbr = seqNumber;
String[] ids = id.split("\\.");
sensorId = Integer.parseInt(ids[0]);
groupCode = ids[1].charAt(0);
unitcode = Byte.parseByte(ids[2]);
switch (valueSelector) {
case COMMAND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
} else {
throw new RFXComException("Can't convert " + type + " to Command");
}
break;
default:
throw new RFXComException("Can't convert " + type + " to " + valueSelector);
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:RFXComLighting6Message.java
示例18: translateBoolean2State
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
protected State translateBoolean2State(boolean b) {
Class<? extends State> c = item.getState().getClass();
Class<? extends Item> itemClass = item.getClass();
if (c == UnDefType.class && itemClass == SwitchItem.class) {
return b ? OnOffType.ON : OnOffType.OFF;
} else if (c == UnDefType.class && itemClass == ContactItem.class) {
return b ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
} else if (c == OnOffType.class && itemClass == SwitchItem.class) {
return b ? OnOffType.ON : OnOffType.OFF;
} else if (c == OpenClosedType.class
&& itemClass == SwitchItem.class) {
return b ? OnOffType.ON : OnOffType.OFF;
} else if (c == OnOffType.class && itemClass == ContactItem.class) {
return b ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
} else if (c == OpenClosedType.class
&& itemClass == ContactItem.class) {
return b ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
} else {
return UnDefType.UNDEF;
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:WagoGenericBindingProvider.java
示例19: testReceiveButtonPress
import org.openhab.core.library.types.OnOffType; //导入依赖的package包/类
@Test
public void testReceiveButtonPress() {
parameterAddress = new EnoceanParameterAddress(EnoceanId.fromString(EnoceanBindingProviderMock.DEVICE_ID), Parameter.I);
provider.setParameterAddress(parameterAddress);
binding.addBindingProvider(provider);
provider.setItem(new SwitchItem("dummie"));
binding.valueChanged(parameterAddress, ButtonState.PRESSED);
assertEquals("Update State", OnOffType.ON, publisher.getUpdateState());
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:11,代码来源:RockerSwitchTest.java
示例20: setState
import org.openhab.core.library.types.OnOffType; //导入依赖的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.OnOffType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论