]> git.basschouten.com Git - openhab-addons.git/blob
471943c079778b7d06e8a6dd860cd6f53828e81d
[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.nikobus.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.nikobus.internal.NikobusBindingConstants;
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
24 /**
25  * The {@link NikobusBaseThingHandler} class defines utility logic to be consumed by Nikobus thing(s).
26  *
27  * @author Boris Krivonog - Initial contribution
28  */
29 @NonNullByDefault
30 abstract class NikobusBaseThingHandler extends BaseThingHandler {
31     private @Nullable String address;
32
33     protected NikobusBaseThingHandler(Thing thing) {
34         super(thing);
35     }
36
37     @Override
38     public void initialize() {
39         address = (String) getConfig().get(NikobusBindingConstants.CONFIG_ADDRESS);
40         if (address == null) {
41             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "Address must be set!");
42             return;
43         }
44
45         updateStatus(ThingStatus.UNKNOWN);
46     }
47
48     protected @Nullable NikobusPcLinkHandler getPcLink() {
49         Bridge bridge = getBridge();
50         if (bridge != null) {
51             return (NikobusPcLinkHandler) bridge.getHandler();
52         }
53         return null;
54     }
55
56     protected String getAddress() {
57         String address = this.address;
58         if (address == null) {
59             throw new IllegalStateException();
60         }
61         return address;
62     }
63 }