]> git.basschouten.com Git - openhab-addons.git/blob
6b8aa1f56dc16fa3414af2e75fb172f6e5e842a9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.somfytahoma.internal.handler;
14
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.QuantityType;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.types.Command;
22 import org.openhab.core.types.RefreshType;
23
24 /**
25  * The {@link SomfyTahomaValveHeatingSystemHandler} is responsible for handling commands,
26  * which are sent to one of the channels of the valve heating system thing.
27  *
28  * @author Ondrej Pecta - Initial contribution
29  */
30 @NonNullByDefault
31 public class SomfyTahomaValveHeatingSystemHandler extends SomfyTahomaBaseThingHandler {
32
33     public SomfyTahomaValveHeatingSystemHandler(Thing thing) {
34         super(thing);
35         stateNames.put(TARGET_TEMPERATURE, TARGET_ROOM_TEMPERATURE_STATE);
36         stateNames.put(BATTERY_LEVEL, BATTERY_LEVEL_STATE);
37         stateNames.put(DEROGATION_HEATING_MODE, "io:DerogationHeatingModeState");
38         stateNames.put(DEROGATED_TARGET_TEMPERATURE, "core:DerogatedTargetTemperatureState");
39         stateNames.put(CURRENT_HEATING_MODE, "io:CurrentHeatingModeState");
40         stateNames.put(OPEN_CLOSED_VALVE, "core:OpenClosedValveState");
41         stateNames.put(OPERATING_MODE, "core:OperatingModeState");
42     }
43
44     @Override
45     public void handleCommand(ChannelUID channelUID, Command command) {
46         super.handleCommand(channelUID, command);
47         if (command instanceof RefreshType) {
48             return;
49         } else {
50             if (DEROGATED_TARGET_TEMPERATURE.equals(channelUID.getId()) && command instanceof QuantityType) {
51                 QuantityType type = (QuantityType) command;
52                 String param = "[" + type.doubleValue() + ", \"next_mode\"]";
53                 sendCommand(COMMAND_SET_DEROGATION, param);
54             } else if (DEROGATION_HEATING_MODE.equals(channelUID.getId())) {
55                 switch (command.toString()) {
56                     case "auto":
57                         sendCommand("exitDerogation");
58                         break;
59                     case "away":
60                     case "comfort":
61                     case "eco":
62                     case "frostprotection":
63                         String param = "[\"" + command.toString() + "\", \"next_mode\"]";
64                         sendCommand(COMMAND_SET_DEROGATION, param);
65                         break;
66                     default:
67
68                 }
69             }
70         }
71     }
72 }