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.api.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.api.dto.clip2.enums.DirectionType;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.types.State;
22 import org.openhab.core.types.UnDefType;
25 * DTO for rotation element of a tap dial switch.
27 * @author Andrew Fiddian-Green - Initial contribution
30 public class Rotation {
31 private @Nullable String direction;
32 private @Nullable Integer duration;
33 private @Nullable Integer steps;
35 public @Nullable DirectionType getDirection() {
36 String direction = this.direction;
37 return Objects.nonNull(direction) ? DirectionType.valueOf(direction.toUpperCase()) : null;
40 public int getDuration() {
41 Integer duration = this.duration;
42 return Objects.nonNull(duration) ? duration.intValue() : 0;
45 public int getSteps() {
46 Integer steps = this.steps;
47 return Objects.nonNull(steps) ? steps.intValue() : 0;
51 * Get the state corresponding to a relative rotary dial's last steps value. Clockwise rotations are positive, and
52 * counter clockwise rotations negative.
54 * @return the state or UNDEF.
56 public State getStepsState() {
57 DirectionType direction = getDirection();
58 Integer steps = this.steps;
59 if (Objects.nonNull(direction) && Objects.nonNull(steps)) {
60 return new DecimalType(DirectionType.CLOCK_WISE.equals(direction) ? steps.intValue() : -steps.intValue());
62 return UnDefType.NULL;