From 5401afd830a5a63973b3eecc25676d5c01fd4b36 Mon Sep 17 00:00:00 2001
From: jpawlowski <jpawlowski@users.noreply.github.com>
Date: Sat, 18 May 2019 11:22:58 +0000
Subject: [PATCH] UConv: allow custom thesholds for climate condition

git-svn-id: https://svn.fhem.de/fhem/trunk@19399 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
 fhem/FHEM/UConv.pm | 82 ++++++++++++++++++++++++++++++----------------
 1 file changed, 54 insertions(+), 28 deletions(-)

diff --git a/fhem/FHEM/UConv.pm b/fhem/FHEM/UConv.pm
index 84b47af6a..535c5af8e 100644
--- a/fhem/FHEM/UConv.pm
+++ b/fhem/FHEM/UConv.pm
@@ -1053,26 +1053,39 @@ sub c2condition($;$$) {
     my $rgb = "FFFFFF";
     $lang = "en" if ( !$lang );
 
+    my $thresholds;
+
     if ($roomType) {
-        $roomType = "living"
-          if ( looks_like_number($roomType) );
+        if (   ref($roomType)
+            && ref($roomType) eq 'ARRAY'
+            && scalar @{$roomType} == 6 )
+        {
+            $thresholds = $roomType;
+        }
+        elsif (ref($roomType)
+            || looks_like_number($roomType)
+            || !defined( $ideal_clima{$roomType} ) )
+        {
+            $thresholds = $ideal_clima{living}{c};
+        }
+        else {
+            $thresholds = $ideal_clima{$roomType}{c};
+        }
     }
     else {
-        $roomType = "outdoor";
+        $thresholds = $ideal_clima{outdoor}{c};
     }
 
-    if ( defined( $ideal_clima{$roomType} ) ) {
-        my $i = 0;
-        foreach my $th ( @{ $ideal_clima{$roomType}{c} } ) {
-            if ( $data > $th ) {
-                $val = $clima_names{c}{$lang}[$i];
-                $rgb = $clima_names{c}{rgb}[$i];
-            }
-            else {
-                last;
-            }
-            $i++;
+    my $i = 0;
+    foreach my $th ( @{$thresholds} ) {
+        if ( $data > $th ) {
+            $val = $clima_names{c}{ lc($lang) }[$i];
+            $rgb = $clima_names{c}{rgb}[$i];
         }
+        else {
+            last;
+        }
+        $i++;
     }
 
     return ( $val, $rgb ) if (wantarray);
@@ -1086,26 +1099,39 @@ sub humidity2condition($;$$) {
     my $rgb = "FFFFFF";
     $lang = "en" if ( !$lang );
 
+    my $thresholds;
+
     if ($roomType) {
-        $roomType = "living"
-          if ( looks_like_number($roomType) );
+        if (   ref($roomType)
+            && ref($roomType) eq 'ARRAY'
+            && scalar @{$roomType} == 5 )
+        {
+            $thresholds = $roomType;
+        }
+        elsif (ref($roomType)
+            || looks_like_number($roomType)
+            || !defined( $ideal_clima{$roomType} ) )
+        {
+            $thresholds = $ideal_clima{living}{h};
+        }
+        else {
+            $thresholds = $ideal_clima{$roomType}{h};
+        }
     }
     else {
-        $roomType = "outdoor";
+        $thresholds = $ideal_clima{outdoor}{h};
     }
 
-    if ( defined( $ideal_clima{$roomType} ) ) {
-        my $i = 0;
-        foreach my $th ( @{ $ideal_clima{$roomType}{h} } ) {
-            if ( $data > $th ) {
-                $val = $clima_names{h}{$lang}[$i];
-                $rgb = $clima_names{h}{rgb}[$i];
-            }
-            else {
-                last;
-            }
-            $i++;
+    my $i = 0;
+    foreach my $th ( @{$thresholds} ) {
+        if ( $data > $th ) {
+            $val = $clima_names{h}{ lc($lang) }[$i];
+            $rgb = $clima_names{h}{rgb}[$i];
         }
+        else {
+            last;
+        }
+        $i++;
     }
 
     return ( $val, $rgb ) if (wantarray);