add configuration forecast data
This commit is contained in:
		@@ -137,8 +137,8 @@ sub Weather_Initialize($) {
 | 
				
			|||||||
    $hash->{SetFn}      = 'Weather_Set';
 | 
					    $hash->{SetFn}      = 'Weather_Set';
 | 
				
			||||||
    $hash->{AttrList}   = 
 | 
					    $hash->{AttrList}   = 
 | 
				
			||||||
          'disable:0,1 '
 | 
					          'disable:0,1 '
 | 
				
			||||||
        . 'forecast:hourly,daily,any,off '
 | 
					        . 'forecast:hourly,daily,every,off '
 | 
				
			||||||
        . 'forecastLimit: '
 | 
					        . 'forecastLimit '
 | 
				
			||||||
        . $readingFnAttributes;
 | 
					        . $readingFnAttributes;
 | 
				
			||||||
    $hash->{NotifyFn}= 'Weather_Notify';
 | 
					    $hash->{NotifyFn}= 'Weather_Notify';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -226,13 +226,18 @@ sub Weather_WriteReadings($$) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ### forecast
 | 
					    ### forecast
 | 
				
			||||||
    if ( ref( $dataRef->{forecast} ) eq 'HASH' ) {
 | 
					    if (  ref( $dataRef->{forecast} ) eq 'HASH'
 | 
				
			||||||
 | 
					      and AttrVal($name, 'forecast', 'every') ne 'off' ) {
 | 
				
			||||||
            ## hourly
 | 
					            ## hourly
 | 
				
			||||||
            if (  defined($dataRef->{forecast}->{hourly})
 | 
					            if (  defined($dataRef->{forecast}->{hourly})
 | 
				
			||||||
              and ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY'
 | 
					              and ref( $dataRef->{forecast}->{hourly} ) eq 'ARRAY'
 | 
				
			||||||
          and scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0 )
 | 
					              and scalar( @{ $dataRef->{forecast}->{hourly} } ) > 0
 | 
				
			||||||
 | 
					              and (AttrVal($name, 'forecast', 'every') eq 'every'
 | 
				
			||||||
 | 
					                or AttrVal($name, 'forecast', 'hourly') eq 'hourly')
 | 
				
			||||||
 | 
					              )
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                my $i= 0;
 | 
					                my $i= 0;
 | 
				
			||||||
 | 
					                my $limit = AttrVal($name,'forecastLimit',-1);
 | 
				
			||||||
                foreach my $fc (@{$dataRef->{forecast}->{hourly}}) {
 | 
					                foreach my $fc (@{$dataRef->{forecast}->{hourly}}) {
 | 
				
			||||||
                    $i++;
 | 
					                    $i++;
 | 
				
			||||||
                    my $f= "hfc" . $i ."_";
 | 
					                    my $f= "hfc" . $i ."_";
 | 
				
			||||||
@@ -252,14 +257,21 @@ sub Weather_WriteReadings($$) {
 | 
				
			|||||||
                        my $wdir= degrees_to_direction($dataRef->{forecast}->{hourly}[$i-1]{wind_direction}, @directions_txt_i18n);
 | 
					                        my $wdir= degrees_to_direction($dataRef->{forecast}->{hourly}[$i-1]{wind_direction}, @directions_txt_i18n);
 | 
				
			||||||
                        readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{hourly}[$i-1]{wind_speed} . ' km/h');
 | 
					                        readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{hourly}[$i-1]{wind_speed} . ' km/h');
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    last if ( $i == $limit and $limit > 0 );
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ## daily
 | 
					            ## daily
 | 
				
			||||||
        if (  defined($dataRef->{forecast}->{daily}) and ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY'
 | 
					            if (  defined($dataRef->{forecast}->{daily})
 | 
				
			||||||
          and scalar( @{ $dataRef->{forecast}->{daily} } ) > 0 )
 | 
					              and ref( $dataRef->{forecast}->{daily} ) eq 'ARRAY'
 | 
				
			||||||
 | 
					              and scalar( @{ $dataRef->{forecast}->{daily} } ) > 0
 | 
				
			||||||
 | 
					              and (AttrVal($name, 'forecast', 'every') eq 'every'
 | 
				
			||||||
 | 
					                or AttrVal($name, 'forecast', 'daily') eq 'daily')
 | 
				
			||||||
 | 
					              )
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                my $i= 0;
 | 
					                my $i= 0;
 | 
				
			||||||
 | 
					                my $limit = AttrVal($name,'forecastLimit',-1);
 | 
				
			||||||
                foreach my $fc (@{$dataRef->{forecast}->{daily}}) {
 | 
					                foreach my $fc (@{$dataRef->{forecast}->{daily}}) {
 | 
				
			||||||
                    $i++;
 | 
					                    $i++;
 | 
				
			||||||
                    my $f= "fc" . $i ."_";
 | 
					                    my $f= "fc" . $i ."_";
 | 
				
			||||||
@@ -279,6 +291,8 @@ sub Weather_WriteReadings($$) {
 | 
				
			|||||||
                        my $wdir= degrees_to_direction($dataRef->{forecast}->{daily}[$i-1]{wind_direction}, @directions_txt_i18n);
 | 
					                        my $wdir= degrees_to_direction($dataRef->{forecast}->{daily}[$i-1]{wind_direction}, @directions_txt_i18n);
 | 
				
			||||||
                        readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{daily}[$i-1]{wind_speed} . ' km/h');
 | 
					                        readingsBulkUpdate($hash, $f . 'wind_condition', 'Wind: ' . $wdir . ' ' . $dataRef->{forecast}->{daily}[$i-1]{wind_speed} . ' km/h');
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    last if ( $i == $limit and $limit > 0 );
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -480,11 +494,11 @@ sub WeatherIconIMGTag($) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#####################################
 | 
					#####################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sub WeatherAsHtmlV($;$) {
 | 
					sub WeatherAsHtmlV($;$$) {
 | 
				
			||||||
    my ($d,$items) = @_;
 | 
					    my ($d,$items,$f) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $d = "<none>" if(!$d);
 | 
					    $d = "<none>" if(!$d);
 | 
				
			||||||
    $items = 9 if( !$items );
 | 
					    $items = 6 if( !$items );
 | 
				
			||||||
    return "$d is not a Weather instance<br>"
 | 
					    return "$d is not a Weather instance<br>"
 | 
				
			||||||
        if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather");
 | 
					        if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -492,6 +506,16 @@ sub WeatherAsHtmlV($;$) {
 | 
				
			|||||||
    my $width= int(ICONSCALE*ICONWIDTH);
 | 
					    my $width= int(ICONSCALE*ICONWIDTH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    my $ret = '<table class="weather">';
 | 
					    my $ret = '<table class="weather">';
 | 
				
			||||||
 | 
					    my $fc;
 | 
				
			||||||
 | 
					    if (  defined($f)
 | 
				
			||||||
 | 
					      and ($f eq 'h'
 | 
				
			||||||
 | 
					        or $f eq 'd')
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $fc = ( $f eq 'd' ? 'fc' : 'hfc' );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else { $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' ); }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td><td class="weatherValue">%s<br>%s°C  %s%%<br>%s</td></tr>',
 | 
					    $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td><td class="weatherValue">%s<br>%s°C  %s%%<br>%s</td></tr>',
 | 
				
			||||||
        $width,
 | 
					        $width,
 | 
				
			||||||
        WeatherIconIMGTag(ReadingsVal($d, "icon", "")),
 | 
					        WeatherIconIMGTag(ReadingsVal($d, "icon", "")),
 | 
				
			||||||
@@ -499,14 +523,13 @@ sub WeatherAsHtmlV($;$) {
 | 
				
			|||||||
        ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", ""),
 | 
					        ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", ""),
 | 
				
			||||||
        ReadingsVal($d, "wind_condition", ""));
 | 
					        ReadingsVal($d, "wind_condition", ""));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    my $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' );
 | 
					 | 
				
			||||||
    for(my $i=1; $i<$items; $i++) {
 | 
					    for(my $i=1; $i<$items; $i++) {
 | 
				
			||||||
        $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td><td class="weatherValue"><span class="weatherDay">%s: %s</span><br><span class="weatherMin">min %s°C</span> <span class="weatherMax">max %s°C</span></td></tr>',
 | 
					        $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td><td class="weatherValue"><span class="weatherDay">%s: %s</span><br><span class="weatherMin">min %s°C</span> <span class="weatherMax">max %s°C</span></td></tr>',
 | 
				
			||||||
            $width,
 | 
					            $width,
 | 
				
			||||||
            WeatherIconIMGTag(ReadingsVal($d, "${fc}${i}_icon", "")),
 | 
					            WeatherIconIMGTag(ReadingsVal($d, "${fc}${i}_icon", "")),
 | 
				
			||||||
            ReadingsVal($d, "${fc}${i}_day_of_week", ""),
 | 
					            ReadingsVal($d, "${fc}${i}_day_of_week", ""),
 | 
				
			||||||
            ReadingsVal($d, "${fc}${i}_condition", ""),
 | 
					            ReadingsVal($d, "${fc}${i}_condition", ""),
 | 
				
			||||||
        ReadingsVal($d, "${fc}${i}_low_c", ""), ReadingsVal($d, "${fc}${i}_high_c", ""));
 | 
					            ReadingsVal($d, "${fc}${i}_low_c", " - "), ReadingsVal($d, "${fc}${i}_high_c", " - "));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $ret .= "</table>";
 | 
					    $ret .= "</table>";
 | 
				
			||||||
@@ -519,11 +542,11 @@ sub WeatherAsHtml($;$) {
 | 
				
			|||||||
    WeatherAsHtmlV($d,$i);
 | 
					    WeatherAsHtmlV($d,$i);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sub WeatherAsHtmlH($;$) {
 | 
					sub WeatherAsHtmlH($;$$) {
 | 
				
			||||||
    my ($d,$items) = @_;
 | 
					    my ($d,$items,$f) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $d = "<none>" if(!$d);
 | 
					    $d = "<none>" if(!$d);
 | 
				
			||||||
    $items = 9 if( !$items );
 | 
					    $items = 6 if( !$items );
 | 
				
			||||||
    return "$d is not a Weather instance<br>"
 | 
					    return "$d is not a Weather instance<br>"
 | 
				
			||||||
        if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather");
 | 
					        if(!$defs{$d} || $defs{$d}->{TYPE} ne "Weather");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -535,7 +558,15 @@ sub WeatherAsHtmlH($;$) {
 | 
				
			|||||||
    my $format= '<td><table border=1><tr><td class="weatherIcon" width=%d>%s</td></tr><tr><td class="weatherValue">%s</td></tr><tr><td class="weatherValue">%s°C %s%%</td></tr><tr><td class="weatherValue">%s</td></tr></table></td>';
 | 
					    my $format= '<td><table border=1><tr><td class="weatherIcon" width=%d>%s</td></tr><tr><td class="weatherValue">%s</td></tr><tr><td class="weatherValue">%s°C %s%%</td></tr><tr><td class="weatherValue">%s</td></tr></table></td>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    my $ret = '<table class="weather">';
 | 
					    my $ret = '<table class="weather">';
 | 
				
			||||||
    my $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' );
 | 
					    my $fc;
 | 
				
			||||||
 | 
					    if (  defined($f)
 | 
				
			||||||
 | 
					      and ($f eq 'h'
 | 
				
			||||||
 | 
					        or $f eq 'd')
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $fc = ( $f eq 'd' ? 'fc' : 'hfc' );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else { $fc = ( (defined($h->{READINGS}->{fc1_day_of_week}) and $h->{READINGS}->{fc1_day_of_week}) ? 'fc' : 'hfc' ); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # icons
 | 
					    # icons
 | 
				
			||||||
    $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td>', $width, WeatherIconIMGTag(ReadingsVal($d, "icon", "")));
 | 
					    $ret .= sprintf('<tr><td class="weatherIcon" width=%d>%s</td>', $width, WeatherIconIMGTag(ReadingsVal($d, "icon", "")));
 | 
				
			||||||
@@ -555,14 +586,14 @@ sub WeatherAsHtmlH($;$) {
 | 
				
			|||||||
    # temp/hum | min
 | 
					    # temp/hum | min
 | 
				
			||||||
    $ret .= sprintf('<tr><td class="weatherMin">%s°C %s%%</td>', ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", ""));
 | 
					    $ret .= sprintf('<tr><td class="weatherMin">%s°C %s%%</td>', ReadingsVal($d, "temp_c", ""), ReadingsVal($d, "humidity", ""));
 | 
				
			||||||
    for(my $i=1; $i<$items; $i++) {
 | 
					    for(my $i=1; $i<$items; $i++) {
 | 
				
			||||||
    $ret .= sprintf('<td class="weatherMin">min %s°C</td>', ReadingsVal($d, "${fc}${i}_low_c", ""));
 | 
					        $ret .= sprintf('<td class="weatherMin">min %s°C</td>', ReadingsVal($d, "${fc}${i}_low_c", " - "));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $ret .= '</tr>';
 | 
					    $ret .= '</tr>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # wind | max
 | 
					    # wind | max
 | 
				
			||||||
    $ret .= sprintf('<tr><td class="weatherMax">%s</td>', ReadingsVal($d, "wind_condition", ""));
 | 
					    $ret .= sprintf('<tr><td class="weatherMax">%s</td>', ReadingsVal($d, "wind_condition", ""));
 | 
				
			||||||
    for(my $i=1; $i<$items; $i++) {
 | 
					    for(my $i=1; $i<$items; $i++) {
 | 
				
			||||||
    $ret .= sprintf('<td class="weatherMax">max %s°C</td>', ReadingsVal($d, "${fc}${i}_high_c", ""));
 | 
					        $ret .= sprintf('<td class="weatherMax">max %s°C</td>', ReadingsVal($d, "${fc}${i}_high_c", " - "));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $ret .= "</tr></table>";
 | 
					    $ret .= "</tr></table>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -912,8 +943,8 @@ sub WeatherAsHtmlD($;$) {
 | 
				
			|||||||
    gemäß Plan doch es werden keine Daten vom
 | 
					    gemäß Plan doch es werden keine Daten vom
 | 
				
			||||||
    API angefordert.</li>
 | 
					    API angefordert.</li>
 | 
				
			||||||
    <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
 | 
					    <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
 | 
				
			||||||
    <li>forecast - Anzeige von forecast Daten. Alle, nur Stundenforecast, nur Tageforecast, keine.</li>
 | 
					    <li>forecast - every/hourly/daily/off, Anzeige von forecast Daten. Alle, nur Stundenforecast, nur Tageforecast, keine.</li>
 | 
				
			||||||
    <li>forecastLimit - Anzahl der Forecast-Datensätze.</li>
 | 
					    <li>forecastLimit - Anzahl der Forecast-Datensätze welche als Reading geschrieben werden sollen.</li>
 | 
				
			||||||
  </ul>
 | 
					  </ul>
 | 
				
			||||||
  <br>
 | 
					  <br>
 | 
				
			||||||
</ul>
 | 
					</ul>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user