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.mielecloud.internal.handler;
15 import static org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants.Channels.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.mielecloud.internal.handler.channel.ActionsChannelState;
19 import org.openhab.binding.mielecloud.internal.handler.channel.DeviceChannelState;
20 import org.openhab.binding.mielecloud.internal.handler.channel.TransitionChannelState;
21 import org.openhab.core.library.types.StringType;
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;
29 * ThingHandler implementation for Miele dish warmers.
31 * @author Björn Lange - Initial contribution
34 public class DishWarmerDeviceThingHandler extends AbstractMieleThingHandler {
35 private final Logger logger = LoggerFactory.getLogger(this.getClass());
38 * Creates a new {@link DishWarmerDeviceThingHandler}.
40 * @param thing The thing to handle.
42 public DishWarmerDeviceThingHandler(Thing thing) {
47 public void handleCommand(ChannelUID channelUID, Command command) {
48 super.handleCommand(channelUID, command);
50 if (DISH_WARMER_PROGRAM_ACTIVE.equals(channelUID.getId()) && command instanceof StringType) {
52 triggerProgram(Long.parseLong(command.toString()));
53 } catch (NumberFormatException e) {
54 logger.warn("Failed to activate program: '{}' is not a valid program ID", command.toString());
60 protected void updateDeviceState(DeviceChannelState device) {
61 updateState(channel(DISH_WARMER_PROGRAM_ACTIVE), device.getProgramActiveId());
62 updateState(channel(PROGRAM_ACTIVE_RAW), device.getProgramActiveRaw());
63 updateState(channel(OPERATION_STATE), device.getOperationState());
64 updateState(channel(OPERATION_STATE_RAW), device.getOperationStateRaw());
65 updateState(channel(POWER_ON_OFF), device.getPowerOnOff());
66 updateState(channel(PROGRAM_ELAPSED_TIME), device.getProgramElapsedTime());
67 updateState(channel(TEMPERATURE_TARGET), device.getTemperatureTarget());
68 updateState(channel(TEMPERATURE_CURRENT), device.getTemperatureCurrent());
69 updateState(channel(ERROR_STATE), device.getErrorState());
70 updateState(channel(INFO_STATE), device.getInfoState());
71 updateState(channel(DOOR_STATE), device.getDoorState());
75 protected void updateTransitionState(TransitionChannelState transition) {
76 updateState(channel(PROGRAM_REMAINING_TIME), transition.getProgramRemainingTime());
77 updateState(channel(PROGRAM_PROGRESS), transition.getProgramProgress());
78 if (transition.hasFinishedChanged()) {
79 updateState(channel(FINISH_STATE), transition.getFinishState());
84 protected void updateActionState(ActionsChannelState actions) {
85 updateState(channel(REMOTE_CONTROL_CAN_BE_SWITCHED_ON), actions.getRemoteControlCanBeSwitchedOn());
86 updateState(channel(REMOTE_CONTROL_CAN_BE_SWITCHED_OFF), actions.getRemoteControlCanBeSwitchedOff());