1
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-04 22:19:38 +00:00

31_HUEDevice.pm: allow perl code with setList and configList attributes

git-svn-id: https://svn.fhem.de/fhem/trunk@19721 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2019-06-27 10:47:33 +00:00
parent 3bb615661b
commit cfdf834e28
2 changed files with 31 additions and 11 deletions

View File

@ -1,5 +1,6 @@
# 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.
- feature: 31_HUEDevice: allow perl code with setList and configList attributes
- bugfix: 95_Astro: v2.0.2: Calculate astronomical season based on ecliptic - bugfix: 95_Astro: v2.0.2: Calculate astronomical season based on ecliptic
latitude instead of static day of the year to make season latitude instead of static day of the year to make season
transition times more reliable. Also, seasons for transition times more reliable. Also, seasons for

View File

@ -624,6 +624,8 @@ HUEDevice_Set($@)
my ($cmd, @args) = @aa; my ($cmd, @args) = @aa;
my %obj; my %obj;
my @match;
my $entries;
$hash->{helper}->{update_timeout} = AttrVal($name, "delayedUpdate", 1); $hash->{helper}->{update_timeout} = AttrVal($name, "delayedUpdate", 1);
@ -711,37 +713,53 @@ HUEDevice_Set($@)
return undef; return undef;
} elsif( my @match = grep { $cmd eq $_ } keys %{($hash->{helper}{setList}{cmds}?$hash->{helper}{setList}{cmds}:{})} ) { } elsif( @match = grep { $cmd eq $_ } keys %{($hash->{helper}{setList}{cmds}?$hash->{helper}{setList}{cmds}:{})} ) {
return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $hash->{helper}{setList}{cmds}{$match[0]} ); return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $hash->{helper}{setList}{cmds}{$match[0]} );
} elsif( my $entries = $hash->{helper}{setList}{regex} ) { } elsif( $entries = $hash->{helper}{setList}{regex} ) {
foreach my $entry (@{$entries}) { foreach my $entry (@{$entries}) {
if( join(' ', @aa) =~ /$entry->{regex}/ ) { if( join(' ', @aa) =~ /$entry->{regex}/ ) {
my $VALUE1 = $1; my $VALUE1 = $1;
my $VALUE2 = $2; my $VALUE2 = $2;
my $VALUE3 = $3; my $VALUE3 = $3;
my $json = $entry->{json}; my $json = $entry->{json};
$json =~ s/\$1/$VALUE1/; if( $json =~ m/^perl:{(.*)}$/ ) {
$json =~ s/\$2/$VALUE2/; $json = eval $json;
$json =~ s/\$3/$VALUE3/; if($@) {
Log3 $name, 3, "$name: configList: ". join(' ', @aa). ": ". $@;
return "error: ". join(' ', @aa). ": ". $@;
}
} else {
$json =~ s/\$1/$VALUE1/;
$json =~ s/\$2/$VALUE2/;
$json =~ s/\$3/$VALUE3/;
}
return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $json ); return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $json );
} }
} }
} elsif( my @match = grep { $cmd eq $_ } keys %{($hash->{helper}{configList}{cmds}?$hash->{helper}{configList}{cmds}:{})} ) { } elsif( @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]} ); return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $hash->{helper}{configList}{cmds}{$match[0]} );
} elsif( my $entries = $hash->{helper}{configList}{regex} ) { } elsif( $entries = $hash->{helper}{configList}{regex} ) {
foreach my $entry (@{$entries}) { foreach my $entry (@{$entries}) {
if( join(' ', @aa) =~ /$entry->{regex}/ ) { if( join(' ', @aa) =~ /$entry->{regex}/ ) {
my $VALUE1 = $1; my $VALUE1 = $1;
my $VALUE2 = $2; my $VALUE2 = $2;
my $VALUE3 = $3; my $VALUE3 = $3;
my $json = $entry->{json}; my $json = $entry->{json};
$json =~ s/\$1/$VALUE1/; if( $json =~ m/^perl:{(.*)}$/ ) {
$json =~ s/\$2/$VALUE2/; $json = eval $json;
$json =~ s/\$3/$VALUE3/; if($@) {
Log3 $name, 3, "$name: configList: ". join(' ', @aa). ": ". $@;
return "error: ". join(' ', @aa). ": ". $@;
}
} else {
$json =~ s/\$1/$VALUE1/;
$json =~ s/\$2/$VALUE2/;
$json =~ s/\$3/$VALUE3/;
}
return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $json ); return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $json );
} }
@ -1810,7 +1828,8 @@ HUEDevice_Attr($$$;$)
absent:{&lt;json&gt;}</code></li> absent:{&lt;json&gt;}</code></li>
<li>configList<br> <li>configList<br>
The list of know config commands for sensor type devices. one command per line, eg.: <code><br> The list of know config commands for sensor type devices. one command per line, eg.: <code><br>
mode:{&lt;json&gt;}</code></li> attr mySensor mode:{&lt;json&gt;}\<br>
/heatsetpoint (.*)/:perl:{'{"heatsetpoint":'. $VALUE1 * 100 .'}'}</code></li>
<li>subType<br> <li>subType<br>
extcolordimmer -> device has rgb and color temperatur control<br> extcolordimmer -> device has rgb and color temperatur control<br>
colordimmer -> device has rgb controll<br> colordimmer -> device has rgb controll<br>