2 * Copyright (c) 2010-2024 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.airquality.internal.handler;
15 import java.util.Collection;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.airquality.internal.api.ApiBridge;
21 import org.openhab.binding.airquality.internal.discovery.AirQualityDiscoveryService;
22 import org.openhab.core.i18n.LocationProvider;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.ThingStatus;
26 import org.openhab.core.thing.ThingStatusDetail;
27 import org.openhab.core.thing.binding.BaseBridgeHandler;
28 import org.openhab.core.thing.binding.ThingHandlerService;
29 import org.openhab.core.types.Command;
32 * The {@link AirQualityBridgeHandler} is responsible for handling communication
33 * with the service via the API.
35 * @author Gaƫl L'hopital - Initial contribution
38 public class AirQualityBridgeHandler extends BaseBridgeHandler {
39 private final LocationProvider locationProvider;
40 private @Nullable ApiBridge apiBridge;
42 public AirQualityBridgeHandler(Bridge bridge, LocationProvider locationProvider) {
44 this.locationProvider = locationProvider;
48 public void initialize() {
49 String apiKey = (String) getConfig().get("apiKey");
50 if (apiKey != null && apiKey.length() != 0) {
51 apiBridge = new ApiBridge(apiKey);
52 updateStatus(ThingStatus.ONLINE);
55 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/null-or-empty-api-key");
60 public void handleCommand(ChannelUID channelUID, Command command) {
64 public @Nullable ApiBridge getApiBridge() {
69 public Collection<Class<? extends ThingHandlerService>> getServices() {
70 return Set.of(AirQualityDiscoveryService.class);
73 public LocationProvider getLocationProvider() {
74 return locationProvider;