Skip to content

Commit

Permalink
[homeconnect] Add missing channel update handler configuration (openh…
Browse files Browse the repository at this point in the history
…ab#10785)

* [homeconnect] Add missing channel update handler configuration

Related to dryer, washer and washer/dryer appliances

Signed-off-by: Laurent Garnier <[email protected]>

* 2 new methods to factorize duplicated code

Signed-off-by: Laurent Garnier <[email protected]>

* Apply spotless

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and thinkingstone committed Nov 7, 2021
1 parent f31b640 commit f94e2d2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,25 @@ protected ChannelUpdateHandler updateProgramOptionsStateDescriptionsAndSelectedP
}));
}

protected ChannelUpdateHandler getAndUpdateSelectedProgramStateUpdateHandler() {
return (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
defaultSelectedProgramStateUpdateHandler().handle(channel.get().getUID(), cache);
}
};
}

protected ChannelUpdateHandler getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler() {
return (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler()
.handle(channel.get().getUID(), cache);
}
};
}

protected ChannelUpdateHandler defaultActiveProgramStateUpdateHandler() {
return (channelUID, cache) -> updateState(channelUID, cache.putIfAbsentAndGet(channelUID, () -> {
Optional<HomeConnectApiClient> apiClient = getApiClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
handlers.put(CHANNEL_ACTIVE_PROGRAM_STATE, defaultActiveProgramStateUpdateHandler());
handlers.put(CHANNEL_SELECTED_PROGRAM_STATE,
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());

// register dryer specific handlers
handlers.put(CHANNEL_DRYER_DRYING_TARGET,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
Expand Down Expand Up @@ -89,18 +88,8 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
}
return UnDefType.UNDEF;
})));
handlers.put(CHANNEL_SETPOINT_TEMPERATURE, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
defaultSelectedProgramStateUpdateHandler().handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_DURATION, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
defaultSelectedProgramStateUpdateHandler().handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_SETPOINT_TEMPERATURE, getAndUpdateSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_DURATION, getAndUpdateSelectedProgramStateUpdateHandler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient;
Expand All @@ -26,7 +25,6 @@
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
Expand Down Expand Up @@ -65,20 +63,13 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());

// register washer specific handlers
handlers.put(CHANNEL_WASHER_SPIN_SPEED, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler()
.handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_WASHER_TEMPERATURE, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler()
.handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_WASHER_SPIN_SPEED,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_TEMPERATURE,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
// register dryer specific handlers
handlers.put(CHANNEL_DRYER_DRYING_TARGET,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
}

@Override
Expand All @@ -103,6 +94,7 @@ protected void configureEventHandlers(Map<String, EventHandler> handlers) {
handlers.put(EVENT_WASHER_SPIN_SPEED,
event -> getThingChannel(CHANNEL_WASHER_SPIN_SPEED).ifPresent(channel -> updateState(channel.getUID(),
event.getValue() == null ? UnDefType.UNDEF : new StringType(event.getValue()))));
// register dryer specific event handlers
handlers.put(EVENT_DRYER_DRYING_TARGET,
event -> getThingChannel(CHANNEL_DRYER_DRYING_TARGET).ifPresent(channel -> updateState(channel.getUID(),
event.getValue() == null ? UnDefType.UNDEF : new StringType(event.getValue()))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient;
Expand All @@ -26,7 +25,6 @@
import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
Expand Down Expand Up @@ -65,20 +63,14 @@ protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler>
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());

// register washer specific handlers
handlers.put(CHANNEL_WASHER_SPIN_SPEED, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler()
.handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_WASHER_TEMPERATURE, (channelUID, cache) -> {
Optional<Channel> channel = getThingChannel(CHANNEL_SELECTED_PROGRAM_STATE);
if (channel.isPresent()) {
updateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler()
.handle(channel.get().getUID(), cache);
}
});
handlers.put(CHANNEL_WASHER_SPIN_SPEED,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_TEMPERATURE,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_IDOS1,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
handlers.put(CHANNEL_WASHER_IDOS2,
getAndUpdateProgramOptionsStateDescriptionsAndSelectedProgramStateUpdateHandler());
}

@Override
Expand Down

0 comments on commit f94e2d2

Please sign in to comment.