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_INTRS;
16 import static org.openhab.binding.satel.internal.config.IntRSConfig.PORT;
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.IntRSConfig;
25 import org.openhab.binding.satel.internal.protocol.IntRSModule;
26 import org.openhab.binding.satel.internal.protocol.SatelModule;
27 import org.openhab.core.config.core.status.ConfigStatusMessage;
28 import org.openhab.core.io.transport.serial.SerialPortManager;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.ThingStatus;
31 import org.openhab.core.thing.ThingStatusDetail;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * {@link IntRSBridgeHandler} is a bridge handler for INT-RS communication module.
38 * All {@link SatelThingHandler}s use it to receive events and execute commands.
40 * @author Krzysztof Goworek - Initial contribution
43 public class IntRSBridgeHandler extends SatelBridgeHandler {
45 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_INTRS);
47 private final Logger logger = LoggerFactory.getLogger(IntRSBridgeHandler.class);
49 private final SerialPortManager serialPortManager;
51 public IntRSBridgeHandler(Bridge bridge, SerialPortManager serialPortManager) {
53 this.serialPortManager = serialPortManager;
57 public void initialize() {
58 logger.debug("Initializing handler");
60 final IntRSConfig config = getConfigAs(IntRSConfig.class);
61 final String port = config.getPort();
62 if (!port.isBlank()) {
63 SatelModule satelModule = new IntRSModule(port, serialPortManager, config.getTimeout(),
64 config.hasExtCommandsSupport());
65 super.initialize(satelModule);
67 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
68 "Cannot connect to Satel INT-RS module. Serial port is not set.");
73 public Collection<ConfigStatusMessage> getConfigStatus() {
74 // The bridge serial port to be used for checks
75 final String port = (String) getThing().getConfiguration().get(PORT);
76 Collection<ConfigStatusMessage> configStatusMessages;
78 // Check whether a serial port is provided
80 configStatusMessages = List.of(ConfigStatusMessage.Builder.error(PORT).withMessageKeySuffix("portEmpty")
81 .withArguments(PORT).build());
83 configStatusMessages = Collections.emptyList();
86 return configStatusMessages;