]> git.basschouten.com Git - openhab-addons.git/blob
d237878aec3addd3ef40a1eeeac382975eb9ca18
[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.hdpowerview.internal.dto;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Shade coordinate system (a.k.a. position kind), as returned by the HD PowerView hub.
20  *
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.
26  *
27  * @author Andy Lintner - Initial contribution of the original enum called
28  *         ShadePositionKind
29  *
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
33  */
34 @NonNullByDefault
35 public enum CoordinateSystem {
36     /*-
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
46      *
47      * The position element can take on multiple states depending on the family of
48      * shade under control.
49      *
50      * The ranges of position integer values are
51      *      shades: 0..65535
52      *      vanes: 0..32767
53      *
54      * Shade fully up: (top-down: open, bottom-up: closed)
55      *      posKind: 1 {ZERO_IS_CLOSED}
56      *      position: 65535
57      *
58      * Shade and vane fully down: (top-down: closed, bottom-up: open)
59      *      posKind: 1 {ZERO_IS_CLOSED}
60      *      position1: 0
61      *
62      * ALTERNATE: Shade and vane fully down: (top-down: closed, bottom-up: open)
63      *      posKind: 3 {VANE_COORDS}
64      *      position: 0
65      *
66      * Shade fully down (closed) and vane fully up (open):
67      *      posKind: 3 {VANE_COORDS}
68      *      position: 32767
69      *
70      * Dual action, secondary top-down shade fully up (closed):
71      *      posKind: 2 {ZERO_IS_OPEN}
72      *      position: 0
73      *
74      * Dual action, secondary top-down shade fully down (open):
75      *      posKind: 2 {ZERO_IS_OPEN}
76      *      position: 65535
77      *
78      */
79     NONE,
80     PRIMARY_POSITION,
81     SECONDARY_POSITION,
82     VANE_TILT_POSITION,
83     ERROR_UNKNOWN;
84
85     public static final int MAX_SHADE = 65535;
86     public static final int MAX_VANE = 32767;
87
88     /**
89      * Converts an HD PowerView posKind integer value to a CoordinateSystem enum value.
90      *
91      * @param posKind input integer value.
92      * @return corresponding CoordinateSystem enum.
93      */
94     public static CoordinateSystem fromPosKind(int posKind) {
95         try {
96             return CoordinateSystem.values()[posKind];
97         } catch (ArrayIndexOutOfBoundsException e) {
98             return ERROR_UNKNOWN;
99         }
100     }
101
102     /**
103      * Check if the coordinate system matches the given posKind.
104      *
105      * @param posKind
106      * @return true if equal.
107      */
108     public boolean equals(@Nullable Integer posKind) {
109         return (posKind != null) && (posKind.intValue() == ordinal());
110     }
111 }