本文整理汇总了Java中org.eclipse.smarthome.core.library.items.SwitchItem类的典型用法代码示例。如果您正苦于以下问题:Java SwitchItem类的具体用法?Java SwitchItem怎么用?Java SwitchItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwitchItem类属于org.eclipse.smarthome.core.library.items包,在下文中一共展示了SwitchItem类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToOpenHABItem
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
public static org.openhab.core.items.Item mapToOpenHABItem(Item item) {
org.openhab.core.items.Item result = null;
if(item instanceof StringItem) result = new org.openhab.core.library.items.StringItem(item.getName());
if(item instanceof SwitchItem) result = new org.openhab.core.library.items.SwitchItem(item.getName());
if(item instanceof ContactItem) result = new org.openhab.core.library.items.ContactItem(item.getName());
if(item instanceof NumberItem) result = new org.openhab.core.library.items.NumberItem(item.getName());
if(item instanceof RollershutterItem) result = new org.openhab.core.library.items.RollershutterItem(item.getName());
if(item instanceof DimmerItem) result = new org.openhab.core.library.items.DimmerItem(item.getName());
if(item instanceof ColorItem) result = new org.openhab.core.library.items.ColorItem(item.getName());
if(item instanceof DateTimeItem) result = new org.openhab.core.library.items.DateTimeItem(item.getName());
if(item instanceof ESHCallItem) result = new org.openhab.library.tel.items.CallItem(item.getName());
if(item instanceof GroupItem) {
GroupItem gItem = (GroupItem) item;
org.openhab.core.items.Item baseItem = ItemMapper.mapToOpenHABItem(gItem.getBaseItem());
org.openhab.core.items.GroupItem ohgItem;
if(baseItem instanceof GenericItem) {
ohgItem = new org.openhab.core.items.GroupItem(item.getName(), (GenericItem) baseItem);
} else {
ohgItem = new org.openhab.core.items.GroupItem(item.getName());
}
for(Item member : gItem.getMembers()) {
org.openhab.core.items.Item ohMember = ItemMapper.mapToOpenHABItem(member);
if(ohMember != null) {
ohgItem.addMember(ohMember);
}
}
result = ohgItem;
}
if(result instanceof org.openhab.core.items.GenericItem) {
org.openhab.core.items.GenericItem genericItem = (GenericItem) result;
if(item.getState()!=null) {
genericItem.setState(TypeParser.parseState(genericItem.getAcceptedDataTypes(), item.getState().toString()));
}
}
return result;
}
示例2: setSwitchState
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setSwitchState(boolean state) throws Exception {
GenericItem item = getItem();
if (item instanceof SwitchItem) {
((SwitchItem) item).send(state ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof GroupItem) {
((GroupItem) item).send(state ? OnOffType.ON : OnOffType.OFF);
}
return CompletableFuture.completedFuture(null);
}
示例3: setLightbulbPowerState
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setLightbulbPowerState(boolean value) throws Exception {
GenericItem item = getItem();
if (item instanceof SwitchItem) {
((SwitchItem) item).send(value ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof GroupItem) {
((GroupItem) item).send(value ? OnOffType.ON : OnOffType.OFF);
}
return CompletableFuture.completedFuture(null);
}
示例4: HomekitSwitchImpl
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
public HomekitSwitchImpl(HomekitTaggedItem taggedItem, ItemRegistry itemRegistry, HomekitAccessoryUpdater updater) {
super(taggedItem, itemRegistry, updater, SwitchItem.class);
}
示例5: HomekitLightbulbImpl
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
public HomekitLightbulbImpl(HomekitTaggedItem taggedItem, ItemRegistry itemRegistry,
HomekitAccessoryUpdater updater) {
super(taggedItem, itemRegistry, updater, SwitchItem.class);
}
示例6: sendCommand
import org.eclipse.smarthome.core.library.items.SwitchItem; //导入依赖的package包/类
@Override
public void sendCommand(String itemName, String commandString) {
try {
if (itemRegistry != null) {
Item item = itemRegistry.getItem(itemName);
Command command = null;
if (item != null) {
if (this.eventPublisher != null) {
if ("toggle".equalsIgnoreCase(commandString)
&& (item instanceof SwitchItem || item instanceof RollershutterItem)) {
if (OnOffType.ON.equals(item.getStateAs(OnOffType.class))) {
command = OnOffType.OFF;
}
if (OnOffType.OFF.equals(item.getStateAs(OnOffType.class))) {
command = OnOffType.ON;
}
if (UpDownType.UP.equals(item.getStateAs(UpDownType.class))) {
command = UpDownType.DOWN;
}
if (UpDownType.DOWN.equals(item.getStateAs(UpDownType.class))) {
command = UpDownType.UP;
}
} else {
command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
}
if (command != null) {
logger.debug("Received command '{}' for item '{}'", commandString, itemName);
this.eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command));
} else {
logger.warn("Received invalid command '{}' for item '{}'", commandString, itemName);
}
}
} else {
logger.warn("Received command '{}' for non-existent item '{}'", commandString, itemName);
}
} else {
return;
}
} catch (ItemNotFoundException e) {
logger.warn("Received command for a non-existent item '{}'", itemName);
}
}