本文整理汇总了Java中org.openhab.core.library.items.NumberItem类的典型用法代码示例。如果您正苦于以下问题:Java NumberItem类的具体用法?Java NumberItem怎么用?Java NumberItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberItem类属于org.openhab.core.library.items包,在下文中一共展示了NumberItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createState
import org.openhab.core.library.items.NumberItem; //导入依赖的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);
}
}
示例2: createState
import org.openhab.core.library.items.NumberItem; //导入依赖的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 if (itemType.isAssignableFrom(DateTimeItem.class)) {
return DateTimeType.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);
}
}
示例3: validateItemType
import org.openhab.core.library.items.NumberItem; //导入依赖的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");
}
}
示例4: createState
import org.openhab.core.library.items.NumberItem; //导入依赖的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);
}
}
示例5: getIcon
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getIcon(String itemName) {
for(ItemUIProvider provider : itemUIProviders) {
String currentIcon = provider.getIcon(itemName);
if(currentIcon!=null) {
return currentIcon;
}
}
// do some reasonable default, if no provider had an answer
// try to get the item type from the item name
Class<? extends Item> itemType = getItemType(itemName);
if(itemType==null) return null;
// we handle items here that have no specific widget,
// e.g. the default widget of a rollerblind is "Switch".
// We want to provide a dedicated default icon for it
// like "rollerblind".
if (itemType.equals(NumberItem.class) ||
itemType.equals(ContactItem.class) ||
itemType.equals(RollershutterItem.class)) {
return itemType.getSimpleName().replace("Item", "").toLowerCase();
}
return null;
}
示例6: updateMessageWaitingItem
import org.openhab.core.library.items.NumberItem; //导入依赖的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());
}
}
示例7: testExecute
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
@Test
@Ignore("needs real client credentials")
public void testExecute() throws Exception {
final Dictionary<String, String> config = new Hashtable<String, String>();
config.put(NetatmoBinding.CONFIG_CLIENT_ID, CLIENT_ID);
config.put(NetatmoBinding.CONFIG_CLIENT_SECRET, CLIENT_SECRET);
config.put(NetatmoBinding.CONFIG_REFRESH_TOKEN, REFRESH_TOKEN);
final NetatmoBinding binding = new NetatmoBinding();
binding.updated(config);
final NetatmoGenericBindingProvider provider = new NetatmoGenericBindingProvider();
provider.processBindingConfiguration("netatmo.items", new NumberItem(
"Netatmo_OfficeInParis_Bosssoffice_Temperature"),
"70:ee:50:00:02:20#Temperature");
provider.processBindingConfiguration("netatmo.items", new NumberItem(
"Netatmo_OfficeInParis_NetatmoHQ_Temperature"),
"70:ee:50:00:02:20#02:00:00:00:02:a0#Temperature");
provider.processBindingConfiguration("netatmo.items", new NumberItem(
"Netatmo_OfficeInParis_NetatmoHQ_Humidity"),
"70:ee:50:00:02:20#02:00:00:00:02:a0#Humidity");
binding.addBindingProvider(provider);
binding.execute();
}
示例8: createOneWireDeviceProperty
import org.openhab.core.library.items.NumberItem; //导入依赖的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;
}
示例9: mapCommandToItemType
import org.openhab.core.library.items.NumberItem; //导入依赖的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;
}
}
示例10: validateItemType
import org.openhab.core.library.items.NumberItem; //导入依赖的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");
}
}
示例11: createState
import org.openhab.core.library.items.NumberItem; //导入依赖的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);
}
}
示例12: resolveDataTypeFromItemType
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
SimaticTypes resolveDataTypeFromItemType(Item item, String address) throws BindingConfigParseException {
Class<? extends Item> itemType = item.getClass();
if (itemType.isAssignableFrom(NumberItem.class)) {
switch (SimaticPLCAddress.create(address).dataType) {
case DWORD:
return SimaticTypes.DWORD;
case WORD:
return SimaticTypes.WORD;
default:
return SimaticTypes.BYTE;
}
} else if (itemType.isAssignableFrom(SwitchItem.class)) {
return SimaticTypes.BYTE;
} else if (itemType.isAssignableFrom(DimmerItem.class)) {
return SimaticTypes.BYTE;
} else if (itemType.isAssignableFrom(ColorItem.class)) {
logger.warn("Item %s has not specified datatype. Setted to RGB.", item.getName());
return SimaticTypes.RGB;
} else if (itemType.isAssignableFrom(StringItem.class)) {
logger.warn("Item %s has not specified datatype with length. Setted to ARRAY with length 32.",
item.getName());
return SimaticTypes.ARRAY;
} else if (itemType.isAssignableFrom(ContactItem.class)) {
return SimaticTypes.BYTE;
} else if (itemType.isAssignableFrom(RollershutterItem.class)) {
return SimaticTypes.WORD;
} else {
throw new BindingConfigParseException("Unsupported item type: " + item);
}
}
示例13: objectToState
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
/**
* Converts a value to a {@link State} which is suitable for the given {@link Item}. This is
* needed for querying a {@link HistoricState}.
*
* @param value to be converted to a {@link State}
* @param itemName name of the {@link Item} to get the {@link State} for
* @return the state of the item represented by the itemName parameter,
* else the string value of the Object parameter
*/
private State objectToState(Object value, String itemName) {
String valueStr = String.valueOf(value);
if (itemRegistry != null) {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof NumberItem) {
return new DecimalType(valueStr);
} else if (item instanceof ColorItem) {
return new HSBType(valueStr);
} else if (item instanceof DimmerItem) {
return new PercentType(valueStr);
} else if (item instanceof SwitchItem) {
return string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF)
? OnOffType.OFF
: OnOffType.ON;
} else if (item instanceof ContactItem) {
return (string2DigitalValue(valueStr).equals(DIGITAL_VALUE_OFF))
? OpenClosedType.CLOSED
: OpenClosedType.OPEN;
} else if (item instanceof RollershutterItem) {
return new PercentType(valueStr);
} else if (item instanceof DateTimeItem) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(new BigDecimal(valueStr).longValue());
return new DateTimeType(calendar);
} else {
return new StringType(valueStr);
}
} catch (ItemNotFoundException e) {
logger.warn("Could not find item '{}' in registry", itemName);
}
}
// just return a StringType as a fallback
return new StringType(valueStr);
}
示例14: addLine
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
/**
* Adds a line for the item to the graph definition.
* The color of the line is determined by the counter, it simply picks the according index from LINECOLORS (and rolls over if necessary).
*
* @param graphDef the graph definition to fill
* @param item the item to add a line for
* @param counter defines the number of the datasource and is used to determine the line color
*/
protected void addLine(RrdGraphDef graphDef, Item item, int counter) {
Color color = LINECOLORS[counter%LINECOLORS.length];
String label = itemUIRegistry.getLabel(item.getName());
String rrdName = RRD4jService.DB_FOLDER + File.separator + item.getName() + ".rrd";
ConsolFun consolFun;
if(label!=null && label.contains("[") && label.contains("]")) {
label = label.substring(0, label.indexOf('['));
}
try {
RrdDb db = new RrdDb(rrdName);
consolFun = db.getRrdDef().getArcDefs()[0].getConsolFun();
db.close();
} catch (IOException e) {
consolFun = ConsolFun.MAX;
}
if(item instanceof NumberItem) {
// we only draw a line
graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); //RRD4jService.getConsolidationFunction(item));
graphDef.line(Integer.toString(counter), color, label, 2);
} else {
// we draw a line and fill the area beneath it with a transparent color
graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); //RRD4jService.getConsolidationFunction(item));
Color areaColor = AREACOLORS[counter%LINECOLORS.length];
graphDef.area(Integer.toString(counter), areaColor);
graphDef.line(Integer.toString(counter), color, label, 2);
}
}
示例15: validateItemType
import org.openhab.core.library.items.NumberItem; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
@Override
public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
if (!(item instanceof NumberItem)) {
throw new BindingConfigParseException("item '" + item.getName() + "' is of type '"
+ item.getClass().getSimpleName()
+ "', only NumberItems are allowed - please check your *.items configuration");
}
}