2 * Copyright (c) 2010-2022 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 {
28 * Converts a volume from AmpliPi to an openHAB PercentType
30 * @param volume volume from AmpliPi
31 * @return according PercentType for openHAB
33 public static PercentType volumeToPercentType(Integer volume) {
34 // AmpliPi volumes range from -79..0
35 return new PercentType((volume + 79) * 100 / 79);
39 * Converts a volume as PercentType from openHAB to an integer for AmpliPi
41 * @param volume volume as PercentType
42 * @return according volume as int for AmpliPi
44 public static int percentTypeToVolume(PercentType volume) {
45 // AmpliPi volumes range from -79..0
46 return (volume.intValue() * 79 / 100) - 79;