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