]> git.basschouten.com Git - openhab-addons.git/blob
e1d0a0685f75cd714c70c74b9483709a72b74fc7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.fronius.internal.math;
14
15 /**
16  * Helper class for unit conversions
17  *
18  * @author Thomas Rokohl - Initial contribution
19  *
20  */
21 public class KilowattConverter {
22
23     public static double getConvertFactor(String fromUnit, String toUnit) {
24         String adjustedFromUnit = fromUnit.replace("Wh", "");
25         String adjustedtoUnit = toUnit.replace("Wh", "");
26         return SiPrefixFactors.getFactorToBaseUnit(adjustedFromUnit) * 1
27                 / SiPrefixFactors.getFactorToBaseUnit(adjustedtoUnit);
28     }
29
30     public static double convertTo(double value, String fromUnit, String toUnit) {
31         return value * getConvertFactor(fromUnit, toUnit);
32     }
33 }