fix umlaute problem
This commit is contained in:
		| @@ -664,7 +664,7 @@ sub Weather_Define($$) { | |||||||
|     readingsSingleUpdate( $hash, 'state', 'Initialized', 1 ); |     readingsSingleUpdate( $hash, 'state', 'Initialized', 1 ); | ||||||
|     Weather_LanguageInitialize( $hash->{LANG} ); |     Weather_LanguageInitialize( $hash->{LANG} ); | ||||||
|  |  | ||||||
|     my $apistring = $api . '::Weather'; |     my $apistring = 'FHEM::' . $api . '::Weather'; | ||||||
|     $hash->{fhem}->{api} = $apistring->new( |     $hash->{fhem}->{api} = $apistring->new( | ||||||
|         { |         { | ||||||
|             devName    => $hash->{NAME}, |             devName    => $hash->{NAME}, | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ | |||||||
| # | # | ||||||
| ############################################################################### | ############################################################################### | ||||||
|  |  | ||||||
| package DarkSkyAPI::Weather; | package FHEM::DarkSkyAPI::Weather; | ||||||
| use strict; | use strict; | ||||||
| use warnings; | use warnings; | ||||||
|  |  | ||||||
| @@ -48,7 +48,7 @@ use constant DEMODATA => '{"latitude":50.112,"longitude":8.686,"timezone":"Europ | |||||||
|  |  | ||||||
|  |  | ||||||
| use constant URL => 'https://api.darksky.net/forecast/'; | use constant URL => 'https://api.darksky.net/forecast/'; | ||||||
| use constant VERSION => '0.2.6'; | use constant VERSION => '0.2.7'; | ||||||
|  |  | ||||||
| my %codes = ( | my %codes = ( | ||||||
|     'clear-day'           => 32, |     'clear-day'           => 32, | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ | |||||||
| # https://api.openweathermap.org/data/2.5/forecast?lat=[lat]&lon=[long]&APPID=[API]   Forecast | # https://api.openweathermap.org/data/2.5/forecast?lat=[lat]&lon=[long]&APPID=[API]   Forecast | ||||||
| # https://openweathermap.org/weather-conditions     Icons und Conditions ID's | # https://openweathermap.org/weather-conditions     Icons und Conditions ID's | ||||||
|  |  | ||||||
| package OpenWeatherMapAPI::Weather; | package FHEM::OpenWeatherMapAPI::Weather; | ||||||
| use strict; | use strict; | ||||||
| use warnings; | use warnings; | ||||||
|  |  | ||||||
| @@ -48,7 +48,7 @@ eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode "; | |||||||
| # use Data::Dumper;    # for Debug only | # use Data::Dumper;    # for Debug only | ||||||
| ## API URL | ## API URL | ||||||
| use constant URL => 'https://api.openweathermap.org/data/2.5/'; | use constant URL => 'https://api.openweathermap.org/data/2.5/'; | ||||||
| use constant VERSION => '0.2.3'; | use constant VERSION => '0.2.4'; | ||||||
| ## URL . 'weather?' for current data | ## URL . 'weather?' for current data | ||||||
| ## URL . 'forecast?' for forecast data | ## URL . 'forecast?' for forecast data | ||||||
|  |  | ||||||
| @@ -264,12 +264,12 @@ sub _ProcessingRetrieveData($$) { | |||||||
| #                 print 'Response: ' . Dumper $data; | #                 print 'Response: ' . Dumper $data; | ||||||
|                 ###### Ab hier wird die ResponseHash Referenze für die Rückgabe zusammen gestellt |                 ###### Ab hier wird die ResponseHash Referenze für die Rückgabe zusammen gestellt | ||||||
|                 $self->{cached}->{current_date_time} = |                 $self->{cached}->{current_date_time} = | ||||||
|                 encode_utf8(strftime( "%a, %e %b %Y %H:%M", |                 strftimeWrapper( "%a, %e %b %Y %H:%M", | ||||||
|                     localtime( $self->{fetchTime} ) )); |                     localtime( $self->{fetchTime} ) ); | ||||||
|  |  | ||||||
|                 if ( $self->{endpoint} eq 'weather' ) { |                 if ( $self->{endpoint} eq 'weather' ) { | ||||||
|                     $self->{cached}->{country}       = $data->{sys}->{country}; |                     $self->{cached}->{country}       = $data->{sys}->{country}; | ||||||
|                     $self->{cached}->{city}          = $data->{name}; |                     $self->{cached}->{city}          = encode_utf8($data->{name}); | ||||||
|                     $self->{cached}->{license}{text} = 'none'; |                     $self->{cached}->{license}{text} = 'none'; | ||||||
|                     $self->{cached}->{current}       = { |                     $self->{cached}->{current}       = { | ||||||
|                         'temperature' => int( |                         'temperature' => int( | ||||||
| @@ -311,18 +311,18 @@ sub _ProcessingRetrieveData($$) { | |||||||
|                             int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), |                             int( sprintf( "%.1f", $data->{visibility} ) + 0.5 ), | ||||||
|                         'code'       => $codes{ $data->{weather}->[0]->{id} }, |                         'code'       => $codes{ $data->{weather}->[0]->{id} }, | ||||||
|                         'iconAPI'    => $data->{weather}->[0]->{icon}, |                         'iconAPI'    => $data->{weather}->[0]->{icon}, | ||||||
|                         'sunsetTime' => encode_utf8(strftime( |                         'sunsetTime' => strftimeWrapper( | ||||||
|                             "%a, %e %b %Y %H:%M", |                             "%a, %e %b %Y %H:%M", | ||||||
|                             localtime( $data->{sys}->{sunset} ) |                             localtime( $data->{sys}->{sunset} ) | ||||||
|                         )), |                         ), | ||||||
|                         'sunriseTime' => encode_utf8(strftime( |                         'sunriseTime' => strftimeWrapper( | ||||||
|                             "%a, %e %b %Y %H:%M", |                             "%a, %e %b %Y %H:%M", | ||||||
|                             localtime( $data->{sys}->{sunrise} ) |                             localtime( $data->{sys}->{sunrise} ) | ||||||
|                         )), |                         ), | ||||||
|                         'pubDate' => encode_utf8(strftime( |                         'pubDate' => strftimeWrapper( | ||||||
|                             "%a, %e %b %Y %H:%M", |                             "%a, %e %b %Y %H:%M", | ||||||
|                             localtime( $data->{dt} ) |                             localtime( $data->{dt} ) | ||||||
|                         )), |                         ), | ||||||
|                     }; |                     }; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -338,12 +338,12 @@ sub _ProcessingRetrieveData($$) { | |||||||
|                             push( |                             push( | ||||||
|                                 @{ $self->{cached}->{forecast}->{hourly} }, |                                 @{ $self->{cached}->{forecast}->{hourly} }, | ||||||
|                                 { |                                 { | ||||||
|                                     'pubDate' => encode_utf8(strftime( |                                     'pubDate' => strftimeWrapper( | ||||||
|                                         "%a, %e %b %Y %H:%M", |                                         "%a, %e %b %Y %H:%M", | ||||||
|                                         localtime( |                                         localtime( | ||||||
|                                             ( $data->{list}->[$i]->{dt} ) - 3600 |                                             ( $data->{list}->[$i]->{dt} ) - 3600 | ||||||
|                                         ) |                                         ) | ||||||
|                                     )), |                                     ), | ||||||
|                                     'day_of_week' => strftime( |                                     'day_of_week' => strftime( | ||||||
|                                         "%a, %H:%M", |                                         "%a, %H:%M", | ||||||
|                                         localtime( |                                         localtime( | ||||||
| @@ -472,7 +472,7 @@ sub _ErrorHandling($$) { | |||||||
|     my ( $self, $err ) = @_; |     my ( $self, $err ) = @_; | ||||||
|  |  | ||||||
|     $self->{cached}->{current_date_time} = |     $self->{cached}->{current_date_time} = | ||||||
|       encode_utf8(strftime( "%a, %e %b %Y %H:%M", localtime( $self->{fetchTime} ) )), |       strftimeWrapper( "%a, %e %b %Y %H:%M", localtime( $self->{fetchTime} ) ), | ||||||
|       $self->{cached}->{status} = $err; |       $self->{cached}->{status} = $err; | ||||||
|     $self->{cached}->{validity} = 'stale'; |     $self->{cached}->{validity} = 'stale'; | ||||||
| } | } | ||||||
| @@ -493,6 +493,25 @@ sub _CreateForecastRef($) { | |||||||
|     return $forecastRef; |     return $forecastRef; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | sub strftimeWrapper(@) { | ||||||
|  |     my $string = POSIX::strftime(@_); | ||||||
|  |  | ||||||
|  |     $string =~ s/\xe4/ä/g; | ||||||
|  |     $string =~ s/\xc4/Ä/g; | ||||||
|  |     $string =~ s/\xf6/ö/g; | ||||||
|  |     $string =~ s/\xd6/Ö/g; | ||||||
|  |     $string =~ s/\xfc/ü/g; | ||||||
|  |     $string =~ s/\xdc/Ü/g; | ||||||
|  |     $string =~ s/\xdf/ß/g; | ||||||
|  |     $string =~ s/\xdf/ß/g; | ||||||
|  |     $string =~ s/\xe1/á/g; | ||||||
|  |     $string =~ s/\xe9/é/g; | ||||||
|  |     $string =~ s/\xc1/Á/g; | ||||||
|  |     $string =~ s/\xc9/É/g; | ||||||
|  |  | ||||||
|  |     return $string; | ||||||
|  | } | ||||||
|  |  | ||||||
| ############################################################################## | ############################################################################## | ||||||
|  |  | ||||||
| 1; | 1; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user