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.meteoblue.internal.handler;
15 import static org.openhab.binding.meteoblue.internal.MeteoBlueBindingConstants.THING_TYPE_BRIDGE;
19 import org.openhab.binding.meteoblue.internal.MeteoBlueBridgeConfig;
20 import org.openhab.core.io.net.http.HttpUtil;
21 import org.openhab.core.thing.Bridge;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.thing.ThingStatusDetail;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseBridgeHandler;
27 import org.openhab.core.types.Command;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link MeteoBlueBridgeHandler} is responsible for handling the
33 * bridge things created to use the meteoblue weather service.
35 * @author Chris Carman - Initial contribution
37 public class MeteoBlueBridgeHandler extends BaseBridgeHandler {
38 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE);
39 private final Logger logger = LoggerFactory.getLogger(MeteoBlueBridgeHandler.class);
41 private String apiKey;
43 public MeteoBlueBridgeHandler(Bridge bridge) {
48 * Initialize the bridge.
51 public void initialize() {
52 logger.debug("Initializing meteoblue bridge");
54 MeteoBlueBridgeConfig config = getConfigAs(MeteoBlueBridgeConfig.class);
55 String apiKeyTemp = config.getApiKey();
56 if (apiKeyTemp == null || apiKeyTemp.isBlank()) {
57 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
58 "Cannot initialize meteoblue bridge. No apiKey provided.");
68 * No commands are supported here.
71 public void handleCommand(ChannelUID channelUID, Command command) {
74 public String getApiKey() {
75 return new String(apiKey);
78 private void healthCheck() {
79 String url = "http://my.meteoblue.com/packages/";
81 HttpUtil.executeUrl("GET", url, 30 * 1000);
82 logger.trace("HealthCheck succeeded.");
83 updateStatus(ThingStatus.ONLINE);
84 } catch (Exception e) {
85 logger.trace("HealthCheck failed", e);
86 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "HealthCheck failed");