2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hdpowerview.internal.handler;
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;
25 * Abstract class for Things that are managed through an HD PowerView hub
27 * @author Andy Lintner - Initial contribution
30 abstract class AbstractHubbedThingHandler extends BaseThingHandler {
32 private final Logger logger = LoggerFactory.getLogger(AbstractHubbedThingHandler.class);
34 public AbstractHubbedThingHandler(Thing thing) {
38 protected @Nullable HDPowerViewHubHandler getBridgeHandler() {
39 Bridge bridge = getBridge();
41 logger.error("Thing {} must belong to a hub", getThing().getThingTypeUID().getId());
44 ThingHandler handler = bridge.getHandler();
45 if (!(handler instanceof HDPowerViewHubHandler)) {
46 logger.debug("Thing {} belongs to the wrong hub type", getThing().getThingTypeUID().getId());
49 return (HDPowerViewHubHandler) handler;