]> git.basschouten.com Git - openhab-addons.git/blob
86169372e0b1abec8203736237f3947059681bac
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.satel.internal.handler;
14
15 import static org.openhab.binding.satel.internal.SatelBindingConstants.THING_TYPE_ETHM1;
16 import static org.openhab.binding.satel.internal.config.Ethm1Config.HOST;
17
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Set;
22
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;
34
35 /**
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.
38  *
39  * @author Krzysztof Goworek - Initial contribution
40  */
41 @NonNullByDefault
42 public class Ethm1BridgeHandler extends SatelBridgeHandler {
43
44     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ETHM1);
45
46     private final Logger logger = LoggerFactory.getLogger(Ethm1BridgeHandler.class);
47
48     public Ethm1BridgeHandler(Bridge bridge) {
49         super(bridge);
50     }
51
52     @Override
53     public void initialize() {
54         logger.debug("Initializing handler");
55
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);
61         } else {
62             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
63                     "Cannot connect to Satel ETHM-1 module. IP address or host name not set.");
64         }
65     }
66
67     @Override
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;
72
73         // Check whether an IP address is provided
74         if (host.isBlank()) {
75             configStatusMessages = List.of(ConfigStatusMessage.Builder.error(HOST).withMessageKeySuffix("hostEmpty")
76                     .withArguments(HOST).build());
77         } else {
78             configStatusMessages = Collections.emptyList();
79         }
80
81         return configStatusMessages;
82     }
83 }