]> git.basschouten.com Git - openhab-addons.git/blob
3b35e74cb4ead4efe9a2c64ae59b9650ed14e4b2
[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.lutron.internal.radiora.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
18 import org.openhab.core.thing.Bridge;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.thing.ThingStatus;
21 import org.openhab.core.thing.ThingStatusDetail;
22 import org.openhab.core.thing.binding.BaseThingHandler;
23 import org.openhab.core.thing.binding.ThingHandler;
24
25 /**
26  * Base class for non bridge handlers for Lutron RadioRA devices
27  *
28  * @author Jeff Lauterbach - Initial Contribution
29  *
30  */
31 @NonNullByDefault
32 public abstract class LutronHandler extends BaseThingHandler {
33
34     public LutronHandler(Thing thing) {
35         super(thing);
36     }
37
38     public @Nullable RS232Handler getRS232Handler() {
39         Bridge bridge = getBridge();
40         if (bridge == null) {
41             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "Unable to get bridge");
42             return null;
43         }
44         ThingHandler th = bridge.getHandler();
45         if (th instanceof RS232Handler handler) {
46             return handler;
47         } else {
48             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Bridge not properly configured.");
49             return null;
50         }
51     }
52
53     /**
54      * Returns true if system numbers match, meaning that either both are 2 or both are 1 or 0 (n/a).
55      */
56     public static boolean systemsMatch(int a, int b) {
57         return ((a == 2 && b == 2) || ((a == 0 || a == 1) && (b == 0 || b == 1)));
58     }
59
60     public abstract void handleFeedback(RadioRAFeedback feedback);
61
62     @Override
63     public void initialize() {
64         updateStatus(ThingStatus.ONLINE);
65     }
66 }