]> git.basschouten.com Git - openhab-addons.git/blob
9cc6309732b135559578433eb9a0159fc98a0f23
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.airbase;
14
15 import java.util.LinkedHashMap;
16 import java.util.Map;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import java.util.stream.IntStream;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.daikin.internal.api.InfoParser;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Holds information from the basic_info call.
28  *
29  * @author Paul Smedley - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class AirbaseZoneInfo {
34     private static final Logger LOGGER = LoggerFactory.getLogger(AirbaseZoneInfo.class);
35
36     public String zonenames = "";
37     public boolean zone[] = new boolean[9];
38
39     private AirbaseZoneInfo() {
40     }
41
42     public static AirbaseZoneInfo parse(String response) {
43         LOGGER.debug("Parsing string: \"{}\"", response);
44
45         Map<String, String> responseMap = InfoParser.parse(response);
46
47         AirbaseZoneInfo info = new AirbaseZoneInfo();
48         info.zonenames = Optional.ofNullable(responseMap.get("zone_name")).orElse("");
49         String zoneinfo = Optional.ofNullable(responseMap.get("zone_onoff")).orElse("");
50
51         String[] zones = zoneinfo.split("%3b");
52
53         for (int i = 1; i < 9; i++) {
54             info.zone[i] = "1".equals(zones[i - 1]);
55         }
56         return info;
57     }
58
59     public Map<String, String> getParamString() {
60         Map<String, String> params = new LinkedHashMap<>();
61         String onoffstring = IntStream.range(1, zone.length).mapToObj(idx -> zone[idx] ? "1" : "0")
62                 .collect(Collectors.joining("%3b"));
63         params.put("zone_name", zonenames);
64         params.put("zone_onoff", onoffstring);
65
66         return params;
67     }
68 }