From 0e2fec6e430d476a4f425c4a446f739b481f3e8b Mon Sep 17 00:00:00 2001 From: deespe <> Date: Thu, 27 Oct 2016 23:46:19 +0000 Subject: [PATCH] 98_Hyperion: fix identifying off state after boot effect, some value checking corrections and slider adjustments, update commandref git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12449 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/98_Hyperion.pm | 165 ++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/FHEM/98_Hyperion.pm b/FHEM/98_Hyperion.pm index 0b93e0fc0..63e9b2acf 100644 --- a/FHEM/98_Hyperion.pm +++ b/FHEM/98_Hyperion.pm @@ -92,6 +92,7 @@ sub Hyperion_Define($$) { $attr{$name}{alias} = "Ambilight"; $attr{$name}{"event-on-change-reading"} = ".*"; + $attr{$name}{"event-on-update-reading"} = "serverResponse"; $attr{$name}{devStateIcon} = '{(Hyperion_devStateIcon($name),"toggle")}'; $attr{$name}{group} = "colordimmer"; $attr{$name}{homebridgeMapping} = $Hyperion_homebridgeMapping; @@ -269,18 +270,18 @@ sub Hyperion_Read($) my $adjB = $adj ? join(",",@{$adj->{blueAdjust}}) : undef; my $corS = $corr ? join(",",@{$corr->{correctionValues}}) : undef; my $temP = $temp ? join(",",@{$temp->{correctionValues}}) : undef; - my $blkL = $trans->{blacklevel} ? sprintf("%.3f",$trans->{blacklevel}->[0]).",".sprintf("%.3f",$trans->{blacklevel}->[1]).",".sprintf("%.3f",$trans->{blacklevel}->[2]) : undef; - my $gamM = $trans->{gamma} ? sprintf("%.3f",$trans->{gamma}->[0]).",".sprintf("%.3f",$trans->{gamma}->[1]).",".sprintf("%.3f",$trans->{gamma}->[2]) : undef; - my $thrE = $trans->{threshold} ? sprintf("%.3f",$trans->{threshold}->[0]).",".sprintf("%.3f",$trans->{threshold}->[1]).",".sprintf("%.3f",$trans->{threshold}->[2]) : undef; - my $whiL = $trans->{whitelevel} ? sprintf("%.3f",$trans->{whitelevel}->[0]).",".sprintf("%.3f",$trans->{whitelevel}->[1]).",".sprintf("%.3f",$trans->{whitelevel}->[2]) : undef; - my $lumG = defined $trans->{luminanceGain} ? sprintf("%.3f",$trans->{luminanceGain}) : undef; - my $lumM = defined $trans->{luminanceMinimum} ? sprintf("%.3f",$trans->{luminanceMinimum}) : undef; - my $satG = defined $trans->{saturationGain} ? sprintf("%.3f",$trans->{saturationGain}) : undef; - my $satL = defined $trans->{saturationLGain} ? sprintf("%.3f",$trans->{saturationLGain}) : undef; - my $valG = defined $trans->{valueGain} ? sprintf("%.3f",$trans->{valueGain}) : undef; - $hash->{hostname} = $data->{hostname} if (($data->{hostname} && !$hash->{hostname}) || ($data->{hostname} && $hash->{hostname} ne $data->{hostname})); - $hash->{build_version} = $vers if (($vers && !$hash->{build_version}) || ($vers && $hash->{build_version} ne $vers)); - $hash->{build_time} = $data->{hyperion_build}->[0]->{time} if (($data->{hyperion_build}->[0]->{time} && !$hash->{build_time}) || ($data->{hyperion_build}->[0]->{time} && $hash->{build_time} ne $data->{hyperion_build}->[0]->{time})); + my $blkL = $trans->{blacklevel} ? sprintf("%.2f",$trans->{blacklevel}->[0]).",".sprintf("%.2f",$trans->{blacklevel}->[1]).",".sprintf("%.2f",$trans->{blacklevel}->[2]) : undef; + my $gamM = $trans->{gamma} ? sprintf("%.2f",$trans->{gamma}->[0]).",".sprintf("%.2f",$trans->{gamma}->[1]).",".sprintf("%.2f",$trans->{gamma}->[2]) : undef; + my $thrE = $trans->{threshold} ? sprintf("%.2f",$trans->{threshold}->[0]).",".sprintf("%.2f",$trans->{threshold}->[1]).",".sprintf("%.2f",$trans->{threshold}->[2]) : undef; + my $whiL = $trans->{whitelevel} ? sprintf("%.2f",$trans->{whitelevel}->[0]).",".sprintf("%.2f",$trans->{whitelevel}->[1]).",".sprintf("%.2f",$trans->{whitelevel}->[2]) : undef; + my $lumG = defined $trans->{luminanceGain} ? sprintf("%.2f",$trans->{luminanceGain}) : undef; + my $lumM = defined $trans->{luminanceMinimum} ? sprintf("%.2f",$trans->{luminanceMinimum}) : undef; + my $satG = defined $trans->{saturationGain} ? sprintf("%.2f",$trans->{saturationGain}) : undef; + my $satL = defined $trans->{saturationLGain} ? sprintf("%.2f",$trans->{saturationLGain}) : undef; + my $valG = defined $trans->{valueGain} ? sprintf("%.2f",$trans->{valueGain}) : undef; + $hash->{hostname} = $data->{hostname} if (($data->{hostname} && !$hash->{hostname}) || ($data->{hostname} && $hash->{hostname} ne $data->{hostname})); + $hash->{build_version} = $vers if (($vers && !$hash->{build_version}) || ($vers && $hash->{build_version} ne $vers)); + $hash->{build_time} = $data->{hyperion_build}->[0]->{time} if (($data->{hyperion_build}->[0]->{time} && !$hash->{build_time}) || ($data->{hyperion_build}->[0]->{time} && $hash->{build_time} ne $data->{hyperion_build}->[0]->{time})); readingsBeginUpdate($hash); readingsBulkUpdate($hash,"adjustRed",$adjR); readingsBulkUpdate($hash,"adjustGreen",$adjG); @@ -342,7 +343,7 @@ sub Hyperion_Read($) } else { - if ($prio) + if ($prio && $data->{priorities}->[0]->{duration_ms} && !$data->{priorities}->[1]->{priority}) { readingsBulkUpdate($hash,"mode","clearall"); readingsBulkUpdate($hash,"mode_before_off","clearall"); @@ -399,17 +400,13 @@ sub Hyperion_GetConfigs($) if ($count > 1) { my $configs = join(",",@files); - readingsSingleUpdate($hash,".configs",$configs,1) - if (ReadingsVal($name,".configs","") ne $configs); - $attr{$name}{webCmd} = $Hyperion_webCmd_config - if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd); + readingsSingleUpdate($hash,".configs",$configs,1) if (ReadingsVal($name,".configs","") ne $configs); + $attr{$name}{webCmd} = $Hyperion_webCmd_config if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd); } else { - fhem "deletereading $name .configs" - if (defined ReadingsVal($name,".configs",undef)); - $attr{$name}{webCmd} = $Hyperion_webCmd - if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd_config); + fhem "deletereading $name .configs" if (defined ReadingsVal($name,".configs",undef)); + $attr{$name}{webCmd} = $Hyperion_webCmd if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd_config); return "Found just one config file. Please add at least one more config file to properly use this function." if ($count == 1); return "No config files found!"; @@ -481,15 +478,15 @@ sub Hyperion_Set($@) $Hyperion_sets_local{gamma} = "textField" if (ReadingsVal($name,"gamma","")); $Hyperion_sets_local{threshold} = "textField" if (ReadingsVal($name,"threshold","")); $Hyperion_sets_local{whitelevel} = "textField" if (ReadingsVal($name,"whitelevel","")); - $Hyperion_sets_local{luminanceGain} = "slider,0,0.010,1.999,1" if (ReadingsVal($name,"luminanceGain","")); - $Hyperion_sets_local{luminanceMinimum} = "slider,0,0.010,1.999,1" if (ReadingsVal($name,"luminanceMinimum","")); - $Hyperion_sets_local{saturationGain} = "slider,0,0.010,1.999,1" if (ReadingsVal($name,"saturationGain","")); - $Hyperion_sets_local{saturationLGain} = "slider,0,0.010,1.999,1" if (ReadingsVal($name,"saturationLGain","")); - $Hyperion_sets_local{valueGain} = "slider,0,0.010,1.999,1" if (ReadingsVal($name,"valueGain","")); + $Hyperion_sets_local{luminanceGain} = "slider,0,0.01,5,1" if (ReadingsVal($name,"luminanceGain","")); + $Hyperion_sets_local{luminanceMinimum} = "slider,0,0.01,5,1" if (ReadingsVal($name,"luminanceMinimum","")); + $Hyperion_sets_local{saturationGain} = "slider,0,0.01,5,1" if (ReadingsVal($name,"saturationGain","")); + $Hyperion_sets_local{saturationLGain} = "slider,0,0.01,5,1" if (ReadingsVal($name,"saturationLGain","")); + $Hyperion_sets_local{valueGain} = "slider,0,0.01,5,1" if (ReadingsVal($name,"valueGain","")); my $params = join(" ",map {"$_:$Hyperion_sets_local{$_}"} keys %Hyperion_sets_local); my %obj; - Log3 $name,4,"$name: Hyperion_Set cmd: $cmd" if (defined $cmd); - Log3 $name,4,"$name: Hyperion_Set value: $value" if (defined $value && $value ne ""); + Log3 $name,4,"$name: Hyperion_Set cmd: $cmd"; + Log3 $name,4,"$name: Hyperion_Set value: $value" if ($value); Log3 $name,4,"$name: Hyperion_Set duration: $duration, priority: $priority"; if ($cmd eq "configFile") { @@ -551,8 +548,7 @@ sub Hyperion_Set($@) $obj{color} = [$r,$g,$b]; $obj{command} = "color"; $obj{priority} = $priority * 1; - $obj{duration} = $duration * 1000 - if ($duration > 0); + $obj{duration} = $duration * 1000 if ($duration > 0); } elsif ($cmd eq "dim") { @@ -584,10 +580,7 @@ sub Hyperion_Set($@) my $dimStep = (defined $value) ? int $value : int AttrVal($name,"hyperionDimStep",5); my $dimUp = ($dim + $dimStep < 100) ? $dim + $dimStep : 100; my $dimDown = ($dim - $dimStep > 0) ? $dim - $dimStep : 0; - fhem "set $name dim $dimUp" - if ($cmd eq "dimUp"); - fhem "set $name dim $dimDown" - if ($cmd eq "dimDown"); + $cmd eq "dimUp" ? fhem "set $name dim $dimUp" : fhem "set $name dim $dimDown"; return undef; } elsif ($cmd eq "effect") @@ -599,13 +592,11 @@ sub Hyperion_Set($@) $obj{effect} = \%ef; $obj{command} = "effect"; $obj{priority} = $priority * 1; - $obj{duration} = $duration * 1000 - if ($duration > 0); + $obj{duration} = $duration * 1000 if ($duration > 0); } elsif ($cmd eq "clearall") { - return "$cmd need no additional value of $value" - if (defined $value); + return "$cmd need no additional value of $value" if (defined $value); $obj{command} = $cmd; } elsif ($cmd eq "clear") @@ -618,16 +609,14 @@ sub Hyperion_Set($@) } elsif ($cmd eq "off") { - return "$cmd need no additional value of $value" - if (defined $value); + return "$cmd need no additional value of $value" if (defined $value); $obj{command} = "color"; $obj{color} = [0,0,0]; $obj{priority} = 0; } elsif ($cmd eq "on") { - return "$cmd need no additional value of $value" - if (defined $value); + return "$cmd need no additional value of $value" if (defined $value); my $rmode = ReadingsVal($name,"mode_before_off","rgb"); my $rrgb = ReadingsVal($name,"rgb",""); my $reffect = ReadingsVal($name,"effect",""); @@ -648,16 +637,14 @@ sub Hyperion_Set($@) } elsif ($cmd eq "toggle") { - return "$cmd need no additional value of $value" - if (defined $value); + return "$cmd need no additional value of $value" if (defined $value); my $rstate = Value($name); ($rstate ne "off") ? fhem "set ".$name." off" : fhem "set ".$name." on"; return undef; } elsif ($cmd eq "mode") { - return "The value of mode has to be rgb,effect,clearall,off" - if ($value !~ /^(off|clearall|rgb|effect)$/); + return "The value of mode has to be rgb,effect,clearall,off" if ($value !~ /^(off|clearall|rgb|effect)$/); Log3 $name,4,"$name: cmd: $cmd, value: $value"; my $rmode = $value; my $rrgb = ReadingsVal($name,"rgb",""); @@ -683,28 +670,29 @@ sub Hyperion_Set($@) } elsif ($cmd =~ /^(luminanceGain|luminanceMinimum|saturationGain|saturationLGain|valueGain)$/) { - return "The value of $cmd has to be between 0.000 an 1.999 in steps of 0.001." - if ($value !~ /^(\d)(\.\d)?(\d{1,2})?$/ || int $1 > 1); - $value = sprintf("%.3f",$value) * 1; + return "The value of $cmd has to be from 0.00 to 5.00 in steps of 0.01." + if ($value !~ /^((\d)\.(\d){1,2})?$/ || $1 > 5); + $value = sprintf("%.4f",$value) * 1; my %tr = ($cmd => $value); $obj{command} = "transform"; $obj{transform} = \%tr; } elsif ($cmd =~ /^(blacklevel|gamma|threshold|whitelevel)$/) { - return "Each of the three comma separated values of $cmd has to be between 0.000 an 9.999 in steps of 0.001" - if ($value !~ /^((\d)\.(\d){1,3}),((\d)\.(\d){1,3}),((\d)\.(\d){1,3})$/ || int $1 > 9 || int $4 > 9 || int $7 > 9); - my $arr = Hyperion_list2array($value,"%.3f"); + return "Each of the three comma separated values of $cmd must be from 0.00 to 1.00 in steps of 0.01" + if ($cmd =~ /^blacklevel|threshold|whitelevel$/ && ($value !~ /^((\d)\.(\d){1,2}),((\d)\.(\d){1,2}),((\d)\.(\d){1,2})$/ || $1 > 1 || $4 > 1 || $7 > 1)); + return "Each of the three comma separated values of $cmd must be from 0.00 to 5.00 in steps of 0.01" + if ($cmd eq "gamma" && ($value !~ /^((\d)\.(\d){1,2}),((\d)\.(\d){1,2}),((\d)\.(\d){1,2})$/ || $1 > 5 || $4 > 5 || $7 > 5)); + my $arr = Hyperion_list2array($value,"%.4f"); my %ar = ($cmd => $arr); $obj{command} = "transform"; $obj{transform} = \%ar; } elsif ($cmd =~ /^(correction|colorTemperature)$/) { - $cmd = "temperature" - if ($cmd eq "colorTemperature"); - return "Each of the three comma separated values of $cmd has to be between 0 an 255 in steps of 1" - if ($value !~ /^(\d{1,3})?,(\d{1,3})?,(\d{1,3})?$/ || int $1 > 255 || int $2 > 255 || int $3 > 255); + $cmd = "temperature" if ($cmd eq "colorTemperature"); + return "Each of the three comma separated values of $cmd must be from 0 to 255 in steps of 1" + if ($value !~ /^(\d{1,3})?,(\d{1,3})?,(\d{1,3})?$/ || $1 > 255 || $2 > 255 || $3 > 255); my $arr = Hyperion_list2array($value,"%d"); my %ar = ("correctionValues" => $arr); $obj{command} = $cmd; @@ -712,11 +700,11 @@ sub Hyperion_Set($@) } elsif ($cmd =~ /^(adjustRed|adjustGreen|adjustBlue)$/) { - return "Each of the three comma separated values of $cmd has to be between 0 an 255 in steps of 1" - if ($value !~ /^(\d{1,3})?,(\d{1,3})?,(\d{1,3})?$/ || int $1 > 255 || int $2 > 255 || int $3 > 255); - $cmd = "redAdjust" if ($cmd eq "adjustRed"); + return "Each of the three comma separated values of $cmd must be from 0 an 255 in steps of 1" + if ($value !~ /^(\d{1,3})?,(\d{1,3})?,(\d{1,3})?$/ || $1 > 255 || $2 > 255 || $3 > 255); + $cmd = "redAdjust" if ($cmd eq "adjustRed"); $cmd = "greenAdjust" if ($cmd eq "adjustGreen"); - $cmd = "blueAdjust" if ($cmd eq "adjustBlue"); + $cmd = "blueAdjust" if ($cmd eq "adjustBlue"); my $arr = Hyperion_list2array($value,"%d"); my %ar = ($cmd => $arr); $obj{command} = "adjustment"; @@ -920,15 +908,18 @@ sub Hyperion_devStateIcon($;$)