Search in sources :

Example 21 with SwitchItem

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.");
        }
    }
}
Also used : BitSet(java.util.BitSet) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 22 with SwitchItem

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));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 23 with SwitchItem

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;
}
Also used : OneWireDevicePropertyPushButtonBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyPushButtonBindingConfig) OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchMinMaxNumberWarningBindingConfig) OneWireDevicePropertySwitchBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertySwitchBindingConfig) OneWireDevicePropertyStringBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyStringBindingConfig) ContactItem(org.openhab.core.library.items.ContactItem) OneWireClearCacheControlBindingConfig(org.openhab.binding.onewire.internal.control.OneWireClearCacheControlBindingConfig) StringItem(org.openhab.core.library.items.StringItem) OneWireDevicePropertyNumberBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyNumberBindingConfig) NumberItem(org.openhab.core.library.items.NumberItem) OneWireDevicePropertyContactBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyContactBindingConfig) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 24 with SwitchItem

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());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) ModuleChannel(org.openhab.binding.nikobus.internal.config.ModuleChannel) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 25 with SwitchItem

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();
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) ColorItem(org.openhab.core.library.items.ColorItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ContactItem(org.openhab.core.library.items.ContactItem) MSensor(org.openhab.binding.tinkerforge.internal.model.MSensor) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) SwitchSensor(org.openhab.binding.tinkerforge.internal.model.SwitchSensor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

SwitchItem (org.openhab.core.library.items.SwitchItem)55 NumberItem (org.openhab.core.library.items.NumberItem)25 DimmerItem (org.openhab.core.library.items.DimmerItem)21 Test (org.junit.Test)18 ContactItem (org.openhab.core.library.items.ContactItem)17 Item (org.openhab.core.items.Item)15 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 DecimalType (org.openhab.core.library.types.DecimalType)15 ColorItem (org.openhab.core.library.items.ColorItem)12 StringItem (org.openhab.core.library.items.StringItem)12 PercentType (org.openhab.core.library.types.PercentType)11 StringType (org.openhab.core.library.types.StringType)10 State (org.openhab.core.types.State)8 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)7 DateTimeType (org.openhab.core.library.types.DateTimeType)7 Calendar (java.util.Calendar)6 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)5 HSBType (org.openhab.core.library.types.HSBType)5 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)4