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.tado.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.tado.internal.api.client.HomeApi;
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.binding.BaseThingHandler;
22 import org.openhab.core.thing.binding.BridgeHandler;
25 * Common base class for home-based thing-handler.
27 * @author Dennis Frommknecht - Initial contribution
30 public abstract class BaseHomeThingHandler extends BaseThingHandler {
32 public BaseHomeThingHandler(Thing thing) {
36 public @Nullable Long getHomeId() {
37 TadoHomeHandler handler = getHomeHandler();
38 return handler.getHomeId();
41 protected TadoHomeHandler getHomeHandler() {
42 Bridge bridge = getBridge();
44 throw new IllegalStateException("Bridge not initialized");
46 BridgeHandler handler = bridge.getHandler();
47 if (!(handler instanceof TadoHomeHandler)) {
48 throw new IllegalStateException("Handler not initialized");
50 return (TadoHomeHandler) handler;
53 protected HomeApi getApi() {
54 TadoHomeHandler handler = getHomeHandler();
55 return handler.getApi();
58 protected void onSuccessfulOperation() {
59 // update without error -> we're back online
60 if (getThing().getStatus() == ThingStatus.OFFLINE) {
61 updateStatus(ThingStatus.ONLINE);