]> git.basschouten.com Git - openhab-addons.git/blob
41332bd2a544fb8c07b70a3fa55b37db09a3bc40
[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 SomfyTahomaHitachiATWMCHandler} is responsible for handling commands,
30  * which are sent to one of the channels of the Hitachi Air To Water Main Component thing.
31  *
32  * @author Ondrej Pecta - Initial contribution
33  */
34 @NonNullByDefault
35 public class SomfyTahomaHitachiATWMCHandler extends SomfyTahomaBaseThingHandler {
36
37     public SomfyTahomaHitachiATWMCHandler(Thing thing) {
38         super(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");
59     }
60
61     @Override
62     public void handleCommand(ChannelUID channelUID, Command command) {
63         super.handleCommand(channelUID, command);
64         if (command instanceof RefreshType) {
65             return;
66         } else {
67             switch (channelUID.getId()) {
68                 case AUTO_MANU_MODE:
69                     if (command instanceof StringType) {
70                         sendCommand("setGlobalAutoManuMode", "[\"" + command + "\"]");
71                     }
72                     break;
73                 case UNIT_CONTROL:
74                     if (command instanceof StringType) {
75                         sendCommand("setControlUnit", "[\"" + command + "\"]");
76                     }
77                     break;
78                 case UNIT_MODE_CONTROL:
79                     if (command instanceof StringType) {
80                         sendCommand("setControlUnitMode", "[\"" + command + "\"]");
81                     }
82                     break;
83                 case BLOCK_MENU_CONTROL:
84                     if (command instanceof StringType) {
85                         sendCommand("setControlBlockMenu", "[\"" + command + "\"]");
86                     }
87                     break;
88                 case SPACE_MODE:
89                     if (command instanceof StringType) {
90                         sendCommand("setSpaceMode", "[\"" + command + "\"]");
91                     }
92                     break;
93                 case ECO_MODE_TARGET_OFFSET:
94                     sendTempCommand("setEcoModeOffset", command);
95                     break;
96                 default:
97                     getLogger().debug("This channel doesn't accept any commands");
98             }
99         }
100     }
101
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);
108             }
109         }
110     }
111 }