]> git.basschouten.com Git - openhab-addons.git/blob
e0938e1a2cdb140142801d648d991f94a86ccbeb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.nikohomecontrol.internal.handler;
14
15 import java.net.InetAddress;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.nikohomecontrol.internal.protocol.nhc1.NikoHomeControlCommunication1;
21 import org.openhab.core.thing.Bridge;
22 import org.openhab.core.thing.ThingStatus;
23 import org.openhab.core.thing.ThingStatusDetail;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * {@link NikoHomeControlBridgeHandler1} is the handler for a Niko Home Control I IP-interface and connects it to
29  * the framework.
30  *
31  * @author Mark Herwege - Initial Contribution
32  */
33 @NonNullByDefault
34 public class NikoHomeControlBridgeHandler1 extends NikoHomeControlBridgeHandler {
35
36     private final Logger logger = LoggerFactory.getLogger(NikoHomeControlBridgeHandler1.class);
37
38     public NikoHomeControlBridgeHandler1(Bridge nikoHomeControlBridge) {
39         super(nikoHomeControlBridge);
40     }
41
42     @Override
43     public void initialize() {
44         logger.debug("initializing bridge handler");
45
46         setConfig();
47         InetAddress addr = getAddr();
48         int port = getPort();
49
50         logger.debug("bridge handler host {}, port {}", addr, port);
51
52         if (addr != null) {
53             nhcComm = new NikoHomeControlCommunication1(this, scheduler);
54             startCommunication();
55         } else {
56             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
57                     "Cannot resolve bridge IP with hostname " + config.addr);
58         }
59     }
60
61     @Override
62     protected void updateProperties() {
63         Map<String, String> properties = new HashMap<>();
64
65         NikoHomeControlCommunication1 comm = (NikoHomeControlCommunication1) nhcComm;
66         if (comm != null) {
67             properties.put("softwareVersion", comm.getSystemInfo().getSwVersion());
68             properties.put("apiVersion", comm.getSystemInfo().getApi());
69             properties.put("language", comm.getSystemInfo().getLanguage());
70             properties.put("currency", comm.getSystemInfo().getCurrency());
71             properties.put("units", comm.getSystemInfo().getUnits());
72             properties.put("tzOffset", comm.getSystemInfo().getTz());
73             properties.put("dstOffset", comm.getSystemInfo().getDst());
74             properties.put("configDate", comm.getSystemInfo().getLastConfig());
75             properties.put("energyEraseDate", comm.getSystemInfo().getLastEnergyErase());
76             properties.put("connectionStartDate", comm.getSystemInfo().getTime());
77
78             thing.setProperties(properties);
79         }
80     }
81 }