diff --git a/utils.go b/utils.go index acc2eb591a3ca9b2894f154ac231c0af1d5b3998..c42eb8d42e38474e0942af8151e2613a8a673708 100644 --- a/utils.go +++ b/utils.go @@ -96,6 +96,22 @@ func roundToDecimal(value float64, places int) float64 { return math.Round(value*pow) / pow } +func normalizeUnit(value float64, unit string) (float64, error) { + switch unit { + case "lqi": + return value * 100 / 255, nil + case "°F": + return (value - 32) * 5 / 9, nil + case "°K": + return value - 273.15, nil + case "mV", "mW", "mA": + return value / 1000, nil + case "V", "%", "A", "W", "Wh": + return value, nil + } + return 0, fmt.Errorf("Unknown unit %s", unit) +} + // convert Mired to Kelvin and Kelvin to Mired // Mired = 1,000,000 / Temperature in Kelvin func convertMired(value int) int {