Search in sources :

Example 31 with SwitchItem

use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.

the class NikobusGenericBindingProviderTest method parseButtonWithRefresh.

private void parseButtonWithRefresh(String name, String config, Button.PressType type, String address, String[] groups) throws BindingConfigParseException {
    Item item = new SwitchItem(name);
    provider.processBindingConfiguration("context", item, config);
    Button button = (Button) provider.getItemConfig(name);
    assertEquals(name, button.getName());
    assertEquals(address, button.getAddress());
    assertEquals(type, button.getType());
    String[] modules = (String[]) Whitebox.getInternalState(button, "impactedModules");
    assertEquals(groups.length, modules.length);
    for (int i = 0; i < groups.length; i++) {
        assertEquals(groups[i], modules[i]);
    }
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) Button(org.openhab.binding.nikobus.internal.config.Button) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 32 with SwitchItem

use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.

the class NikobusGenericBindingProviderTest method parseButton.

private void parseButton(String name, String config, Button.PressType type, String address) throws BindingConfigParseException {
    Item item = new SwitchItem(name);
    provider.processBindingConfiguration("context", item, config);
    Button button = (Button) provider.getItemConfig(name);
    assertEquals(name, button.getName());
    assertEquals(address, button.getAddress());
    assertEquals(type, button.getType());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) Button(org.openhab.binding.nikobus.internal.config.Button) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 33 with SwitchItem

use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.

the class AudioZone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int num = 0;
    String str = "";
    int source = new Integer(properties.getSource());
    switch(config.getObjectType()) {
        case AUDIOZONE_MUTE:
            num = properties.isMute() ? 1 : 0;
            break;
        case AUDIOZONE_POWER:
            num = properties.isOn() ? 1 : 0;
            break;
        case AUDIOZONE_SOURCE:
            num = properties.getSource();
            break;
        case AUDIOZONE_VOLUME:
            num = properties.getVolume();
            break;
        case AUDIOZONE_TEXT:
            if (sourceValid(source)) {
                str = audioSources.get(source).formatAudioText();
            }
            break;
        case AUDIOZONE_TEXT_FIELD1:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(0);
            }
            break;
        case AUDIOZONE_TEXT_FIELD2:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(1);
            }
            break;
        case AUDIOZONE_TEXT_FIELD3:
            if (sourceValid(source)) {
                str = audioSources.get(source).getAudioText(2);
            }
            break;
        case AUDIOZONE_KEY:
            num = -1;
            break;
        default:
            return;
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", num);
        publisher.postUpdate(item.getName(), new PercentType(num));
    } else if (item instanceof NumberItem) {
        logger.debug("updating number type {}", num);
        publisher.postUpdate(item.getName(), new DecimalType(num));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", num > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), num > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", str);
        publisher.postUpdate(item.getName(), new StringType(str));
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 34 with SwitchItem

use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.

the class DigitalSTROMBinding method updateItemState.

private void updateItemState(Item item) {
    if (item != null) {
        Device device = deviceMap.get(item.getName());
        if (device != null) {
            State state = null;
            if (item instanceof DimmerItem) {
                state = new PercentType(getPercent(device.getMaxOutPutValue(), device.getOutputValue()));
            } else if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
                state = device.getOutputValue() > 0 ? OnOffType.ON : OnOffType.OFF;
            } else if (item instanceof NumberItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            } else if (item instanceof RollershutterItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.context != null && confItem.context.equals(ContextConfig.slat)) {
                        int output = getPercent(device.getMaxSlatPosition(), device.getSlatPosition());
                        state = new PercentType(100 - output);
                    } else if (confItem.context != null && confItem.context.equals(ContextConfig.awning)) {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(output);
                    } else {
                        int output = getPercent(device.getMaxOutPutValue(), device.getOutputValue());
                        state = new PercentType(100 - output);
                    }
                }
            } else if (item instanceof StringItem) {
                DigitalSTROMBindingConfig confItem = getConfigForItemName(item.getName());
                if (confItem != null) {
                    if (confItem.sensor != null) {
                        int value = -1;
                        switch(confItem.sensor) {
                            case TEMPERATURE_INDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_INDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            case TEMPERATURE_OUTDOORS:
                                value = device.getTemperatureSensorValue();
                                if (value != -1) {
                                    // Celsius
                                    // TODO use resolution
                                    state = new DecimalType((double) (value) / 40 - 43.15);
                                // from sensor
                                }
                                break;
                            case RELATIVE_HUMIDITY_OUTDOORS:
                                value = device.getHumiditySensorValue();
                                if (value != -1) {
                                    // Percent
                                    // TODO use resolution from
                                    state = new DecimalType((double) (value) / 40);
                                // sensor
                                }
                                break;
                            default:
                                break;
                        }
                    } else if (confItem.consumption != null) {
                        int value = -1;
                        switch(confItem.consumption) {
                            case ACTIVE_POWER:
                                value = device.getPowerConsumption();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            case OUTPUT_CURRENT:
                                value = device.getEnergyMeterValue();
                                if (value != -1) {
                                    state = new DecimalType(value);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            eventPublisher.postUpdate(item.getName(), state);
        } else {
            logger.error("couldn't update item state, because device is null: " + item.getName());
        }
    } else {
        logger.error("couldn't update item state, because item is null");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Device(org.openhab.binding.digitalstrom.internal.client.entity.Device) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DigitalSTROMBindingConfig(org.openhab.binding.digitalstrom.internal.config.DigitalSTROMBindingConfig) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 35 with SwitchItem

use of org.openhab.core.library.items.SwitchItem in project openhab1-addons by openhab.

the class HueGenericBindingProvider method processBindingConfiguration.

@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    try {
        if (bindingConfig != null) {
            String[] configParts = bindingConfig.split(";");
            if (item instanceof ColorItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], BindingType.rgb.name(), null);
                addBindingConfig(item, hueBindingConfig);
            } else if (item instanceof DimmerItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], configParts.length < 2 ? null : configParts[1], configParts.length < 3 ? null : configParts[2]);
                addBindingConfig(item, hueBindingConfig);
            } else if (item instanceof SwitchItem) {
                BindingConfig hueBindingConfig = new HueBindingConfig(configParts[0], BindingType.switching.name(), null);
                addBindingConfig(item, hueBindingConfig);
            }
        } else {
            logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.warn("bindingConfig is invalid (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : BindingConfig(org.openhab.core.binding.BindingConfig) DimmerItem(org.openhab.core.library.items.DimmerItem) ColorItem(org.openhab.core.library.items.ColorItem) 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