2 * Copyright (c) 2010-2023 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.digitalstrom.internal.lib.config;
16 * The {@link Config} contains all configurations for the digitalSTROM-Library.
18 * @author Michael Ochel - Initial contribution
19 * @author Matthias Siegele - Initial contribution
23 /* Client configuration */
24 // connection configuration
26 * The default application name to generate the application token.
28 public static final String DEFAULT_APPLICATION_NAME = "openHAB";
30 * Defines the used tread pool name to get a thread pool from {@link ThreadPoolManager}.
32 public static final String THREADPOOL_NAME = "digitalSTROM";
34 private String applicationName = DEFAULT_APPLICATION_NAME;
37 private String userName;
38 private String password;
39 private String appToken;
40 private String trustCertPath;
45 * Default connection timeout
47 public static final int DEFAULT_CONNECTION_TIMEOUT = 4000;
49 * High connection timeout for requests that take some time.
51 public static final int HIGH_CONNECTION_TIMEOUT = 60000;
53 * Default read timeout
55 public static final int DEFAULT_READ_TIMEOUT = 10000;
57 * High read timeout for requests that take some time.
59 public static final int HIGH_READ_TIMEOUT = 60000;
61 * Default connection timeout for sensor readings from devices
63 public static final int DEFAULT_SENSORDATA_CONNECTION_TIMEOUT = 4000;
65 * Default read timeout for sensor readings from devices
67 public static final int DEFAULT_SENSORDATA_READ_TIMEOUT = 20000;
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;
74 /* Internal Configurations */
77 * The default number of days after the trash devices is deleted.
79 public static final int DEFAULT_TRASH_DEVICE_DELETE_TIME = 7;
80 private int trashDeviceDeleteTime = DEFAULT_TRASH_DEVICE_DELETE_TIME;
83 * The default milliseconds after the trash devices will be checked if its time to delete.
85 public static final int DEFAULT_BIN_CHECK_TIME = 360000; // in milliseconds
86 private int binCheckTime = DEFAULT_BIN_CHECK_TIME; // in milliseconds
88 // Device update config
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.
94 public static final int DEFAULT_POLLING_FREQUENCY = 1000; // in milliseconds
95 private int pollingFrequency = DEFAULT_POLLING_FREQUENCY; // in milliseconds
98 // Sensodata read config
101 * The default interval to refresh the sensor data.
103 public static final int DEFAULT_SENSORDATA_REFRESH_INTERVAL = 60000;
104 private int sensordataRefreshInterval = DEFAULT_SENSORDATA_REFRESH_INTERVAL;
107 * The default interval to refresh the total power sensor data.
109 public static final int DEFAULT_TOTAL_POWER_UPDATE_INTERVAL = 30000;
110 private int totalPowerUpdateInterval = DEFAULT_TOTAL_POWER_UPDATE_INTERVAL;
113 * Default time to wait between another {@link SensorJob} can be executed on a circuit.
115 public static final int DEFAULT_SENSOR_READING_WAIT_TIME = 60000;
116 private int sensorReadingWaitTime = DEFAULT_SENSOR_READING_WAIT_TIME;
118 // sensor data Prioritys
120 * Priority for never refresh the sensor value.
122 public static final String REFRESH_PRIORITY_NEVER = "never";
124 * Priority for refresh the sensor value with low priority.
126 public static final String REFRESH_PRIORITY_LOW = "low";
128 * Priority for refresh the sensor value with medium priority.
130 public static final String REFRESH_PRIORITY_MEDIUM = "medium";
132 * Priority for refresh the sensor value with high priority.
134 public static final String REFRESH_PRIORITY_HIGH = "high";
136 // max sensor reading cyclic to wait
138 * The default factor to prioritize medium {@link SensorJob}s down.
140 public static final long DEFAULT_MEDIUM_PRIORITY_FACTOR = 5;
142 * The default factor to prioritize low {@link SensorJob}s down.
144 public static final long DEFAULT_LOW_PRIORITY_FACTOR = 10;
146 private long mediumPriorityFactor = DEFAULT_MEDIUM_PRIORITY_FACTOR;
147 private long lowPriorityFactor = DEFAULT_LOW_PRIORITY_FACTOR;
150 * Defines the event polling interval of the {@link EventListener} in milliseconds.
152 private int eventListenerRefreshinterval = DEFAULT_POLLING_FREQUENCY;
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.
158 public static final int DEFAULT_STANDBY_ACTIVE_POWER = 2;
160 private int standbyActivePower = DEFAULT_STANDBY_ACTIVE_POWER;
163 * Creates a new {@link Config} and set the given hostAddress, userName, password and applicationToken. The other
164 * configurations will be set to default.
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
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;
179 * Creates a {@link Config} with default values.
182 // config with default values
186 * Returns the host name from the server.
188 * @return the host address
190 public String getHost() {
195 * Sets the host name of the Server.
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>
202 * @param hostAddress of the digitalSTROM-Server
204 public void setHost(String hostAddress) {
205 this.host = hostAddress;
209 * Returns the username.
211 * @return the username
213 public String getUserName() {
220 * @param userName to set
222 public void setUserName(String userName) {
223 this.userName = userName;
227 * Returns the password.
229 * @return the password
231 public String getPassword() {
238 * @param password to set
240 public void setPassword(String password) {
241 this.password = password;
245 * Returns the Application-Token.
247 * @return the Application-Token
249 public String getAppToken() {
254 * Sets the Application-Token.
256 * @param applicationToken to set
258 public void setAppToken(String applicationToken) {
259 this.appToken = applicationToken;
263 * Returns the connection timeout.
265 * @return the connection timeout
267 public int getConnectionTimeout() {
268 return connectionTimeout;
272 * Sets the connection timeout.
274 * @param connectionTimeout to set
276 public void setConnectionTimeout(int connectionTimeout) {
277 this.connectionTimeout = connectionTimeout;
281 * Returns the read timeout.
283 * @return the read timeout
285 public int getReadTimeout() {
290 * Sets the read timeout.
292 * @param readTimeout the readTimeout to set
294 public void setReadTimeout(int readTimeout) {
295 this.readTimeout = readTimeout;
299 * Returns the connection timeout for sensor readings from devices.
301 * @return the connection sensor data timeout
303 public int getSensordataConnectionTimeout() {
304 return sensordataConnectionTimeout;
308 * Sets the connection timeout for sensor readings from devices.
310 * @param sensordataConnectionTimeout to set
312 public void setSensordataConnectionTimeout(int sensordataConnectionTimeout) {
313 this.sensordataConnectionTimeout = sensordataConnectionTimeout;
317 * Returns the read timeout for sensor readings from devices.
319 * @return the read sensor data timeout
321 public int getSensordataReadTimeout() {
322 return sensordataReadTimeout;
326 * Sets the connection timeout for sensor readings from devices.
328 * @param sensordataReadTimeout to set
330 public void setSensordataReadTimeout(int sensordataReadTimeout) {
331 this.sensordataReadTimeout = sensordataReadTimeout;
335 * Returns the path to the SSL-Certificate.
337 * @return the path to the trust certification
339 public String getTrustCertPath() {
340 return trustCertPath;
344 * Return the SSL-Certificate of the server.
346 * @return the SSL-Certificate of the server
348 public String getCert() {
353 * Sets the SSL-Certificate of the server, will be set automatically by the {@link HttpTransportImpl} if no
354 * SSL-Certification path is set.
356 * @param cert of the digitalSTROM-Server to set
358 public void setCert(String cert) {
363 * Sets the path to the SSL-Certificate. It can be an absolute or relative path.
365 * @param trustCertPath path to a SSL-Certificate
367 public void setTrustCertPath(String trustCertPath) {
368 this.trustCertPath = trustCertPath;
372 * Returns the number of days after the trash devices is deleted.
374 * @return the trash-device delete time in days
376 public int getTrashDeviceDeleteTime() {
377 return trashDeviceDeleteTime;
381 * Sets the number of days after the trash devices is deleted.
383 * @param trashDeviceDeleteTime in days
385 public void setTrashDeviceDeleteTime(int trashDeviceDeleteTime) {
386 this.trashDeviceDeleteTime = trashDeviceDeleteTime;
390 * Sets the milliseconds after the trash devices will be checked, if its time to delete.
392 * @return the bin check time in milliseconds
394 public int getBinCheckTime() {
399 * Returns the milliseconds after the trash devices will be checked, if its time to delete.
401 * @param binCheckTime in milliseconds
403 public void setBinCheckTime(int binCheckTime) {
404 this.binCheckTime = binCheckTime;
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.
411 * @return the pollingFrequency in milliseconds
413 public int getPollingFrequency() {
414 return pollingFrequency;
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.
421 * @param pollingFrequency to set
423 public void setPollingFrequency(int pollingFrequency) {
424 this.pollingFrequency = pollingFrequency;
428 * Returns the interval in milliseconds to refresh the sensor data.
430 * @return the sensor data refresh interval in milliseconds
432 public int getSensordataRefreshInterval() {
433 return sensordataRefreshInterval;
437 * Sets the interval in milliseconds to refresh the sensor data.
439 * @param sensordataRefreshInterval in milliseconds.
441 public void setSensordataRefreshInterval(int sensordataRefreshInterval) {
442 this.sensordataRefreshInterval = sensordataRefreshInterval;
446 * Returns the interval to refresh the total power sensor data.
448 * @return the total power update interval in milliseconds.
450 public int getTotalPowerUpdateInterval() {
451 return totalPowerUpdateInterval;
455 * Sets the interval in milliseconds to refresh the total power sensor data.
457 * @param totalPowerUpdateInterval in milliseconds
459 public void setTotalPowerUpdateInterval(int totalPowerUpdateInterval) {
460 this.totalPowerUpdateInterval = totalPowerUpdateInterval;
464 * Returns the time in milliseconds to wait between another {@link SensorJob} can be executed on a circuit.
466 * @return the sensor reading wait time in milliseconds
468 public int getSensorReadingWaitTime() {
469 return sensorReadingWaitTime;
473 * Sets the time in milliseconds to wait between another {@link SensorJob} can be executed on a circuit.
475 * @param sensorReadingWaitTime in milliseconds
477 public void setSensorReadingWaitTime(int sensorReadingWaitTime) {
478 this.sensorReadingWaitTime = sensorReadingWaitTime;
482 * Returns the factor to prioritize medium {@link SensorJob}s in the {@link SensorJobExecutor} down.
484 * @return the medium priority factor
486 public long getMediumPriorityFactor() {
487 return mediumPriorityFactor;
491 * Sets the factor to prioritize medium {@link SensorJob}s in the {@link SensorJobExecutor} down.
493 * @param mediumPriorityFactor to set
495 public void setMediumPriorityFactor(long mediumPriorityFactor) {
496 this.mediumPriorityFactor = mediumPriorityFactor;
500 * Returns the factor to prioritize low {@link SensorJob}s in the {@link SensorJobExecutor} down.
502 * @return the low priority factor
504 public long getLowPriorityFactor() {
505 return lowPriorityFactor;
509 * Sets the factor to prioritize low {@link SensorJob}s in the {@link SensorJobExecutor}down.
511 * @param lowPriorityFactor to set
513 public void setLowPriorityFactor(long lowPriorityFactor) {
514 this.lowPriorityFactor = lowPriorityFactor;
518 * Returns the polling interval in milliseconds to poll the {@link Event}s in the {@link EventListener}.
520 * @return the EventListener refresh interval in milliseconds
522 public int getEventListenerRefreshinterval() {
523 return eventListenerRefreshinterval;
527 * Sets the polling interval in milliseconds to poll the {@link Event}s in the {@link EventListener}.
529 * @param eventListenerRefreshinterval to set
531 public void setEventListenerRefreshinterval(int eventListenerRefreshinterval) {
532 this.eventListenerRefreshinterval = eventListenerRefreshinterval;
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.
539 * @return the standby active power
541 public int getStandbyActivePower() {
542 return standbyActivePower;
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.
549 * @param standbyActivePower to set
551 public void setStandbyActivePower(int standbyActivePower) {
552 this.standbyActivePower = standbyActivePower;
556 * Returns the application name to generate the application token.
558 * @return the applicationName
560 public String getApplicationName() {
561 return applicationName;
565 * Sets the application name to generate the application token.
567 * @param applicationName to set
569 public void setApplicationName(String applicationName) {
570 this.applicationName = applicationName;
574 * Removes the configured username and password from this {@link Config}.
576 public void removeUsernameAndPassword() {
577 this.userName = null;
578 this.password = null;
582 * Updates this {@link Config} with the configuration of given {@link Config}.
584 * @param config new config
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());
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 + "]";