本文整理汇总了Java中org.openhab.core.library.items.SwitchItem类的典型用法代码示例。如果您正苦于以下问题:Java SwitchItem类的具体用法?Java SwitchItem怎么用?Java SwitchItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwitchItem类属于org.openhab.core.library.items包,在下文中一共展示了SwitchItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToState
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
private State mapToState(double value, String itemName) {
if(itemRegistry!=null) {
try {
Item item = itemRegistry.getItem(itemName);
if(item instanceof SwitchItem && !(item instanceof DimmerItem)) {
return value==0.0d ? OnOffType.OFF : OnOffType.ON;
} else if(item instanceof ContactItem) {
return value==0.0d ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
}
} catch (ItemNotFoundException e) {
logger.debug("Could not find item '{}' in registry", itemName);
}
}
// just return a DecimalType as a fallback
return new DecimalType(value);
}
示例2: parseButtonWithRefresh
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
private void parseButtonWithRefresh(String name, String config,
Button.PressType type, String address, String[] groups)
throws BindingConfigParseException {
Item item = new SwitchItem(name);
provider.processBindingConfiguration("context", item, config);
Button button = (Button) provider.getItemConfig(name);
assertEquals(name, button.getName());
assertEquals(address, button.getAddress());
assertEquals(type, button.getType());
String[] modules = (String[]) Whitebox.getInternalState(button,
"impactedModules");
assertEquals(groups.length, modules.length);
for (int i = 0; i < groups.length; i++) {
assertEquals(groups[i], modules[i]);
}
}
示例3: testParseBindingConfigIn
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
@Test
public void testParseBindingConfigIn() throws BindingConfigParseException {
String cmdLine = "/usr/bin/uptime";
String itemName = "Switch";
SwitchItem item = new SwitchItem(itemName);
String bindingConfig = "<[" + cmdLine + ":60000:]";
provider.processBindingConfiguration("New", item, bindingConfig);
Assert.assertTrue(provider.providesBinding());
Assert.assertTrue(provider.providesBindingFor(itemName));
Assert.assertEquals(cmdLine, provider.getCommandLine(itemName));
Assert.assertEquals(60000, provider.getRefreshInterval(itemName));
Assert.assertEquals("", provider.getTransformation(itemName));
List<String> itemNames = provider.getInBindingItemNames();
Assert.assertEquals(itemName, itemNames.get(0));
}
示例4: validateItemType
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
public void validateItemType(Item item, String bindingConfig)
throws BindingConfigParseException {
if (!(item instanceof SwitchItem || item instanceof DimmerItem)) {
throw new BindingConfigParseException(
"item '"
+ item.getName()
+ "' is of type '"
+ item.getClass().getSimpleName()
+ "', only Switch- and DimmerItems are allowed - please check your *.items configuration");
}
if (bindingConfig.length() != 6) {
throw new BindingConfigParseException(
"The configured address must consist of 2 bytes housecode and 1 byte device address");
}
}
示例5: validateItemType
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
@Override
public void validateItemType(Item item, String bindingConfig)
throws BindingConfigParseException {
if (!(item instanceof NumberItem || item instanceof SwitchItem
|| item instanceof ContactItem || item instanceof StringItem
|| item instanceof DateTimeItem || item instanceof DimmerItem || item instanceof RollershutterItem)) {
throw new BindingConfigParseException(
"Item '"
+ item.getName()
+ "' is of type '"
+ item.getClass().getSimpleName()
+ "', only NumberItems, SwitchItems, ContactItems, DateTimeItem, StringItem, DimmerItem or RollershutterItem are allowed - please check your *.items configuration");
}
}
示例6: createState
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
private State createState(Class<? extends Item> itemType,
String transformedResponse) {
try {
if (itemType.isAssignableFrom(NumberItem.class)) {
return DecimalType.valueOf(transformedResponse);
} else if (itemType.isAssignableFrom(SwitchItem.class)) {
return OnOffType.valueOf(transformedResponse);
} else if (itemType.isAssignableFrom(DimmerItem.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);
}
}
示例7: newCallItemUpdate
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
/**
* Update items for new calls
* @param config
* @param channel
*/
private void newCallItemUpdate(FreeswitchBindingConfig config, Channel channel){
if (config.getItemType().isAssignableFrom(SwitchItem.class)) {
eventPublisher.postUpdate(config.getItemName(), OnOffType.ON);
}
else if (config.getItemType().isAssignableFrom(CallItem.class)) {
eventPublisher.postUpdate(config.getItemName(), channel.getCall());
}
else if (config.getItemType().isAssignableFrom(StringItem.class)) {
eventPublisher.postUpdate(config.getItemName(),
new StringType(String.format("%s : %s",
channel.getEventHeader(CID_NAME),
channel.getEventHeader(CID_NUMBER))));
}
else {
logger.warn("handleHangupCall - postUpdate for itemType '{}' is undefined", config.getItemName());
}
}
示例8: updateMessageWaitingItem
import org.openhab.core.library.items.SwitchItem; //导入依赖的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());
}
}
示例9: translateBoolean2State
import org.openhab.core.library.items.SwitchItem; //导入依赖的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;
}
}
示例10: createOneWireDeviceProperty
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
/**
* @param pvItem
* @param pvBindingConfig
* @return a new BindingConfig, corresponding to the given <code><pvItem/code> and <code><pvBindingConfig/code>
* @throws BindingConfigParseException
*/
public static OneWireBindingConfig createOneWireDeviceProperty(Item pvItem, String pvBindingConfig) throws BindingConfigParseException {
logger.debug("createOneWireDeviceProperty: " + pvItem.getName() + " - bindingConfig:" + pvBindingConfig);
OneWireBindingConfig lvNewBindingConfig = null;
if (OneWireClearCacheControlBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
lvNewBindingConfig = new OneWireClearCacheControlBindingConfig(pvBindingConfig);
} else if (OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
lvNewBindingConfig = new OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(pvBindingConfig);
} else if (pvItem instanceof NumberItem) {
lvNewBindingConfig = new OneWireDevicePropertyNumberBindingConfig(pvBindingConfig);
} else if (pvItem instanceof ContactItem) {
lvNewBindingConfig = new OneWireDevicePropertyContactBindingConfig(pvBindingConfig);
} else if (pvItem instanceof SwitchItem) {
lvNewBindingConfig = new OneWireDevicePropertySwitchBindingConfig(pvBindingConfig);
} else if (pvItem instanceof StringItem) {
lvNewBindingConfig = new OneWireDevicePropertyStringBindingConfig(pvBindingConfig);
} else {
throw new UnsupportedOperationException("the item-type " + pvItem.getClass() + " cannot be a onewire device");
}
logger.debug("created newBindingConfig: " + lvNewBindingConfig.toString());
return lvNewBindingConfig;
}
示例11: mapCommandToItemType
import org.openhab.core.library.items.SwitchItem; //导入依赖的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;
}
}
示例12: testOrFunction_differntTypes
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
@Test
public void testOrFunction_differntTypes() {
DimmerItem dimmer1 = new DimmerItem("TestDimmer1");
dimmer1.setState(new DecimalType("42"));
DimmerItem dimmer2 = new DimmerItem("TestDimmer2");
dimmer2.setState(new DecimalType("0"));
SwitchItem switch1 = new SwitchItem("TestSwitch1");
switch1.setState(OnOffType.ON);
SwitchItem switch2 = new SwitchItem("TestSwitch2");
switch2.setState(OnOffType.OFF);
items.add(dimmer1);
items.add(dimmer2);
items.add(switch1);
items.add(switch2);
function = new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF);
State state = function.calculate(items);
State decimalState = function.getStateAs(items, DecimalType.class);
Assert.assertEquals(OnOffType.ON, state);
Assert.assertEquals(new DecimalType("2"), decimalState);
}
示例13: validateItemType
import org.openhab.core.library.items.SwitchItem; //导入依赖的package包/类
/**
* @{inheritDoc
*/
@Override
public void validateItemType(Item item, String bindingConfig)
throws BindingConfigParseException {
if (!(item instanceof SwitchItem
|| item instanceof NumberItem
|| item instanceof DimmerItem
|| item instanceof RollershutterItem
|| item instanceof StringItem)) {
throw new BindingConfigParseException(
"item '"
+ item.getName()
+ "' is of type '"
+ item.getClass().getSimpleName()
+ "', only SwitchItem, NumberItem, DimmerItem, RollershutterItem and StringItem are allowed - please check your *.items configuration");
}
}
示例14: createState
import org.openhab.core.library.items.SwitchItem; //导入依赖的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);
}
}
示例15: handleNewCall
import org.openhab.core.library.items.SwitchItem; //导入依赖的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);
}
}