]> git.basschouten.com Git - openhab-addons.git/blob
7f043596f93fb99ca4f9ba5913d5c16a9a8bac3c
[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.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  * @author Jimmy Tanagra - Refactor zone array to 0-based
31  *
32  */
33 @NonNullByDefault
34 public class AirbaseZoneInfo {
35     private static final Logger LOGGER = LoggerFactory.getLogger(AirbaseZoneInfo.class);
36
37     public String zonenames = "";
38     public boolean[] zone = new boolean[8];
39
40     private AirbaseZoneInfo() {
41     }
42
43     public static AirbaseZoneInfo parse(String response) {
44         LOGGER.trace("Parsing string: \"{}\"", response);
45
46         Map<String, String> responseMap = InfoParser.parse(response);
47
48         AirbaseZoneInfo info = new AirbaseZoneInfo();
49         info.zonenames = Optional.ofNullable(responseMap.get("zone_name")).orElse("");
50         String zoneinfo = Optional.ofNullable(responseMap.get("zone_onoff")).orElse("");
51
52         String[] zones = zoneinfo.split(";");
53
54         int count = Math.min(info.zone.length, zones.length);
55         for (int i = 0; i < count; i++) {
56             info.zone[i] = "1".equals(zones[i]);
57         }
58         return info;
59     }
60
61     public Map<String, String> getParamString() {
62         Map<String, String> params = new LinkedHashMap<>();
63         String onoffstring = IntStream.range(0, zone.length).mapToObj(idx -> zone[idx] ? "1" : "0")
64                 .collect(Collectors.joining(";"));
65         params.put("zone_name", zonenames);
66         params.put("zone_onoff", onoffstring);
67
68         return params;
69     }
70 }