Skip to content

Commit

Permalink
[homeconnect] Predefined temp / spin speeds options for unsupported
Browse files Browse the repository at this point in the history
washer programs

Fix #10701

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo committed Jul 6, 2021
1 parent 19897da commit ac46039
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
private final AtomicBoolean accessible;
private final Logger logger = LoggerFactory.getLogger(AbstractHomeConnectThingHandler.class);
private final Map<String, List<AvailableProgramOption>> availableProgramOptionsCache;
private final Map<String, List<AvailableProgramOption>> unsupportedProgramOptions;

public AbstractHomeConnectThingHandler(Thing thing,
HomeConnectDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
Expand All @@ -116,9 +117,11 @@ public AbstractHomeConnectThingHandler(Thing thing,
expiringStateMap = new ExpiringStateMap(Duration.ofSeconds(CACHE_TTL_SEC));
accessible = new AtomicBoolean(false);
availableProgramOptionsCache = new ConcurrentHashMap<>();
unsupportedProgramOptions = new ConcurrentHashMap<>();

configureEventHandlers(eventHandlers);
configureChannelUpdateHandlers(channelUpdateHandlers);
configureUnsupportedProgramOptions(unsupportedProgramOptions);
}

@Override
Expand Down Expand Up @@ -485,6 +488,9 @@ protected Optional<Channel> getThingChannel(String channelId) {
*/
protected abstract void configureEventHandlers(final Map<String, EventHandler> handlers);

protected void configureUnsupportedProgramOptions(final Map<String, List<AvailableProgramOption>> programOptions) {
}

protected boolean isChannelLinkedToProgramOptionNotFullySupportedByApi() {
return false;
}
Expand Down Expand Up @@ -1475,12 +1481,26 @@ protected void updateProgramOptionsStateDescriptions(String programKey)
try {
availableProgramOptions = apiClient.get().getProgramOptions(getThingHaId(), programKey);
if (availableProgramOptions == null) {
// Program is unsupported, save in cache an empty list of options to avoid calling again the API
// for this program
availableProgramOptions = emptyList();
logger.debug("Saving empty options in cache for unsupported program '{}'.", programKey);
// Program is unsupported, to avoid calling again the API for this program, save in cache either
// the predefined options provided by the binding if they exist, or an empty list of options
if (unsupportedProgramOptions.containsKey(programKey)) {
availableProgramOptions = unsupportedProgramOptions.get(programKey);
availableProgramOptions = availableProgramOptions != null ? availableProgramOptions
: emptyList();
logger.debug("Saving predefined options in cache for unsupported program '{}'.",
programKey);
} else {
availableProgramOptions = emptyList();
logger.debug("Saving empty options in cache for unsupported program '{}'.", programKey);
}
availableProgramOptionsCache.put(programKey, availableProgramOptions);
} else {
// If no options are returned by the API, using predefined options if available
if (availableProgramOptions.isEmpty() && unsupportedProgramOptions.containsKey(programKey)) {
availableProgramOptions = unsupportedProgramOptions.get(programKey);
availableProgramOptions = availableProgramOptions != null ? availableProgramOptions
: emptyList();
}
cacheToSet = true;
}
} catch (CommunicationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflineException;
import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
import org.openhab.binding.homeconnect.internal.client.model.AvailableProgramOption;
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.ChannelUID;
Expand Down Expand Up @@ -121,6 +122,78 @@ protected void configureEventHandlers(Map<String, EventHandler> handlers) {
event.getValue() == null ? UnDefType.UNDEF : new StringType(event.getValue()))));
}

@Override
protected void configureUnsupportedProgramOptions(Map<String, List<AvailableProgramOption>> programOptions) {
programOptions.put("LaundryCare.Washer.Program.Cotton.Eco4060", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature",
List.of("LaundryCare.Washer.EnumType.Temperature.Auto")),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed", //
List.of("LaundryCare.Washer.EnumType.SpinSpeed.RPM400",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM600",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM800",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1200",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1400"))));

programOptions.put("LaundryCare.Washer.Program.Cotton.Colour", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature", //
List.of("LaundryCare.Washer.EnumType.Temperature.Cold",
"LaundryCare.Washer.EnumType.Temperature.GC20",
"LaundryCare.Washer.EnumType.Temperature.GC30",
"LaundryCare.Washer.EnumType.Temperature.GC40",
"LaundryCare.Washer.EnumType.Temperature.GC60",
"LaundryCare.Washer.EnumType.Temperature.GC90")),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed", //
List.of("LaundryCare.Washer.EnumType.SpinSpeed.RPM400",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM600",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM800",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1200",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1400"))));

// Auto30 is provided by the API but with empty options, so we defined predefined values for this program
programOptions.put("LaundryCare.Washer.Program.Auto30", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature",
List.of("LaundryCare.Washer.EnumType.Temperature.Auto")),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed",
List.of("LaundryCare.Washer.EnumType.SpinSpeed.Auto"))));

programOptions.put("LaundryCare.Washer.Program.Super153045.Super1530", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature", //
List.of("LaundryCare.Washer.EnumType.Temperature.Cold",
"LaundryCare.Washer.EnumType.Temperature.GC20",
"LaundryCare.Washer.EnumType.Temperature.GC30",
"LaundryCare.Washer.EnumType.Temperature.GC40")),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed", //
List.of("LaundryCare.Washer.EnumType.SpinSpeed.RPM400",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM600",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM800",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1200"))));

programOptions.put("LaundryCare.Washer.Program.Rinse", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature", List.of()),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed", //
List.of("LaundryCare.Washer.EnumType.SpinSpeed.Off",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM400",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM600",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM800",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1200",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1400"))));

programOptions.put("LaundryCare.Washer.Program.Spin.SpinDrain", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature", List.of()),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed", //
List.of("LaundryCare.Washer.EnumType.SpinSpeed.Off",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM400",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM600",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM800",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1200",
"LaundryCare.Washer.EnumType.SpinSpeed.RPM1400"))));

programOptions.put("LaundryCare.Washer.Program.DrumClean", List.of( //
new AvailableProgramOption("LaundryCare.Washer.Option.Temperature", List.of()),
new AvailableProgramOption("LaundryCare.Washer.Option.SpinSpeed",
List.of("LaundryCare.Washer.EnumType.SpinSpeed.RPM1200"))));
}

@Override
protected boolean isChannelLinkedToProgramOptionNotFullySupportedByApi() {
return (getThingChannel(CHANNEL_WASHER_IDOS1).isPresent() && isLinked(CHANNEL_WASHER_IDOS1))
Expand Down

0 comments on commit ac46039

Please sign in to comment.