本文整理匯總了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);
}
}