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.onebusaway.internal.handler;
15 import static org.openhab.binding.onebusaway.internal.OneBusAwayBindingConstants.THING_TYPE_API;
17 import org.openhab.binding.onebusaway.internal.config.ApiConfiguration;
18 import org.openhab.core.thing.Bridge;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.ThingStatus;
21 import org.openhab.core.thing.ThingStatusDetail;
22 import org.openhab.core.thing.ThingTypeUID;
23 import org.openhab.core.thing.binding.BaseBridgeHandler;
24 import org.openhab.core.types.Command;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The {@link ApiHandler} is responsible for storing basic configuration data for talking to a OneBusAway API server.
31 * @author Shawn Wilsher - Initial contribution
33 public class ApiHandler extends BaseBridgeHandler {
34 public static final ThingTypeUID SUPPORTED_THING_TYPE = THING_TYPE_API;
36 private ApiConfiguration config;
37 private Logger logger = LoggerFactory.getLogger(ApiHandler.class);
39 public ApiHandler(Bridge bridge) {
44 public void handleCommand(ChannelUID channelUID, Command command) {
45 logger.warn("The API bridge is a read-only and can not handle commands.");
49 public void initialize() {
50 logger.debug("Initializing OneBusAway bridge...");
52 config = loadAndCheckConfiguration();
54 logger.debug("Initialization of OneBusAway API bridge failed!");
57 updateStatus(ThingStatus.ONLINE);
60 protected String getApiKey() {
61 return config.getApiKey();
64 protected String getApiServer() {
65 return config.getApiServer();
68 private ApiConfiguration loadAndCheckConfiguration() {
69 ApiConfiguration config = getConfigAs(ApiConfiguration.class);
70 if (config.getApiKey() == null) {
71 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "apiKey is not set");
74 if (config.getApiServer() == null) {
75 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "apiServer is not set");