]> git.basschouten.com Git - openhab-addons.git/blob
0ff9bfb060fd345b9fbd60dd404a3520f47e95b1
[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.protocol;
14
15 import java.util.Map;
16 import java.util.concurrent.ConcurrentHashMap;
17
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;
23
24 /**
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.
28  * <ul>
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.
33  * </ul>
34  *
35  * @author Mark Herwege - Initial Contribution
36  */
37 @NonNullByDefault
38 public abstract class NikoHomeControlCommunication {
39
40     private final Logger logger = LoggerFactory.getLogger(NikoHomeControlCommunication.class);
41
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<>();
45
46     protected final NhcControllerEvent handler;
47
48     protected NikoHomeControlCommunication(NhcControllerEvent handler) {
49         this.handler = handler;
50     }
51
52     /**
53      * Start Communication with Niko Home Control system.
54      */
55     public abstract void startCommunication();
56
57     /**
58      * Stop Communication with Niko Home Control system.
59      */
60     public abstract void stopCommunication();
61
62     /**
63      * Close and restart communication with Niko Home Control system.
64      */
65     public synchronized void restartCommunication() {
66         stopCommunication();
67
68         logger.debug("restart communication from thread {}", Thread.currentThread().getId());
69
70         startCommunication();
71     }
72
73     /**
74      * Method to check if communication with Niko Home Control is active.
75      *
76      * @return True if active
77      */
78     public abstract boolean communicationActive();
79
80     /**
81      * Return all actions in the Niko Home Control Controller.
82      *
83      * @return <code>Map&ltString, {@link NhcAction}></code>
84      */
85     public Map<String, NhcAction> getActions() {
86         return actions;
87     }
88
89     /**
90      * Return all thermostats in the Niko Home Control Controller.
91      *
92      * @return <code>Map&ltString, {@link NhcThermostat}></code>
93      */
94     public Map<String, NhcThermostat> getThermostats() {
95         return thermostats;
96     }
97
98     /**
99      * Return all energyMeters meters in the Niko Home Control Controller.
100      *
101      * @return <code>Map&ltString, {@link NhcEnergyMeter}></code>
102      */
103     public Map<String, NhcEnergyMeter> getEnergyMeters() {
104         return energyMeters;
105     }
106
107     /**
108      * Execute an action command by sending it to Niko Home Control.
109      *
110      * @param actionId
111      * @param value
112      */
113     public abstract void executeAction(String actionId, String value);
114
115     /**
116      * Execute a thermostat command by sending it to Niko Home Control.
117      *
118      * @param thermostatId
119      * @param mode
120      */
121     public abstract void executeThermostat(String thermostatId, String mode);
122
123     /**
124      * Execute a thermostat command by sending it to Niko Home Control.
125      *
126      * @param thermostatId
127      * @param overruleTemp
128      * @param overruleTime
129      */
130     public abstract void executeThermostat(String thermostatId, int overruleTemp, int overruleTime);
131
132     /**
133      * Start retrieving energy meter data from Niko Home Control.
134      *
135      */
136     public void startEnergyMeter(String energyMeterId) {
137     };
138
139     /**
140      * Stop retrieving energy meter data from Niko Home Control.
141      *
142      */
143     public void stopEnergyMeter(String energyMeterId) {
144     };
145 }