2 * Copyright (c) 2010-2022 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.miele.internal.handler;
15 import static org.openhab.binding.miele.internal.MieleBindingConstants.MIELE_DEVICE_CLASS_HOOD;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.miele.internal.exceptions.MieleRpcException;
19 import org.openhab.core.i18n.LocaleProvider;
20 import org.openhab.core.i18n.TranslationProvider;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.gson.JsonElement;
31 * The {@link HoodHandler} is responsible for handling commands,
32 * which are sent to one of the channels
34 * @author Karel Goderis - Initial contribution
35 * @author Kai Kreuzer - fixed handling of REFRESH commands
36 * @author Martin Lepsy - fixed handling of empty JSON results
37 * @author Jacob Laursen - Fixed multicast and protocol support (ZigBee/LAN)
40 public class HoodHandler extends MieleApplianceHandler<HoodChannelSelector> {
42 private final Logger logger = LoggerFactory.getLogger(HoodHandler.class);
44 public HoodHandler(Thing thing, TranslationProvider i18nProvider, LocaleProvider localeProvider) {
45 super(thing, i18nProvider, localeProvider, HoodChannelSelector.class, MIELE_DEVICE_CLASS_HOOD);
49 public void handleCommand(ChannelUID channelUID, Command command) {
50 super.handleCommand(channelUID, command);
52 String channelID = channelUID.getId();
53 String applianceId = this.applianceId;
54 if (applianceId == null) {
55 logger.warn("Command '{}' failed, appliance id is unknown", command);
59 HoodChannelSelector selector = (HoodChannelSelector) getValueSelectorFromChannelID(channelID);
60 JsonElement result = null;
63 MieleBridgeHandler bridgeHandler = getMieleBridgeHandler();
64 if (bridgeHandler == null) {
65 logger.warn("Command '{}' failed, missing bridge handler", command);
70 if (command.equals(OnOffType.ON)) {
71 result = bridgeHandler.invokeOperation(applianceId, modelID, "startLighting");
72 } else if (command.equals(OnOffType.OFF)) {
73 result = bridgeHandler.invokeOperation(applianceId, modelID, "stopLighting");
78 if (command.equals(OnOffType.ON)) {
79 result = bridgeHandler.invokeOperation(applianceId, modelID, "stop");
84 logger.debug("{} is a read-only channel that does not accept commands", selector.getChannelID());
88 if (result != null && isResultProcessable(result)) {
89 logger.debug("Result of operation is {}", result.getAsString());
91 } catch (IllegalArgumentException e) {
93 "An error occurred while trying to set the read-only variable associated with channel '{}' to '{}'",
94 channelID, command.toString());
95 } catch (MieleRpcException e) {
96 Throwable cause = e.getCause();
98 logger.warn("An error occurred while trying to invoke operation: {}", e.getMessage());
100 logger.warn("An error occurred while trying to invoke operation: {} -> {}", e.getMessage(),