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