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.broadlinkthermostat.internal.handler;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.broadlinkthermostat.internal.BroadlinkConfig;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.thing.ThingStatusDetail;
23 import org.openhab.core.thing.binding.BaseThingHandler;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.github.mob41.blapi.BLDevice;
30 * The {@link BroadlinkBaseHandler} is the device handler class for a broadlink device.
32 * @author Florian Mueller - Initial contribution
35 public abstract class BroadlinkBaseHandler extends BaseThingHandler {
37 private final Logger logger = LoggerFactory.getLogger(BroadlinkBaseHandler.class);
42 String macAddress = "";
45 * Creates a new instance of this class for the {@link Thing}.
47 * @param thing the thing that should be handled, not null
49 BroadlinkBaseHandler(Thing thing) {
53 void authenticate(boolean reauth) {
54 logger.debug("Authenticating with broadlink device {}...", thing.getLabel());
56 BLDevice blDevice = this.blDevice;
57 if (blDevice != null && blDevice.auth(reauth)) {
58 updateStatus(ThingStatus.ONLINE);
60 } catch (IOException e) {
61 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
62 "Error while authenticating broadlink device " + thing.getLabel() + ":" + e.getMessage());
67 public void initialize() {
68 BroadlinkConfig config = getConfigAs(BroadlinkConfig.class);
69 host = config.getHost();
70 macAddress = config.getMacAddress();