2 * Copyright (c) 2010-2022 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.builder;
15 import java.io.IOException;
17 import org.openhab.binding.tado.internal.TadoBindingConstants;
18 import org.openhab.binding.tado.internal.TadoBindingConstants.FanLevel;
19 import org.openhab.binding.tado.internal.TadoBindingConstants.FanSpeed;
20 import org.openhab.binding.tado.internal.TadoBindingConstants.HorizontalSwing;
21 import org.openhab.binding.tado.internal.TadoBindingConstants.HvacMode;
22 import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit;
23 import org.openhab.binding.tado.internal.TadoBindingConstants.VerticalSwing;
24 import org.openhab.binding.tado.internal.api.ApiException;
25 import org.openhab.binding.tado.internal.api.model.GenericZoneCapabilities;
26 import org.openhab.binding.tado.internal.api.model.GenericZoneSetting;
27 import org.openhab.binding.tado.internal.api.model.TemperatureObject;
28 import org.openhab.binding.tado.internal.handler.TadoZoneHandler;
31 * Base class for zone settings builder.
33 * @author Dennis Frommknecht - Initial contribution
35 public abstract class ZoneSettingsBuilder {
36 public static ZoneSettingsBuilder of(TadoZoneHandler zoneHandler) {
37 TadoBindingConstants.ZoneType zoneType = zoneHandler.getZoneType();
38 if (zoneType == null) {
39 throw new IllegalArgumentException("Zone type is null");
43 return new HeatingZoneSettingsBuilder();
44 case AIR_CONDITIONING:
45 return new AirConditioningZoneSettingsBuilder();
47 return new HotWaterZoneSettingsBuilder();
49 throw new IllegalArgumentException("Zone type " + zoneHandler.getZoneType() + " unknown");
53 protected HvacMode mode = null;
54 protected Float temperature = null;
55 protected TemperatureUnit temperatureUnit = TemperatureUnit.CELSIUS;
56 protected Boolean swing = null;
57 protected Boolean light = null;
58 protected FanSpeed fanSpeed = null;
59 protected FanLevel fanLevel = null;
60 protected HorizontalSwing horizontalSwing = null;
61 protected VerticalSwing verticalSwing = null;
63 public ZoneSettingsBuilder withMode(HvacMode mode) {
68 public ZoneSettingsBuilder withTemperature(Float temperature, TemperatureUnit temperatureUnit) {
69 this.temperature = temperature;
70 this.temperatureUnit = temperatureUnit;
74 public ZoneSettingsBuilder withSwing(boolean swingOn) {
79 public ZoneSettingsBuilder withFanSpeed(FanSpeed fanSpeed) {
80 this.fanSpeed = fanSpeed;
84 public ZoneSettingsBuilder withFanLevel(FanLevel fanLevel) {
85 this.fanLevel = fanLevel;
89 public ZoneSettingsBuilder withHorizontalSwing(HorizontalSwing horizontalSwing) {
90 this.horizontalSwing = horizontalSwing;
94 public ZoneSettingsBuilder withVerticalSwing(VerticalSwing verticalSwing) {
95 this.verticalSwing = verticalSwing;
99 public abstract GenericZoneSetting build(ZoneStateProvider zoneStateProvider, GenericZoneCapabilities capabilities)
100 throws IOException, ApiException;
102 protected TemperatureObject truncateTemperature(TemperatureObject temperature) {
103 if (temperature == null) {
107 TemperatureObject temperatureObject = new TemperatureObject();
108 if (temperatureUnit == TemperatureUnit.FAHRENHEIT) {
109 temperatureObject.setFahrenheit(temperature.getFahrenheit());
111 temperatureObject.setCelsius(temperature.getCelsius());
114 return temperatureObject;
117 protected TemperatureObject buildDefaultTemperatureObject(float temperatureCelsius, float temperatureFahrenheit) {
118 TemperatureObject temperatureObject = new TemperatureObject();
120 if (temperatureUnit == TemperatureUnit.FAHRENHEIT) {
121 temperatureObject.setFahrenheit(temperatureFahrenheit);
123 temperatureObject.setCelsius(temperatureCelsius);
126 return temperatureObject;
129 public ZoneSettingsBuilder withLight(boolean lightOn) {
130 this.light = lightOn;