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.tado.internal;
15 import java.util.Objects;
16 import java.util.Optional;
17 import java.util.stream.Stream;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.tado.internal.api.model.AcModeCapabilities;
22 import org.openhab.binding.tado.internal.api.model.AirConditioningCapabilities;
23 import org.openhab.binding.tado.internal.api.model.ControlDevice;
24 import org.openhab.binding.tado.internal.api.model.GenericZoneCapabilities;
25 import org.openhab.binding.tado.internal.api.model.TadoSystemType;
26 import org.openhab.binding.tado.internal.api.model.Zone;
29 * The {@link CapabilitiesSupport} class checks which type of channels are needed in a thing that is to be built around
30 * the given capabilities argument, and the (optional) zone argument. It iterates over each of the capabilities
31 * argument's mode specific sub-capabilities to determine the maximum super set of all sub-capabilities. And it checks
32 * the capabilities of the optional zone argument too.
34 * @author Andrew Fiddian-Green - Initial contribution
37 public class CapabilitiesSupport {
38 private final TadoSystemType type;
39 private boolean light;
40 private boolean swing;
41 private boolean fanLevel;
42 private boolean fanSpeed;
43 private boolean verticalSwing;
44 private boolean horizontalSwing;
45 private boolean batteryLowAlarm;
47 public CapabilitiesSupport(GenericZoneCapabilities capabilities, Optional<Zone> zoneOptional) {
48 type = capabilities.getType();
50 if (zoneOptional.isPresent()) {
51 Zone zone = zoneOptional.get();
52 if (zone.getDevices() != null) {
53 batteryLowAlarm = zone.getDevices().stream().map(ControlDevice::getBatteryState)
54 .filter(Objects::nonNull).count() > 0;
58 if (!(capabilities instanceof AirConditioningCapabilities)) {
62 AirConditioningCapabilities acCapabilities = (AirConditioningCapabilities) capabilities;
65 Stream<@Nullable AcModeCapabilities> allCapabilities = Stream.of(
66 acCapabilities.getCOOL(),
67 acCapabilities.getDRY(),
68 acCapabilities.getHEAT(),
69 acCapabilities.getFAN(),
70 acCapabilities.getAUTO());
73 // iterate over all mode capability elements and build the superset of their inner capabilities
74 allCapabilities.forEach(e -> {
76 light |= e.getLight() != null ? e.getLight().size() > 0 : false;
77 swing |= e.getSwings() != null ? e.getSwings().size() > 0 : false;
78 fanLevel |= e.getFanLevel() != null ? e.getFanLevel().size() > 0 : false;
79 fanSpeed |= e.getFanSpeeds() != null ? e.getFanSpeeds().size() > 0 : false;
80 verticalSwing |= e.getVerticalSwing() != null ? e.getVerticalSwing().size() > 0 : false;
81 horizontalSwing |= e.getHorizontalSwing() != null ? e.getHorizontalSwing().size() > 0 : false;
86 public boolean fanLevel() {
90 public boolean fanSpeed() {
94 public boolean horizontalSwing() {
95 return horizontalSwing;
98 public boolean light() {
102 public boolean swing() {
106 public boolean verticalSwing() {
107 return verticalSwing;
110 public boolean acPower() {
111 return type == TadoSystemType.AIR_CONDITIONING;
114 public boolean heatingPower() {
115 return type == TadoSystemType.HEATING;
118 public boolean currentTemperature() {
119 return (type == TadoSystemType.AIR_CONDITIONING) || (type == TadoSystemType.HEATING);
122 public boolean humidity() {
123 return (type == TadoSystemType.AIR_CONDITIONING) || (type == TadoSystemType.HEATING);
126 public boolean batteryLowAlarm() {
127 return batteryLowAlarm;
130 public boolean openWindow() {
131 return (type == TadoSystemType.AIR_CONDITIONING) || (type == TadoSystemType.HEATING);