]> git.basschouten.com Git - openhab-addons.git/blob
4d4ec3081adfaa96d7517b1d6126b6d40b374279
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.plugwiseha.internal.api.model.dto;
14
15 import java.util.Map;
16 import java.util.Optional;
17
18 /**
19  * The {@link ActuatorFunctionalities} class is an object model class that
20  * mirrors the XML structure provided by the Plugwise Home Automation controller
21  * for the collection of actuator functionalities. (e.g. 'offset', 'relay', et
22  * cetera). It extends the {@link CustomCollection} class.
23  * 
24  * @author B. van Wetten - Initial contribution
25  */
26
27 public class ActuatorFunctionalities extends PlugwiseHACollection<ActuatorFunctionality> {
28
29     private static final String THERMOSTAT_FUNCTIONALITY = "thermostat";
30     private static final String OFFSETTEMPERATURE_FUNCTIONALITY = "temperature_offset";
31     private static final String RELAY_FUNCTIONALITY = "relay";
32
33     public Optional<Boolean> getRelayLockState() {
34         return this.getFunctionalityRelay().flatMap(ActuatorFunctionality::getRelayLockState)
35                 .map(Boolean::parseBoolean);
36     }
37
38     public Optional<String> getRegulationControl() {
39         return this.getFunctionalityThermostat().flatMap(ActuatorFunctionality::getRegulationControl);
40     }
41
42     public Optional<Boolean> getCoolingAllowed() {
43         return this.getFunctionalityThermostat().flatMap(ActuatorFunctionality::getCoolingAllowed)
44                 .map(Boolean::parseBoolean);
45     }
46
47     public Optional<Boolean> getPreHeatState() {
48         return this.getFunctionalityThermostat().flatMap(ActuatorFunctionality::getPreHeatState)
49                 .map(Boolean::parseBoolean);
50     }
51
52     public Optional<ActuatorFunctionality> getFunctionalityThermostat() {
53         return Optional.ofNullable(this.get(THERMOSTAT_FUNCTIONALITY));
54     }
55
56     public Optional<ActuatorFunctionality> getFunctionalityOffsetTemperature() {
57         return Optional.ofNullable(this.get(OFFSETTEMPERATURE_FUNCTIONALITY));
58     }
59
60     public Optional<ActuatorFunctionality> getFunctionalityRelay() {
61         return Optional.ofNullable(this.get(RELAY_FUNCTIONALITY));
62     }
63
64     @Override
65     public void merge(Map<String, ActuatorFunctionality> actuatorFunctionalities) {
66         if (actuatorFunctionalities != null) {
67             for (ActuatorFunctionality actuatorFunctionality : actuatorFunctionalities.values()) {
68                 String type = actuatorFunctionality.getType();
69                 ActuatorFunctionality originalActuatorFunctionality = this.get(type);
70
71                 Boolean originalIsOlder = false;
72                 if (originalActuatorFunctionality != null) {
73                     originalIsOlder = originalActuatorFunctionality.isOlderThan(actuatorFunctionality);
74                 }
75
76                 if (originalActuatorFunctionality == null || originalIsOlder) {
77                     this.put(type, actuatorFunctionality);
78                 }
79             }
80         }
81     }
82 }