]> git.basschouten.com Git - openhab-addons.git/blob
2f208918a9bf0cef663618daa1fceef14a93fbf1
[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.allplay.internal;
14
15 import java.util.Dictionary;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * AllPlay binding properties.
22  *
23  * @author Dominic Lerbs - Initial contribution
24  */
25 public class AllPlayBindingProperties {
26
27     private final Logger logger = LoggerFactory.getLogger(AllPlayBindingProperties.class);
28
29     private final int rewindSkipTimeInSec;
30     private final int fastForwardSkipTimeInSec;
31     private final String callbackUrl;
32     private final String zoneMemberSeparator;
33
34     private static final String REWIND_SKIP_TIME_PROPERTY = "rewindSkipTimeInSec";
35     private static final int REWIND_SKIP_TIME_DEFAULT_VALUE = 10;
36     private static final String FAST_FORWARD_SKIP_TIME_PROPERTY = "fastForwardSkipTimeInSec";
37     private static final int FAST_FORWARD_SKIP_TIME_DEFAULT_VALUE = 10;
38     private static final String CALLBACK_URL = "callbackUrl";
39     private static final String ZONE_MEMBER_SEPARATOR_PROPERTY = "zoneMemberSeparator";
40     private static final String ZONE_MEMBER_SEPARATOR_DEFAULT_VALUE = ",";
41
42     public AllPlayBindingProperties(Dictionary<String, Object> properties) {
43         rewindSkipTimeInSec = getIntegerProperty(properties, REWIND_SKIP_TIME_PROPERTY, REWIND_SKIP_TIME_DEFAULT_VALUE);
44         fastForwardSkipTimeInSec = getIntegerProperty(properties, FAST_FORWARD_SKIP_TIME_PROPERTY,
45                 FAST_FORWARD_SKIP_TIME_DEFAULT_VALUE);
46         callbackUrl = (String) properties.get(CALLBACK_URL);
47         zoneMemberSeparator = getStringProperty(properties, ZONE_MEMBER_SEPARATOR_PROPERTY,
48                 ZONE_MEMBER_SEPARATOR_DEFAULT_VALUE);
49     }
50
51     public int getRewindSkipTimeInSec() {
52         return rewindSkipTimeInSec;
53     }
54
55     public int getFastForwardSkipTimeInSec() {
56         return fastForwardSkipTimeInSec;
57     }
58
59     public String getCallbackUrl() {
60         return callbackUrl;
61     }
62
63     private int getIntegerProperty(Dictionary<String, Object> properties, String propertyKey, int defaultValue) {
64         Object configValue = properties.get(propertyKey);
65         int value = defaultValue;
66         if (configValue instanceof String stringValue) {
67             try {
68                 value = Integer.parseInt(stringValue);
69             } catch (NumberFormatException e) {
70                 logger.warn("Unable to convert value {} for config property {} to integer. Using default value.",
71                         configValue, propertyKey);
72             }
73         } else if (configValue instanceof Integer) {
74             value = (int) configValue;
75         }
76         return value;
77     }
78
79     public String getZoneMemberSeparator() {
80         return zoneMemberSeparator;
81     }
82
83     private String getStringProperty(Dictionary<String, Object> properties, String propertyKey, String defaultValue) {
84         String value = (String) properties.get(propertyKey);
85         return value != null ? value : defaultValue;
86     }
87 }