]> git.basschouten.com Git - openhab-addons.git/blob
d8597b72db4564cdedf175383f62e725a026b51d
[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.amplipi.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.PercentType;
17
18 /**
19  * This class has some commonly used static helper functions.
20  *
21  * @author Kai Kreuzer - Initial contribution
22  *
23  */
24 @NonNullByDefault
25 public class AmpliPiUtils {
26     /**
27      * The supported volume range in decibels for the AmpliPi
28      */
29     public static final int MIN_VOLUME_DB = -79;
30     public static final int MAX_VOLUME_DB = 0;
31
32     /**
33      * Converts a volume from AmpliPi to an openHAB PercentType
34      *
35      * @param volume volume from AmpliPi
36      * @return according PercentType for openHAB
37      */
38     public static PercentType volumeToPercentType(Integer volume) {
39         // AmpliPi volumes range from -79..0
40         return new PercentType((volume + 79) * 100 / 79);
41     }
42
43     /**
44      * Converts a volume as PercentType from openHAB to an integer for AmpliPi
45      * 
46      * @param volume volume as PercentType
47      * @return according volume as int for AmpliPi
48      */
49     public static int percentTypeToVolume(PercentType volume) {
50         // AmpliPi volumes range from -79..0
51         return (volume.intValue() * 79 / 100) - 79;
52     }
53 }