2 * Copyright (c) 2010-2021 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.apache.commons.lang.StringUtils;
21 import org.openhab.binding.meteoblue.internal.MeteoBlueBridgeConfig;
22 import org.openhab.core.io.net.http.HttpUtil;
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.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseBridgeHandler;
29 import org.openhab.core.types.Command;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link MeteoBlueBridgeHandler} is responsible for handling the
35 * bridge things created to use the meteoblue weather service.
37 * @author Chris Carman - Initial contribution
39 public class MeteoBlueBridgeHandler extends BaseBridgeHandler {
40 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
41 private final Logger logger = LoggerFactory.getLogger(MeteoBlueBridgeHandler.class);
43 private String apiKey;
45 public MeteoBlueBridgeHandler(Bridge bridge) {
50 * Initialize the bridge.
53 public void initialize() {
54 logger.debug("Initializing meteoblue bridge");
56 MeteoBlueBridgeConfig config = getConfigAs(MeteoBlueBridgeConfig.class);
57 String apiKeyTemp = config.getApiKey();
58 if (StringUtils.isBlank(apiKeyTemp)) {
59 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
60 "Cannot initialize meteoblue bridge. No apiKey provided.");
70 * No commands are supported here.
73 public void handleCommand(ChannelUID channelUID, Command command) {
76 public String getApiKey() {
77 return new String(apiKey);
80 private void healthCheck() {
81 String url = "http://my.meteoblue.com/packages/";
83 HttpUtil.executeUrl("GET", url, 30 * 1000);
84 logger.trace("HealthCheck succeeded.");
85 updateStatus(ThingStatus.ONLINE);
86 } catch (Exception e) {
87 logger.trace("HealthCheck failed", e);
88 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "HealthCheck failed");