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);
}
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);
}
}
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);
}
}
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;
}
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();
}
}
Aggregations