]> git.basschouten.com Git - openhab-addons.git/blob
fc41c6bc1a2f02893cb231d6fe6a84c02a9838e4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.tado.internal.handler;
14
15 import org.openhab.binding.tado.internal.api.client.HomeApi;
16 import org.openhab.core.thing.Bridge;
17 import org.openhab.core.thing.Thing;
18 import org.openhab.core.thing.ThingStatus;
19 import org.openhab.core.thing.binding.BaseThingHandler;
20
21 /**
22  * Common base class for home-based thing-handler.
23  *
24  * @author Dennis Frommknecht - Initial contribution
25  */
26 public abstract class BaseHomeThingHandler extends BaseThingHandler {
27
28     public BaseHomeThingHandler(Thing thing) {
29         super(thing);
30     }
31
32     public Long getHomeId() {
33         TadoHomeHandler handler = getHomeHandler();
34         return handler != null ? handler.getHomeId() : Long.valueOf(0);
35     }
36
37     protected TadoHomeHandler getHomeHandler() {
38         Bridge bridge = getBridge();
39         return bridge != null ? (TadoHomeHandler) bridge.getHandler() : null;
40     }
41
42     protected HomeApi getApi() {
43         TadoHomeHandler handler = getHomeHandler();
44         return handler != null ? handler.getApi() : null;
45     }
46
47     protected void onSuccessfulOperation() {
48         // update without error -> we're back online
49         if (getThing().getStatus() == ThingStatus.OFFLINE) {
50             updateStatus(ThingStatus.ONLINE);
51         }
52     }
53 }