]> git.basschouten.com Git - openhab-addons.git/blob
f48d37723af09fb8cf4621459055ebc7b360a34a
[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_year_power_ex call.
24  *
25  * @author Lukas Agethen - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class EnergyInfoYear {
30     private static final Logger LOGGER = LoggerFactory.getLogger(EnergyInfoYear.class);
31
32     public Optional<Integer[]> energyHeatingThisYear = Optional.empty();
33
34     public Optional<Integer[]> energyCoolingThisYear = Optional.empty();
35
36     private EnergyInfoYear() {
37     }
38
39     public static EnergyInfoYear parse(String response) {
40         LOGGER.trace("Parsing string: \"{}\"", response);
41
42         Map<String, String> responseMap = InfoParser.parse(response);
43
44         EnergyInfoYear info = new EnergyInfoYear();
45         info.energyHeatingThisYear = Optional.ofNullable(responseMap.get("curr_year_heat"))
46                 .flatMap(value -> InfoParser.parseArrayOfInt(value, 12));
47
48         info.energyCoolingThisYear = Optional.ofNullable(responseMap.get("curr_year_cool"))
49                 .flatMap(value -> InfoParser.parseArrayOfInt(value, 12));
50
51         return info;
52     }
53 }