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 robotic vacuum cleaners.
31 * @author Björn Lange - Initial contribution
34 public class RoboticVacuumCleanerDeviceThingHandler extends AbstractMieleThingHandler {
35 private final Logger logger = LoggerFactory.getLogger(this.getClass());
38 * Creates a new {@link RoboticVacuumCleanerDeviceThingHandler}.
40 * @param thing The thing to handle.
42 public RoboticVacuumCleanerDeviceThingHandler(Thing thing) {
47 public void handleCommand(ChannelUID channelUID, Command command) {
48 super.handleCommand(channelUID, command);
50 if (VACUUM_CLEANER_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(VACUUM_CLEANER_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(PROGRAM_START_STOP_PAUSE), device.getProgramStartStopPause());
66 updateState(channel(POWER_ON_OFF), device.getPowerOnOff());
67 updateState(channel(ERROR_STATE), device.getErrorState());
68 updateState(channel(INFO_STATE), device.getInfoState());
69 updateState(channel(BATTERY_LEVEL), device.getBatteryLevel());
73 protected void updateTransitionState(TransitionChannelState transition) {
74 if (transition.hasFinishedChanged()) {
75 updateState(channel(FINISH_STATE), transition.getFinishState());
80 protected void updateActionState(ActionsChannelState actions) {
81 updateState(channel(REMOTE_CONTROL_CAN_BE_STARTED), actions.getRemoteControlCanBeStarted());
82 updateState(channel(REMOTE_CONTROL_CAN_BE_STOPPED), actions.getRemoteControlCanBeStopped());
83 updateState(channel(REMOTE_CONTROL_CAN_BE_PAUSED), actions.getRemoteControlCanBePaused());
84 updateState(channel(REMOTE_CONTROL_CAN_SET_PROGRAM_ACTIVE), actions.getRemoteControlCanSetProgramActive());