From 2e96d6afd6748a2d4e8b8913b4cf83830c7d08ba Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Wed, 19 Jun 2019 19:01:18 +0000 Subject: [PATCH] 31HUEDevice: added configList attribute added optional setsensor|configsensor param to set json git-svn-id: https://svn.fhem.de/fhem/trunk@19652 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/31_HUEDevice.pm | 51 +++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 126f48dfc..52e8852bf 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - feature: 31HUEDevice: added configList attribute + added optional setsensor|configsensor param to set json - bugfix: 73_AMADCommBridge: fix $version bug - update: 95_Astro: v2.0.0 device attributes for language, timezone and locale settings diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index a64adb62d..8863fdcad 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -178,6 +178,7 @@ sub HUEDevice_Initialize($) "transitiontime ". "model:".join(",", sort map { $_ =~ s/ /#/g ;$_} keys %hueModels)." ". "setList:textField-long ". + "configList:textField-long ". "subType:extcolordimmer,colordimmer,ctdimmer,dimmer,switch ". $readingFnAttributes; @@ -701,7 +702,12 @@ HUEDevice_Set($@) return undef; } elsif( $cmd eq 'json' ) { - return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, @args ); + return "usage: json [setsensor|configsensor] " if( !@args ); + my $type = 'setsensor'; + if( $args[0] eq 'setsensor' || $args[0] eq 'configsensor' ) { + $type = shift @args; + } + return HUEBridge_Set( $shash, $shash->{NAME}, $type, $id, @args ); return undef; @@ -722,6 +728,24 @@ HUEDevice_Set($@) } } + + } elsif( my @match = grep { $cmd eq $_ } keys %{($hash->{helper}{configList}{cmds}?$hash->{helper}{configList}{cmds}:{})} ) { + return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $hash->{helper}{configList}{cmds}{$match[0]} ); + + } elsif( my $entries = $hash->{helper}{configList}{regex} ) { + foreach my $entry (@{$entries}) { + if( join(' ', @aa) =~ /$entry->{regex}/ ) { + my $VALUE1 = $1; + my $VALUE2 = $2; + my $VALUE3 = $3; + my $json = $entry->{json}; + $json =~ s/\$1/$VALUE1/; + $json =~ s/\$2/$VALUE2/; + $json =~ s/\$3/$VALUE3/; + return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $json ); + + } + } } my $list = 'statusRequest:noArg'; @@ -734,6 +758,14 @@ HUEDevice_Set($@) $list .= (split( ' ', $entry->{regex} ))[0]; } } + $list .= ' '. join( ':noArg ', keys %{$hash->{helper}{configList}{cmds}} ) if( $hash->{helper}{configList}{cmds} ); + $list .= ':noArg' if( $hash->{helper}{configList}{cmds} ); + if( my $entries = $hash->{helper}{configList}{regex} ) { + foreach my $entry (@{$entries}) { + $list .= ' '; + $list .= (split( ' ', $entry->{regex} ))[0]; + } + } return SetExtensions($hash, $list, $name, @aa); } @@ -1584,20 +1616,20 @@ HUEDevice_Attr($$$;$) { my ($cmd, $name, $attrName, $attrVal) = @_; - if( $attrName eq "setList" ) { + if( $attrName eq 'setList' || $attrName eq 'configList' ) { my $hash = $defs{$name}; - delete $hash->{helper}{setList}; + delete $hash->{helper}{$attrName}; return "$name is not a sensor device" if( $hash->{helper}->{devtype} ne 'S' ); - return "$name is not a CLIP sensor device" if( $hash->{type} && $hash->{type} !~ m/^CLIP/ ); + #return "$name is not a CLIP sensor device" if( $hash->{type} && $hash->{type} !~ m/^CLIP/ ); if( $cmd eq "set" && $attrVal ) { foreach my $line ( split( "\n", $attrVal ) ) { my($cmd,$json) = split( ":", $line,2 ); if( $cmd =~ m'^/(.*)/$' ) { my $regex = $1; - $hash->{helper}{setList}{'regex'} = [] if( !$hash->{helper}{setList}{':regex'} ); - push @{$hash->{helper}{setList}{'regex'}}, { regex => $regex, json => $json }; + $hash->{helper}{$attrName}{'regex'} = [] if( !$hash->{helper}{$attrName}{'regex'} ); + push @{$hash->{helper}{$attrName}{'regex'}}, { regex => $regex, json => $json }; } else { - $hash->{helper}{setList}{cmds}{$cmd} = $json; + $hash->{helper}{$attrName}{cmds}{$cmd} = $json; } } } @@ -1724,6 +1756,8 @@ HUEDevice_Attr($$$;$) The lights are given as a comma sparated list of fhem device names or bridge light numbers.
  • rename <new name>
    Renames the device in the bridge and changes the fhem alias.
  • +
  • json [setsensor|configsensor] <json>
    + send <json> to the state or config endpoints for this device.

  • set extensions are supported.

  • @@ -1764,6 +1798,9 @@ HUEDevice_Attr($$$;$) The list of know set commands for sensor type devices. one command per line, eg.:
    attr mySensor setList present:{<json>}\
    absent:{<json>}
    +
  • configList
    + The list of know config commands for sensor type devices. one command per line, eg.:
    +mode:{<json>}
  • subType
    extcolordimmer -> device has rgb and color temperatur control
    colordimmer -> device has rgb controll