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.allplay.internal;
15 import java.util.Dictionary;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * AllPlay binding properties.
23 * @author Dominic Lerbs - Initial contribution
25 public class AllPlayBindingProperties {
27 private final Logger logger = LoggerFactory.getLogger(AllPlayBindingProperties.class);
29 private final int rewindSkipTimeInSec;
30 private final int fastForwardSkipTimeInSec;
31 private final String callbackUrl;
32 private final String zoneMemberSeparator;
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 = ",";
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);
51 public int getRewindSkipTimeInSec() {
52 return rewindSkipTimeInSec;
55 public int getFastForwardSkipTimeInSec() {
56 return fastForwardSkipTimeInSec;
59 public String getCallbackUrl() {
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) {
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);
73 } else if (configValue instanceof Integer) {
74 value = (int) configValue;
79 public String getZoneMemberSeparator() {
80 return zoneMemberSeparator;
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;