]> git.basschouten.com Git - openhab-addons.git/blob
9e9da402e0f4e749a6d4666d0e96d65c060251d5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mielecloud.internal.handler;
14
15 import static org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants.Channels.*;
16
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;
27
28 /**
29  * ThingHandler implementation for Miele robotic vacuum cleaners.
30  *
31  * @author Björn Lange - Initial contribution
32  */
33 @NonNullByDefault
34 public class RoboticVacuumCleanerDeviceThingHandler extends AbstractMieleThingHandler {
35     private final Logger logger = LoggerFactory.getLogger(this.getClass());
36
37     /**
38      * Creates a new {@link RoboticVacuumCleanerDeviceThingHandler}.
39      *
40      * @param thing The thing to handle.
41      */
42     public RoboticVacuumCleanerDeviceThingHandler(Thing thing) {
43         super(thing);
44     }
45
46     @Override
47     public void handleCommand(ChannelUID channelUID, Command command) {
48         super.handleCommand(channelUID, command);
49
50         if (VACUUM_CLEANER_PROGRAM_ACTIVE.equals(channelUID.getId()) && command instanceof StringType) {
51             try {
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());
55             }
56         }
57     }
58
59     @Override
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());
70     }
71
72     @Override
73     protected void updateTransitionState(TransitionChannelState transition) {
74         if (transition.hasFinishedChanged()) {
75             updateState(channel(FINISH_STATE), transition.getFinishState());
76         }
77     }
78
79     @Override
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());
85     }
86 }