2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nikohomecontrol.internal.protocol;
16 import java.util.concurrent.ConcurrentHashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.nikohomecontrol.internal.protocol.nhc1.NikoHomeControlCommunication1;
20 import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NikoHomeControlCommunication2;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * The {@link NikoHomeControlCommunication} class is an abstract class representing the communication objects with the
26 * Niko Home Control System. {@link NikoHomeControlCommunication1} or {@link NikoHomeControlCommunication2} should be
27 * used for the respective version of Niko Home Control.
29 * <li>Start and stop communication with the Niko Home Control System.
30 * <li>Read all setup and status information from the Niko Home Control Controller.
31 * <li>Execute Niko Home Control commands.
32 * <li>Listen to events from Niko Home Control.
35 * @author Mark Herwege - Initial Contribution
38 public abstract class NikoHomeControlCommunication {
40 private final Logger logger = LoggerFactory.getLogger(NikoHomeControlCommunication.class);
42 protected final Map<String, NhcAction> actions = new ConcurrentHashMap<>();
43 protected final Map<String, NhcThermostat> thermostats = new ConcurrentHashMap<>();
44 protected final Map<String, NhcEnergyMeter> energyMeters = new ConcurrentHashMap<>();
46 protected final NhcControllerEvent handler;
48 protected NikoHomeControlCommunication(NhcControllerEvent handler) {
49 this.handler = handler;
53 * Start Communication with Niko Home Control system.
55 public abstract void startCommunication();
58 * Stop Communication with Niko Home Control system.
60 public abstract void stopCommunication();
63 * Close and restart communication with Niko Home Control system.
65 public synchronized void restartCommunication() {
68 logger.debug("restart communication from thread {}", Thread.currentThread().getId());
74 * Method to check if communication with Niko Home Control is active.
76 * @return True if active
78 public abstract boolean communicationActive();
81 * Return all actions in the Niko Home Control Controller.
83 * @return <code>Map<String, {@link NhcAction}></code>
85 public Map<String, NhcAction> getActions() {
90 * Return all thermostats in the Niko Home Control Controller.
92 * @return <code>Map<String, {@link NhcThermostat}></code>
94 public Map<String, NhcThermostat> getThermostats() {
99 * Return all energyMeters meters in the Niko Home Control Controller.
101 * @return <code>Map<String, {@link NhcEnergyMeter}></code>
103 public Map<String, NhcEnergyMeter> getEnergyMeters() {
108 * Execute an action command by sending it to Niko Home Control.
113 public abstract void executeAction(String actionId, String value);
116 * Execute a thermostat command by sending it to Niko Home Control.
118 * @param thermostatId
121 public abstract void executeThermostat(String thermostatId, String mode);
124 * Execute a thermostat command by sending it to Niko Home Control.
126 * @param thermostatId
127 * @param overruleTemp
128 * @param overruleTime
130 public abstract void executeThermostat(String thermostatId, int overruleTemp, int overruleTime);
133 * Start retrieving energy meter data from Niko Home Control.
136 public void startEnergyMeter(String energyMeterId) {
140 * Stop retrieving energy meter data from Niko Home Control.
143 public void stopEnergyMeter(String energyMeterId) {