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.miele.internal.handler;
15 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.miele.internal.api.dto.DeviceProperty;
19 import org.openhab.binding.miele.internal.exceptions.MieleRpcException;
20 import org.openhab.core.i18n.LocaleProvider;
21 import org.openhab.core.i18n.TimeZoneProvider;
22 import org.openhab.core.i18n.TranslationProvider;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.types.Command;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.google.gson.JsonElement;
33 * The {@link FridgeFreezerHandler} is responsible for handling commands,
34 * which are sent to one of the channels
36 * @author Karel Goderis - Initial contribution
37 * @author Kai Kreuzer - fixed handling of REFRESH commands
38 * @author Martin Lepsy - fixed handling of empty JSON results
39 * @author Jacob Laursen - Fixed multicast and protocol support (ZigBee/LAN)
42 public class FridgeFreezerHandler extends MieleApplianceHandler<FridgeFreezerChannelSelector> {
44 private final Logger logger = LoggerFactory.getLogger(FridgeFreezerHandler.class);
46 public FridgeFreezerHandler(Thing thing, TranslationProvider i18nProvider, LocaleProvider localeProvider,
47 TimeZoneProvider timeZoneProvider) {
48 super(thing, i18nProvider, localeProvider, timeZoneProvider, FridgeFreezerChannelSelector.class,
49 MIELE_DEVICE_CLASS_FRIDGE_FREEZER);
53 public void handleCommand(ChannelUID channelUID, Command command) {
54 super.handleCommand(channelUID, command);
56 String channelID = channelUID.getId();
57 String applianceId = this.applianceId;
58 if (applianceId == null) {
59 logger.warn("Command '{}' failed, appliance id is unknown", command);
63 FridgeFreezerChannelSelector selector = (FridgeFreezerChannelSelector) getValueSelectorFromChannelID(channelID);
64 JsonElement result = null;
67 MieleBridgeHandler bridgeHandler = getMieleBridgeHandler();
68 if (bridgeHandler == null) {
69 logger.warn("Command '{}' failed, missing bridge handler", command);
74 if (command.equals(OnOffType.ON)) {
75 result = bridgeHandler.invokeOperation(applianceId, modelID, "startSuperCooling");
76 } else if (command.equals(OnOffType.OFF)) {
77 result = bridgeHandler.invokeOperation(applianceId, modelID, "stopSuperCooling");
82 if (command.equals(OnOffType.ON)) {
83 result = bridgeHandler.invokeOperation(applianceId, modelID, "startSuperFreezing");
84 } else if (command.equals(OnOffType.OFF)) {
85 result = bridgeHandler.invokeOperation(applianceId, modelID, "stopSuperFreezing");
90 logger.debug("{} is a read-only channel that does not accept commands", selector.getChannelID());
94 if (result != null && isResultProcessable(result)) {
95 logger.debug("Result of operation is {}", result.getAsString());
97 } catch (IllegalArgumentException e) {
99 "An error occurred while trying to set the read-only variable associated with channel '{}' to '{}'",
100 channelID, command.toString());
101 } catch (MieleRpcException e) {
102 Throwable cause = e.getCause();
104 logger.warn("An error occurred while trying to invoke operation: {}", e.getMessage());
106 logger.warn("An error occurred while trying to invoke operation: {} -> {}", e.getMessage(),
113 public void onAppliancePropertyChanged(DeviceProperty dp) {
114 super.onAppliancePropertyChanged(dp);
116 if (!STATE_PROPERTY_NAME.equals(dp.Name)) {
120 // Supercool/superfreeze is not exposed directly as property, but can be deduced from state.
121 OnOffType superCoolState, superFreezeState;
122 if (dp.Value.equals(String.valueOf(STATE_SUPER_COOLING))) {
123 superCoolState = OnOffType.ON;
124 superFreezeState = OnOffType.OFF;
125 } else if (dp.Value.equals(String.valueOf(STATE_SUPER_FREEZING))) {
126 superCoolState = OnOffType.OFF;
127 superFreezeState = OnOffType.ON;
129 superCoolState = OnOffType.OFF;
130 superFreezeState = OnOffType.OFF;
133 ChannelUID superCoolChannelUid = new ChannelUID(getThing().getUID(), SUPERCOOL_CHANNEL_ID);
134 logger.trace("Update state of {} to {} through '{}'", superCoolChannelUid, superCoolState, dp.Name);
135 updateState(superCoolChannelUid, superCoolState);
137 ChannelUID superFreezeChannelUid = new ChannelUID(getThing().getUID(), SUPERFREEZE_CHANNEL_ID);
138 logger.trace("Update state of {} to {} through '{}'", superFreezeChannelUid, superFreezeState, dp.Name);
139 updateState(superFreezeChannelUid, superFreezeState);