]> git.basschouten.com Git - openhab-addons.git/blob
ba79f238d1599e00dbbbc4b6d800e4c985ab8d39
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.homeconnect.internal.handler;
14
15 import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants.*;
16
17 import java.util.Map;
18
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.library.types.OnOffType;
26 import org.openhab.core.thing.ChannelUID;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.types.Command;
29 import org.openhab.core.types.UnDefType;
30
31 /**
32  * The {@link HomeConnectDishwasherHandler} is responsible for handling commands, which are
33  * sent to one of the channels of a dishwasher.
34  *
35  * @author Jonas BrĂ¼stel - Initial contribution
36  */
37 @NonNullByDefault
38 public class HomeConnectDishwasherHandler extends AbstractHomeConnectThingHandler {
39
40     public HomeConnectDishwasherHandler(Thing thing,
41             HomeConnectDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
42         super(thing, dynamicStateDescriptionProvider);
43     }
44
45     @Override
46     protected void configureChannelUpdateHandlers(Map<String, ChannelUpdateHandler> handlers) {
47         // register default update handlers
48         handlers.put(CHANNEL_DOOR_STATE, defaultDoorStateChannelUpdateHandler());
49         handlers.put(CHANNEL_POWER_STATE, defaultPowerStateChannelUpdateHandler());
50         handlers.put(CHANNEL_OPERATION_STATE, defaultOperationStateChannelUpdateHandler());
51         handlers.put(CHANNEL_REMOTE_CONTROL_ACTIVE_STATE, defaultRemoteControlActiveStateChannelUpdateHandler());
52         handlers.put(CHANNEL_REMOTE_START_ALLOWANCE_STATE, defaultRemoteStartAllowanceChannelUpdateHandler());
53         handlers.put(CHANNEL_SELECTED_PROGRAM_STATE, defaultSelectedProgramStateUpdateHandler());
54         handlers.put(CHANNEL_ACTIVE_PROGRAM_STATE, defaultActiveProgramStateUpdateHandler());
55         handlers.put(CHANNEL_AMBIENT_LIGHT_STATE, defaultAmbientLightChannelUpdateHandler());
56     }
57
58     @Override
59     protected void configureEventHandlers(Map<String, EventHandler> handlers) {
60         // register default event handlers
61         handlers.put(EVENT_DOOR_STATE, defaultDoorStateEventHandler());
62         handlers.put(EVENT_REMOTE_CONTROL_ACTIVE, defaultBooleanEventHandler(CHANNEL_REMOTE_CONTROL_ACTIVE_STATE));
63         handlers.put(EVENT_REMOTE_CONTROL_START_ALLOWED,
64                 defaultBooleanEventHandler(CHANNEL_REMOTE_START_ALLOWANCE_STATE));
65         handlers.put(EVENT_REMAINING_PROGRAM_TIME, defaultRemainingProgramTimeEventHandler());
66         handlers.put(EVENT_PROGRAM_PROGRESS, defaultPercentQuantityTypeEventHandler(CHANNEL_PROGRAM_PROGRESS_STATE));
67         handlers.put(EVENT_SELECTED_PROGRAM, defaultSelectedProgramStateEventHandler());
68         handlers.put(EVENT_ACTIVE_PROGRAM, defaultActiveProgramEventHandler());
69         handlers.put(EVENT_POWER_STATE, defaultPowerStateEventHandler());
70         handlers.put(EVENT_OPERATION_STATE, defaultOperationStateEventHandler());
71         handlers.put(EVENT_AMBIENT_LIGHT_STATE, defaultBooleanEventHandler(CHANNEL_AMBIENT_LIGHT_STATE));
72         handlers.put(EVENT_AMBIENT_LIGHT_BRIGHTNESS_STATE,
73                 defaultPercentHandler(CHANNEL_AMBIENT_LIGHT_BRIGHTNESS_STATE));
74         handlers.put(EVENT_AMBIENT_LIGHT_COLOR_STATE, defaultAmbientLightColorStateEventHandler());
75         handlers.put(EVENT_AMBIENT_LIGHT_CUSTOM_COLOR_STATE, defaultAmbientLightCustomColorStateEventHandler());
76     }
77
78     @Override
79     protected void handleCommand(final ChannelUID channelUID, final Command command,
80             final HomeConnectApiClient apiClient)
81             throws CommunicationException, AuthorizationException, ApplianceOfflineException {
82         super.handleCommand(channelUID, command, apiClient);
83
84         if (command instanceof OnOffType) {
85             if (CHANNEL_POWER_STATE.equals(channelUID.getId())) {
86                 apiClient.setPowerState(getThingHaId(),
87                         OnOffType.ON.equals(command) ? STATE_POWER_ON : STATE_POWER_OFF);
88             }
89         }
90
91         handleLightCommands(channelUID, command, apiClient);
92     }
93
94     @Override
95     public String toString() {
96         return "HomeConnectDishwasherHandler [haId: " + getThingHaId() + "]";
97     }
98
99     @Override
100     protected void resetProgramStateChannels() {
101         super.resetProgramStateChannels();
102         getThingChannel(CHANNEL_REMAINING_PROGRAM_TIME_STATE).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
103         getThingChannel(CHANNEL_PROGRAM_PROGRESS_STATE).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
104         getThingChannel(CHANNEL_ACTIVE_PROGRAM_STATE).ifPresent(c -> updateState(c.getUID(), UnDefType.UNDEF));
105     }
106 }