use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class Area method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String str = "";
switch(config.getObjectType()) {
case AREA_ENTRY_TIMER:
setting = properties.getEntryTimer();
break;
case AREA_EXIT_TIMER:
setting = properties.getExitTimer();
break;
case AREA_STATUS_ENTRY_DELAY:
setting = properties.getEntryDelay();
break;
case AREA_STATUS_EXIT_DELAY:
setting = properties.getExitDelay();
break;
case AREA_STATUS_MODE:
setting = properties.getMode();
str = omni ? (setting < omniText.length ? omniText[setting] : "Unknown") : (setting < luminaText.length ? luminaText[setting] : "Unknown");
break;
case AREA_STATUS_ALARM:
setting = properties.getAlarms();
for (int i = 0; i < alarms.length; i++) {
if (((setting >> i) & 1) > 0) {
if (str.length() > 0) {
str += " | ";
}
str += alarms[i];
}
}
break;
default:
break;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(str));
}
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class Thermostat method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String mode = null;
switch(config.getObjectType()) {
case THERMO_COOL_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getCoolSetpoint()) : MessageUtils.omniToF(properties.getCoolSetpoint());
break;
case THERMO_TEMP:
setting = celsius ? MessageUtils.omniToC(properties.getTemperature()) : MessageUtils.omniToF(properties.getTemperature());
break;
case THERMO_HEAT_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getHeatSetpoint()) : MessageUtils.omniToF(properties.getHeatSetpoint());
break;
case THERMO_FAN_MODE:
setting = properties.isFan() ? 1 : 0;
break;
case THERMO_HOLD_MODE:
setting = properties.isHold() ? 1 : 0;
break;
case THERMO_SYSTEM_MODE:
setting = properties.getMode();
if (setting < MODES.length) {
mode = MODES[setting];
}
break;
default:
return;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof SwitchItem) {
publisher.postUpdate(item.getName(), setting > 0 ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof StringItem && mode != null) {
publisher.postUpdate(item.getName(), new StringType(mode));
}
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class OneWireBindingConfigFactory method createOneWireDeviceProperty.
/**
* @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: {} - bindingConfig:{}", pvItem.getName(), pvBindingConfig);
OneWireBindingConfig lvNewBindingConfig = null;
if (OneWireClearCacheControlBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
lvNewBindingConfig = new OneWireClearCacheControlBindingConfig(pvBindingConfig);
} else if (OneWireDevicePropertyPushButtonBindingConfig.isBindingConfigToCreate(pvItem, pvBindingConfig)) {
lvNewBindingConfig = new OneWireDevicePropertyPushButtonBindingConfig(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;
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class WindowHandleTest method setUpDefaultDevice.
@Before
public void setUpDefaultDevice() {
parameterAddress = new EnoceanParameterAddress(EnoceanId.fromString(EnoceanBindingProviderMock.DEVICE_ID));
provider.setParameterAddress(parameterAddress);
provider.setItem(new StringItem("dummie"));
provider.setEep(EEPId.EEP_F6_10_00);
binding.addBindingProvider(provider);
}
use of org.openhab.core.library.items.StringItem in project openhab1-addons by openhab.
the class KM200Comm method sendProvidersState.
/**
* This function sets the state of a service on the device
*
*/
public byte[] sendProvidersState(KM200BindingProvider provider, String item, Command command) {
synchronized (device) {
String type = null;
String dataToSend = null;
KM200CommObject object = null;
Class<? extends Item> itemType = provider.getItemType(item);
String service = checkParameterReplacement(provider, item);
logger.debug("Prepare item for send: {} type: {} item: {}", service, type, itemType.getName());
if (device.blacklistMap.contains(service)) {
logger.debug("Service on blacklist: {}", service);
return null;
}
if (device.serviceMap.containsKey(service)) {
if (device.serviceMap.get(service).getWriteable() == 0) {
logger.error("Service is listed as read-only: {}", service);
return null;
}
object = device.serviceMap.get(service);
type = object.getServiceType();
} else {
logger.error("Service is not in the determined device service list: {}", service);
return null;
}
/* The service is availible, set now the values depeding on the item and binding type */
logger.debug("state of: {} type: {}", command, type);
/* Binding is a NumberItem */
if (itemType.isAssignableFrom(NumberItem.class)) {
BigDecimal bdVal = ((DecimalType) command).toBigDecimal();
/* Check the capabilities of this service */
if (object.getValueParameter() != null) {
@SuppressWarnings("unchecked") List<BigDecimal> valParas = (List<BigDecimal>) object.getValueParameter();
BigDecimal minVal = valParas.get(0);
BigDecimal maxVal = valParas.get(1);
if (bdVal.compareTo(minVal) < 0) {
bdVal = minVal;
}
if (bdVal.compareTo(maxVal) > 0) {
bdVal = maxVal;
}
}
if (type.equals("floatValue")) {
dataToSend = new JSONObject().put("value", bdVal).toString();
} else if (type.equals("stringValue")) {
dataToSend = new JSONObject().put("value", bdVal.toString()).toString();
} else if (type.equals("switchProgram") && object.getVirtual() == 1) {
/* A switchProgram as NumberItem is always virtual */
dataToSend = sendVirtualState(object, itemType, service, command);
} else if (type.equals("errorList") && object.getVirtual() == 1) {
/* A errorList as NumberItem is always virtual */
dataToSend = sendVirtualState(object, itemType, service, command);
} else {
logger.warn("Not supported type for numberItem: {}", type);
}
/* Binding is a StringItem */
} else if (itemType.isAssignableFrom(StringItem.class)) {
String val = ((StringType) command).toString();
/* Check the capabilities of this service */
if (object.getValueParameter() != null) {
@SuppressWarnings("unchecked") List<String> valParas = (List<String>) object.getValueParameter();
if (!valParas.contains(val)) {
logger.warn("Parameter is not in the service parameterlist: {}", val);
return null;
}
}
if (type.equals("stringValue")) {
dataToSend = new JSONObject().put("value", val).toString();
} else if (type.equals("floatValue")) {
dataToSend = new JSONObject().put("value", Float.parseFloat(val)).toString();
} else if (type.equals("switchProgram")) {
if (object.getVirtual() == 1) {
dataToSend = sendVirtualState(object, itemType, service, command);
} else {
/* The JSONArray of switch items can be sended directly */
try {
/* Check whether ths input string is a valid JSONArray */
JSONArray userArray = new JSONArray(val);
dataToSend = userArray.toString();
} catch (Exception e) {
logger.warn("The input for the switchProgram is not a valid JSONArray : {}", e.getMessage());
return null;
}
}
} else {
logger.warn("Not supported type for stringItem: {}", type);
}
/* Binding is a DateTimeItem */
} else if (itemType.isAssignableFrom(DateTimeItem.class)) {
String val = ((DateTimeType) command).toString();
if (type.equals("stringValue")) {
dataToSend = new JSONObject().put("value", val).toString();
} else if (type.equals("switchProgram")) {
dataToSend = sendVirtualState(object, itemType, service, command);
} else {
logger.warn("Not supported type for dateTimeItem: {}", type);
}
/* Binding is a SwitchItem */
} else if (itemType.isAssignableFrom(SwitchItem.class)) {
String val = null;
if (provider.getParameter(item).containsKey("on")) {
if (command == OnOffType.OFF) {
val = provider.getParameter(item).get("off");
} else if (command == OnOffType.ON) {
val = provider.getParameter(item).get("on");
}
} else {
logger.warn("Switch-Item only on configured on/off string values {}", command);
return null;
}
if (type.equals("stringValue")) {
dataToSend = new JSONObject().put("value", val).toString();
} else {
logger.warn("Not supported type for SwitchItem:{}", type);
}
} else {
logger.warn("Bindingtype not supported: {}", itemType.getClass());
return null;
}
/* If some data is availible then we have to send it to device */
if (dataToSend != null) {
/* base64 + encoding */
logger.debug("Encoding: {}", dataToSend);
byte[] encData = encodeMessage(dataToSend);
if (encData == null) {
logger.error("Couldn't encrypt data");
return null;
}
return encData;
} else {
return null;
}
}
}
Aggregations