[homeconnect] Build state options with a unique item for unsupported programs (#10754)

Apply to spin speed, temperature and drying taget channels

Fix #10701

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2021-05-28 15:01:50 +02:00 committed by GitHub
parent fe11c115ea
commit ac7b5eae4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -860,7 +860,7 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
try { try {
String programKey = event.getValue(); String programKey = event.getValue();
if (programKey != null) { if (programKey != null) {
updateProgramOptionsStateDescriptions(programKey); updateProgramOptionsStateDescriptions(programKey, null);
} }
} catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) { } catch (CommunicationException | ApplianceOfflineException | AuthorizationException e) {
logger.debug("Could not update program options. {}", e.getMessage()); logger.debug("Could not update program options. {}", e.getMessage());
@ -1028,7 +1028,7 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
Program program = apiClient.get().getSelectedProgram(getThingHaId()); Program program = apiClient.get().getSelectedProgram(getThingHaId());
if (program != null) { if (program != null) {
updateProgramOptionsStateDescriptions(program.getKey()); updateProgramOptionsStateDescriptions(program.getKey(), program.getOptions());
processProgramOptions(program.getOptions()); processProgramOptions(program.getOptions());
return new StringType(program.getKey()); return new StringType(program.getKey());
@ -1314,7 +1314,7 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
return mapStringType(value); return mapStringType(value);
} }
protected void updateProgramOptionsStateDescriptions(String programKey) protected void updateProgramOptionsStateDescriptions(String programKey, @Nullable List<Option> optionsValues)
throws CommunicationException, AuthorizationException, ApplianceOfflineException { throws CommunicationException, AuthorizationException, ApplianceOfflineException {
Optional<HomeConnectApiClient> apiClient = getApiClient(); Optional<HomeConnectApiClient> apiClient = getApiClient();
if (apiClient.isPresent()) { if (apiClient.isPresent()) {
@ -1326,12 +1326,43 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
Optional<Channel> channelDryingTarget = getThingChannel(CHANNEL_DRYER_DRYING_TARGET); Optional<Channel> channelDryingTarget = getThingChannel(CHANNEL_DRYER_DRYING_TARGET);
if (availableProgramOptions.isEmpty()) { if (availableProgramOptions.isEmpty()) {
channelSpinSpeed.ifPresent( List<Option> options;
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList())); if (optionsValues != null) {
channelTemperature.ifPresent( options = optionsValues;
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList())); } else if (channelSpinSpeed.isPresent() || channelTemperature.isPresent()
channelDryingTarget.ifPresent( || channelDryingTarget.isPresent()) {
channel -> dynamicStateDescriptionProvider.setStateOptions(channel.getUID(), emptyList())); 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())));
} }
availableProgramOptions.forEach(option -> { availableProgramOptions.forEach(option -> {