]> git.basschouten.com Git - openhab-addons.git/blob
ae5f829ccf14c3a226ef947615fa8096b8c5fa95
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 java.math.BigDecimal;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.QuantityType;
22 import org.openhab.core.library.types.StringType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
27
28 /**
29  * The {@link SomfyTahomaHitachiDHWHandler} is responsible for handling commands,
30  * which are sent to one of the channels of the Hitachi DHW thing.
31  *
32  * @author Ondrej Pecta - Initial contribution
33  */
34 @NonNullByDefault
35 public class SomfyTahomaHitachiDHWHandler extends SomfyTahomaBaseThingHandler {
36
37     public SomfyTahomaHitachiDHWHandler(Thing thing) {
38         super(thing);
39         stateNames.put(DHW_MODE, "modbus:DHWModeState");
40         stateNames.put(DHW, "modbus:StatusDHWState");
41         stateNames.put(ANTI_LEGIONELLA, "modbus:StatusAntiLegionellaState");
42         stateNames.put(ANTI_LEGIONELLA_TEMP, "modbus:StatusAntiLegionellaSettingTemperatureState");
43         stateNames.put(DHW_SETTING_TEMP, "modbus:StatusDHWSettingTemperatureState");
44         stateNames.put(DHW_TEMP, "core:DHWTemperatureState");
45         stateNames.put(TARGET_BOOST_MODE, "modbus:YutakiTargetBoostModeState");
46         stateNames.put(BOOST_MODE, "modbus:YutakiBoostModeState");
47         stateNames.put(ALARM_NUMBER, "modbus:AlarmNumberState");
48     }
49
50     @Override
51     public void handleCommand(ChannelUID channelUID, Command command) {
52         super.handleCommand(channelUID, command);
53         if (command instanceof RefreshType) {
54             return;
55         } else {
56             switch (channelUID.getId()) {
57                 case DHW:
58                     if (command instanceof StringType) {
59                         sendCommand("setControlDHW", "[\"" + command + "\"]");
60                     }
61                     break;
62                 case DHW_MODE:
63                     if (command instanceof StringType) {
64                         sendCommand("setDHWMode", "[\"" + command + "\"]");
65                     }
66                     break;
67                 case ANTI_LEGIONELLA:
68                     if (command instanceof StringType) {
69                         sendCommand("setControlAntiLegionella", "[\"" + command + "\"]");
70                     }
71                     break;
72                 case TARGET_BOOST_MODE:
73                     if (command instanceof StringType) {
74                         sendCommand("setTargetBoostMode", "[\"" + command + "\"]");
75                     }
76                     break;
77                 case DHW_SETTING_TEMP:
78                     sendTempCommand("setControlDHWSettingTemperature", command);
79                     break;
80                 case ANTI_LEGIONELLA_TEMP:
81                     sendTempCommand("setControlAntiLegionellaSettingTemperature", command);
82                     break;
83                 default:
84                     getLogger().debug("This channel doesn't accept any commands");
85             }
86         }
87     }
88
89     private void sendTempCommand(String cmd, Command command) {
90         if (command instanceof DecimalType || command instanceof QuantityType) {
91             BigDecimal temperature = toTemperature(command);
92             if (temperature != null) {
93                 String param = "[" + temperature.toPlainString() + "]";
94                 sendCommand(cmd, param);
95             }
96         }
97     }
98 }