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 org.openhab.core.common.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
114 * {@link org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob}
115 * can be executed on a circuit.
117 public static final int DEFAULT_SENSOR_READING_WAIT_TIME = 60000;
118 private int sensorReadingWaitTime = DEFAULT_SENSOR_READING_WAIT_TIME;
120 // sensor data Prioritys
122 * Priority for never refresh the sensor value.
124 public static final String REFRESH_PRIORITY_NEVER = "never";
126 * Priority for refresh the sensor value with low priority.
128 public static final String REFRESH_PRIORITY_LOW = "low";
130 * Priority for refresh the sensor value with medium priority.
132 public static final String REFRESH_PRIORITY_MEDIUM = "medium";
134 * Priority for refresh the sensor value with high priority.
136 public static final String REFRESH_PRIORITY_HIGH = "high";
138 // max sensor reading cyclic to wait
140 * The default factor to prioritize medium
141 * {@link org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob}s down.
143 public static final long DEFAULT_MEDIUM_PRIORITY_FACTOR = 5;
145 * The default factor to prioritize low
146 * {@link org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob}s down.
148 public static final long DEFAULT_LOW_PRIORITY_FACTOR = 10;
150 private long mediumPriorityFactor = DEFAULT_MEDIUM_PRIORITY_FACTOR;
151 private long lowPriorityFactor = DEFAULT_LOW_PRIORITY_FACTOR;
154 * Defines the event polling interval of the
155 * {@link org.openhab.binding.digitalstrom.internal.lib.event.EventListener} in milliseconds.
157 private int eventListenerRefreshinterval = DEFAULT_POLLING_FREQUENCY;
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.
165 public static final int DEFAULT_STANDBY_ACTIVE_POWER = 2;
167 private int standbyActivePower = DEFAULT_STANDBY_ACTIVE_POWER;
170 * Creates a new {@link Config} and set the given hostAddress, userName, password and applicationToken. The other
171 * configurations will be set to default.
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
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;
186 * Creates a {@link Config} with default values.
189 // config with default values
193 * Returns the host name from the server.
195 * @return the host address
197 public String getHost() {
202 * Sets the host name of the Server.
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>
209 * @param hostAddress of the digitalSTROM-Server
211 public void setHost(String hostAddress) {
212 this.host = hostAddress;
216 * Returns the username.
218 * @return the username
220 public String getUserName() {
227 * @param userName to set
229 public void setUserName(String userName) {
230 this.userName = userName;
234 * Returns the password.
236 * @return the password
238 public String getPassword() {
245 * @param password to set
247 public void setPassword(String password) {
248 this.password = password;
252 * Returns the Application-Token.
254 * @return the Application-Token
256 public String getAppToken() {
261 * Sets the Application-Token.
263 * @param applicationToken to set
265 public void setAppToken(String applicationToken) {
266 this.appToken = applicationToken;
270 * Returns the connection timeout.
272 * @return the connection timeout
274 public int getConnectionTimeout() {
275 return connectionTimeout;
279 * Sets the connection timeout.
281 * @param connectionTimeout to set
283 public void setConnectionTimeout(int connectionTimeout) {
284 this.connectionTimeout = connectionTimeout;
288 * Returns the read timeout.
290 * @return the read timeout
292 public int getReadTimeout() {
297 * Sets the read timeout.
299 * @param readTimeout the readTimeout to set
301 public void setReadTimeout(int readTimeout) {
302 this.readTimeout = readTimeout;
306 * Returns the connection timeout for sensor readings from devices.
308 * @return the connection sensor data timeout
310 public int getSensordataConnectionTimeout() {
311 return sensordataConnectionTimeout;
315 * Sets the connection timeout for sensor readings from devices.
317 * @param sensordataConnectionTimeout to set
319 public void setSensordataConnectionTimeout(int sensordataConnectionTimeout) {
320 this.sensordataConnectionTimeout = sensordataConnectionTimeout;
324 * Returns the read timeout for sensor readings from devices.
326 * @return the read sensor data timeout
328 public int getSensordataReadTimeout() {
329 return sensordataReadTimeout;
333 * Sets the connection timeout for sensor readings from devices.
335 * @param sensordataReadTimeout to set
337 public void setSensordataReadTimeout(int sensordataReadTimeout) {
338 this.sensordataReadTimeout = sensordataReadTimeout;
342 * Returns the path to the SSL-Certificate.
344 * @return the path to the trust certification
346 public String getTrustCertPath() {
347 return trustCertPath;
351 * Return the SSL-Certificate of the server.
353 * @return the SSL-Certificate of the server
355 public String getCert() {
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.
364 * @param cert of the digitalSTROM-Server to set
366 public void setCert(String cert) {
371 * Sets the path to the SSL-Certificate. It can be an absolute or relative path.
373 * @param trustCertPath path to a SSL-Certificate
375 public void setTrustCertPath(String trustCertPath) {
376 this.trustCertPath = trustCertPath;
380 * Returns the number of days after the trash devices is deleted.
382 * @return the trash-device delete time in days
384 public int getTrashDeviceDeleteTime() {
385 return trashDeviceDeleteTime;
389 * Sets the number of days after the trash devices is deleted.
391 * @param trashDeviceDeleteTime in days
393 public void setTrashDeviceDeleteTime(int trashDeviceDeleteTime) {
394 this.trashDeviceDeleteTime = trashDeviceDeleteTime;
398 * Sets the milliseconds after the trash devices will be checked, if its time to delete.
400 * @return the bin check time in milliseconds
402 public int getBinCheckTime() {
407 * Returns the milliseconds after the trash devices will be checked, if its time to delete.
409 * @param binCheckTime in milliseconds
411 public void setBinCheckTime(int binCheckTime) {
412 this.binCheckTime = binCheckTime;
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.
419 * @return the pollingFrequency in milliseconds
421 public int getPollingFrequency() {
422 return pollingFrequency;
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.
429 * @param pollingFrequency to set
431 public void setPollingFrequency(int pollingFrequency) {
432 this.pollingFrequency = pollingFrequency;
436 * Returns the interval in milliseconds to refresh the sensor data.
438 * @return the sensor data refresh interval in milliseconds
440 public int getSensordataRefreshInterval() {
441 return sensordataRefreshInterval;
445 * Sets the interval in milliseconds to refresh the sensor data.
447 * @param sensordataRefreshInterval in milliseconds.
449 public void setSensordataRefreshInterval(int sensordataRefreshInterval) {
450 this.sensordataRefreshInterval = sensordataRefreshInterval;
454 * Returns the interval to refresh the total power sensor data.
456 * @return the total power update interval in milliseconds.
458 public int getTotalPowerUpdateInterval() {
459 return totalPowerUpdateInterval;
463 * Sets the interval in milliseconds to refresh the total power sensor data.
465 * @param totalPowerUpdateInterval in milliseconds
467 public void setTotalPowerUpdateInterval(int totalPowerUpdateInterval) {
468 this.totalPowerUpdateInterval = totalPowerUpdateInterval;
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.
476 * @return the sensor reading wait time in milliseconds
478 public int getSensorReadingWaitTime() {
479 return sensorReadingWaitTime;
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.
487 * @param sensorReadingWaitTime in milliseconds
489 public void setSensorReadingWaitTime(int sensorReadingWaitTime) {
490 this.sensorReadingWaitTime = sensorReadingWaitTime;
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.
498 * @return the medium priority factor
500 public long getMediumPriorityFactor() {
501 return mediumPriorityFactor;
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.
509 * @param mediumPriorityFactor to set
511 public void setMediumPriorityFactor(long mediumPriorityFactor) {
512 this.mediumPriorityFactor = mediumPriorityFactor;
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.
520 * @return the low priority factor
522 public long getLowPriorityFactor() {
523 return lowPriorityFactor;
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.
531 * @param lowPriorityFactor to set
533 public void setLowPriorityFactor(long lowPriorityFactor) {
534 this.lowPriorityFactor = lowPriorityFactor;
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}.
542 * @return the EventListener refresh interval in milliseconds
544 public int getEventListenerRefreshinterval() {
545 return eventListenerRefreshinterval;
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}.
553 * @param eventListenerRefreshinterval to set
555 public void setEventListenerRefreshinterval(int eventListenerRefreshinterval) {
556 this.eventListenerRefreshinterval = eventListenerRefreshinterval;
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.
565 * @return the standby active power
567 public int getStandbyActivePower() {
568 return standbyActivePower;
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.
577 * @param standbyActivePower to set
579 public void setStandbyActivePower(int standbyActivePower) {
580 this.standbyActivePower = standbyActivePower;
584 * Returns the application name to generate the application token.
586 * @return the applicationName
588 public String getApplicationName() {
589 return applicationName;
593 * Sets the application name to generate the application token.
595 * @param applicationName to set
597 public void setApplicationName(String applicationName) {
598 this.applicationName = applicationName;
602 * Removes the configured username and password from this {@link Config}.
604 public void removeUsernameAndPassword() {
605 this.userName = null;
606 this.password = null;
610 * Updates this {@link Config} with the configuration of given {@link Config}.
612 * @param config new config
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());
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 + "]";