From 90366352e68daa00a4915decc42bdd93c3372ce4 Mon Sep 17 00:00:00 2001 From: fhemzap <> Date: Sun, 4 Oct 2015 11:03:48 +0000 Subject: [PATCH] HMCCUDEV: Added variable set commands and readony devices git-svn-id: https://svn.fhem.de/fhem/trunk@9364 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/HMCCU/88_HMCCUDEV.pm | 69 ++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/fhem/contrib/HMCCU/88_HMCCUDEV.pm b/fhem/contrib/HMCCU/88_HMCCUDEV.pm index ecbdab161..02935f68e 100644 --- a/fhem/contrib/HMCCU/88_HMCCUDEV.pm +++ b/fhem/contrib/HMCCU/88_HMCCUDEV.pm @@ -10,10 +10,11 @@ # ################################################################ # -# define HMCCUDEV +# define HMCCUDEV [ { readonly | } ] # # set datapoint . -# set devstate +# set devstate +# set # # get datapoint . # @@ -72,6 +73,14 @@ sub HMCCUDEV_Define ($$) # Keep name of CCU device $hash->{ccudev} = $a[2]; + # Set commands / values + if (defined ($a[3]) && $a[3] eq 'readonly') { + $hash->{statevals} = $a[3]; + } + else { + $hash->{statevals} = 'devstate'; + } + # Inform HMCCU device about client device Log 1, "HMCCUDEV: Assigning IO Port"; AssignIoPort ($hash); @@ -89,10 +98,19 @@ sub HMCCUDEV_Attr ($@) { my ($cmd, $name, $attrname, $attrval) = @_; - if (defined ($attrval)) { - if ($cmd eq "set" && $attrname eq "IODev") { + if (defined ($attrval) && $cmd eq "set") { + if ($attrname eq "IODev") { $defs{$name}{IODev} = $defs{$attrval}; } + elsif ($attrname eq "stateval") { + $defs{$name}{statevals} = "devstate"; + my @states = split /,/,$attrval; + foreach my $st (@states) { + my @statesubs = split /:/,$st; + next if (@statesubs != 2); + $defs{$name}{statevals} .= '|'.$statesubs[0]; + } + } } return undef; @@ -143,11 +161,13 @@ sub HMCCUDEV_Set ($@) return undef; } - elsif ($opt eq 'devstate' || $opt eq 'on' || $opt eq 'off') { - my $objvalue = ($opt eq 'on' || $opt eq 'off') ? $opt : join ('%20', @a); + elsif ($opt =~ /($hash->{statevals})/) { + my $cmd = $1; + my $objvalue = ($cmd ne 'devstate') ? $cmd : join ('%20', @a); if ($statechannel eq '') { - return HMCCUDEV_SetError ($hash, "No STATE channel specified"); + return undef; +# return HMCCUDEV_SetError ($hash, "No STATE channel specified"); } if (!defined ($objvalue)) { return HMCCUDEV_SetError ($hash, "Usage: set devstate "); @@ -162,21 +182,17 @@ sub HMCCUDEV_Set ($@) return undef; } else { - my $retmsg = "HMCCUDEV: Unknown argument $opt, choose one of datapoint on:noArg off:noArg"; + my $retmsg = "HMCCUDEV: Unknown argument $opt, choose one of datapoint devstate"; + return undef if ($hash->{statevals} eq 'readonly'); + if ($stateval ne '') { - my @valpairs = split /,/, $stateval; - my $sep = " devstate:"; - foreach my $vp (@valpairs) { - my @sv = split /:/, $vp; - if (@sv == 2) { - $retmsg .= $sep . $sv[0]; - $sep = "," if ($sep ne ','); - } + my @cmdlist = split /\|/,$hash->{statevals}; + shift @cmdlist; + $retmsg .= ':'.join(',',@cmdlist); + foreach my $sv (@cmdlist) { + $retmsg .= ' '.$sv.':noArg'; } } - else { - $retmsg .= " devstate"; - } return $retmsg; } @@ -247,11 +263,14 @@ sub HMCCUDEV_SetError ($$) Define

    - define <name> HMCCUDEV <CCU_Device> + define <name> HMCCUDEV <CCU_Device> [readonly]

    - Example: + If readonly parameter is specified no set command will be available.
    - define window_living HMCCUDEV WIN-LIV-1 + Examples: +
    + define window_living HMCCUDEV WIN-LIV-1 readonly + define temp_control HMCCUDEV TEMP-CONTROL

    CCU_Device - Name of device in CCU without channel or datapoint.
    @@ -270,10 +289,10 @@ sub HMCCUDEV_SetError ($$) Example:
    set light_entrance devstate on
    -
  • set <Name> { on | off } +
  • set <Name> <StateValue>
    - Set state of a CCU device channel is set to 'on' or 'off'. Channel must - be defined as attribute statechannel. State values 'on' and 'off' can + State of a CCU device channel is set to state value. Channel must + be defined as attribute statechannel. State values can be replaced by setting attribute stateval.

  • set <Name> datapoint <channel.datapoint> <Value>