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.satel.internal.handler;
15 import static org.openhab.binding.satel.internal.SatelBindingConstants.THING_TYPE_ETHM1;
16 import static org.openhab.binding.satel.internal.config.Ethm1Config.HOST;
18 import java.util.Collection;
19 import java.util.Collections;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.satel.internal.config.Ethm1Config;
24 import org.openhab.binding.satel.internal.protocol.Ethm1Module;
25 import org.openhab.binding.satel.internal.protocol.SatelModule;
26 import org.openhab.core.config.core.status.ConfigStatusMessage;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.ThingStatus;
29 import org.openhab.core.thing.ThingStatusDetail;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * {@link Ethm1BridgeHandler} is a bridge handler for ETHM-1 communication module.
36 * All {@link SatelThingHandler}s use it to receive events and execute commands.
38 * @author Krzysztof Goworek - Initial contribution
41 public class Ethm1BridgeHandler extends SatelBridgeHandler {
43 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ETHM1);
45 private final Logger logger = LoggerFactory.getLogger(Ethm1BridgeHandler.class);
47 public Ethm1BridgeHandler(Bridge bridge) {
52 public void initialize() {
53 logger.debug("Initializing handler");
55 Ethm1Config config = getConfigAs(Ethm1Config.class);
56 if (!config.getHost().isBlank()) {
57 SatelModule satelModule = new Ethm1Module(config.getHost(), config.getPort(), config.getTimeout(),
58 config.getEncryptionKey(), config.hasExtCommandsSupport());
59 super.initialize(satelModule);
61 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
62 "Cannot connect to Satel ETHM-1 module. IP address or host name not set.");
67 public Collection<ConfigStatusMessage> getConfigStatus() {
68 // The bridge IP address to be used for checks
69 String host = (String) getThing().getConfiguration().get(HOST);
70 Collection<ConfigStatusMessage> configStatusMessages;
72 // Check whether an IP address is provided
74 configStatusMessages = Collections.singletonList(ConfigStatusMessage.Builder.error(HOST)
75 .withMessageKeySuffix("hostEmpty").withArguments(HOST).build());
77 configStatusMessages = Collections.emptyList();
80 return configStatusMessages;