Skip to content

Commit

Permalink
[homeconnect] Undo PR 10754 (openhab#10792)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Luca Calcaterra <calcaterra.luca@gmail.com>
  • Loading branch information
lolodomo authored and lucacalcaterra committed Jul 26, 2021
1 parent 5b76843 commit cf2b110
Showing 1 changed file with 10 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ protected EventHandler updateRemoteControlActiveAndProgramOptionsStateEventHandl
String programKey = programOptionsDelayedUpdate;
if (programKey != null && Boolean.parseBoolean(event.getValue())) {
logger.debug("Delayed update of options for program {}", programKey);
updateProgramOptionsStateDescriptions(programKey, null);
updateProgramOptionsStateDescriptions(programKey);
programOptionsDelayedUpdate = null;
}
} catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) {
Expand All @@ -892,7 +892,7 @@ protected EventHandler updateProgramOptionsAndSelectedProgramStateEventHandler()
logger.debug("Delay update of options for program {}", programKey);
programOptionsDelayedUpdate = programKey;
} else {
updateProgramOptionsStateDescriptions(programKey, null);
updateProgramOptionsStateDescriptions(programKey);
}
}
} catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ protected ChannelUpdateHandler updateProgramOptionsStateDescriptionsAndSelectedP
Program program = apiClient.get().getSelectedProgram(getThingHaId());

if (program != null) {
updateProgramOptionsStateDescriptions(program.getKey(), program.getOptions());
updateProgramOptionsStateDescriptions(program.getKey());
processProgramOptions(program.getOptions());

return new StringType(program.getKey());
Expand Down Expand Up @@ -1367,7 +1367,7 @@ protected String convertWasherSpinSpeed(String value) {
return mapStringType(value);
}

protected void updateProgramOptionsStateDescriptions(String programKey, @Nullable List<Option> optionsValues)
protected void updateProgramOptionsStateDescriptions(String programKey)
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
Optional<HomeConnectApiClient> apiClient = getApiClient();
if (apiClient.isPresent()) {
Expand All @@ -1387,43 +1387,12 @@ protected void updateProgramOptionsStateDescriptions(String programKey, @Nullabl
Optional<Channel> channelDryingTarget = getThingChannel(CHANNEL_DRYER_DRYING_TARGET);

if (availableProgramOptions.isEmpty()) {
List<Option> options;
if (optionsValues != null) {
options = optionsValues;
} else if (channelSpinSpeed.isPresent() || channelTemperature.isPresent()
|| channelDryingTarget.isPresent()) {
Program program = apiClient.get().getSelectedProgram(getThingHaId());
options = program != null ? program.getOptions() : emptyList();
} else {
options = emptyList();
}

channelSpinSpeed.ifPresent(channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(),
options.stream()
.filter(option -> option.getKey() != null && option.getValue() != null
&& OPTION_WASHER_SPIN_SPEED.equals(option.getKey()))
.map(option -> option.getValue())
.map(value -> new StateOption(value == null ? "" : value,
convertWasherSpinSpeed(value == null ? "" : value)))
.collect(Collectors.toList())));
channelTemperature
.ifPresent(channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(),
options.stream()
.filter(option -> option.getKey() != null && option.getValue() != null
&& OPTION_WASHER_TEMPERATURE.equals(option.getKey()))
.map(option -> option.getValue())
.map(value -> new StateOption(value == null ? "" : value,
convertWasherTemperature(value == null ? "" : value)))
.collect(Collectors.toList())));
channelDryingTarget
.ifPresent(channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(),
options.stream()
.filter(option -> option.getKey() != null && option.getValue() != null
&& OPTION_DRYER_DRYING_TARGET.equals(option.getKey()))
.map(option -> option.getValue())
.map(value -> new StateOption(value == null ? "" : value,
mapStringType(value == null ? "" : value)))
.collect(Collectors.toList())));
channelSpinSpeed.ifPresent(
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList()));
channelTemperature.ifPresent(
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList()));
channelDryingTarget.ifPresent(
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList()));
}

availableProgramOptions.forEach(option -> {
Expand Down

0 comments on commit cf2b110

Please sign in to comment.