From 861ab12a8c64ef7431c46e07ff2d6a09471c288a Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 20 Oct 2017 16:48:56 +0200 Subject: [PATCH] add htmlStyle for Web Color --- 46_Aqicn.pm | 123 +++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 68 deletions(-) diff --git a/46_Aqicn.pm b/46_Aqicn.pm index b1b594b..26b6c85 100644 --- a/46_Aqicn.pm +++ b/46_Aqicn.pm @@ -67,7 +67,7 @@ eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Enco eval "use JSON;1" or $missingModul .= "JSON "; -my $version = "0.0.36"; +my $version = "0.0.44"; @@ -352,7 +352,7 @@ sub Aqicn_GetData($;$) { $param->{cl} = $hash->{CL} if( $hash->{TOKEN} and ref($hash->{CL}) eq 'HASH' ); HttpUtils_NonblockingGet($param); - Log3 $name, 3, "Aqicn ($name) - Send with URI: https://$uri"; + Log3 $name, 4, "Aqicn ($name) - Send with URI: https://$uri"; } sub Aqicn_ErrorHandling($$$) { @@ -473,6 +473,7 @@ sub Aqicn_WriteReadings($$) { readingsBulkUpdate($hash,$r,$v); } + readingsBulkUpdateIfChanged($hash,'htmlStyle','
'.Aqicn_AirPollutionLevel($hash,$readings->{'PM2.5-AQI'}).': '.$readings->{'PM2.5-AQI'}.'
'); readingsBulkUpdateIfChanged($hash,'state',Aqicn_AirPollutionLevel($hash,$readings->{'PM2.5-AQI'})); readingsEndUpdate($hash,1); } @@ -569,38 +570,72 @@ sub Aqicn_AirPollutionLevel($$) { my $apl; - if($aqi < 51) { $apl = "Good"} - elsif($aqi < 101) { $apl = "Moderate"} - elsif($aqi < 151) { $apl = "Unhealthy for Sensitive Groups"} - elsif($aqi < 201) { $apl = "Unhealthy"} - elsif($aqi < 301) { $apl = "Very Unhealthy"} - else { $apl = "Hazardous"} + if($aqi < 51) { $apl = 1} + elsif($aqi < 101) { $apl = 2} + elsif($aqi < 151) { $apl = 3} + elsif($aqi < 201) { $apl = 4} + elsif($aqi < 301) { $apl = 5} + else { $apl = 6} if( (AttrVal('global','language','none') eq 'DE' or AttrVal($name,'language','none') eq 'de') and AttrVal($name,'language','none') ne 'en' ) { return Aqicn_i18n_de($apl); } else { - return $apl; + return Aqicn_i18n_en($apl); } } +sub Aqicn_HtmlStyle($) { + + my $aqi = shift; + my $bgColor; + + + if($aqi < 51) { $bgColor = '#009966'} + elsif($aqi < 101) { $bgColor = '#ffde33'} + elsif($aqi < 151) { $bgColor = '#ff9933'} + elsif($aqi < 201) { $bgColor = '#cc0033'} + elsif($aqi < 301) { $bgColor = '#660099'} + else { $bgColor = '#7e0023'} + + return $bgColor; +} + sub Aqicn_i18n_de($) { my $value = shift; my %i18nde = ( - 'Good' => 'Gut', - 'Moderate' => 'Moderat', - 'Unhealthy for Sensitive Groups' => 'Ungesund für empfindliche Personengruppen', - 'Unhealthy' => 'Ungesund', - 'Very Unhealthy' => 'Sehr ungesund', - 'Hazardous' => 'Gefährlich' + 1 => 'Gut', + 2 => 'Moderat', + 3 => 'Ungesund für empfindliche Personengruppen', + 4 => 'Ungesund', + 5 => 'Sehr ungesund', + 6 => 'Gefährlich' ); return $i18nde{$value}; } +sub Aqicn_i18n_en($) { + + my $value = shift; + + + my %i18nen = ( + 1 => 'Good', + 2 => 'Moderate', + 3 => 'Unhealthy for Sensitive Groups', + 4 => 'Unhealthy', + 5 => 'Very Unhealthy', + 6 => 'Hazardous' + ); + + return $i18nen{$value}; +} + + @@ -610,70 +645,22 @@ sub Aqicn_i18n_de($) { =pod =item device -=item summary Modul to retrieves data from a Tesla Powerwall 2AC -=item summary_DE +=item summary +=item summary_DE =begin html -

Tesla Powerwall 2 AC

+

=end html =begin html_DE -

Tesla Powerwall 2 AC

+

=end html_DE =cut