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.yamahareceiver.internal.config;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Zone;
22 * @author Tomasz Maruszak - Initial contribution.
25 public class YamahaZoneConfig {
27 * Zone name, will be one of {@link Zone}.
29 private String zone = "";
31 * Volume relative change factor when sending {@link org.openhab.core.library.types.IncreaseDecreaseType}
34 private float volumeRelativeChangeFactor = 0.5f; // Default: 0.5 percent
36 * Minimum allowed volume in dB.
38 private float volumeDbMin = -80f; // -80.0 dB
40 * Maximum allowed volume in dB.
42 private float volumeDbMax = 12f; // 12.0 dB
44 public @Nullable Zone getZone() {
45 return YamahaUtils.tryParseEnum(Zone.class, zone);
48 public String getZoneValue() {
52 public float getVolumeRelativeChangeFactor() {
53 return volumeRelativeChangeFactor;
56 public float getVolumeDbMin() {
60 public float getVolumeDbMax() {
64 private float getVolumeDbRange() {
65 return getVolumeDbMax() - getVolumeDbMin();
69 * Converts from volume percentage to volume dB.
71 * @param volume volume percentage
74 public float getVolumeDb(float volume) {
75 return volume * getVolumeDbRange() / 100.0f + getVolumeDbMin();
79 * Converts from volume dB to volume percentage.
81 * @param volumeDb volume dB
82 * @return volume percentage
84 public float getVolumePercentage(float volumeDb) {
85 float volume = (volumeDb - getVolumeDbMin()) * 100.0f / getVolumeDbRange();
86 if (volume < 0 || volume > 100) {
87 volume = Math.max(0, Math.min(volume, 100));