本文整理汇总了Java中org.eclipse.smarthome.core.items.GenericItem类的典型用法代码示例。如果您正苦于以下问题:Java GenericItem类的具体用法?Java GenericItem怎么用?Java GenericItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericItem类属于org.eclipse.smarthome.core.items包,在下文中一共展示了GenericItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribe
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
public void subscribe(GenericItem item, String key, HomekitCharacteristicChangeCallback callback) {
if (item == null) {
return;
}
ItemKey itemKey = new ItemKey(item, key);
if (subscriptionsByName.containsKey(itemKey)) {
logger.error("Received duplicate subscription on {}", item.getName());
}
subscriptionsByName.compute(itemKey, (k, v) -> {
if (v != null) {
logger.error("Received duplicate subscription on {}", item.getName());
unsubscribe(item, key);
}
Subscription subscription = (changedItem, oldState, newState) -> callback.changed();
item.addStateChangeListener(subscription);
return subscription;
});
}
示例2: processCommand
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
private void processCommand(Item item, Command command) {
if (item instanceof GenericItem) {
GenericItem genItem = (GenericItem) item;
if (command instanceof State) {
genItem.setState((State) command);
} else {
throw new IllegalStateException("Cannot parse command " + command + " to state");
}
} else {
throw new IllegalStateException("Cannot parse command " + command + " to state");
}
}
示例3: createItem
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
public GenericItem createItem(String itemTypeName, String itemName) {
if (itemTypeName.equals(ITEM_TYPE))
return new ESHCallItem(itemName);
else {
return null;
}
}
示例4: registerItems
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
/**
* listen for state changes from the requested items
*/
@Override
public void registerItems() {
for (Item item : items.keySet()) {
if (item instanceof GenericItem) {
((GenericItem) item).addStateChangeListener(stateEventListener);
}
}
}
示例5: registerItem
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
/**
* listens to state changes of the given item, if it is part of the
* requested items
*
* @param item
* - the new item, that should be listened to
*/
@Override
public void registerItem(Item item) {
if (item == null || items.containsKey(item) || !itemNames.contains(item.getName())) {
return;
}
if (item instanceof GenericItem) {
((GenericItem) item).addStateChangeListener(stateEventListener);
}
}
示例6: unregisterItem
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
/**
* listens to state changes of the given item, if it is part of the
* requested items
*
* @param item
* - the new item, that should be listened to
*/
@Override
public void unregisterItem(Item item) {
if (item == null || items.containsKey(item) || !itemNames.contains(item.getName())) {
return;
}
if (item instanceof GenericItem) {
((GenericItem) item).removeStateChangeListener(stateEventListener);
items.remove(item);
}
}
示例7: unsubscribe
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
public void unsubscribe(GenericItem item, String key) {
if (item == null) {
return;
}
subscriptionsByName.computeIfPresent(new ItemKey(item, key), (k, v) -> {
item.removeStateChangeListener(v);
return null;
});
}
示例8: setSwitchState
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的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);
}
示例9: getGenericItem
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T extends GenericItem> T getGenericItem(String name) {
Item item = getItemRegistry().get(name);
if (item == null) {
return null;
}
if (!(item instanceof GenericItem)) {
throw new RuntimeException("Expected GenericItem, found " + item.getClass().getCanonicalName());
}
return (T) item;
}
示例10: setLightbulbPowerState
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的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);
}
示例11: setBrightness
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setBrightness(Integer value) throws Exception {
GenericItem item = getItem();
if (item instanceof DimmerItem) {
((DimmerItem) item).send(new PercentType(value));
} else if (item instanceof GroupItem) {
((GroupItem) item).send(new PercentType(value));
}
return CompletableFuture.completedFuture(null);
}
示例12: AbstractDevice
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
public AbstractDevice(DeviceType type, Item item) {
this.type = type;
this.item = item;
params = new DeviceParameters();
links = new HashMap<>();
if (item instanceof GenericItem) {
((GenericItem) item).addStateChangeListener(this);
}
}
示例13: destroy
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
public void destroy() {
if (item instanceof GenericItem) {
((GenericItem) item).removeStateChangeListener(this);
}
deviceRegistry = null;
actionRegistry = null;
item = null;
}
示例14: setState
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
protected void setState(GenericItem item, State newState) {
State oldState = item.getState();
item.setState(newState);
drools.stateChanged(new ItemStateChangedEvent(item, newState, oldState));
}
示例15: ItemKey
import org.eclipse.smarthome.core.items.GenericItem; //导入依赖的package包/类
public ItemKey(GenericItem item, String key) {
this.item = item;
this.key = key;
}