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 SomfyTahomaHitachiATWMCHandler} is responsible for handling commands,
30 * which are sent to one of the channels of the Hitachi Air To Water Main Component thing.
32 * @author Ondrej Pecta - Initial contribution
35 public class SomfyTahomaHitachiATWMCHandler extends SomfyTahomaBaseThingHandler {
37 public SomfyTahomaHitachiATWMCHandler(Thing thing) {
39 stateNames.put(AUTO_MANU_MODE, "core:AutoManuModeState");
40 stateNames.put(UNIT_CONTROL, "modbus:ControlUnitState");
41 stateNames.put(UNIT_MODE_STATUS, "modbus:StatusUnitModeState");
42 stateNames.put(UNIT_MODE_CONTROL, "modbus:ControlUnitModeState");
43 stateNames.put(BLOCK_MENU_CONTROL, "modbus:ControlBlockMenuState");
44 stateNames.put(SPACE_MODE, "modbus:SpaceModeState");
45 stateNames.put(ECO_MODE_TARGET_OFFSET, "modbus:EcoModeOffsetTargetState");
46 stateNames.put(COMM_ALARM_BIT_STATUS, "modbus:StatusCommunicationAlarmBitState");
47 stateNames.put(OPERATION, "modbus:OperationState");
48 stateNames.put(OUTDOOR_TEMP, "modbus:OutdoorAmbientTemperatureState");
49 stateNames.put(WATER_INLET_TEMP, "modbus:WaterInletUnitTemperatureState");
50 stateNames.put(WATER_OUTLET_TEMP, "modbus:WaterOutletUnitTemperatureState");
51 stateNames.put(ECO_MODE_OFFSET, "modbus:EcoModeOffsetState");
52 stateNames.put(WATER_OUTLET_HP_TEMP, "modbus:WaterOutletHpTemperatureState");
53 stateNames.put(LIQUID_TEMP_THMI, "modbus:LiquidTemperatureTHMIState");
54 stateNames.put(LIQUID_TEMP, "modbus:LiquidTemperatureState");
55 stateNames.put(COMPRESSOR_RUNNING_CURRENT, "modbus:CompressorRunningCurrentState");
56 stateNames.put(WATER_TEMP_SETTING, "modbus:WaterTemperatureSettingState");
57 stateNames.put(YUTAKI_OPERATING_MODE, "modbus:YutakiVirtualOperatingModeState");
58 stateNames.put(ALARM_NUMBER, "modbus:AlarmNumberState");
62 public void handleCommand(ChannelUID channelUID, Command command) {
63 super.handleCommand(channelUID, command);
64 if (command instanceof RefreshType) {
67 switch (channelUID.getId()) {
69 if (command instanceof StringType) {
70 sendCommand("setGlobalAutoManuMode", "[\"" + command + "\"]");
74 if (command instanceof StringType) {
75 sendCommand("setControlUnit", "[\"" + command + "\"]");
78 case UNIT_MODE_CONTROL:
79 if (command instanceof StringType) {
80 sendCommand("setControlUnitMode", "[\"" + command + "\"]");
83 case BLOCK_MENU_CONTROL:
84 if (command instanceof StringType) {
85 sendCommand("setControlBlockMenu", "[\"" + command + "\"]");
89 if (command instanceof StringType) {
90 sendCommand("setSpaceMode", "[\"" + command + "\"]");
93 case ECO_MODE_TARGET_OFFSET:
94 sendTempCommand("setEcoModeOffset", command);
97 getLogger().debug("This channel doesn't accept any commands");
102 private void sendTempCommand(String cmd, Command command) {
103 if (command instanceof DecimalType || command instanceof QuantityType) {
104 BigDecimal temperature = toTemperature(command);
105 if (temperature != null) {
106 String param = "[" + temperature.toPlainString() + "]";
107 sendCommand(cmd, param);