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.hue.internal.dto.clip2;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.hue.internal.exceptions.DTOPresentButEmptyException;
21 import com.google.gson.annotations.SerializedName;
24 * DTO for dimming brightness of a light.
26 * @author Andrew Fiddian-Green - Initial contribution
29 public class Dimming {
30 private @Nullable Double brightness;
31 private @Nullable @SerializedName("min_dim_level") Double minimumDimmingLevel;
33 public static final double DEFAULT_MINIMUM_DIMMIMG_LEVEL = 0.5f;
36 * @throws DTOPresentButEmptyException to indicate that the DTO is present but empty.
38 public double getBrightness() throws DTOPresentButEmptyException {
39 Double brightness = this.brightness;
40 if (Objects.nonNull(brightness)) {
43 throw new DTOPresentButEmptyException("'dimming' DTO is present but empty");
46 public @Nullable Double getMinimumDimmingLevel() {
47 return minimumDimmingLevel;
50 public Dimming setBrightness(double brightness) {
51 this.brightness = brightness;
55 public Dimming setMinimumDimmingLevel(Double minimumDimmingLevel) {
56 this.minimumDimmingLevel = minimumDimmingLevel;
60 public @Nullable String toPropertyValue() {
61 Double minimumDimmingLevel = this.minimumDimmingLevel;
62 if (Objects.nonNull(minimumDimmingLevel)) {
63 return String.format("%.1f %% .. 100 %%", minimumDimmingLevel.doubleValue());