2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 19:36:02 +00:00

allow slider and dropdown menu widgets as commands

git-svn-id: https://svn.fhem.de/fhem/trunk@4985 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2014-02-18 18:30:54 +00:00
parent 547b80c5fe
commit f616edef23
2 changed files with 88 additions and 30 deletions

View File

@ -1,6 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- SVN - SVN
- feature: readingsGroup: allow FHEMWEB slider and dropdown menus as commands
- feature FB_CALLMONITOR: new attribute "disable" to - feature FB_CALLMONITOR: new attribute "disable" to
disable FB_CALLMONITOR disable FB_CALLMONITOR
- feature: YAMAHA_BD: new attribute "disable" to disable cyclic status - feature: YAMAHA_BD: new attribute "disable" to disable cyclic status

View File

@ -27,6 +27,7 @@ use vars qw($FW_ME);
use vars qw($FW_wname); use vars qw($FW_wname);
use vars qw($FW_subdir); use vars qw($FW_subdir);
use vars qw(%FW_hiddenroom); use vars qw(%FW_hiddenroom);
use vars qw(%FW_visibleDeviceHash);
use vars qw(%FW_webArgs); # all arguments specified in the GET use vars qw(%FW_webArgs); # all arguments specified in the GET
sub readingsGroup_Initialize($) sub readingsGroup_Initialize($)
@ -398,6 +399,7 @@ readingsGroup_2html($)
$txt = FW_makeImage( $icon, $icon, "icon" ); $txt = FW_makeImage( $icon, $icon, "icon" );
$cmd = lookup2($commands,$name,$d,$icon) if( !defined($cmd) ); $cmd = lookup2($commands,$name,$d,$icon) if( !defined($cmd) );
($txt,undef) = readingsGroup_makeLink($txt,undef,$cmd); ($txt,undef) = readingsGroup_makeLink($txt,undef,$cmd);
} elsif( $first || $multi == 1 ) { } elsif( $first || $multi == 1 ) {
@ -414,7 +416,36 @@ readingsGroup_2html($)
$ret .= "<td><div $name_style class=\"dname\">$txt</div></td>"; $ret .= "<td><div $name_style class=\"dname\">$txt</div></td>";
} }
} else {
my $cmd = lookup2($commands,$name,$d,$txt);
if( $cmd =~ m/^(\w.*):(\S.*)?$/ ) {
my $set = $1;
my $values = $2;
if( !$values ) {
my %extPage = ();
my ($allSets, undef, undef) = FW_devState($name, "", \%extPage);
if( $allSets && $allSets =~ m/$set:([^ ]*)/) {
$values = $1;
}
}
my $room = $FW_webArgs{room};
$room = "&detail=$FW_webArgs{detail}" if( $FW_webArgs{"detail"} );
my $htmlTxt;
foreach my $fn (sort keys %{$data{webCmdFn}}) {
no strict "refs";
$htmlTxt = &{$data{webCmdFn}{$fn}}($FW_wname,$name,$room,$set,$values);
use strict "refs";
last if(defined($htmlTxt));
}
$txt = $htmlTxt if( $htmlTxt );
}
} }
my $inform_id = ""; my $inform_id = "";
$inform_id = "informId=\"$d-$name.i$item.item\"" if( $readings ); $inform_id = "informId=\"$d-$name.i$item.item\"" if( $readings );
$ret .= "<td><div $name_style $inform_id>$txt</div></td>"; $ret .= "<td><div $name_style $inform_id>$txt</div></td>";
@ -495,8 +526,40 @@ readingsGroup_2html($)
} }
} }
$cmd = lookup2($commands,$name,$n,$v) if( !$devStateIcon ); my $webCmdFn = 0;
($v,$devStateIcon) = readingsGroup_makeLink($v,$devStateIcon,$cmd); if( !$devStateIcon ) {
$cmd = lookup2($commands,$name,$n,$v) if( !$devStateIcon );
if( $cmd =~ m/^(\w.*):(\S.*)?$/ ) {
my $set = $1;
my $values = $2;
if( !$values ) {
my %extPage = ();
my ($allSets, undef, undef) = FW_devState($name, $room, \%extPage);
if( $allSets && $allSets =~ m/$set:([^ ]*)/) {
$values = $1;
}
}
my $room = $FW_webArgs{room};
$room = "&detail=$FW_webArgs{detail}" if( $FW_webArgs{"detail"} );
my $htmlTxt;
foreach my $fn (sort keys %{$data{webCmdFn}}) {
no strict "refs";
$htmlTxt = &{$data{webCmdFn}{$fn}}($FW_wname,$name,$room,$set,$values);
use strict "refs";
last if(defined($htmlTxt));
}
if( $htmlTxt ) {
$v = $htmlTxt;
$webCmdFn = 1;
}
}
}
($v,$devStateIcon) = readingsGroup_makeLink($v,$devStateIcon,$cmd) if( !$webCmdFn );
if( $first || $multi == 1 ) { if( $first || $multi == 1 ) {
$ret .= sprintf("<tr class=\"%s\">", ($row&1)?"odd":"even"); $ret .= sprintf("<tr class=\"%s\">", ($row&1)?"odd":"even");
@ -529,12 +592,7 @@ readingsGroup_detailFn()
my $hash = $defs{$d}; my $hash = $defs{$d};
if( 1 || $hash->{alwaysTrigger} ) { $hash->{mayBeVisible} = 1;
delete( $hash->{helper}->{myDisplay} );
} else {
Log3 $hash->{NAME}, 5, "opened: $FW_cname";
$hash->{helper}->{myDisplay}->{$FW_cname} = 1;
}
return readingsGroup_2html($d); return readingsGroup_2html($d);
} }
@ -556,29 +614,16 @@ readingsGroup_Notify($$)
return if( AttrVal($name,"disable", 0) > 0 ); return if( AttrVal($name,"disable", 0) > 0 );
if( 1 || $hash->{alwaysTrigger} ) { if( $hash->{alwaysTrigger} ) {
} elsif( !defined($hash->{helper}{myDisplay}) } elsif( !defined($hash->{mayBeVisible}) ) {
|| !%{$hash->{helper}{myDisplay}} ) {
Log3 $name, 5, "$name: not on any display, ignoring notify"; Log3 $name, 5, "$name: not on any display, ignoring notify";
return undef; return undef;
} else { } else {
foreach my $display ( keys %{$hash->{helper}{myDisplay}} ) { if( $FW_visibleDeviceHash{$name} ) {
if( defined($defs{$display}) ) { } else {
my $filter = $defs{$display}->{inform}; Log3 $name, 5, "$name: no longer visible, ignoring notify";
return undef if( !defined($filter) ); delete( $hash->{mayBeVisible} );
my $rn = AttrVal($name, "room", ""); return undef;
if($filter eq "all" || $rn =~ m/\b$filter\b/) {
Log3 $name, 5, "$name: do update";
} else {
Log3 $name, 5, "$name: $display is not my room, ignoring notify";
delete( $hash->{helper}{myDisplay}{$display} );
return undef;
}
} else {
Log3 $name, 5, "$name: $display is closed, ignoring notify";
delete( $hash->{helper}{myDisplay}{$display} );
return undef;
}
} }
} }
@ -746,6 +791,10 @@ readingsGroup_Notify($$)
} }
$cmd = lookup2($commands,$n,$reading,$value); $cmd = lookup2($commands,$n,$reading,$value);
if( $cmd =~ m/^(\w.*):(\S.*)?$/ ) {
next;
}
($value,undef) = readingsGroup_makeLink($value,undef,$cmd); ($value,undef) = readingsGroup_makeLink($value,undef,$cmd);
$value = "<div $value_style>$value</div>" if( $value_style ); $value = "<div $value_style>$value</div>" if( $value_style );
@ -971,8 +1020,16 @@ readingsGroup_Attr($$$)
<code>attr devices valueIcon {state => '%devStateIcon'}</code> <code>attr devices valueIcon {state => '%devStateIcon'}</code>
<code>attr rgMediaPlayer valueIcon { "playStatus.paused" => "rc_PLAY", "playStatus.playing" => "rc_PAUSE" }</code></li> <code>attr rgMediaPlayer valueIcon { "playStatus.paused" => "rc_PLAY", "playStatus.playing" => "rc_PAUSE" }</code></li>
<li>commands<br> <li>commands<br>
Makes a reading or icon clickable and specifies the command that should be executed. eg.:<br> Can be used in to different ways:
<code>attr rgMediaPlayer commands { "playStatus.paused" => "set %DEVICE play", "playStatus.playing" => "set %DEVICE pause" }</code></li> <ul>
<li>To make a reading or icon clickable by directly specifying the command that should be executed. eg.:<br>
<code>attr rgMediaPlayer commands { "playStatus.paused" => "set %DEVICE play", "playStatus.playing" => "set %DEVICE pause" }</code></li><br>
<li>Or if the mapped command is of the form &lt;command&gt;:[&lt;modifier&gt;] then the normal <a href="#FHEMWEB">FHEMWEB</a>
webCmd widget for &lt;modifier&gt; will be used for this command. if &lt;modifier&gt; is omitted then the FHEMWEB lookup mechanism for &lt;command&gt; will be used. eg:<br>
<code>attr rgMediaPlayer commands { volume => "volume:slider,0,1,100" }</code><br>
<code>attr lights commands { pct => "pct:", dim => "dim:" }</code></li>
</ul>
</li>
</ul><br> </ul><br>
The nameStyle and valueStyle attributes can also contain a perl expression enclosed in {} that returns the style The nameStyle and valueStyle attributes can also contain a perl expression enclosed in {} that returns the style