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