2 * Copyright (c) 2010-2022 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.somfytahoma.internal.handler;
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
17 import java.math.BigDecimal;
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;
29 * The {@link SomfyTahomaHitachiDHWHandler} is responsible for handling commands,
30 * which are sent to one of the channels of the Hitachi DHW thing.
32 * @author Ondrej Pecta - Initial contribution
35 public class SomfyTahomaHitachiDHWHandler extends SomfyTahomaBaseThingHandler {
37 public SomfyTahomaHitachiDHWHandler(Thing 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");
51 public void handleCommand(ChannelUID channelUID, Command command) {
52 super.handleCommand(channelUID, command);
53 if (command instanceof RefreshType) {
56 switch (channelUID.getId()) {
58 if (command instanceof StringType) {
59 sendCommand("setControlDHW", "[\"" + command + "\"]");
63 if (command instanceof StringType) {
64 sendCommand("setDHWMode", "[\"" + command + "\"]");
68 if (command instanceof StringType) {
69 sendCommand("setControlAntiLegionella", "[\"" + command + "\"]");
72 case TARGET_BOOST_MODE:
73 if (command instanceof StringType) {
74 sendCommand("setTargetBoostMode", "[\"" + command + "\"]");
77 case DHW_SETTING_TEMP:
78 sendTempCommand("setControlDHWSettingTemperature", command);
80 case ANTI_LEGIONELLA_TEMP:
81 sendTempCommand("setControlAntiLegionellaSettingTemperature", command);
84 getLogger().debug("This channel doesn't accept any commands");
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);