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