]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homeconnect] Build state options with a unique item for unsupported programs (#10754)
authorlolodomo <lg.hc@free.fr>
Fri, 28 May 2021 13:01:50 +0000 (15:01 +0200)
committerGitHub <noreply@github.com>
Fri, 28 May 2021 13:01:50 +0000 (15:01 +0200)
Apply to spin speed, temperature and drying taget channels

Fix #10701

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/handler/AbstractHomeConnectThingHandler.java

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