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