Search in sources :

Example 1 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class LaMetricTimeHandler method setAppChannelStateDescription.

private void setAppChannelStateDescription() {
    List<StateOption> options = new ArrayList<>();
    for (Application app : getApps().values()) {
        for (Widget widget : app.getWidgets().values()) {
            options.add(new StateOption(new WidgetRef(widget.getPackageName(), widget.getId()).toString(), LaMetricTimeUtil.getAppLabel(app, widget)));
        }
    }
    stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), LaMetricTimeBindingConstants.CHANNEL_APP), options);
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) ArrayList(java.util.ArrayList) Widget(org.openhab.binding.lametrictime.api.local.model.Widget) WidgetRef(org.openhab.binding.lametrictime.internal.WidgetRef) Application(org.openhab.binding.lametrictime.api.local.model.Application) StateOption(org.openhab.core.types.StateOption)

Example 2 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class VehicleChannelHandler method updateCheckControls.

protected void updateCheckControls(List<CCMMessage> ccl) {
    if (ccl.isEmpty()) {
        // No Check Control available - show not active
        CCMMessage ccm = new CCMMessage();
        ccm.ccmDescriptionLong = Constants.NO_ENTRIES;
        ccm.ccmDescriptionShort = Constants.NO_ENTRIES;
        ccm.ccmId = -1;
        ccm.ccmMileage = -1;
        ccl.add(ccm);
    }
    // add all elements to options
    checkControlList = ccl;
    List<StateOption> ccmDescriptionOptions = new ArrayList<>();
    List<StateOption> ccmDetailsOptions = new ArrayList<>();
    List<StateOption> ccmMileageOptions = new ArrayList<>();
    boolean isSelectedElementIn = false;
    int index = 0;
    for (CCMMessage ccEntry : checkControlList) {
        ccmDescriptionOptions.add(new StateOption(Integer.toString(index), ccEntry.ccmDescriptionShort));
        ccmDetailsOptions.add(new StateOption(Integer.toString(index), ccEntry.ccmDescriptionLong));
        ccmMileageOptions.add(new StateOption(Integer.toString(index), Integer.toString(ccEntry.ccmMileage)));
        if (selectedCC.equals(ccEntry.ccmDescriptionShort)) {
            isSelectedElementIn = true;
        }
        index++;
    }
    setOptions(CHANNEL_GROUP_CHECK_CONTROL, NAME, ccmDescriptionOptions);
    setOptions(CHANNEL_GROUP_CHECK_CONTROL, DETAILS, ccmDetailsOptions);
    setOptions(CHANNEL_GROUP_CHECK_CONTROL, MILEAGE, ccmMileageOptions);
    // if current selected item isn't anymore in the list select first entry
    if (!isSelectedElementIn) {
        selectCheckControl(0);
    }
}
Also used : CCMMessage(org.openhab.binding.bmwconnecteddrive.internal.dto.status.CCMMessage) ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption)

Example 3 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class VehicleChannelHandler method updateDestinations.

protected void updateDestinations(List<Destination> dl) {
    // if list is empty add "undefined" element
    if (dl.isEmpty()) {
        Destination dest = new Destination();
        dest.city = Constants.NO_ENTRIES;
        dest.lat = -1;
        dest.lon = -1;
        dl.add(dest);
    }
    // add all elements to options
    destinationList = dl;
    List<StateOption> destinationNameOptions = new ArrayList<>();
    List<StateOption> destinationGPSOptions = new ArrayList<>();
    boolean isSelectedElementIn = false;
    int index = 0;
    for (Destination destination : destinationList) {
        destinationNameOptions.add(new StateOption(Integer.toString(index), destination.getAddress()));
        destinationGPSOptions.add(new StateOption(Integer.toString(index), destination.getCoordinates()));
        if (selectedDestination.equals(destination.getAddress())) {
            isSelectedElementIn = true;
        }
        index++;
    }
    setOptions(CHANNEL_GROUP_DESTINATION, NAME, destinationNameOptions);
    setOptions(CHANNEL_GROUP_DESTINATION, GPS, destinationGPSOptions);
    // if current selected item isn't anymore in the list select first entry
    if (!isSelectedElementIn) {
        selectDestination(0);
    }
}
Also used : Destination(org.openhab.binding.bmwconnecteddrive.internal.dto.Destination) ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption)

Example 4 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class DsChannelTypeProvider method getStageDescription.

private StateDescriptionFragment getStageDescription(String channelID, Locale locale) {
    if (channelID.contains(STAGE.toLowerCase())) {
        List<StateOption> stateOptions = new ArrayList<>();
        if (channelID.contains(LIGHT)) {
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON), locale)));
            if (channelID.contains("3")) {
                stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON, getText(getStageChannelOption(LIGHT, DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON), locale)));
            }
        } else {
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_OFF), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_BOTH_ON), locale)));
            stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_FIRST_ON), locale)));
            if (channelID.contains("3")) {
                stateOptions.add(new StateOption(DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON, getText(getStageChannelOption(GENERAL, DigitalSTROMBindingConstants.OPTION_COMBINED_SECOND_ON), locale)));
            }
        }
        return StateDescriptionFragmentBuilder.create().withReadOnly(false).withOptions(stateOptions).build();
    }
    if (channelID.contains(TEMPERATURE_CONTROLLED)) {
        return StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(0)).withMaximum(new BigDecimal(50)).withStep(new BigDecimal(0.1)).withPattern("%.1f °C").withReadOnly(false).build();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption) BigDecimal(java.math.BigDecimal)

Example 5 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class HomeConnectHoodHandler method updateSelectedProgramStateDescription.

