2 * Copyright (c) 2010-2021 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.daikin.internal.api;
15 import java.util.HashMap;
17 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.daikin.internal.api.Enums.FanMovement;
21 import org.openhab.binding.daikin.internal.api.Enums.FanSpeed;
22 import org.openhab.binding.daikin.internal.api.Enums.Mode;
23 import org.openhab.binding.daikin.internal.api.Enums.SpecialMode;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Class for holding the set of parameters used by set and get control info.
30 * @author Tim Waterhouse - Initial Contribution
31 * @author Paul Smedley <paul@smedley.id.au> - mods for Daikin Airbase
35 public class ControlInfo {
36 private static final Logger LOGGER = LoggerFactory.getLogger(ControlInfo.class);
38 public String ret = "";
39 public boolean power = false;
40 public Mode mode = Mode.AUTO;
41 /** Degrees in Celsius. */
42 public Optional<Double> temp = Optional.empty();
43 public FanSpeed fanSpeed = FanSpeed.AUTO;
44 public FanMovement fanMovement = FanMovement.STOPPED;
45 /* Not supported by all units. Sets the target humidity for dehumidifying. */
46 public Optional<Integer> targetHumidity = Optional.empty();
47 public SpecialMode specialMode = SpecialMode.UNKNOWN;
49 private ControlInfo() {
52 public static ControlInfo parse(String response) {
53 LOGGER.debug("Parsing string: \"{}\"", response);
55 Map<String, String> responseMap = InfoParser.parse(response);
57 ControlInfo info = new ControlInfo();
58 info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
59 info.power = "1".equals(responseMap.get("pow"));
60 info.mode = Optional.ofNullable(responseMap.get("mode")).flatMap(value -> InfoParser.parseInt(value))
61 .map(value -> Mode.fromValue(value)).orElse(Mode.AUTO);
62 info.temp = Optional.ofNullable(responseMap.get("stemp")).flatMap(value -> InfoParser.parseDouble(value));
63 info.fanSpeed = Optional.ofNullable(responseMap.get("f_rate")).map(value -> FanSpeed.fromValue(value))
64 .orElse(FanSpeed.AUTO);
65 info.fanMovement = Optional.ofNullable(responseMap.get("f_dir")).flatMap(value -> InfoParser.parseInt(value))
66 .map(value -> FanMovement.fromValue(value)).orElse(FanMovement.STOPPED);
67 info.targetHumidity = Optional.ofNullable(responseMap.get("shum")).flatMap(value -> InfoParser.parseInt(value));
69 info.specialMode = Optional.ofNullable(responseMap.get("adv")).map(value -> SpecialMode.fromValue(value))
70 .orElse(SpecialMode.UNKNOWN);
74 public Map<String, String> getParamString() {
75 Map<String, String> params = new HashMap<>();
76 params.put("pow", power ? "1" : "0");
77 params.put("mode", Integer.toString(mode.getValue()));
78 params.put("f_rate", fanSpeed.getValue());
79 params.put("f_dir", Integer.toString(fanMovement.getValue()));
80 params.put("stemp", temp.orElse(20.0).toString());
81 params.put("shum", targetHumidity.map(value -> value.toString()).orElse(""));