diff --git a/fhem/CHANGED b/fhem/CHANGED index 4d3a8a8ac..e8d76dfad 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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. + - change: 70_DENON_AVR: model reporting for newer AVRs - change: 57_SSCal: expand composite Event, fix API behavior if entry with 'is_all_day' is at first position - change: 70_DENON_AVR: soundmode related improvements (thx Shasow3561) diff --git a/fhem/FHEM/70_DENON_AVR.pm b/fhem/FHEM/70_DENON_AVR.pm index 668c4679f..62a106cbe 100755 --- a/fhem/FHEM/70_DENON_AVR.pm +++ b/fhem/FHEM/70_DENON_AVR.pm @@ -318,8 +318,8 @@ my $DENON_db = { 'VVD' => 'Vivid', 'STM' => 'Stream', 'CTM' => 'Custom', - 'DAY' => 'Day', - 'NGT' => 'Night', + 'DAY' => 'ISF_Day', + 'NGT' => 'ISF_Night', }, 'PW' => { 'on' => 'ON', @@ -978,7 +978,7 @@ DENON_GetKey($$;$) { } } -sub DENON_AVR_PerformHttpRequest { +sub DENON_AVR_RequestDeviceinfo { my ($hash) = @_; my $name = $hash->{NAME}; @@ -990,13 +990,62 @@ sub DENON_AVR_PerformHttpRequest { hash => $hash, method => "GET", header => "User-Agent: FHEM\r\nAccept: application/xml", - callback => \&DENON_AVR_ParseHttpResponse + callback => \&DENON_AVR_ParseDeviceinfoResponse }; HttpUtils_NonblockingGet($param); } -sub DENON_AVR_ParseHttpResponse { +sub DENON_AVR_ParseDeviceinfoResponse { + my ($param, $err, $data) = @_; + my $hash = $param->{hash}; + my $name = $hash->{NAME}; + my $return; + + if($err ne "") { + Log3 $name, 0, "DENON_AVR ($name) - Error while requesting ".$param->{url}." - $err"; + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, 'httpState', 'ERROR', 0); + readingsBulkUpdate($hash, 'httpError', $err, 0); + readingsEndUpdate($hash, 0); + + DENON_AVR_RequestProductTypeName($hash); + } elsif($data ne "") { + readingsDelete($hash, 'httpState'); + readingsDelete($hash, 'httpError'); + + Log3 $name, 5, "DENON_AVR ($name) - Deviceinfo.xml\n$data"; + my $ref = XMLin($data, KeyAttr => { }, ForceArray => [ ]); + + my $codes = { + '0' => 'Denon', + '1' => 'Marantz' + }; + my $brandCode = $ref->{BrandCode}; + + $hash->{model} = $codes->{$brandCode} . ' ' . $ref->{ModelName}; + } +} + +sub DENON_AVR_RequestProductTypeName { + my ($hash) = @_; + my $name = $hash->{NAME}; + + my $url = "http://$hash->{IP}/ajax/get_config?type=25"; + Log3 $name, 4, "DENON_AVR ($name) - requesting $url"; + my $param = { + url => "$url", + timeout => 5, + hash => $hash, + method => "GET", + header => "User-Agent: FHEM\r\nAccept: application/xml", + callback => \&DENON_AVR_ParseProductTypeName + }; + + HttpUtils_NonblockingGet($param); +} + +sub DENON_AVR_ParseProductTypeName { my ($param, $err, $data) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; @@ -1009,16 +1058,13 @@ sub DENON_AVR_ParseHttpResponse { readingsBulkUpdate($hash, 'httpError', $err, 0); readingsEndUpdate($hash, 0); } elsif($data ne "") { - Log3 $name, 5, "DENON_AVR ($name) - Deviceinfo.xml\n$data"; - my $ref = XMLin($data, KeyAttr => { }, ForceArray => [ ]); + readingsDelete($hash, 'httpState'); + readingsDelete($hash, 'httpError'); - my $codes = { - '0' => 'Denon', - '1' => 'Marantz' - }; - my $brandCode = $ref->{BrandCode}; + my $productTypeName = $data =~ s/|<\/productTypeName>//rg; + Log3 $name, 4, "DENON_AVR ($name) - productTypeName: $productTypeName"; - $hash->{model} = $codes->{$brandCode} . ' ' . $ref->{ModelName}; + $hash->{model} = $productTypeName; } } @@ -1069,7 +1115,7 @@ DENON_AVR_Define($$) return $msg; } - RemoveInternalTimer($hash); + RemoveInternalTimer($hash); DevIo_CloseDev($hash); my $name = $a[0]; @@ -1114,7 +1160,7 @@ DENON_AVR_Define($$) { $hash->{IP} = $a[2]; use XML::Simple qw(:strict); - DENON_AVR_PerformHttpRequest($hash); + DENON_AVR_RequestDeviceinfo($hash); $hash->{DeviceName} = $hash->{DeviceName} . ":23" if ( $hash->{DeviceName} !~ m/^(.+):([0-9]+)$/ );