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.hdpowerview.internal.dto;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * Shade coordinate system (a.k.a. position kind), as returned by the HD PowerView hub.
21 * @param NONE a coordinate system that does not refer to any type of physical rail.
22 * @param PRIMARY_POSITION primary rail, whose coordinate value 0 means shade is closed.
23 * @param SECONDARY_POSITION secondary rail, whose coordinate value 0 means shade is open.
24 * @param VANE_TILT_POSITION vane/tilt operator, whose coordinate system is for vanes.
25 * @param ERROR_UNKNOWN unsupported coordinate system.
27 * @author Andy Lintner - Initial contribution of the original enum called
30 * @author Andrew Fiddian-Green - Rewritten as a new enum called
31 * CoordinateSystem to support secondary rail positions and be more
32 * explicit on coordinate directions and ranges
35 public enum CoordinateSystem {
37 * Specifies the coordinate system used for the position of the shade. Top-down
38 * shades are in the same coordinate space as bottom-up shades. Shade position
39 * values for top-down shades would be reversed for bottom-up shades. For
40 * example, since 65535 is the open value for a bottom-up shade, it is the
41 * closed value for a top-down shade. The top-down/bottom-up shade is different
42 * in that instead of the top and bottom rail operating in one coordinate space
43 * like the top-down and the bottom-up, it operates in two where the top
44 * (middle) rail closed value is 0 and the bottom (primary) rail closed position
45 * is also 0 and fully open for both is 65535
47 * The position element can take on multiple states depending on the family of
48 * shade under control.
50 * The ranges of position integer values are
54 * Shade fully up: (top-down: open, bottom-up: closed)
55 * posKind: 1 {ZERO_IS_CLOSED}
58 * Shade and vane fully down: (top-down: closed, bottom-up: open)
59 * posKind: 1 {ZERO_IS_CLOSED}
62 * ALTERNATE: Shade and vane fully down: (top-down: closed, bottom-up: open)
63 * posKind: 3 {VANE_COORDS}
66 * Shade fully down (closed) and vane fully up (open):
67 * posKind: 3 {VANE_COORDS}
70 * Dual action, secondary top-down shade fully up (closed):
71 * posKind: 2 {ZERO_IS_OPEN}
74 * Dual action, secondary top-down shade fully down (open):
75 * posKind: 2 {ZERO_IS_OPEN}
85 public static final int MAX_SHADE = 65535;
86 public static final int MAX_VANE = 32767;
89 * Converts an HD PowerView posKind integer value to a CoordinateSystem enum value.
91 * @param posKind input integer value.
92 * @return corresponding CoordinateSystem enum.
94 public static CoordinateSystem fromPosKind(int posKind) {
96 return CoordinateSystem.values()[posKind];
97 } catch (ArrayIndexOutOfBoundsException e) {
103 * Check if the coordinate system matches the given posKind.
106 * @return true if equal.
108 public boolean equals(@Nullable Integer posKind) {
109 return (posKind != null) && (posKind.intValue() == ordinal());