From ca90c844b5fc31f692f934dcb136921ba915b4c1 Mon Sep 17 00:00:00 2001 From: risiko79 <> Date: Mon, 27 Jul 2015 18:12:20 +0000 Subject: [PATCH] pilight_xyz: send raw code, setExtensions git-svn-id: https://svn.fhem.de/fhem/trunk@8994 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 + fhem/FHEM/10_pilight_ctrl.pm | 15 ++-- fhem/FHEM/30_pilight_dimmer.pm | 52 ++++++----- fhem/FHEM/30_pilight_raw.pm | 157 +++++++++++++++++++++++++++++++++ fhem/FHEM/30_pilight_switch.pm | 32 ++++--- fhem/MAINTAINER.txt | 1 + 6 files changed, 222 insertions(+), 38 deletions(-) create mode 100644 fhem/FHEM/30_pilight_raw.pm diff --git a/fhem/CHANGED b/fhem/CHANGED index 2dea2a686..1ae1dad3e 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # 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: 30_pilight_dimmer.pm: SetExtensions (on-for-timer, etc.) + - feature: 30_pilight_switch.pm: SetExtensions (on-for-timer, etc.) + - feature: 30_pilight_raw.pm: send raw codes to pilight - feature: 95_Dashboard: added new attribute dashboard_tabXdevices which supports devspec definitions for shown dashboard groups. Storage of current opened tab and restore when opening dashboard. diff --git a/fhem/FHEM/10_pilight_ctrl.pm b/fhem/FHEM/10_pilight_ctrl.pm index 699ef9581..40775fc6d 100644 --- a/fhem/FHEM/10_pilight_ctrl.pm +++ b/fhem/FHEM/10_pilight_ctrl.pm @@ -1,5 +1,5 @@ ############################################## -# $Id: 10_pilight_ctrl.pm 1.08 2015-06-23 Risiko $ +# $Id: 10_pilight_ctrl.pm 1.09 2015-07-21 Risiko $ # # Usage # @@ -33,6 +33,7 @@ # V 1.07 2015-06-23 - FIX: reading state always contains a valid value, checking reading state removed # V 1.08 2015-06-23 - FIX: clear send queue by reset # V 1.08 2015-06-23 - NEW: attribute SendTimeout for abort sending command non blocking +# V 1.09 2015-07-21 - NEW: support submodule pilight_raw to send raw codes ############################################## package main; @@ -54,7 +55,8 @@ sub pilight_ctrl_Reset($); my %sets = ( "reset:noArg" => "", "disconnect:noArg" => ""); my %matchList = ( "1:pilight_switch" => "^PISWITCH", "2:pilight_dimmer" => "^PISWITCH|^PIDIMMER|^PISCREEN", - "3:pilight_temp" => "^PITEMP") ; + "3:pilight_temp" => "^PITEMP", + "4:pilight_raw" => "^PIRAW") ; my @idList = ("id","systemcode","gpio"); my @unitList = ("unit","unitcode","programcode"); @@ -80,7 +82,7 @@ sub pilight_ctrl_Initialize($) $hash->{StateFn} = "pilight_ctrl_State"; $hash->{AttrList}= "ignoreProtocol brands ContactAsSwitch SendTimeout ".$readingFnAttributes; - $hash->{Clients} = ":pilight_switch:pilight_dimmer:pilight_temp:"; + $hash->{Clients} = ":pilight_switch:pilight_dimmer:pilight_temp:pilight_raw:"; #$hash->{MatchList} = \%matchList; #only for autocreate } @@ -387,8 +389,8 @@ sub pilight_ctrl_Write($@) my $id = $defs{$cName}->{ID}; my $unit = $defs{$cName}->{UNIT}; - $id = "\"".$id."\"" if (!isdigit($id)); - $unit = "\"".$unit."\"" if (!isdigit($unit)); + $id = "\"".$id."\"" if (defined($id) && !isdigit($id)); + $unit = "\"".$unit."\"" if (defined($unit) && !isdigit($unit)); my $code; switch($cType){ @@ -418,6 +420,9 @@ sub pilight_ctrl_Write($@) $code .= ",\"dimlevel\":$args[0]" if (defined($args[0])); $code .= "}"; } + case m/raw/ { + $code = "{\"protocol\":[\"$proto\"],\"code\":\"$state\"}"; + } else {Log3 $me, 3, "$me(Write): unsupported client ($cName) -> $cType"; return;} } diff --git a/fhem/FHEM/30_pilight_dimmer.pm b/fhem/FHEM/30_pilight_dimmer.pm index c4ad65baf..c171c0d01 100644 --- a/fhem/FHEM/30_pilight_dimmer.pm +++ b/fhem/FHEM/30_pilight_dimmer.pm @@ -1,5 +1,5 @@ ############################################## -# $Id: 30_pilight_dimmer.pm 0.54 2015-05-30 Risiko $ +# $Id: 30_pilight_dimmer.pm 0.55 2015-07-27 Risiko $ # # Usage # @@ -14,6 +14,7 @@ # V 0.52 2015-05-25 - CHG: attributes dimlevel_on, dimlevel_off # V 0.53 2015-05-30 - FIX: set dimlevel 0 # V 0.54 2015-05-30 - FIX: StateFn +# V 0.55 2015-07-27 - NEW: SetExtensions on-for-timer ############################################## package main; @@ -24,6 +25,8 @@ use Time::HiRes qw(gettimeofday); use JSON; use Switch; #libswitch-perl +use SetExtensions; + sub pilight_dimmer_Initialize($) { my ($hash) = @_; @@ -179,33 +182,37 @@ sub pilight_dimmer_ConvDimToDev($$) ##################################### sub pilight_dimmer_Set($$) { - my ($hash, @a) = @_; - my $me = shift @a; - - return "no set value specified" if(int(@a) < 1); + my ($hash, $me, $cmd, @a) = @_; + + return "no set value specified" unless defined($cmd); + my $dimlevel_max_dev = AttrVal($me, "dimlevel_max_device",15); my $dimlevel_step = AttrVal($me, "dimlevel_step",1); my $dimlevel_max = AttrVal($me, "dimlevel_max",$dimlevel_max_dev); - my $canSet = "on:noArg off:noArg"; - $canSet .= " up:noArg down:noArg" if ($hash->{helper}{ISSCREEN}); + my %sets = ("on:noArg"=>0, "off:noArg"=>0); + $sets{"dimlevel:slider,0,$dimlevel_step,$dimlevel_max"} = 1; - return "Unknown argument ?, choose one of $canSet dimlevel:slider,0,$dimlevel_step,$dimlevel_max" if($a[0] eq "?"); + $sets{"up:noArg"} = 0 if ($hash->{helper}{ISSCREEN}); + $sets{"down:noArg"} = 0 if ($hash->{helper}{ISSCREEN}); + + my @match = grep( $_ =~ /^$cmd($|:)/, keys %sets ); + return SetExtensions($hash, join(" ", keys %sets), $me, $cmd, @a) unless @match == 1; + return "$cmd expects $sets{$match[0]} parameters" unless (@a eq $sets{$match[0]}); - my $set = $a[0]; my $dimlevel = undef; my $currlevel = ReadingsVal($me,"dimlevel",0); - if ($set =~ m/up|down/ and !$hash->{helper}{ISSCREEN}) { + if ($cmd =~ m/up|down/ and !$hash->{helper}{ISSCREEN}) { Log3 $me, 1, "$me(Set): up|down not supported"; return undef; } if ($hash->{helper}{OWN_DIM} == 1) { - switch($set) { + switch($cmd) { case "dimlevel" { - $dimlevel = pilight_dimmer_ConvDimToDev($me,$a[1]); - $set = "on"; + $dimlevel = pilight_dimmer_ConvDimToDev($me,$a[0]); + $cmd = "on"; } case "on" { my $dimlevel_on = AttrVal($me, "dimlevel_on",$currlevel); @@ -214,19 +221,19 @@ sub pilight_dimmer_Set($$) } } } else { # device without dimlevel support - switch($set) { + switch($cmd) { case "dimlevel" { - my $newlevel = $a[1]; + my $newlevel = $a[0]; my $cnt = int(($newlevel - $currlevel) / $dimlevel_step); return undef if ($cnt==0); - $set = "up" if ($cnt>0); - $set = "down" if ($cnt<0); + $cmd = "up" if ($cnt>0); + $cmd = "down" if ($cnt<0); $cnt = abs($cnt) - 1; # correction for loop -1 if ($newlevel == 0) { - $set = "off"; + $cmd = "off"; $cnt=0; #break for loop my $dimlevel_off = AttrVal($me, "dimlevel_off",$newlevel); readingsSingleUpdate($hash,"dimlevel",$dimlevel_off,1); @@ -235,7 +242,7 @@ sub pilight_dimmer_Set($$) Log3 $me, 5, "$me(Set): cnt $cnt"; for (my $i=0; $i < $cnt; $i++) { - pilight_dimmer_Write($hash,$set,undef); + pilight_dimmer_Write($hash,$cmd,undef); } } case "on" { @@ -257,9 +264,9 @@ sub pilight_dimmer_Set($$) } } - delete $hash->{helper}{DEV_DIMLEVEL} if ($set eq "off"); + delete $hash->{helper}{DEV_DIMLEVEL} if ($cmd eq "off"); - pilight_dimmer_Write($hash,$set,$dimlevel); + pilight_dimmer_Write($hash,$cmd,$dimlevel); #keinen Trigger bei Set auslösen #Aktualisierung erfolgt in Parse my $skipTrigger = 1; @@ -329,6 +336,9 @@ sub pilight_dimmer_State($$$$)
define <name> pilight_raw
+ Set
+Readings
+