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