FHEM Forum

FHEM => Sonstiges => Thema gestartet von: Ralli am 03 Februar 2016, 17:51:09

Titel: Perl-Frage für weitere Modifikation von 60_HMRPC
Beitrag von: Ralli am 03 Februar 2016, 17:51:09
Hallo zusammen,

ich brauche mal Perl-Nachhilfe  >:(.

Ich möchte meine 60_HMRPC.pl weiter modifizieren. Ziel ist es, eine Rückgabe aus der RPC-Schnittstelle, die wie folgt aussieht (Inhalt von $res), weiter zu verarbeiten:


0  'ADDRESS' => 'LEQ0383781', 'CONNECTED' => 1, 'DEFAULT' => 0, 'DESCRIPTION' => '', 'DUTY_CYCLE' => 5, 'FIRMWARE_VERSION' => 964, 'TYPE' => 'Lan Interface'
1  'ADDRESS' => 'LEQ1198108', 'CONNECTED' => 1, 'DEFAULT' => 0, 'DESCRIPTION' => '', 'DUTY_CYCLE' => 0, 'FIRMWARE_VERSION' => 967, 'TYPE' => 'Lan Interface'
2  'ADDRESS' => 'MEQ0461046', 'CONNECTED' => 1, 'DEFAULT' => 0, 'DESCRIPTION' => '', 'DUTY_CYCLE' => 0, 'FIRMWARE_VERSION' => '1.4.1', 'TYPE' => 'HMLGW2'
3  'ADDRESS' => 'MEQ0462840', 'CONNECTED' => 1, 'DEFAULT' => 1, 'DESCRIPTION' => 'CCU2-Coprocessor', 'DUTY_CYCLE' => 0, 'FIRMWARE_VERSION' => '1.4.1', 'TYPE' => 'CCU2'


Und zwar so, dass ich darauf die Homematic-Adressen nehme, das dazu gehörige Device suche und dann mit entsprechenden Readings fülle. Ich komme aber irgendwie mit Scalar, Array, Hash usw. nicht klar. Grundlagenproblem. Kann mir bei dem u.a. Codefragment mal ein wenig aushelfen?


                my $ret=$hash->{client}->simple_request(@a);
                # We convert using Dumpvalue. As this only prints, we need
                # to temporarily redirect STDOUT
                my $res="";
                open(my $temp,"+>",\$res);
                my $oldout=select($temp);
                $dumper->dumpValue($ret);
                close(select($oldout));
### ab hier geht's los
                if ($ret) {
                        my %resultlist = split /\n/,$res;  ### nur für das Logging
                        foreach (%resultlist) {
                                Log 4,"HMRPC $ccu: $cmd $rrq = $_";
                        }
                        if ($rrq eq "listBidcosInterfaces") {
                                my @readingslist=("CONNECTED","DEFAULT","DESCRIPTION","DUTY_CYCLE","FIRMWARE_VERSION","TYPE");
                                my $device;
                                my $devhash;
                                foreach ($ret) {
                                        $device=\$_;
                                        Log 3,"HMRPC $ccu $cmd $rrq device = $device->{ADDRESS}";
                                        $devhash=$modules{HMDEV}{defptr}{$device->{ADDRESS}};
                                        if ($devhash) {
                                                Log 3,"HMRPC $ccu: $cmd $rrq devhash = $devhash";
                                                readingsBeginUpdate($devhash);
                                                foreach (@readingslist) {
                                                        Log 3, "HMRPC $ccu: req listBidcosInterfaces: $device->{ADDRESS} $_ $device->{$_}";
                                                        readingsBulkUpdate($devhash, $_, $device->{$_});
                                                }
                                                readingsEndUpdate($devhash, 1);
                                        }
                                }
                        # return undef;
                        }
                }
                return $res;