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.hdpowerview.internal.dto.gen3;
15 import java.math.BigDecimal;
16 import java.math.MathContext;
17 import java.math.RoundingMode;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.hdpowerview.internal.dto.CoordinateSystem;
21 import org.openhab.core.library.types.PercentType;
22 import org.openhab.core.types.State;
23 import org.openhab.core.types.UnDefType;
26 * DTO for the position of a shade as returned by an HD PowerView Generation 3 Gateway.
28 * @author Andrew Fiddian-Green - Initial contribution
31 public class ShadePosition {
32 private static final MathContext MATH_CONTEXT = new MathContext(4, RoundingMode.HALF_UP);
34 private @NonNullByDefault({}) Double primary;
35 private @NonNullByDefault({}) Double secondary;
36 private @NonNullByDefault({}) Double tilt;
38 public State getState(CoordinateSystem posKindCoords) {
40 switch (posKindCoords) {
41 case PRIMARY_POSITION:
44 case SECONDARY_POSITION:
47 case VANE_TILT_POSITION:
53 return value != null ? new PercentType(new BigDecimal(value * 100f, MATH_CONTEXT)) : UnDefType.UNDEF;
57 * Set a new position value for this object based on the given coordinates, and the given new value.
59 * @param coordinates which of the position fields shall be set.
60 * @param percent the new value in percent.
61 * @return this object.
63 public ShadePosition setPosition(CoordinateSystem coordinates, PercentType percent) {
64 Double value = percent.doubleValue() / 100f;
65 switch (coordinates) {
66 case PRIMARY_POSITION:
69 case SECONDARY_POSITION:
72 case VANE_TILT_POSITION: