2 * Copyright (c) 2010-2023 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.airbase;
15 import java.util.LinkedHashMap;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import java.util.stream.IntStream;
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;
27 * Holds information from the basic_info call.
29 * @author Paul Smedley - Initial contribution
30 * @author Jimmy Tanagra - Refactor zone array to 0-based
34 public class AirbaseZoneInfo {
35 private static final Logger LOGGER = LoggerFactory.getLogger(AirbaseZoneInfo.class);
37 public String zonenames = "";
38 public boolean[] zone = new boolean[8];
40 private AirbaseZoneInfo() {
43 public static AirbaseZoneInfo parse(String response) {
44 LOGGER.trace("Parsing string: \"{}\"", response);
46 Map<String, String> responseMap = InfoParser.parse(response);
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("");
52 String[] zones = zoneinfo.split(";");
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]);
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);