]> git.basschouten.com Git - openhab-addons.git/blob
cced3c913b70c1df4977c3db9f2a702c98d84a10
[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.Set;
21
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;
33
34 /**
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.
37  *
38  * @author Krzysztof Goworek - Initial contribution
39  */
40 @NonNullByDefault
41 public class Ethm1BridgeHandler extends SatelBridgeHandler {
42
43     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ETHM1);
44
45     private final Logger logger = LoggerFactory.getLogger(Ethm1BridgeHandler.class);
46
47     public Ethm1BridgeHandler(Bridge bridge) {
48         super(bridge);
49     }
50
51     @Override
52     public void initialize() {
53         logger.debug("Initializing handler");
54
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);
60         } else {
61             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
62                     "Cannot connect to Satel ETHM-1 module. IP address or host name not set.");
63         }
64     }
65
66     @Override
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;
71
72         // Check whether an IP address is provided
73         if (host.isBlank()) {
74             configStatusMessages = Collections.singletonList(ConfigStatusMessage.Builder.error(HOST)
75                     .withMessageKeySuffix("hostEmpty").withArguments(HOST).build());
76         } else {
77             configStatusMessages = Collections.emptyList();
78         }
79
80         return configStatusMessages;
81     }
82 }