@Override
protected void updateSelectedProgramStateDescription() {
    // update hood program actions
    if (isBridgeOffline() || !isThingAccessibleViaServerSentEvents()) {
        return;
    }
    Optional<HomeConnectApiClient> apiClient = getApiClient();
    if (apiClient.isPresent()) {
        try {
            ArrayList<StateOption> stateOptions = new ArrayList<>();
            getPrograms().forEach(availableProgram -> {
                if (PROGRAM_HOOD_AUTOMATIC.equals(availableProgram.getKey())) {
                    stateOptions.add(new StateOption(COMMAND_AUTOMATIC, mapStringType(availableProgram.getKey())));
                } else if (PROGRAM_HOOD_DELAYED_SHUT_OFF.equals(availableProgram.getKey())) {
                    stateOptions.add(new StateOption(COMMAND_DELAYED_SHUT_OFF, mapStringType(availableProgram.getKey())));
                } else if (PROGRAM_HOOD_VENTING.equals(availableProgram.getKey())) {
                    try {
                        List<AvailableProgramOption> availableProgramOptions = apiClient.get().getProgramOptions(getThingHaId(), PROGRAM_HOOD_VENTING);
                        if (availableProgramOptions == null || availableProgramOptions.isEmpty()) {
                            throw new CommunicationException("Program " + PROGRAM_HOOD_VENTING + " is unsupported");
                        }
                        availableProgramOptions.forEach(option -> {
                            if (OPTION_HOOD_VENTING_LEVEL.equalsIgnoreCase(option.getKey())) {
                                option.getAllowedValues().stream().filter(s -> !STAGE_FAN_OFF.equalsIgnoreCase(s)).forEach(s -> stateOptions.add(createVentingStateOption(s)));
                            } else if (OPTION_HOOD_INTENSIVE_LEVEL.equalsIgnoreCase(option.getKey())) {
                                option.getAllowedValues().stream().filter(s -> !STAGE_INTENSIVE_STAGE_OFF.equalsIgnoreCase(s)).forEach(s -> stateOptions.add(createVentingStateOption(s)));
                            }
                        });
                    } catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) {
                        logger.warn("Could not fetch hood program options. error={}", e.getMessage());
                        stateOptions.add(createVentingStateOption(STAGE_FAN_STAGE_01));
                        stateOptions.add(createVentingStateOption(STAGE_FAN_STAGE_02));
                        stateOptions.add(createVentingStateOption(STAGE_FAN_STAGE_03));
                        stateOptions.add(createVentingStateOption(STAGE_FAN_STAGE_04));
                        stateOptions.add(createVentingStateOption(STAGE_FAN_STAGE_05));
                        stateOptions.add(createVentingStateOption(STAGE_INTENSIVE_STAGE_1));
                        stateOptions.add(createVentingStateOption(STAGE_INTENSIVE_STAGE_2));
                    }
                }
            });
            stateOptions.add(new StateOption(COMMAND_STOP, "Stop"));
            getThingChannel(CHANNEL_HOOD_ACTIONS_STATE).ifPresent(channel -> getDynamicStateDescriptionProvider().setStateOptions(channel.getUID(), stateOptions));
        } catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) {
            logger.debug("Could not fetch available programs. thing={}, haId={}, error={}", getThingLabel(), getThingHaId(), e.getMessage());
            removeSelectedProgramStateDescription();
        }
    } else {
        removeSelectedProgramStateDescription();
    }
}
Also used : AvailableProgramOption(org.openhab.binding.homeconnect.internal.client.model.AvailableProgramOption) StringType(org.openhab.core.library.types.StringType) AuthorizationException(org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) ArrayList(java.util.ArrayList) Thing(org.openhab.core.thing.Thing) Map(java.util.Map) ChannelUID(org.openhab.core.thing.ChannelUID) Data(org.openhab.binding.homeconnect.internal.client.model.Data) CommunicationException(org.openhab.binding.homeconnect.internal.client.exception.CommunicationException) ApplianceOfflineException(org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflineException) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) HomeConnectApiClient(org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) AvailableProgramOption(org.openhab.binding.homeconnect.internal.client.model.AvailableProgramOption) UnDefType(org.openhab.core.types.UnDefType) StateOption(org.openhab.core.types.StateOption) HomeConnectBindingConstants(org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants) String.format(java.lang.String.format) List(java.util.List) PercentType(org.openhab.core.library.types.PercentType) Optional(java.util.Optional) HomeConnectDynamicStateDescriptionProvider(org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider) HomeConnectApiClient(org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient) CommunicationException(org.openhab.binding.homeconnect.internal.client.exception.CommunicationException) AuthorizationException(org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException) ArrayList(java.util.ArrayList) ApplianceOfflineException(org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflineException) StateOption(org.openhab.core.types.StateOption)

Aggregations

StateOption (org.openhab.core.types.StateOption)109 ArrayList (java.util.ArrayList)68 ChannelUID (org.openhab.core.thing.ChannelUID)45 BigDecimal (java.math.BigDecimal)22 Test (org.junit.jupiter.api.Test)20 List (java.util.List)17 Nullable (org.eclipse.jdt.annotation.Nullable)17 Channel (org.openhab.core.thing.Channel)17 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)16 StateDescription (org.openhab.core.types.StateDescription)16 StringType (org.openhab.core.library.types.StringType)14 StateDescriptionFragmentBuilder (org.openhab.core.types.StateDescriptionFragmentBuilder)13 Map (java.util.Map)11 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)11 StateDescriptionFragment (org.openhab.core.types.StateDescriptionFragment)11 Thing (org.openhab.core.thing.Thing)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Collectors (java.util.stream.Collectors)9 OnOffType (org.openhab.core.library.types.OnOffType)8