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;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.satel.internal.config.IntRSConfig;
24 import org.openhab.binding.satel.internal.protocol.IntRSModule;
25 import org.openhab.binding.satel.internal.protocol.SatelModule;
26 import org.openhab.core.config.core.status.ConfigStatusMessage;
27 import org.openhab.core.io.transport.serial.SerialPortManager;
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 IntRSBridgeHandler} is a bridge handler for INT-RS communication module.
37 * All {@link SatelThingHandler}s use it to receive events and execute commands.
39 * @author Krzysztof Goworek - Initial contribution
42 public class IntRSBridgeHandler extends SatelBridgeHandler {
44 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_INTRS);
46 private final Logger logger = LoggerFactory.getLogger(IntRSBridgeHandler.class);
48 private final SerialPortManager serialPortManager;
50 public IntRSBridgeHandler(Bridge bridge, SerialPortManager serialPortManager) {
52 this.serialPortManager = serialPortManager;
56 public void initialize() {
57 logger.debug("Initializing handler");
59 final IntRSConfig config = getConfigAs(IntRSConfig.class);
60 final String port = config.getPort();
61 if (!port.isBlank()) {
62 SatelModule satelModule = new IntRSModule(port, serialPortManager, config.getTimeout(),
63 config.hasExtCommandsSupport());
64 super.initialize(satelModule);
66 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
67 "Cannot connect to Satel INT-RS module. Serial port is not set.");
72 public Collection<ConfigStatusMessage> getConfigStatus() {
73 // The bridge serial port to be used for checks
74 final String port = (String) getThing().getConfiguration().get(PORT);
75 Collection<ConfigStatusMessage> configStatusMessages;
77 // Check whether a serial port is provided
79 configStatusMessages = Collections.singletonList(ConfigStatusMessage.Builder.error(PORT)
80 .withMessageKeySuffix("portEmpty").withArguments(PORT).build());
82 configStatusMessages = Collections.emptyList();
85 return configStatusMessages;