]> git.basschouten.com Git - openhab-addons.git/blob
f747c91b4e3b75c827a3ec179f81717888adf87b
[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.anel.internal;
14
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.thing.ThingTypeUID;
21
22 /**
23  * The {@link IAnelConstants} class defines common constants, which are
24  * used across the whole binding.
25  *
26  * @author Patrick Koenemann - Initial contribution
27  */
28 @NonNullByDefault
29 public interface IAnelConstants {
30
31     String BINDING_ID = "anel";
32
33     /** Message sent to Anel devices to detect new dfevices and to request the current state. */
34     String BROADCAST_DISCOVERY_MSG = "wer da?";
35     /** Expected prefix for all received Anel status messages. */
36     String STATUS_RESPONSE_PREFIX = "NET-PwrCtrl";
37     /** Separator of the received Anel status messages. */
38     String STATUS_SEPARATOR = ":";
39
40     /** Status message String if the current user / password does not match. */
41     String ERROR_CREDENTIALS = ":NoPass:Err";
42     /** Status message String if the current user does not have enough rights. */
43     String ERROR_INSUFFICIENT_RIGHTS = ":NoAccess:Err";
44
45     /** Property name to uniquely identify (discovered) things. */
46     String UNIQUE_PROPERTY_NAME = "mac";
47
48     /** Default port used to send message to Anel devices. */
49     int DEFAULT_SEND_PORT = 75;
50     /** Default port used to receive message from Anel devices. */
51     int DEFAULT_RECEIVE_PORT = 77;
52
53     /** Static refresh interval for heartbeat for Thing status. */
54     int REFRESH_INTERVAL_SEC = 60;
55
56     /** Thing is set OFFLINE after so many communication errors. */
57     int ATTEMPTS_WITH_COMMUNICATION_ERRORS = 3;
58
59     /** Thing is set OFFLINE if it did not respond to so many refresh requests. */
60     int UNANSWERED_REFRESH_REQUESTS_TO_SET_THING_OFFLINE = 5;
61
62     /** Thing Type UID for Anel Net-PwrCtrl HOME. */
63     ThingTypeUID THING_TYPE_ANEL_HOME = new ThingTypeUID(BINDING_ID, "home");
64     /** Thing Type UID for Anel Net-PwrCtrl PRO / POWER. */
65     ThingTypeUID THING_TYPE_ANEL_SIMPLE = new ThingTypeUID(BINDING_ID, "simple-firmware");
66     /** Thing Type UID for Anel Net-PwrCtrl ADV / IO / HUT. */
67     ThingTypeUID THING_TYPE_ANEL_ADVANCED = new ThingTypeUID(BINDING_ID, "advanced-firmware");
68     /** All supported Thing Type UIDs. */
69     Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_ANEL_HOME, THING_TYPE_ANEL_SIMPLE,
70             THING_TYPE_ANEL_ADVANCED);
71
72     /** The device type is part of the status response and is mapped to the thing types. */
73     Map<Character, ThingTypeUID> DEVICE_TYPE_TO_THING_TYPE = Map.of( //
74             'H', THING_TYPE_ANEL_HOME, // HOME
75             'P', THING_TYPE_ANEL_SIMPLE, // PRO / POWER
76             'h', THING_TYPE_ANEL_ADVANCED, // HUT (and variants, e.g. h3 for HUT3)
77             'a', THING_TYPE_ANEL_ADVANCED, // ADV
78             'i', THING_TYPE_ANEL_ADVANCED); // IO
79
80     // All remaining constants are Channel ids
81
82     String CHANNEL_NAME = "prop#name";
83     String CHANNEL_TEMPERATURE = "prop#temperature";
84
85     List<String> CHANNEL_RELAY_NAME = List.of("r1#name", "r2#name", "r3#name", "r4#name", "r5#name", "r6#name",
86             "r7#name", "r8#name");
87
88     // second character must be the index b/c it is parsed in AnelCommandHandler!
89     List<String> CHANNEL_RELAY_STATE = List.of("r1#state", "r2#state", "r3#state", "r4#state", "r5#state", "r6#state",
90             "r7#state", "r8#state");
91
92     List<String> CHANNEL_RELAY_LOCKED = List.of("r1#locked", "r2#locked", "r3#locked", "r4#locked", "r5#locked",
93             "r6#locked", "r7#locked", "r8#locked");
94
95     List<String> CHANNEL_IO_NAME = List.of("io1#name", "io2#name", "io3#name", "io4#name", "io5#name", "io6#name",
96             "io7#name", "io8#name");
97
98     List<String> CHANNEL_IO_MODE = List.of("io1#mode", "io2#mode", "io3#mode", "io4#mode", "io5#mode", "io6#mode",
99             "io7#mode", "io8#mode");
100
101     // third character must be the index b/c it is parsed in AnelCommandHandler!
102     List<String> CHANNEL_IO_STATE = List.of("io1#state", "io2#state", "io3#state", "io4#state", "io5#state",
103             "io6#state", "io7#state", "io8#state");
104
105     String CHANNEL_SENSOR_TEMPERATURE = "sensor#temperature";
106     String CHANNEL_SENSOR_HUMIDITY = "sensor#humidity";
107     String CHANNEL_SENSOR_BRIGHTNESS = "sensor#brightness";
108
109     /**
110      * @param channelId A channel ID.
111      * @return The zero-based index of the relay or IO channel (<code>0-7</code>); <code>-1</code> if it's not a relay
112      *         or IO channel.
113      */
114     static int getIndexFromChannel(String channelId) {
115         if (channelId.startsWith("r") && channelId.length() > 2) {
116             return Character.getNumericValue(channelId.charAt(1)) - 1;
117         }
118         if (channelId.startsWith("io") && channelId.length() > 2) {
119             return Character.getNumericValue(channelId.charAt(2)) - 1;
120         }
121         return -1; // not a relay or io channel
122     }
123 }