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.amplipi.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.PercentType;
19 * This class has some commonly used static helper functions.
21 * @author Kai Kreuzer - Initial contribution
25 public class AmpliPiUtils {
27 * The supported volume range in decibels for the AmpliPi
29 public static final int MIN_VOLUME_DB = -79;
30 public static final int MAX_VOLUME_DB = 0;
33 * Converts a volume from AmpliPi to an openHAB PercentType
35 * @param volume volume from AmpliPi
36 * @return according PercentType for openHAB
38 public static PercentType volumeToPercentType(Integer volume) {
39 // AmpliPi volumes range from -79..0
40 return new PercentType((volume + 79) * 100 / 79);
44 * Converts a volume as PercentType from openHAB to an integer for AmpliPi
46 * @param volume volume as PercentType
47 * @return according volume as int for AmpliPi
49 public static int percentTypeToVolume(PercentType volume) {
50 // AmpliPi volumes range from -79..0
51 return (volume.intValue() * 79 / 100) - 79;