use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.
the class RPiRcSwitchGenericBindingProvider method processBindingConfiguration.
/*
* (non-Javadoc)
*
* @see org.openhab.model.item.binding.AbstractGenericBindingProvider#
* processBindingConfiguration(java.lang.String,
* org.openhab.core.items.Item, java.lang.String)
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (item instanceof SwitchItem) {
// Group address
String groupAddressString = StringUtils.substringBefore(bindingConfig, ":");
// Device address
String deviceAddressString = StringUtils.substringAfter(bindingConfig, ":");
if (deviceAddressString == null || deviceAddressString.isEmpty() || groupAddressString == null || groupAddressString.isEmpty()) {
LOGGER.error("The item configuration '" + bindingConfig + "' is invalid. Valid format is <group-address>:<device-address>.");
return;
}
// Store the configuration
try {
BitSet groupAddress = RCSwitch.getSwitchGroupAddress(groupAddressString);
int deviceAddress = Integer.parseInt(deviceAddressString);
RPiRcSwitchBindingConfig config = new RPiRcSwitchBindingConfig(groupAddress, deviceAddress);
this.addBindingConfig(item, config);
} catch (IndexOutOfBoundsException e) {
LOGGER.error("The group address '" + groupAddressString + "' is invalid. The group address must have 5 bits, e.g. 10101.");
} catch (NumberFormatException e) {
LOGGER.error("The device address '" + deviceAddressString + "' is invalid. The device address must be an Integer value, e.g. 4.");
}
}
}
use of org.openhab.core.library.items.SwitchItem 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.SwitchItem 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.SwitchItem in project openhab1-addons by openhab.
the class NikobusGenericBindingProviderTest method parseChannelConfig.
private void parseChannelConfig(String name, String config, String address, int channel) throws BindingConfigParseException {
Item item = new SwitchItem(name);
provider.processBindingConfiguration("context", item, config);
ModuleChannel c = (ModuleChannel) provider.getItemConfig(name);
assertEquals(name, c.getName());
assertEquals(address, c.getAddress());
}
use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.
the class TinkerforgeBinding method updateItemValues.
/**
* Triggers an update of state values for all devices.
*
* @param provider The {@code TinkerforgeBindingProvider} which is bound to the device as
* {@code Item}
* @param itemName The name of the {@code Item} as String
* @param only_poll_enabled Fetch only the values of devices which do not support callback
* listeners. These devices are marked with poll "true" flag.
*/
protected void updateItemValues(TinkerforgeBindingProvider provider, String itemName, boolean only_poll_enabled) {
if (tinkerforgeEcosystem == null) {
logger.warn("tinkerforge ecosystem not yet ready");
return;
}
String deviceUid = provider.getUid(itemName);
Item item = provider.getItem(itemName);
String deviceSubId = provider.getSubId(itemName);
String deviceName = provider.getName(itemName);
if (deviceName != null) {
String[] ids = getDeviceIdsForDeviceName(deviceName);
deviceUid = ids[0];
deviceSubId = ids[1];
}
MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
if (mDevice != null && mDevice.getEnabledA().get()) {
if (only_poll_enabled && !mDevice.isPoll()) {
// do nothing
logger.debug("{} omitting fetch value for no poll{}:{}", LoggerConstants.ITEMUPDATE, deviceUid, deviceSubId);
} else {
if (mDevice instanceof MSensor) {
((MSensor<?>) mDevice).fetchSensorValue();
} else if (mDevice instanceof SwitchSensor && item instanceof SwitchItem) {
((SwitchSensor) mDevice).fetchSwitchState();
} else if (mDevice instanceof DigitalActor) {
((DigitalActor) mDevice).fetchDigitalValue();
}
}
}
}
Aggregations