当前位置: 首页>>代码示例>>Java>>正文


Java DimmerItem类代码示例

本文整理汇总了Java中org.openhab.core.library.items.DimmerItem的典型用法代码示例。如果您正苦于以下问题:Java DimmerItem类的具体用法?Java DimmerItem怎么用?Java DimmerItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DimmerItem类属于org.openhab.core.library.items包,在下文中一共展示了DimmerItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapToState

import org.openhab.core.library.items.DimmerItem; //导入依赖的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);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:RRD4jService.java

示例2: validateItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的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");
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:21,代码来源:FS20GenericBindingProvider.java

示例3: validateItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的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");

	}

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:18,代码来源:IhcGenericBindingProvider.java

示例4: createState

import org.openhab.core.library.items.DimmerItem; //导入依赖的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);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:Enigma2Binding.java

示例5: mapCommandToItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的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;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:PulseaudioBinding.java

示例6: validateItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的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");
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:SamsungTvGenericBindingProvider.java

示例7: testOrFunction_differntTypes

import org.openhab.core.library.items.DimmerItem; //导入依赖的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);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:24,代码来源:ArithmeticGroupFunctionTest.java

示例8: storeData

import org.openhab.core.library.items.DimmerItem; //导入依赖的package包/类
@BeforeClass
public static void storeData() throws InterruptedException {
    DimmerItem item = (DimmerItem) items.get(name);

    item.setState(state1);

    beforeStore = new Date();
    Thread.sleep(10);
    service.store(item);
    afterStore1 = new Date();
    Thread.sleep(10);
    item.setState(state2);
    service.store(item);
    Thread.sleep(10);
    afterStore2 = new Date();

    logger.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
            AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:20,代码来源:DimmerItemIntegrationTest.java

示例9: mapToState

import org.openhab.core.library.items.DimmerItem; //导入依赖的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;
            } else if (item instanceof DimmerItem || item instanceof RollershutterItem) {
                // make sure Items that need PercentTypes instead of
                // DecimalTypes
                // do receive the right information
                return new PercentType((int) Math.round(value * 100));
            }
        } catch (ItemNotFoundException e) {
            logger.debug("Could not find item '{}' in registry", itemName);
        }
    }
    // just return a DecimalType as a fallback
    return new DecimalType(value);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:22,代码来源:RRD4jService.java

示例10: createState

import org.openhab.core.library.items.DimmerItem; //导入依赖的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);
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:17,代码来源:Enigma2Binding.java

示例11: updateItemPWM

import org.openhab.core.library.items.DimmerItem; //导入依赖的package包/类
public void updateItemPWM(String itemName, String couplerName, int module, int values[]) {
    for (WagoBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            WagoBindingConfig conf = provider.getConfig(itemName);
            if (conf.couplerName.equals(couplerName) && conf.module == module) {
                State currentState = conf.getItemState();
                State newState;
                if (conf.getItem() instanceof DimmerItem) {
                    newState = new PercentType((int) ((float) values[conf.channel] / 1023 * 100));
                } else if (conf.getItem() instanceof SwitchItem) {
                    if (values[conf.channel] == 0) {
                        newState = OnOffType.OFF;
                    } else {
                        newState = OnOffType.ON;
                    }
                } else {
                    logger.debug("Unsupported Itemtype");
                    return;
                }
                if (!newState.equals(currentState)) {
                    eventPublisher.postUpdate(itemName, newState);
                }
            }
        }
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:27,代码来源:WagoBinding.java

示例12: mapCommandToItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的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;
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:PulseaudioBinding.java

示例13: testRegisterWriteIncreaseWithRead2

import org.openhab.core.library.items.DimmerItem; //导入依赖的package包/类
@Test
public void testRegisterWriteIncreaseWithRead2() throws BindingConfigParseException {
    // Read index 1 (value=10) and index 0 (value=9).
    // INCREASE command increments last read value (9) by one -> 10. Written to index 0
    provider.processBindingConfiguration("test.items", new DimmerItem("Item1"),
            String.format(">[%1$s:0],<[%1$s:1],<[%1$s:0]", SLAVE_NAME));
    binding.execute(); // read
    verify(eventPublisher).postUpdate("Item1", new DecimalType(10));
    verify(eventPublisher).postUpdate("Item1", new DecimalType(9));
    verifyNoMoreInteractions(eventPublisher);

    binding.receiveCommand("Item1", IncreaseDecreaseType.INCREASE);
    // Binding cannot execute the command since there is no polled value
    // -> no change in registers
    assertThat(spi.getRegister(0).getValue(), is(equalTo(10)));
    assertThat(spi.getRegister(1).getValue(), is(equalTo(10)));
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:WriteRegisterExtendedItemConfigurationTestCase.java

示例14: testRegisterWriteIncreaseWithRead3

import org.openhab.core.library.items.DimmerItem; //导入依赖的package包/类
@Test
public void testRegisterWriteIncreaseWithRead3() throws BindingConfigParseException {
    // same as testRegisterWriteIncreaseWithRead2 but order of read connections is flipped
    provider.processBindingConfiguration("test.items", new DimmerItem("Item1"),
            String.format(">[%1$s:0],<[%1$s:0],<[%1$s:1]", SLAVE_NAME));
    binding.execute(); // read
    verify(eventPublisher).postUpdate("Item1", new DecimalType(10));
    verify(eventPublisher).postUpdate("Item1", new DecimalType(9));
    verifyNoMoreInteractions(eventPublisher);

    binding.receiveCommand("Item1", IncreaseDecreaseType.INCREASE);
    // Binding cannot execute the command since there is no polled value
    // -> no change in registers
    assertThat(spi.getRegister(0).getValue(), is(equalTo(11)));
    assertThat(spi.getRegister(1).getValue(), is(equalTo(10)));
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:17,代码来源:WriteRegisterExtendedItemConfigurationTestCase.java

示例15: validateItemType

import org.openhab.core.library.items.DimmerItem; //导入依赖的package包/类
/**
 * @{inheritDoc
 */
@Override
public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
    logger.debug("validating item '{}' against config '{}'", item, bindingConfig);

    if (item instanceof SwitchItem) {
        ; // OK, nothing to validate
    } else if (item instanceof ContactItem) {
        ; // OK, nothing to validate
    } else if (item instanceof NumberItem) {
        ; // OK, nothing to validate
    } else if (item instanceof RollershutterItem) {
        ; // OK, nothing to validate
    } else if (item instanceof DimmerItem) {
        ; // OK, nothing to validate
    } else {
        throw new BindingConfigParseException(
                "item '" + item.getName() + "' is of type '" + item.getClass().getSimpleName()
                        + " - not yet implemented, please check your *.items configuration");
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:24,代码来源:SappGenericBindingProvider.java


注:本文中的org.openhab.core.library.items.DimmerItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。