From 0ffabfccf9a348a673d44bb244a77744b1434e8e Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sun, 30 Aug 2015 16:45:18 +0000 Subject: [PATCH] 10_ZWave.pm: add configRequestAll and associationRequestAll git-svn-id: https://svn.fhem.de/fhem/trunk@9176 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_ZWDongle.pm | 3 +- fhem/FHEM/10_ZWave.pm | 78 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/fhem/FHEM/00_ZWDongle.pm b/fhem/FHEM/00_ZWDongle.pm index a44b96c32..0928b9230 100755 --- a/fhem/FHEM/00_ZWDongle.pm +++ b/fhem/FHEM/00_ZWDongle.pm @@ -644,6 +644,7 @@ ZWDongle_Read($@) $hash->{SendRetries}++; $hash->{MaxSendRetries}++ if($hash->{MaxSendRetries}<7); $data = substr($data, 2); + select(undef, undef, undef, 0.1); # configRequestAll: 0.05 is not enough next; } @@ -704,10 +705,10 @@ sub ZWDongle_ReadAnswer($$$) { my ($hash, $arg, $regexp) = @_; + Log3 $hash, 4, "ZWDongle_ReadAnswer arg:$arg regexp:".($regexp ? $regexp:""); return ("No FD (dummy device?)", undef) if(!$hash || ($^O !~ /Win/ && !defined($hash->{FD}))); my $to = ($hash->{RA_Timeout} ? $hash->{RA_Timeout} : 3); - Log3 $hash, 4, "ZWDongle_ReadAnswer arg:$arg regexp:".($regexp ? $regexp:""); for(;;) { diff --git a/fhem/FHEM/10_ZWave.pm b/fhem/FHEM/10_ZWave.pm index 7b6917330..3d8240ec1 100755 --- a/fhem/FHEM/10_ZWave.pm +++ b/fhem/FHEM/10_ZWave.pm @@ -238,7 +238,8 @@ my %zwave_class = ( set => { configDefault=>"04%02x80", configByte => "04%02x01%02x", configWord => "04%02x02%04x", - configLong => "04%02x04%08x" }, + configLong => "04%02x04%08x", + configRequestAll => 'ZWave_configRequestAll($hash)' }, get => { config => "05%02x" }, parse => { "^..70..(..)(..)(.*)" => 'ZWave_configParse($hash,$1,$2,$3)'} }, ALARM => { id => '71', @@ -306,9 +307,13 @@ my %zwave_class = ( } }, ASSOCIATION => { id => '85', set => { associationAdd => "01%02x%02x*", - associationDel => "04%02x%02x*" }, - get => { association => "02%02x", }, - parse => { "..8503(..)(..)..(.*)" => '"assocGroup_$1:Max $2 Nodes $3"'}, + associationDel => "04%02x%02x*", + associationRequest => "02%02x", + associationRequestAll => 'ZWave_associationRequest($hash,"")' }, + get => { association => "02%02x", + associationGroups => "05" }, + parse => { "..8503(..)(..)..(.*)" => '"assocGroup_$1:Max $2 Nodes $3"', + "..8506(..)" => '"assocGroups:".hex($1)' }, init => { ORDER=>10, CMD=> '"set $NAME associationAdd 1 $CTRLID"' } }, VERSION => { id => '86', set => { versionClassRequest => 'ZWave_versionClassRequest($hash,"%s")'}, @@ -389,6 +394,7 @@ my %zwave_cmdArgs = ( } ); +my %zwave_parseHook; # nodeId:regexp => fn, used by assocRequest my %zwave_modelConfig; my %zwave_modelIdAlias = ( "010f-0301-1001" => "Fibaro_FGRM222", "0115-0100-0102" => "ZME_KFOB" ); @@ -623,7 +629,7 @@ ZWave_Cmd($$@) } } - if($cmd =~ m/^config/) { + if($cmd =~ m/^config/ && $cmd ne "configRequestAll") { my ($err, $cmd) = ZWave_configCheckParam($hash, $type, $cmd, $cmdFmt, @a); return $err if($err); $cmdFmt = $cmd; @@ -632,6 +638,7 @@ ZWave_Cmd($$@) my ($err, $ncmd) = eval($cmdFmt) if($cmdFmt !~ m/^\d/); return $err if($err); $cmdFmt = $ncmd if(defined($ncmd)); + return "" if($ncmd && $ncmd eq "EMPTY"); # e.g. configRequestAll } Log3 $name, 2, "ZWave $type $name $cmd ".join(" ", @a); @@ -1335,7 +1342,9 @@ ZWave_configCheckParam($$$$@) my $h = $mc->{config}{$cmd}; return ("", sprintf($fmt, @arg)) if(!$h); - return ("", sprintf("05%02x", $h->{index})) if($type eq "get"); + # Support "set XX configYY request" for configRequestAll + return ("", sprintf("05%02x", $h->{index})) + if($type eq "get" || ($type eq "set" && $arg[0] eq "request")); my $t = $h->{type}; if($t eq "list") { @@ -1556,6 +1565,42 @@ ZWave_configParse($$$$) return "config_$cmdId:$val"; } +sub +ZWave_configRequestAll($) +{ + my ($hash) = @_; + my $mc = ZWave_configGetHash($hash); + return ("configRequestAll: no model specific configs found", undef) + if(!$mc || !$mc->{config}); + #use Data::Dumper; + #Log 1, Dumper $mc; + foreach my $c (sort keys %{$mc->{config}}) { + my $r = ZWave_Cmd("set", $hash, $hash->{NAME}, $c, "request"); + Log 1, "$c: $r" if($r); + } + return ("","EMPTY"); +} + +sub +ZWave_associationRequest($$) +{ + my ($hash, $data) = @_; + + if(!$data) { # called by the user + $zwave_parseHook{"$hash->{id}:..85"} = \&ZWave_associationRequest; + return("", "05"); + } + + my $nGrp = ($data =~ m/..8506(..)/ ? $1 : + ReadingsVal($hash->{NAME}, "assocGroups", 0)); + my $grp = 0; + $grp = $1 if($data =~ m/..8503(..)/); + return if($grp >= $nGrp); + $zwave_parseHook{"$hash->{id}:..85"} = \&ZWave_associationRequest; + ZWave_Cmd("set", $hash, $hash->{NAME}, "associationRequest", $grp+1); +} + + my %zwave_roleType = ( "00"=>"CentralStaticController", "01"=>"SubStaticController", @@ -1946,6 +1991,15 @@ ZWave_Parse($$@) $matched++; } } + + foreach my $h (keys %zwave_parseHook) { + if("$id:$arg" =~ m/$h/) { + my $fn = $zwave_parseHook{$h}; + delete $zwave_parseHook{$h}; + $fn->($hash, $arg); + } + } + push @event, "UNPARSED:$className $arg" if(!$matched); } @@ -2086,6 +2140,10 @@ s2Hex($) controllerNodeId"
  • associationDel groupId nodeId ...
    Remove the specified list of nodeIds from the assotion group groupId.
  • +
  • associationRequest groupId
    + corresponds to "get association", used by associationRequestAll
  • +
  • associationRequestAll
    + request association info for all possibe groups.


  • Class BASIC
  • basicValue value
    @@ -2145,6 +2203,10 @@ s2Hex($)
  • configDefault cfgAddress
    Reset the configuration parameter for the cfgAddress parameter to its default value. See the device documentation to determine this value.
  • +
  • configRequestAll
    + If the model of a device is set, and configuration descriptions are + available from the database for this device, then request the value of all + known configuration parameters.


  • Class INDICATOR
  • indicatorOn
    @@ -2315,6 +2377,9 @@ s2Hex($) return the list of nodeIds in the association group groupId in the form:
    assocGroup_X:Max Y, Nodes id,id...
  • +
  • associationGroups
    + return the number of association groups
    +

  • Class BASIC
  • basicStatus
    @@ -2553,6 +2618,7 @@ s2Hex($)

    Class ASSOCIATION
  • assocGroup_X:Max Y Nodes A,B,...
  • +
  • assocGroups:X


  • Class BASIC
  • basicReport:XY