2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.homeconnect.internal.handler;
15 import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.homeconnect.internal.client.HomeConnectApiClient;
21 import org.openhab.binding.homeconnect.internal.client.exception.ApplianceOfflineException;
22 import org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException;
23 import org.openhab.binding.homeconnect.internal.client.exception.CommunicationException;
24 import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
25 import org.openhab.core.thing.ChannelUID;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.UnDefType;
31 * The {@link HomeConnectCoffeeMakerHandler} is responsible for handling commands, which are
32 * sent to one of the channels of a coffee machine.
34 * @author Jonas BrĂ¼stel - Initial contribution
37 public class HomeConnectCoffeeMakerHandler extends AbstractHomeConnectThingHandler {
39 public HomeConnectCoffeeMakerHandler(Thing thing,
40 HomeConnectDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
41 super(thing, dynamicStateDescriptionProvider);
45 protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler> handlers) {
46 // register default update handlers
47 handlers.put(CHANNEL_OPERATION_STATE, defaultOperationStateChannelUpdateHandler());
48 handlers.put(CHANNEL_POWER_STATE, defaultPowerStateChannelUpdateHandler());
49 handlers.put(CHANNEL_REMOTE_START_ALLOWANCE_STATE, defaultRemoteStartAllowanceChannelUpdateHandler());
50 handlers.put(CHANNEL_LOCAL_CONTROL_ACTIVE_STATE, defaultLocalControlActiveStateChannelUpdateHandler());
51 handlers.put(CHANNEL_SELECTED_PROGRAM_STATE, defaultSelectedProgramStateUpdateHandler());
52 handlers.put(CHANNEL_ACTIVE_PROGRAM_STATE, defaultActiveProgramStateUpdateHandler());
56 protected void configureEventHandlers(Map<String, EventHandler> handlers) {
57 // register default SSE event handlers
58 handlers.put(EVENT_REMOTE_CONTROL_START_ALLOWED,
59 defaultBooleanEventHandler(CHANNEL_REMOTE_START_ALLOWANCE_STATE));
60 handlers.put(EVENT_LOCAL_CONTROL_ACTIVE, defaultBooleanEventHandler(CHANNEL_LOCAL_CONTROL_ACTIVE_STATE));
61 handlers.put(EVENT_SELECTED_PROGRAM, defaultSelectedProgramStateEventHandler());
62 handlers.put(EVENT_COFFEEMAKER_BEAN_CONTAINER_EMPTY,
63 defaultEventPresentStateEventHandler(CHANNEL_COFFEEMAKER_BEAN_CONTAINER_EMPTY_STATE));
64 handlers.put(EVENT_COFFEEMAKER_DRIP_TRAY_FULL,
65 defaultEventPresentStateEventHandler(CHANNEL_COFFEEMAKER_DRIP_TRAY_FULL_STATE));
66 handlers.put(EVENT_COFFEEMAKER_WATER_TANK_EMPTY,
67 defaultEventPresentStateEventHandler(CHANNEL_COFFEEMAKER_WATER_TANK_EMPTY_STATE));
68 handlers.put(EVENT_ACTIVE_PROGRAM, defaultActiveProgramEventHandler());
69 handlers.put(EVENT_POWER_STATE, defaultPowerStateEventHandler());
70 handlers.put(EVENT_OPERATION_STATE, defaultOperationStateEventHandler());
72 // register coffee maker specific SSE event handlers
73 handlers.put(EVENT_PROGRAM_PROGRESS, event -> {
74 if (event.getValue() == null || event.getValueAsInt() == 0) {
75 getLinkedChannel(CHANNEL_PROGRAM_PROGRESS_STATE)
76 .ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
78 defaultPercentQuantityTypeEventHandler(CHANNEL_PROGRAM_PROGRESS_STATE).handle(event);
84 protected void handleCommand(ChannelUID channelUID, Command command, HomeConnectApiClient apiClient)
85 throws CommunicationException, AuthorizationException, ApplianceOfflineException {
86 super.handleCommand(channelUID, command, apiClient);
88 // turn coffee maker on and standby
89 handlePowerCommand(channelUID, command, apiClient, STATE_POWER_STANDBY);
93 public String toString() {
94 return "HomeConnectCoffeeMakerHandler [haId: " + getThingHaId() + "]";
98 protected void resetProgramStateChannels(boolean offline) {
99 super.resetProgramStateChannels(offline);
100 getLinkedChannel(CHANNEL_PROGRAM_PROGRESS_STATE).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
101 getLinkedChannel(CHANNEL_ACTIVE_PROGRAM_STATE).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));