]> git.basschouten.com Git - openhab-addons.git/blob
2256c2ba7ec1e0b48a30e97d2fefaee21ae47b2e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.daikin.internal.api;
14
15 import java.util.Map;
16 import java.util.Optional;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Holds information from the get_sensor_info call.
24  *
25  * @author Tim Waterhouse - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class SensorInfo {
30     private static final Logger LOGGER = LoggerFactory.getLogger(SensorInfo.class);
31
32     public Optional<Double> indoortemp = Optional.empty();
33     public Optional<Double> indoorhumidity = Optional.empty();
34     public Optional<Double> outdoortemp = Optional.empty();
35     public Optional<Double> compressorfrequency = Optional.empty();
36
37     private SensorInfo() {
38     }
39
40     public static SensorInfo parse(String response) {
41         LOGGER.trace("Parsing string: \"{}\"", response);
42
43         Map<String, String> responseMap = InfoParser.parse(response);
44
45         SensorInfo info = new SensorInfo();
46         info.indoortemp = Optional.ofNullable(responseMap.get("htemp")).flatMap(value -> InfoParser.parseDouble(value));
47         info.indoorhumidity = Optional.ofNullable(responseMap.get("hhum"))
48                 .flatMap(value -> InfoParser.parseDouble(value));
49         info.outdoortemp = Optional.ofNullable(responseMap.get("otemp"))
50                 .flatMap(value -> InfoParser.parseDouble(value));
51         info.compressorfrequency = Optional.ofNullable(responseMap.get("cmpfreq"))
52                 .flatMap(value -> InfoParser.parseDouble(value));
53
54         return info;
55     }
56 }