]> git.basschouten.com Git - openhab-addons.git/blob
27324f1984f941f9c816dd73d27445a96d13c764
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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     /**
28      * Converts a volume from AmpliPi to an openHAB PercentType
29      *
30      * @param volume volume from AmpliPi
31      * @return according PercentType for openHAB
32      */
33     public static PercentType volumeToPercentType(Integer volume) {
34         // AmpliPi volumes range from -79..0
35         return new PercentType((volume + 79) * 100 / 79);
36     }
37
38     /**
39      * Converts a volume as PercentType from openHAB to an integer for AmpliPi
40      * 
41      * @param volume volume as PercentType
42      * @return according volume as int for AmpliPi
43      */
44     public static int percentTypeToVolume(PercentType volume) {
45         // AmpliPi volumes range from -79..0
46         return (volume.intValue() * 79 / 100) - 79;
47     }
48 }