]> git.basschouten.com Git - openhab-addons.git/blob
b6b847d59964f4165798a1d7fc316c5332b42b71
[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.hue.internal.api.dto.clip2;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.hue.internal.exceptions.DTOPresentButEmptyException;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * DTO for dimming brightness of a light.
25  *
26  * @author Andrew Fiddian-Green - Initial contribution
27  */
28 @NonNullByDefault
29 public class Dimming {
30     private @Nullable Double brightness;
31     private @Nullable @SerializedName("min_dim_level") Double minimumDimmingLevel;
32
33     public static final double DEFAULT_MINIMUM_DIMMIMG_LEVEL = 0.5f;
34
35     /**
36      * @throws DTOPresentButEmptyException to indicate that the DTO is present but empty.
37      */
38     public double getBrightness() throws DTOPresentButEmptyException {
39         Double brightness = this.brightness;
40         if (Objects.nonNull(brightness)) {
41             return brightness;
42         }
43         throw new DTOPresentButEmptyException("'dimming' DTO is present but empty");
44     }
45
46     public @Nullable Double getMinimumDimmingLevel() {
47         return minimumDimmingLevel;
48     }
49
50     public Dimming setBrightness(double brightness) {
51         this.brightness = brightness;
52         return this;
53     }
54
55     public Dimming setMinimumDimmingLevel(Double minimumDimmingLevel) {
56         this.minimumDimmingLevel = minimumDimmingLevel;
57         return this;
58     }
59
60     public @Nullable String toPropertyValue() {
61         Double minimumDimmingLevel = this.minimumDimmingLevel;
62         if (Objects.nonNull(minimumDimmingLevel)) {
63             return String.format("%.1f %% .. 100 %%", minimumDimmingLevel.doubleValue());
64         }
65         return null;
66     }
67 }