]> git.basschouten.com Git - openhab-addons.git/blob
2860854af50a2dfd3ab7c99f21dbc7d7350849c7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.digitalstrom.internal.lib.config;
14
15 /**
16  * The {@link Config} contains all configurations for the digitalSTROM-Library.
17  *
18  * @author Michael Ochel - Initial contribution
19  * @author Matthias Siegele - Initial contribution
20  */
21 public class Config {
22
23     /* Client configuration */
24     // connection configuration
25     /**
26      * The default application name to generate the application token.
27      */
28     public static final String DEFAULT_APPLICATION_NAME = "openHAB";
29     /**
30      * Defines the used tread pool name to get a thread pool from {@link ThreadPoolManager}.
31      */
32     public static final String THREADPOOL_NAME = "digitalSTROM";
33
34     private String applicationName = DEFAULT_APPLICATION_NAME;
35
36     private String host;
37     private String userName;
38     private String password;
39     private String appToken;
40     private String trustCertPath;
41     private String cert;
42
43     // Timeouts
44     /**
45      * Default connection timeout
46      */
47     public static final int DEFAULT_CONNECTION_TIMEOUT = 4000;
48     /**
49      * High connection timeout for requests that take some time.
50      */
51     public static final int HIGH_CONNECTION_TIMEOUT = 60000;
52     /**
53      * Default read timeout
54      */
55     public static final int DEFAULT_READ_TIMEOUT = 10000;
56     /**
57      * High read timeout for requests that take some time.
58      */
59     public static final int HIGH_READ_TIMEOUT = 60000;
60     /**
61      * Default connection timeout for sensor readings from devices
62      */
63     public static final int DEFAULT_SENSORDATA_CONNECTION_TIMEOUT = 4000;
64     /**
65      * Default read timeout for sensor readings from devices
66      */
67     public static final int DEFAULT_SENSORDATA_READ_TIMEOUT = 20000;
68
69     private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
70     private int readTimeout = DEFAULT_READ_TIMEOUT;
71     private int sensordataConnectionTimeout = DEFAULT_SENSORDATA_CONNECTION_TIMEOUT;
72     private int sensordataReadTimeout = DEFAULT_SENSORDATA_READ_TIMEOUT;
73
74     /* Internal Configurations */
75     // Trash Bin Config
76     /**
77      * The default number of days after the trash devices is deleted.
78      */
79     public static final int DEFAULT_TRASH_DEVICE_DELETE_TIME = 7;
80     private int trashDeviceDeleteTime = DEFAULT_TRASH_DEVICE_DELETE_TIME;
81
82     /**
83      * The default milliseconds after the trash devices will be checked if its time to delete.
84      */
85     public static final int DEFAULT_BIN_CHECK_TIME = 360000; // in milliseconds
86     private int binCheckTime = DEFAULT_BIN_CHECK_TIME; // in milliseconds
87
88     // Device update config
89
90     /**
91      * Default interval of the polling frequency in milliseconds. The digitalSTROM-rules state that the
92      * polling interval must to be at least 1 second.
93      */
94     public static final int DEFAULT_POLLING_FREQUENCY = 1000; // in milliseconds
95     private int pollingFrequency = DEFAULT_POLLING_FREQUENCY; // in milliseconds
96
97     /* Sensordata */
98     // Sensodata read config
99
100     /**
101      * The default interval to refresh the sensor data.
102      */
103     public static final int DEFAULT_SENSORDATA_REFRESH_INTERVAL = 60000;
104     private int sensordataRefreshInterval = DEFAULT_SENSORDATA_REFRESH_INTERVAL;
105
106     /**
107      * The default interval to refresh the total power sensor data.
108      */
109     public static final int DEFAULT_TOTAL_POWER_UPDATE_INTERVAL = 30000;
110     private int totalPowerUpdateInterval = DEFAULT_TOTAL_POWER_UPDATE_INTERVAL;
111
112     /**
113      * Default time to wait between another {@link SensorJob} can be executed on a circuit.
114      */
115     public static final int DEFAULT_SENSOR_READING_WAIT_TIME = 60000;
116     private int sensorReadingWaitTime = DEFAULT_SENSOR_READING_WAIT_TIME;
117
118     // sensor data Prioritys
119     /**
120      * Priority for never refresh the sensor value.
121      */
122     public static final String REFRESH_PRIORITY_NEVER = "never";
123     /**
124      * Priority for refresh the sensor value with low priority.
125      */
126     public static final String REFRESH_PRIORITY_LOW = "low";
127     /**
128      * Priority for refresh the sensor value with medium priority.
129      */
130     public static final String REFRESH_PRIORITY_MEDIUM = "medium";
131     /**
132      * Priority for refresh the sensor value with high priority.
133      */
134     public static final String REFRESH_PRIORITY_HIGH = "high";
135
136     // max sensor reading cyclic to wait
137     /**
138      * The default factor to prioritize medium {@link SensorJob}s down.
139      */
140     public static final long DEFAULT_MEDIUM_PRIORITY_FACTOR = 5;
141     /**
142      * The default factor to prioritize low {@link SensorJob}s down.
143      */
144     public static final long DEFAULT_LOW_PRIORITY_FACTOR = 10;
145
146     private long mediumPriorityFactor = DEFAULT_MEDIUM_PRIORITY_FACTOR;
147     private long lowPriorityFactor = DEFAULT_LOW_PRIORITY_FACTOR;
148
149     /**
150      * Defines the event polling interval of the {@link EventListener} in milliseconds.
151      */
152     private int eventListenerRefreshinterval = DEFAULT_POLLING_FREQUENCY;
153
154     /**
155      * The default max standby active power for a device. It's needed to set a {@link Device} with output mode
156      * {@link OutputModeEnum#WIPE} on if it isen't any more in standby mode.
157      */
158     public static final int DEFAULT_STANDBY_ACTIVE_POWER = 2;
159
160     private int standbyActivePower = DEFAULT_STANDBY_ACTIVE_POWER;
161
162     /**
163      * Creates a new {@link Config} and set the given hostAddress, userName, password and applicationToken. The other
164      * configurations will be set to default.
165      *
166      * @param hostAddress of the digitalSTROM-Server, must not be null
167      * @param userName to login, can be null
168      * @param password to login, can be null
169      * @param applicationToken to login , can be null
170      */
171     public Config(String hostAddress, String userName, String password, String applicationToken) {
172         this.host = hostAddress;
173         this.userName = userName;
174         this.password = password;
175         this.appToken = applicationToken;
176     }
177
178     /**
179      * Creates a {@link Config} with default values.
180      */
181     public Config() {
182         // config with default values
183     }
184
185     /**
186      * Returns the host name from the server.
187      *
188      * @return the host address
189      */
190     public String getHost() {
191         return host;
192     }
193
194     /**
195      * Sets the host name of the Server.
196      * <br>
197      * <br>
198      * <b>Note:</b><br>
199      * If the host dosen't use the default port (8080), the port has to be set after the host name. e.g.
200      * <i>my-digitalSTROM-Server.com:58080</i>
201      *
202      * @param hostAddress of the digitalSTROM-Server
203      */
204     public void setHost(String hostAddress) {
205         this.host = hostAddress;
206     }
207
208     /**
209      * Returns the username.
210      *
211      * @return the username
212      */
213     public String getUserName() {
214         return userName;
215     }
216
217     /**
218      * Sets the username.
219      *
220      * @param userName to set
221      */
222     public void setUserName(String userName) {
223         this.userName = userName;
224     }
225
226     /**
227      * Returns the password.
228      *
229      * @return the password
230      */
231     public String getPassword() {
232         return password;
233     }
234
235     /**
236      * Sets the password.
237      *
238      * @param password to set
239      */
240     public void setPassword(String password) {
241         this.password = password;
242     }
243
244     /**
245      * Returns the Application-Token.
246      *
247      * @return the Application-Token
248      */
249     public String getAppToken() {
250         return appToken;
251     }
252
253     /**
254      * Sets the Application-Token.
255      *
256      * @param applicationToken to set
257      */
258     public void setAppToken(String applicationToken) {
259         this.appToken = applicationToken;
260     }
261
262     /**
263      * Returns the connection timeout.
264      *
265      * @return the connection timeout
266      */
267     public int getConnectionTimeout() {
268         return connectionTimeout;
269     }
270
271     /**
272      * Sets the connection timeout.
273      *
274      * @param connectionTimeout to set
275      */
276     public void setConnectionTimeout(int connectionTimeout) {
277         this.connectionTimeout = connectionTimeout;
278     }
279
280     /**
281      * Returns the read timeout.
282      *
283      * @return the read timeout
284      */
285     public int getReadTimeout() {
286         return readTimeout;
287     }
288
289     /**
290      * Sets the read timeout.
291      *
292      * @param readTimeout the readTimeout to set
293      */
294     public void setReadTimeout(int readTimeout) {
295         this.readTimeout = readTimeout;
296     }
297
298     /**
299      * Returns the connection timeout for sensor readings from devices.
300      *
301      * @return the connection sensor data timeout
302      */
303     public int getSensordataConnectionTimeout() {
304         return sensordataConnectionTimeout;
305     }
306
307     /**
308      * Sets the connection timeout for sensor readings from devices.
309      *
310      * @param sensordataConnectionTimeout to set
311      */
312     public void setSensordataConnectionTimeout(int sensordataConnectionTimeout) {
313         this.sensordataConnectionTimeout = sensordataConnectionTimeout;
314     }
315
316     /**
317      * Returns the read timeout for sensor readings from devices.
318      *
319      * @return the read sensor data timeout
320      */
321     public int getSensordataReadTimeout() {
322         return sensordataReadTimeout;
323     }
324
325     /**
326      * Sets the connection timeout for sensor readings from devices.
327      *
328      * @param sensordataReadTimeout to set
329      */
330     public void setSensordataReadTimeout(int sensordataReadTimeout) {
331         this.sensordataReadTimeout = sensordataReadTimeout;
332     }
333
334     /**
335      * Returns the path to the SSL-Certificate.
336      *
337      * @return the path to the trust certification
338      */
339     public String getTrustCertPath() {
340         return trustCertPath;
341     }
342
343     /**
344      * Return the SSL-Certificate of the server.
345      *
346      * @return the SSL-Certificate of the server
347      */
348     public String getCert() {
349         return cert;
350     }
351
352     /**
353      * Sets the SSL-Certificate of the server, will be set automatically by the {@link HttpTransportImpl} if no
354      * SSL-Certification path is set.
355      *
356      * @param cert of the digitalSTROM-Server to set
357      */
358     public void setCert(String cert) {
359         this.cert = cert;
360     }
361
362     /**
363      * Sets the path to the SSL-Certificate. It can be an absolute or relative path.
364      *
365      * @param trustCertPath path to a SSL-Certificate
366      */
367     public void setTrustCertPath(String trustCertPath) {
368         this.trustCertPath = trustCertPath;
369     }
370
371     /**
372      * Returns the number of days after the trash devices is deleted.
373      *
374      * @return the trash-device delete time in days
375      */
376     public int getTrashDeviceDeleteTime() {
377         return trashDeviceDeleteTime;
378     }
379
380     /**
381      * Sets the number of days after the trash devices is deleted.
382      *
383      * @param trashDeviceDeleteTime in days
384      */
385     public void setTrashDeviceDeleteTime(int trashDeviceDeleteTime) {
386         this.trashDeviceDeleteTime = trashDeviceDeleteTime;
387     }
388
389     /**
390      * Sets the milliseconds after the trash devices will be checked, if its time to delete.
391      *
392      * @return the bin check time in milliseconds
393      */
394     public int getBinCheckTime() {
395         return binCheckTime;
396     }
397
398     /**
399      * Returns the milliseconds after the trash devices will be checked, if its time to delete.
400      *
401      * @param binCheckTime in milliseconds
402      */
403     public void setBinCheckTime(int binCheckTime) {
404         this.binCheckTime = binCheckTime;
405     }
406
407     /**
408      * Returns the interval of the polling frequency in milliseconds. The digitalSTROM-rules state that the
409      * polling interval must to be at least 1 second.
410      *
411      * @return the pollingFrequency in milliseconds
412      */
413     public int getPollingFrequency() {
414         return pollingFrequency;
415     }
416
417     /**
418      * Sets the interval of the polling frequency in milliseconds. The digitalSTROM-rules state that the
419      * polling interval must to be at least 1 second.
420      *
421      * @param pollingFrequency to set
422      */
423     public void setPollingFrequency(int pollingFrequency) {
424         this.pollingFrequency = pollingFrequency;
425     }
426
427     /**
428      * Returns the interval in milliseconds to refresh the sensor data.
429      *
430      * @return the sensor data refresh interval in milliseconds
431      */
432     public int getSensordataRefreshInterval() {
433         return sensordataRefreshInterval;
434     }
435
436     /**
437      * Sets the interval in milliseconds to refresh the sensor data.
438      *
439      * @param sensordataRefreshInterval in milliseconds.
440      */
441     public void setSensordataRefreshInterval(int sensordataRefreshInterval) {
442         this.sensordataRefreshInterval = sensordataRefreshInterval;
443     }
444
445     /**
446      * Returns the interval to refresh the total power sensor data.
447      *
448      * @return the total power update interval in milliseconds.
449      */
450     public int getTotalPowerUpdateInterval() {
451         return totalPowerUpdateInterval;
452     }
453
454     /**
455      * Sets the interval in milliseconds to refresh the total power sensor data.
456      *
457      * @param totalPowerUpdateInterval in milliseconds
458      */
459     public void setTotalPowerUpdateInterval(int totalPowerUpdateInterval) {
460         this.totalPowerUpdateInterval = totalPowerUpdateInterval;
461     }
462
463     /**
464      * Returns the time in milliseconds to wait between another {@link SensorJob} can be executed on a circuit.
465      *
466      * @return the sensor reading wait time in milliseconds
467      */
468     public int getSensorReadingWaitTime() {
469         return sensorReadingWaitTime;
470     }
471
472     /**
473      * Sets the time in milliseconds to wait between another {@link SensorJob} can be executed on a circuit.
474      *
475      * @param sensorReadingWaitTime in milliseconds
476      */
477     public void setSensorReadingWaitTime(int sensorReadingWaitTime) {
478         this.sensorReadingWaitTime = sensorReadingWaitTime;
479     }
480
481     /**
482      * Returns the factor to prioritize medium {@link SensorJob}s in the {@link SensorJobExecutor} down.
483      *
484      * @return the medium priority factor
485      */
486     public long getMediumPriorityFactor() {
487         return mediumPriorityFactor;
488     }
489
490     /**
491      * Sets the factor to prioritize medium {@link SensorJob}s in the {@link SensorJobExecutor} down.
492      *
493      * @param mediumPriorityFactor to set
494      */
495     public void setMediumPriorityFactor(long mediumPriorityFactor) {
496         this.mediumPriorityFactor = mediumPriorityFactor;
497     }
498
499     /**
500      * Returns the factor to prioritize low {@link SensorJob}s in the {@link SensorJobExecutor} down.
501      *
502      * @return the low priority factor
503      */
504     public long getLowPriorityFactor() {
505         return lowPriorityFactor;
506     }
507
508     /**
509      * Sets the factor to prioritize low {@link SensorJob}s in the {@link SensorJobExecutor}down.
510      *
511      * @param lowPriorityFactor to set
512      */
513     public void setLowPriorityFactor(long lowPriorityFactor) {
514         this.lowPriorityFactor = lowPriorityFactor;
515     }
516
517     /**
518      * Returns the polling interval in milliseconds to poll the {@link Event}s in the {@link EventListener}.
519      *
520      * @return the EventListener refresh interval in milliseconds
521      */
522     public int getEventListenerRefreshinterval() {
523         return eventListenerRefreshinterval;
524     }
525
526     /**
527      * Sets the polling interval in milliseconds to poll the {@link Event}s in the {@link EventListener}.
528      *
529      * @param eventListenerRefreshinterval to set
530      */
531     public void setEventListenerRefreshinterval(int eventListenerRefreshinterval) {
532         this.eventListenerRefreshinterval = eventListenerRefreshinterval;
533     }
534
535     /**
536      * Returns the max standby active power for a device. It's needed to set a {@link Device} with output mode
537      * {@link OutputModeEnum#WIPE} on if it isen't any more in standby mode.
538      *
539      * @return the standby active power
540      */
541     public int getStandbyActivePower() {
542         return standbyActivePower;
543     }
544
545     /**
546      * Sets the max standby active power for a device. It's needed to set a {@link Device} with output mode
547      * {@link OutputModeEnum#WIPE} on if it isen't any more in standby mode.
548      *
549      * @param standbyActivePower to set
550      */
551     public void setStandbyActivePower(int standbyActivePower) {
552         this.standbyActivePower = standbyActivePower;
553     }
554
555     /**
556      * Returns the application name to generate the application token.
557      *
558      * @return the applicationName
559      */
560     public String getApplicationName() {
561         return applicationName;
562     }
563
564     /**
565      * Sets the application name to generate the application token.
566      *
567      * @param applicationName to set
568      */
569     public void setApplicationName(String applicationName) {
570         this.applicationName = applicationName;
571     }
572
573     /**
574      * Removes the configured username and password from this {@link Config}.
575      */
576     public void removeUsernameAndPassword() {
577         this.userName = null;
578         this.password = null;
579     }
580
581     /**
582      * Updates this {@link Config} with the configuration of given {@link Config}.
583      *
584      * @param config new config
585      */
586     public void updateConfig(Config config) {
587         setHost(config.getHost());
588         setUserName(config.getUserName());
589         setPassword(config.getPassword());
590         setAppToken(config.getAppToken());
591         setConnectionTimeout(config.getConnectionTimeout());
592         setReadTimeout(config.getReadTimeout());
593         setSensordataConnectionTimeout(config.getSensordataConnectionTimeout());
594         setSensordataReadTimeout(config.getSensordataReadTimeout());
595         setTrustCertPath(config.getTrustCertPath());
596         setTrashDeviceDeleteTime(config.getTrashDeviceDeleteTime());
597         setBinCheckTime(config.getBinCheckTime());
598         setPollingFrequency(config.getPollingFrequency());
599         setSensordataRefreshInterval(config.getSensordataRefreshInterval());
600         setTotalPowerUpdateInterval(config.getTotalPowerUpdateInterval());
601         setSensorReadingWaitTime(config.getSensorReadingWaitTime());
602         setMediumPriorityFactor(config.getMediumPriorityFactor());
603         setLowPriorityFactor(config.getLowPriorityFactor());
604         setEventListenerRefreshinterval(config.getEventListenerRefreshinterval());
605         setStandbyActivePower(config.getStandbyActivePower());
606         setApplicationName(config.getApplicationName());
607     }
608
609     @Override
610     public String toString() {
611         return "Config [applicationName=" + applicationName + ", host=" + host + ", userName=" + userName
612                 + ", password=" + password + ", appToken=" + appToken + ", connectionTimeout=" + connectionTimeout
613                 + ", readTimeout=" + readTimeout + ", sensordataConnectionTimeout=" + sensordataConnectionTimeout
614                 + ", sensordataReadTimeout=" + sensordataReadTimeout + ", trustCertPath=" + trustCertPath
615                 + ", trashDeviceDeleteTime=" + trashDeviceDeleteTime + ", binCheckTime=" + binCheckTime
616                 + ", pollingFrequency=" + pollingFrequency + ", sensordataRefreshInterval=" + sensordataRefreshInterval
617                 + ", totalPowerUpdateInterval=" + totalPowerUpdateInterval + ", sensorReadingWaitTime="
618                 + sensorReadingWaitTime + ", mediumPriorityFactor=" + mediumPriorityFactor + ", lowPriorityFactor="
619                 + lowPriorityFactor + ", eventListenerRefreshinterval=" + eventListenerRefreshinterval
620                 + ", standbyActivePower=" + standbyActivePower + "]";
621     }
622 }