]> git.basschouten.com Git - openhab-addons.git/blob
4443576fb49ac9bd1d4b281a5b095db2b2554f0a
[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.draytonwiser.internal;
14
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
26
27 /**
28  * The {@link DraytonWiserBindingConstants} class defines common constants, which are
29  * used across the whole binding.
30  *
31  * @author Andrew Schofield - Initial contribution
32  */
33 @NonNullByDefault
34 public class DraytonWiserBindingConstants {
35
36     public static final String BINDING_ID = "draytonwiser";
37
38     public static final String REFRESH_INTERVAL = "refresh";
39     public static final int DEFAULT_REFRESH_SECONDS = 60;
40
41     public static final int OFFLINE_TEMPERATURE = -32768;
42
43     // Web Service Endpoints
44     public static final String DEVICE_ENDPOINT = "data/domain/Device/";
45     public static final String ROOMSTATS_ENDPOINT = "data/domain/RoomStat/";
46     public static final String TRVS_ENDPOINT = "data/domain/SmartValve/";
47     public static final String ROOMS_ENDPOINT = "data/domain/Room/";
48     public static final String HEATCHANNELS_ENDPOINT = "data/domain/HeatingChannel/";
49     public static final String SYSTEM_ENDPOINT = "data/domain/System/";
50     public static final String STATION_ENDPOINT = "data/network/Station/";
51     public static final String DOMAIN_ENDPOINT = "data/domain/";
52     public static final String HOTWATER_ENDPOINT = "data/domain/HotWater/";
53     public static final String SMARTPLUG_ENDPOINT = "data/domain/SmartPlug/";
54
55     // bridge
56     public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "heathub");
57
58     // List of all Thing Type UIDs
59     public static final ThingTypeUID THING_TYPE_CONTROLLER = new ThingTypeUID(BINDING_ID, "boiler-controller");
60     public static final ThingTypeUID THING_TYPE_ROOM = new ThingTypeUID(BINDING_ID, "room");
61     public static final ThingTypeUID THING_TYPE_ROOMSTAT = new ThingTypeUID(BINDING_ID, "roomstat");
62     public static final ThingTypeUID THING_TYPE_ITRV = new ThingTypeUID(BINDING_ID, "itrv");
63     public static final ThingTypeUID THING_TYPE_HOTWATER = new ThingTypeUID(BINDING_ID, "hotwater");
64     public static final ThingTypeUID THING_TYPE_SMARTPLUG = new ThingTypeUID(BINDING_ID, "smart-plug");
65
66     // properties
67     public static final String PROP_ADDRESS = "networkAddress";
68     public static final String PROP_SERIAL_NUMBER = "serialNumber";
69     public static final String PROP_NAME = "name";
70     public static final String PROP_ID = "id";
71
72     // List of all Channel ids
73     public static final String CHANNEL_CURRENT_TEMPERATURE = "currentTemperature";
74     public static final String CHANNEL_CURRENT_HUMIDITY = "currentHumidity";
75     public static final String CHANNEL_CURRENT_SETPOINT = "currentSetPoint";
76     public static final String CHANNEL_CURRENT_BATTERY_VOLTAGE = "currentBatteryVoltage";
77     public static final String CHANNEL_CURRENT_BATTERY_LEVEL = "currentBatteryLevel";
78     public static final String CHANNEL_CURRENT_WISER_BATTERY_LEVEL = "currentWiserBatteryLevel";
79     public static final String CHANNEL_CURRENT_DEMAND = "currentDemand";
80     public static final String CHANNEL_HEAT_REQUEST = "heatRequest";
81     public static final String CHANNEL_CURRENT_SIGNAL_RSSI = "currentSignalRSSI";
82     public static final String CHANNEL_CURRENT_SIGNAL_LQI = "currentSignalLQI";
83     public static final String CHANNEL_CURRENT_SIGNAL_STRENGTH = "currentSignalStrength";
84     public static final String CHANNEL_CURRENT_WISER_SIGNAL_STRENGTH = "currentWiserSignalStrength";
85     public static final String CHANNEL_HEATING_OVERRIDE = "heatingOverride";
86     public static final String CHANNEL_HOT_WATER_OVERRIDE = "hotWaterOverride";
87     public static final String CHANNEL_HEATCHANNEL_1_DEMAND = "heatChannel1Demand";
88     public static final String CHANNEL_HEATCHANNEL_2_DEMAND = "heatChannel2Demand";
89     public static final String CHANNEL_HEATCHANNEL_1_DEMAND_STATE = "heatChannel1DemandState";
90     public static final String CHANNEL_HEATCHANNEL_2_DEMAND_STATE = "heatChannel2DemandState";
91     public static final String CHANNEL_HOTWATER_DEMAND_STATE = "hotWaterDemandState";
92     public static final String CHANNEL_AWAY_MODE_STATE = "awayModeState";
93     public static final String CHANNEL_ECO_MODE_STATE = "ecoModeState";
94     public static final String CHANNEL_MANUAL_MODE_STATE = "manualModeState";
95     public static final String CHANNEL_ZIGBEE_CONNECTED = "zigbeeConnected";
96     public static final String CHANNEL_HOT_WATER_SETPOINT = "hotWaterSetPoint";
97     public static final String CHANNEL_HOT_WATER_BOOST_DURATION = "hotWaterBoostDuration";
98     public static final String CHANNEL_HOT_WATER_BOOSTED = "hotWaterBoosted";
99     public static final String CHANNEL_HOT_WATER_BOOST_REMAINING = "hotWaterBoostRemaining";
100     public static final String CHANNEL_ROOM_BOOST_DURATION = "roomBoostDuration";
101     public static final String CHANNEL_ROOM_BOOSTED = "roomBoosted";
102     public static final String CHANNEL_ROOM_BOOST_REMAINING = "roomBoostRemaining";
103     public static final String CHANNEL_ROOM_WINDOW_STATE_DETECTION = "windowStateDetection";
104     public static final String CHANNEL_ROOM_WINDOW_STATE = "windowState";
105     public static final String CHANNEL_DEVICE_LOCKED = "deviceLocked";
106     public static final String CHANNEL_SMARTPLUG_OUTPUT_STATE = "plugOutputState";
107     public static final String CHANNEL_SMARTPLUG_AWAY_ACTION = "plugAwayAction";
108     public static final String CHANNEL_COMFORT_MODE_STATE = "comfortModeState";
109     public static final String CHANNEL_SMARTPLUG_INSTANTANEOUS_POWER = "plugInstantaneousPower";
110     public static final String CHANNEL_SMARTPLUG_ENERGY_DELIVERED = "plugEnergyDelivered";
111
112     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
113             .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, THING_TYPE_ROOMSTAT,
114                     THING_TYPE_BRIDGE, THING_TYPE_ITRV, THING_TYPE_HOTWATER, THING_TYPE_SMARTPLUG)));
115
116     // Lookups from text representations to useful values
117
118     public enum SignalStrength {
119         VERYGOOD(4),
120         GOOD(3),
121         MEDIUM(2),
122         POOR(1),
123         NOSIGNAL(0);
124
125         private final int signalStrength;
126
127         SignalStrength(final int signalStrength) {
128             this.signalStrength = signalStrength;
129         }
130
131         public static State toSignalStrength(final String strength) {
132             try {
133                 return new DecimalType(SignalStrength.valueOf(strength.toUpperCase()).signalStrength);
134             } catch (final IllegalArgumentException e) {
135                 // Catch unrecognized values.
136                 return UnDefType.UNDEF;
137             }
138         }
139     }
140
141     public enum BatteryLevel {
142         FULL(100),
143         NORMAL(80),
144         TWOTHIRDS(60),
145         ONETHIRD(40),
146         LOW(20),
147         CRITICAL(0);
148
149         private final int batteryLevel;
150
151         private BatteryLevel(final int batteryLevel) {
152             this.batteryLevel = batteryLevel;
153         }
154
155         public static State toBatteryLevel(final @Nullable String level) {
156             if (level != null) {
157                 try {
158                     return new DecimalType(BatteryLevel.valueOf(level.toUpperCase()).batteryLevel);
159                 } catch (final IllegalArgumentException e) {
160                     // Catch unrecognized values.
161                     return UnDefType.UNDEF;
162                 }
163             } else {
164                 return UnDefType.UNDEF;
165             }
166         }
167     }
168 }