]> git.basschouten.com Git - openhab-addons.git/blob
eec8c168f1381045593990dd5cce45b45da8c1ce
[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.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.thing.Bridge;
18 import org.openhab.core.thing.Thing;
19 import org.openhab.core.thing.binding.BaseThingHandler;
20 import org.openhab.core.thing.binding.ThingHandler;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Abstract class for Things that are managed through an HD PowerView hub
26  *
27  * @author Andy Lintner - Initial contribution
28  */
29 @NonNullByDefault
30 abstract class AbstractHubbedThingHandler extends BaseThingHandler {
31
32     private final Logger logger = LoggerFactory.getLogger(AbstractHubbedThingHandler.class);
33
34     public AbstractHubbedThingHandler(Thing thing) {
35         super(thing);
36     }
37
38     protected @Nullable HDPowerViewHubHandler getBridgeHandler() {
39         Bridge bridge = getBridge();
40         if (bridge == null) {
41             logger.error("Thing {} must belong to a hub", getThing().getThingTypeUID().getId());
42             return null;
43         }
44         ThingHandler handler = bridge.getHandler();
45         if (!(handler instanceof HDPowerViewHubHandler)) {
46             logger.debug("Thing {} belongs to the wrong hub type", getThing().getThingTypeUID().getId());
47             return null;
48         }
49         return (HDPowerViewHubHandler) handler;
50     }
51 }