From b8507e5b16d5af5b4cad84aa5a2acf8ca933851f Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Wed, 20 Dec 2017 05:41:22 +0000 Subject: [PATCH] 31_PLAYBULB: support for new devicetype, GardenaSmart bugfixes, UWZ replace Iconv git-svn-id: https://svn.fhem.de/fhem/trunk@15650 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 ++ fhem/FHEM/31_PLAYBULB.pm | 5 +-- fhem/FHEM/73_GardenaSmartBridge.pm | 2 +- fhem/FHEM/74_GardenaSmartDevice.pm | 52 ++++++++++++------------------ fhem/FHEM/77_UWZ.pm | 21 ++++++------ 5 files changed, 39 insertions(+), 44 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index cdd4ff82f..8c5c191fd 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 73_GardenaSmart: v0.4.0 bugfixes + - feature: 31_PLAYBULB: v1.4.0 support for Sphere Model BTL301w + - change: 77_UWZ: v2.0.0, replace Iconv-Converter with perl encode() - change: 93_DbLog: V3.4.0, importCacheFile, addCacheLine use char filter (switch it on with attribute useCharfilter) - feature: 98_GOOGLECAST: support displaying websites on Chromecast diff --git a/fhem/FHEM/31_PLAYBULB.pm b/fhem/FHEM/31_PLAYBULB.pm index 3a4e96d69..cdcfc7b16 100644 --- a/fhem/FHEM/31_PLAYBULB.pm +++ b/fhem/FHEM/31_PLAYBULB.pm @@ -41,7 +41,7 @@ use Blocking; use SetExtensions; -my $version = "1.2.8"; +my $version = "1.4.0"; @@ -56,6 +56,7 @@ my %playbulbModels = ( BTL400M_v18 => {'aColor' => '0x23' ,'aEffect' => '0x21' ,'aBattery' => '0x2e' ,'aDevicename' => '0x7'}, # Garden BTL400M_v37 => {'aColor' => '0x1b' ,'aEffect' => '0x19' ,'aBattery' => '0x24' ,'aDevicename' => '0x7'}, # Garden neue Version BTL100C_v10 => {'aColor' => '0x1b' ,'aEffect' => '0x19' ,'aBattery' => 'none' ,'aDevicename' => 'none'}, # Color LED + BTL301W => {'aColor' => '0x29' ,'aEffect' => '0x27' ,'aBattery' => '0x34' ,'aDevicename' => '0x3'}, # Sphere Model BTL 301 W ); my %effects = ( @@ -107,7 +108,7 @@ sub PLAYBULB_Initialize($) { $hash->{DefFn} = "PLAYBULB_Define"; $hash->{UndefFn} = "PLAYBULB_Undef"; $hash->{AttrFn} = "PLAYBULB_Attr"; - $hash->{AttrList} = "model:BTL300_v5,BTL300_v6,BTL201_v2,BTL201M_V16,BTL505_v1,BTL400M_v18,BTL400M_v37,BTL100C_v10,BTL305_v14 ". + $hash->{AttrList} = "model:BTL300_v5,BTL300_v6,BTL201_v2,BTL201M_V16,BTL505_v1,BTL400M_v18,BTL400M_v37,BTL100C_v10,BTL305_v14,BTL301W ". "sshHost ". $readingFnAttributes; diff --git a/fhem/FHEM/73_GardenaSmartBridge.pm b/fhem/FHEM/73_GardenaSmartBridge.pm index 69e6b3b48..d9844fa75 100644 --- a/fhem/FHEM/73_GardenaSmartBridge.pm +++ b/fhem/FHEM/73_GardenaSmartBridge.pm @@ -68,7 +68,7 @@ eval "use JSON;1" or $missingModul .= "JSON "; eval "use IO::Socket::SSL;1" or $missingModul .= "IO::Socket::SSL "; -my $version = "0.2.8"; +my $version = "0.4.0"; diff --git a/fhem/FHEM/74_GardenaSmartDevice.pm b/fhem/FHEM/74_GardenaSmartDevice.pm index 180b2b1c4..0c54d02b1 100644 --- a/fhem/FHEM/74_GardenaSmartDevice.pm +++ b/fhem/FHEM/74_GardenaSmartDevice.pm @@ -62,13 +62,10 @@ use strict; use warnings; use Time::Local; -use Data::Dumper; #debugging - -# eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Encode "; wird nicht benötigt eval "use JSON;1" or $missingModul .= "JSON "; -my $version = "0.2.3"; +my $version = "0.4.0"; @@ -102,6 +99,7 @@ sub GardenaSmartDevice_Initialize($) { $hash->{AttrFn} = "GardenaSmartDevice_Attr"; $hash->{AttrList} = "readingValueLanguage:de,en ". "model ". + "IODev ". $readingFnAttributes; foreach my $d(sort keys %{$modules{GardenaSmartDevice}{defptr}}) { @@ -115,39 +113,29 @@ sub GardenaSmartDevice_Define($$) { my ( $hash, $def ) = @_; my @a = split( "[ \t]+", $def ); - splice( @a, 1, 1 ); - my $iodev; - my $i = 0; - - foreach my $param ( @a ) { - if( $param =~ m/IODev=([^\s]*)/ ) { - - $iodev = $1; - splice( @a, $i, 3 ); - last; - } - - $i++; - } - - - return "too few parameters: define GardenaSmartDevice " if( @a != 3 ) ; + return "too few parameters: define GardenaSmartDevice " if( @a < 3 ) ; return "Cannot define Gardena Bridge device. Perl modul $missingModul is missing." if ( $missingModul ); - - my ($name,$deviceId,$category) = @a; - - $hash->{DEVICEID} = $deviceId; - $hash->{VERSION} = $version; + + my $name = $a[0]; + my $deviceId = $a[2]; + my $category = $a[3]; + + $hash->{DEVICEID} = $deviceId; + $hash->{VERSION} = $version; + + + + CommandAttr(undef,"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}") if(AttrVal($name,'IODev','none') eq 'none'); + + my $iodev = AttrVal($name,'IODev','none'); + AssignIoPort($hash,$iodev) if( !$hash->{IODev} ); if(defined($hash->{IODev}->{NAME})) { - Log3 $name, 3, "GardenaSmartDevice ($name) - I/O device is " . $hash->{IODev}->{NAME}; - } else { - Log3 $name, 1, "GardenaSmartDevice ($name) - no I/O device"; } @@ -158,6 +146,7 @@ sub GardenaSmartDevice_Define($$) { return "GardenaSmartDevice device $name on GardenaSmartBridge $iodev already defined." if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{NAME} ne $name ); + $attr{$name}{room} = "GardenaSmart" if( not defined( $attr{$name}{room} ) ); $attr{$name}{model} = $category if( not defined( $attr{$name}{model} ) ); @@ -313,9 +302,8 @@ sub GardenaSmartDevice_Parse($$) { } else { - Log3 $name, 3, "GardenaSmartDevice ($name) - autocreate new device " . makeDeviceName($decode_json->{name}) . " with deviceId $decode_json->{id}, model $decode_json->{category} and IODev IODev=$name"; - #return "UNDEFINED " . join('',split("[ \t]+",$decode_json->{name})) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category} IODev=$name"; - return "UNDEFINED " . makeDeviceName($decode_json->{name}) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category} IODev=$name"; + Log3 $name, 3, "GardenaSmartDevice ($name) - autocreate new device " . makeDeviceName($decode_json->{name}) . " with deviceId $decode_json->{id}, model $decode_json->{category}"; + return "UNDEFINED " . makeDeviceName($decode_json->{name}) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category}"; } } } diff --git a/fhem/FHEM/77_UWZ.pm b/fhem/FHEM/77_UWZ.pm index d798e1b78..7b0703fbd 100644 --- a/fhem/FHEM/77_UWZ.pm +++ b/fhem/FHEM/77_UWZ.pm @@ -7,6 +7,7 @@ # Special thanks goes to comitters: # - Marko Oldenburg (leongaultier at gmail dot com) # - Hanjo (Forum) patch for sort by creation +# - cb1 patch Replace Iconv with native perl encode() # # Storm warnings from unwetterzentrale.de # inspired by 59_PROPLANTA.pm @@ -53,7 +54,6 @@ eval "use HTTP::Request;1" or $missingModul .= "HTTP::Request "; eval "use HTML::Parser;1" or $missingModul .= "HTML::Parser "; eval "use JSON;1" or $missingModul .= "JSON "; eval "use Encode::Guess;1" or $missingModul .= "Encode::Guess "; -eval "use Text::Iconv;1" or $missingModul .= "Text::Iconv "; require 'Blocking.pm'; require 'HttpUtils.pm'; @@ -61,7 +61,7 @@ use vars qw($readingFnAttributes); use vars qw(%defs); my $MODUL = "UWZ"; -my $version = "1.8.0"; +my $version = "2.0.0"; @@ -772,7 +772,6 @@ sub UWZ_Run($) { my $response = UWZ_JSONAcquire($hash,$hash->{URL}); UWZ_Log $hash, 5, length($response)." characters captured"; - my $converter = Text::Iconv->new("windows-1252","UTF-8"); my $uwz_warnings = JSON->new->ascii->decode($response); my $enc = guess_encoding($uwz_warnings); @@ -938,10 +937,12 @@ sub UWZ_Run($) { $message .= "Warn_".$i."_levelName|".$single_warning->{'payload'}{'levelName'}."|"; UWZ_Log $hash, 4, "Warn_".$i."_AltitudeMin: ".$enc->decode($single_warning->{'payload'}{'altMin'}); - $message .= "Warn_".$i."_AltitudeMin|".$converter->convert($single_warning->{'payload'}{'altMin'})."|"; + + $message .= "Warn_".$i."_AltitudeMin|".encode("UTF-8", decode("iso-8859-1", $single_warning->{'payload'}{'altMin'}))."|"; UWZ_Log $hash, 4, "Warn_".$i."_AltitudeMax: ".$enc->decode($single_warning->{'payload'}{'altMax'}); - $message .= "Warn_".$i."_AltitudeMax|".$converter->convert($single_warning->{'payload'}{'altMax'})."|"; + + $message .= "Warn_".$i."_AltitudeMax|".encode("UTF-8", decode("iso-8859-1", $single_warning->{'payload'}{'altMax'}))."|"; my $uclang = "EN"; if (AttrVal( $name, 'lang',undef) ) { @@ -955,10 +956,12 @@ sub UWZ_Run($) { } } UWZ_Log $hash, 4, "Warn_".$i."_LongText: ".$enc->decode($single_warning->{'payload'}{'translationsLongText'}{$uclang}); - $message .= "Warn_".$i."_LongText|".$converter->convert($single_warning->{'payload'}{'translationsLongText'}{$uclang})."|"; + + $message .= "Warn_".$i."_LongText|".encode("UTF-8", decode("iso-8859-1", $single_warning->{'payload'}{'translationsLongText'}{$uclang}))."|"; UWZ_Log $hash, 4, "Warn_".$i."_ShortText: ".$enc->decode($single_warning->{'payload'}{'translationsShortText'}{$uclang}); - $message .= "Warn_".$i."_ShortText|".$converter->convert($single_warning->{'payload'}{'translationsShortText'}{$uclang})."|"; + + $message .= "Warn_".$i."_ShortText|".encode("UTF-8", decode("iso-8859-1", $single_warning->{'payload'}{'translationsShortText'}{$uclang}))."|"; ### if (AttrVal( $name, 'localiconbase',undef) ) { @@ -1530,7 +1533,7 @@ sub UWZSearchAreaID($$) { A maximum of 10 thunderstorm warnings will be served. Additional the module provides a few functions to create HTML-Templates which can be used with weblink.
- The following Perl-Modules are used within this module: HTTP::Request, LWP::UserAgent, JSON, Encode::Guess, Text::Iconv und HTML::Parse. + The following Perl-Modules are used within this module: HTTP::Request, LWP::UserAgent, JSON, Encode::Guess und HTML::Parse.

Define
    @@ -1950,7 +1953,7 @@ sub UWZSearchAreaID($$) { Es werden maximal 10 Standortbezogene Unwetterwarnungen zur Verfügung gestellt. Weiterhin verfügt das Modul über HTML-Templates welche als weblink verwendet werden können.
    - Es nutzt die Perl-Module HTTP::Request, LWP::UserAgent, JSON, Encode::Guess, Text::Iconv und HTML::Parse. + Es nutzt die Perl-Module HTTP::Request, LWP::UserAgent, JSON, Encode::Guess und HTML::Parse.

    Define