98_Hyperion: config only available if at least two files are found and other code improvements

git-svn-id: https://svn.fhem.de/fhem/trunk@12287 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
deespe 2016-10-06 22:11:01 +00:00
parent 073230e086
commit 113b85b5eb
2 changed files with 158 additions and 87 deletions

View File

@ -1,6 +1,8 @@
# 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: 98_Hyperion: config only available if at least two files are found
code improvements
- feature: 50_TelegramBot: urlescaped filenames / location send-receive - feature: 50_TelegramBot: urlescaped filenames / location send-receive
timeout for send timeout for send
- feature: 73_ElectricityCalculator: header and readingFnAttributes added - feature: 73_ElectricityCalculator: header and readingFnAttributes added

View File

@ -84,7 +84,8 @@ sub Hyperion_Define($$)
{ {
my ($hash,$def) = @_; my ($hash,$def) = @_;
my @args = split("[ \t]+",$def); my @args = split("[ \t]+",$def);
return "Usage: define <name> Hyperion <IP> <PORT> [<INTERVAL>]" if (@args < 4); return "Usage: define <name> Hyperion <IP> <PORT> [<INTERVAL>]"
if (@args < 4);
my ($name,$type,$host,$port,$interval) = @args; my ($name,$type,$host,$port,$interval) = @args;
if ($interval) if ($interval)
{ {
@ -127,7 +128,7 @@ sub Hyperion_Notify($$)
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return if ($dev->{NAME} ne "global"); return if ($dev->{NAME} ne "global");
return if (!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}})); return if (!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}}));
return undef if( AttrVal($name, "disable", 0) ); return undef if (AttrVal($name,"disable",0));
Hyperion_OpenDev($hash); Hyperion_OpenDev($hash);
return undef; return undef;
} }
@ -136,11 +137,14 @@ sub Hyperion_OpenDev($)
{ {
my ($hash) = @_; my ($hash) = @_;
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
$hash->{STATE} = DevIo_OpenDev($hash,0,"Hyperion_DoInit",sub($$$) { $hash->{STATE} = DevIo_OpenDev($hash,0,"Hyperion_DoInit",sub($$$)
{
my ($h,$err) = @_; my ($h,$err) = @_;
readingsSingleUpdate($hash,"lastError",$err,1) if($err); readingsSingleUpdate($hash,"lastError",$err,1)
if ($err);
readingsSingleUpdate($hash,"serverResponse","ERROR",1); readingsSingleUpdate($hash,"serverResponse","ERROR",1);
readingsSingleUpdate($hash,"state","ERROR",1) if (Value($hash->{NAME}) ne "ERROR"); readingsSingleUpdate($hash,"state","ERROR",1)
if (Value($hash->{NAME}) ne "ERROR");
return $err ? "Error: $err" : $hash->{DeviceName}." connected"; return $err ? "Error: $err" : $hash->{DeviceName}." connected";
}); });
return undef; return undef;
@ -177,8 +181,8 @@ sub Hyperion_Get($@)
{ {
my ($hash,$name,$cmd) = @_; my ($hash,$name,$cmd) = @_;
my $params = "configFiles:noArg devStateIcon:noArg statusRequest:noArg"; my $params = "configFiles:noArg devStateIcon:noArg statusRequest:noArg";
return "get $name needs one parameter: $params" if (!$cmd); return "get $name needs one parameter: $params"
if (!$cmd);
if ($cmd eq "configFiles") if ($cmd eq "configFiles")
{ {
Hyperion_GetConfigs($hash); Hyperion_GetConfigs($hash);
@ -211,7 +215,8 @@ sub Hyperion_Read($)
my %Hyperion_sets_local = %Hyperion_sets; my %Hyperion_sets_local = %Hyperion_sets;
if ($result=~ /^\{"success":true\}$/) if ($result=~ /^\{"success":true\}$/)
{ {
fhem "sleep 1; get $name statusRequest" if (AttrVal($name,"queryAfterSet",1) == 1 || !$hash->{INTERVAL}); fhem "sleep 1; get $name statusRequest"
if (AttrVal($name,"queryAfterSet",1) == 1 || !$hash->{INTERVAL});
return undef; return undef;
} }
elsif ($result =~ /^\{"info":\{.+\},"success":true\}$/) elsif ($result =~ /^\{"info":\{.+\},"success":true\}$/)
@ -230,14 +235,16 @@ sub Hyperion_Read($)
if (AttrVal($name,"hyperionVersionCheck",1) == 1) if (AttrVal($name,"hyperionVersionCheck",1) == 1)
{ {
my $error; my $error;
$error = "Can't detect your version of hyperion!" if (!$data->{hyperion_build}->[0]->{version}); $error = "Can't detect your version of hyperion!"
if (!$data->{hyperion_build}->[0]->{version});
if (!$error) if (!$error)
{ {
my $ver = (split("V",(split(" ",$data->{hyperion_build}->[0]->{version}))[0]))[1]; my $ver = (split("V",(split(" ",$data->{hyperion_build}->[0]->{version}))[0]))[1];
$ver =~ s/\.//g; $ver =~ s/\.//g;
my $rver = $Hyperion_requiredVersion; my $rver = $Hyperion_requiredVersion;
$rver =~ s/\.//g; $rver =~ s/\.//g;
$error = "Your version of hyperion (detected version: ".$data->{hyperion_build}->[0]->{version}.") is not (longer) supported by this module!" if ($ver<$rver); $error = "Your version of hyperion (detected version: ".$data->{hyperion_build}->[0]->{version}.") is not (longer) supported by this module!"
if ($ver<$rver);
} }
if ($error) if ($error)
{ {
@ -280,29 +287,47 @@ sub Hyperion_Read($)
my $satG = sprintf("%.3f",$trans->{saturationGain}); my $satG = sprintf("%.3f",$trans->{saturationGain});
my $satL = (defined $trans->{saturationLGain}) ? sprintf("%.3f",$trans->{saturationLGain}) : undef; my $satL = (defined $trans->{saturationLGain}) ? sprintf("%.3f",$trans->{saturationLGain}) : undef;
my $valG = sprintf("%.3f",$trans->{valueGain}); my $valG = sprintf("%.3f",$trans->{valueGain});
$Hyperion_sets_local{effect} = $effectList if (length $effectList > 0); $Hyperion_sets_local{effect} = $effectList
if (length $effectList > 0);
if ($configs) if ($configs)
{ {
$Hyperion_sets_local{configFile} = $configs; $Hyperion_sets_local{configFile} = $configs;
$attr{$name}{webCmd} = $Hyperion_webCmd_config if (!$attr{$name}{webCmd} || AttrVal($name,"webCmd","") eq $Hyperion_webCmd); $attr{$name}{webCmd} = $Hyperion_webCmd_config
if (!$attr{$name}{webCmd} || AttrVal($name,"webCmd","") eq $Hyperion_webCmd);
} }
$attr{$name}{alias} = "Ambilight" if (!$attr{$name}{alias}); $attr{$name}{alias} = "Ambilight"
$attr{$name}{devStateIcon} = '{(Hyperion_devStateIcon($name),"toggle")}' if (!$attr{$name}{devStateIcon}); if (!$attr{$name}{alias});
$attr{$name}{group} = "colordimmer" if (!$attr{$name}{group}); $attr{$name}{devStateIcon} = '{(Hyperion_devStateIcon($name),"toggle")}'
$attr{$name}{homebridgeMapping} = $Hyperion_homebridgeMapping if (!$attr{$name}{homebridgeMapping}); if (!$attr{$name}{devStateIcon});
$attr{$name}{icon} = "light_led_stripe_rgb" if (!$attr{$name}{icon}); $attr{$name}{group} = "colordimmer"
$attr{$name}{lightSceneParamsToSave} = "state" if (!$attr{$name}{lightSceneParamsToSave}); if (!$attr{$name}{group});
$attr{$name}{room} = "Hyperion" if (!$attr{$name}{room}); $attr{$name}{homebridgeMapping} = $Hyperion_homebridgeMapping
$attr{$name}{userattr} = "lightSceneParamsToSave" if (!$attr{$name}{userattr} && index($attr{"global"}{userattr},"lightSceneParamsToSave") == -1); if (!$attr{$name}{homebridgeMapping});
$attr{$name}{userattr} = "lightSceneParamsToSave ".$attr{$name}{userattr} if ($attr{$name}{userattr} && index($attr{$name}{userattr},"lightSceneParamsToSave") == -1 && index($attr{"global"}{userattr},"lightSceneParamsToSave") == -1); $attr{$name}{icon} = "light_led_stripe_rgb"
$attr{$name}{userattr} = "homebridgeMapping" if (!$attr{$name}{userattr} && index($attr{"global"}{userattr},"homebridgeMapping") == -1); if (!$attr{$name}{icon});
$attr{$name}{userattr} = "homebridgeMapping ".$attr{$name}{userattr} if ($attr{$name}{userattr} && index($attr{$name}{userattr},"homebridgeMapping") == -1 && index($attr{"global"}{userattr},"homebridgeMapping") == -1); $attr{$name}{lightSceneParamsToSave} = "state"
$attr{$name}{webCmd} = $Hyperion_webCmd if (!$attr{$name}{webCmd} || ($attr{$name}{webCmd} && !$Hyperion_sets_local{configFile})); if (!$attr{$name}{lightSceneParamsToSave});
$attr{$name}{webCmd} = $Hyperion_webCmd_config if ($attr{$name}{webCmd} && $Hyperion_sets_local{configFile} && $attr{$name}{webCmd} eq $Hyperion_webCmd); $attr{$name}{room} = "Hyperion"
if (!$attr{$name}{room});
$attr{$name}{userattr} = "lightSceneParamsToSave"
if (!$attr{$name}{userattr} && index($attr{"global"}{userattr},"lightSceneParamsToSave") == -1);
$attr{$name}{userattr} = "lightSceneParamsToSave ".$attr{$name}{userattr}
if ($attr{$name}{userattr} && index($attr{$name}{userattr},"lightSceneParamsToSave") == -1 && index($attr{"global"}{userattr},"lightSceneParamsToSave") == -1);
$attr{$name}{userattr} = "homebridgeMapping"
if (!$attr{$name}{userattr} && index($attr{"global"}{userattr},"homebridgeMapping") == -1);
$attr{$name}{userattr} = "homebridgeMapping ".$attr{$name}{userattr}
if ($attr{$name}{userattr} && index($attr{$name}{userattr},"homebridgeMapping") == -1 && index($attr{"global"}{userattr},"homebridgeMapping") == -1);
$attr{$name}{webCmd} = $Hyperion_webCmd
if (!$attr{$name}{webCmd} || ($attr{$name}{webCmd} && !$Hyperion_sets_local{configFile}));
$attr{$name}{webCmd} = $Hyperion_webCmd_config
if ($attr{$name}{webCmd} && $Hyperion_sets_local{configFile} && $attr{$name}{webCmd} eq $Hyperion_webCmd);
$hash->{helper}{sets} = join(" ",map {"$_:$Hyperion_sets_local{$_}"} keys %Hyperion_sets_local); $hash->{helper}{sets} = join(" ",map {"$_:$Hyperion_sets_local{$_}"} keys %Hyperion_sets_local);
$hash->{hostname} = $data->{hostname} if (($data->{hostname} && !$hash->{hostname}) || ($data->{hostname} && $hash->{hostname} ne $data->{hostname})); $hash->{hostname} = $data->{hostname}
$hash->{build_version} = $vers if (($vers && !$hash->{build_version}) || ($vers && $hash->{build_version} ne $vers)); if (($data->{hostname} && !$hash->{hostname}) || ($data->{hostname} && $hash->{hostname} ne $data->{hostname}));
$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})); $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); readingsBeginUpdate($hash);
Hyperion_readingsBulkUpdateIfChanged($hash,"adjustRed",$adjR); Hyperion_readingsBulkUpdateIfChanged($hash,"adjustRed",$adjR);
Hyperion_readingsBulkUpdateIfChanged($hash,"adjustGreen",$adjG); Hyperion_readingsBulkUpdateIfChanged($hash,"adjustGreen",$adjG);
@ -310,18 +335,25 @@ sub Hyperion_Read($)
Hyperion_readingsBulkUpdateIfChanged($hash,"blacklevel",$blkL); Hyperion_readingsBulkUpdateIfChanged($hash,"blacklevel",$blkL);
Hyperion_readingsBulkUpdateIfChanged($hash,"colorTemperature",$temP); Hyperion_readingsBulkUpdateIfChanged($hash,"colorTemperature",$temP);
Hyperion_readingsBulkUpdateIfChanged($hash,"correction",$corS); Hyperion_readingsBulkUpdateIfChanged($hash,"correction",$corS);
Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0]) if (!defined ReadingsVal($name,"effect",undef)); Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0])
Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0]) if (!defined ReadingsVal($name,"effect",undef)); if (!defined ReadingsVal($name,"effect",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,".effects", $effectList) if ($effectList); Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0])
if (!defined ReadingsVal($name,"effect",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,".effects", $effectList)
if ($effectList);
Hyperion_readingsBulkUpdateIfChanged($hash,"duration",$duration); Hyperion_readingsBulkUpdateIfChanged($hash,"duration",$duration);
Hyperion_readingsBulkUpdateIfChanged($hash,"gamma",$gamM); Hyperion_readingsBulkUpdateIfChanged($hash,"gamma",$gamM);
Hyperion_readingsBulkUpdateIfChanged($hash,"id",$id); Hyperion_readingsBulkUpdateIfChanged($hash,"id",$id);
Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceGain",$lumG); Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceGain",$lumG);
Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceMinimum",$lumM) if ($lumM); Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceMinimum",$lumM)
Hyperion_readingsBulkUpdateIfChanged($hash,"priority",$prio) if (defined $prio); if ($lumM);
Hyperion_readingsBulkUpdateIfChanged($hash,"rgb","ff0d0d") if (!defined ReadingsVal($name,"rgb",undef)); Hyperion_readingsBulkUpdateIfChanged($hash,"priority",$prio)
if (defined $prio);
Hyperion_readingsBulkUpdateIfChanged($hash,"rgb","ff0d0d")
if (!defined ReadingsVal($name,"rgb",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,"saturationGain",$satG); Hyperion_readingsBulkUpdateIfChanged($hash,"saturationGain",$satG);
Hyperion_readingsBulkUpdateIfChanged($hash,"saturationLGain",$satL) if ($satL); Hyperion_readingsBulkUpdateIfChanged($hash,"saturationLGain",$satL)
if ($satL);
Hyperion_readingsBulkUpdateIfChanged($hash,"threshold",$thrE); Hyperion_readingsBulkUpdateIfChanged($hash,"threshold",$thrE);
Hyperion_readingsBulkUpdateIfChanged($hash,"valueGain",$valG); Hyperion_readingsBulkUpdateIfChanged($hash,"valueGain",$valG);
Hyperion_readingsBulkUpdateIfChanged($hash,"whitelevel",$whiL); Hyperion_readingsBulkUpdateIfChanged($hash,"whitelevel",$whiL);
@ -388,7 +420,8 @@ sub Hyperion_Read($)
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
Hyperion_readingsBulkUpdateIfChanged($hash,"lastError","error while requesting ".$hash->{DeviceName}); Hyperion_readingsBulkUpdateIfChanged($hash,"lastError","error while requesting ".$hash->{DeviceName});
readingsBulkUpdate($hash,"serverResponse","ERROR"); readingsBulkUpdate($hash,"serverResponse","ERROR");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","ERROR") if (Value($name) ne "ERROR"); Hyperion_readingsBulkUpdateIfChanged($hash,"state","ERROR")
if (Value($name) ne "ERROR");
} }
return undef; return undef;
} }
@ -413,20 +446,28 @@ sub Hyperion_GetConfigs($)
$cmd .= " $user\@$ip $com"; $cmd .= " $user\@$ip $com";
@files = Hyperion_listFilesInDir($hash,$cmd); @files = Hyperion_listFilesInDir($hash,$cmd);
} }
return "No files found on server $ip in directory $dir. Maybe the wrong directory? If SSH is used, has the user ".AttrVal($name,"hyperionSshUser","pi")." been configured to log in without entering a password (http://www.linuxproblem.org/art_9.html)?" if (scalar(@files) == 0); return "No files found on server $ip in directory $dir. Maybe the wrong directory? If SSH is used, has the user ".AttrVal($name,"hyperionSshUser","pi")." been configured to log in without entering a password (http://www.linuxproblem.org/art_9.html)?"
if (scalar @files > 0) if (scalar @files == 0);
if (scalar @files > 1)
{ {
my $configs = join(",",@files); my $configs = join(",",@files);
readingsSingleUpdate($hash,".configs",$configs,1) if (ReadingsVal($name,".configs","") ne $configs); readingsSingleUpdate($hash,".configs",$configs,1)
$attr{$name}{webCmd} = $Hyperion_webCmd_config if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd); if (ReadingsVal($name,".configs","") ne $configs);
$attr{$name}{webCmd} = $Hyperion_webCmd_config
if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd);
} }
else else
{ {
fhem "deletereading $name .configs" if (defined ReadingsVal($name,".configs",undef)); fhem "deletereading $name .configs"
$attr{$name}{webCmd} = $Hyperion_webCmd if (AttrVal($name,"webCmd","") eq $Hyperion_webCmd_config); 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 (scalar @files == 1);
return "No config files found!";
} }
Hyperion_GetUpdate($hash); Hyperion_GetUpdate($hash);
return "Found at least one config file. Please refresh this page to see the result."; return "Found at least two config files. Please refresh this page to see the result.";
} }
sub Hyperion_listFilesInDir($$) sub Hyperion_listFilesInDir($$)
@ -472,7 +513,8 @@ sub Hyperion_Set($@)
my ($hash,$name,@aa) = @_; my ($hash,$name,@aa) = @_;
my ($cmd,@args) = @aa; my ($cmd,@args) = @aa;
my $value = (defined($args[0])) ? $args[0] : undef; my $value = (defined($args[0])) ? $args[0] : undef;
return "\"set $name\" needs at least one argument and maximum five arguments" if (scalar @aa < 1 || scalar @aa > 4); return "\"set $name\" needs at least one argument and maximum five arguments"
if (scalar @aa < 1 || scalar @aa > 4);
my $duration = (defined $args[1]) ? int $args[1] : int AttrVal($name,"hyperionDefaultDuration",0); my $duration = (defined $args[1]) ? int $args[1] : int AttrVal($name,"hyperionDefaultDuration",0);
my $priority = (defined $args[2]) ? int $args[2] : int AttrVal($name,"hyperionDefaultPriority",0); my $priority = (defined $args[2]) ? int $args[2] : int AttrVal($name,"hyperionDefaultPriority",0);
my $sets = $hash->{helper}{sets}; my $sets = $hash->{helper}{sets};
@ -523,81 +565,97 @@ sub Hyperion_Set($@)
Log3 $name,4,"$name: NOT restarted Hyperion with $binpath $confdir$value, status: $status"; Log3 $name,4,"$name: NOT restarted Hyperion with $binpath $confdir$value, status: $status";
readingsSingleUpdate($hash,"lastError",$status,1); readingsSingleUpdate($hash,"lastError",$status,1);
readingsSingleUpdate($hash,"serverResponse","ERROR",1); readingsSingleUpdate($hash,"serverResponse","ERROR",1);
readingsSingleUpdate($hash,"state","ERROR",1) if (Value($name) ne "ERROR"); readingsSingleUpdate($hash,"state","ERROR",1)
if (Value($name) ne "ERROR");
return "$name NOT restarted Hyperion with $binpath $confdir$value, status: $status"; return "$name NOT restarted Hyperion with $binpath $confdir$value, status: $status";
} }
} }
elsif ($cmd eq "rgb") elsif ($cmd eq "rgb")
{ {
return "Value of $cmd has to be in RGB hex format like ffffff or 3F7D90" if ($value !~ /^(\d|[a-f|A-F]){6}$/); return "Value of $cmd has to be in RGB hex format like ffffff or 3F7D90"
if ($value !~ /^(\d|[a-f|A-F]){6}$/);
$value = lc($value); $value = lc($value);
my ($r,$g,$b) = Color::hex2rgb($value); my ($r,$g,$b) = Color::hex2rgb($value);
$obj{color} = [$r,$g,$b]; $obj{color} = [$r,$g,$b];
$obj{command} = "color"; $obj{command} = "color";
$obj{priority} = $priority * 1; $obj{priority} = $priority * 1;
$obj{duration} = $duration * 1000 if ($duration > 0); $obj{duration} = $duration * 1000
if ($duration > 0);
} }
elsif ($cmd eq "dim") elsif ($cmd eq "dim")
{ {
return "Value of $cmd has to be between 1 and 100" if ($value !~ /^(\d+)$/ || int($1) > 100 || int($1) < 1); return "Value of $cmd has to be between 1 and 100"
if ($value !~ /^(\d+)$/ || int($1) > 100 || int($1) < 1);
my $rgb = ReadingsVal($name,"rgb","ffffff"); my $rgb = ReadingsVal($name,"rgb","ffffff");
$value = $value + 1 if ($cmd eq "dim" && $value < 100); $value = $value + 1
if ($cmd eq "dim" && $value < 100);
$value = $value / 100; $value = $value / 100;
my ($r,$g,$b) = Color::hex2rgb($rgb); my ($r,$g,$b) = Color::hex2rgb($rgb);
my ($h,$s,$v) = Color::rgb2hsv($r / 255,$g / 255,$b / 255); my ($h,$s,$v) = Color::rgb2hsv($r / 255,$g / 255,$b / 255);
my ($rn,$gn,$bn); my ($rn,$gn,$bn);
($rn,$gn,$bn) = Color::hsv2rgb($h,$s,$value) if ($cmd eq "dim"); ($rn,$gn,$bn) = Color::hsv2rgb($h,$s,$value)
if ($cmd eq "dim");
$rn = int($rn * 255); $rn = int($rn * 255);
$gn = int($gn * 255); $gn = int($gn * 255);
$bn = int($bn * 255); $bn = int($bn * 255);
$obj{color} = [$rn,$gn,$bn]; $obj{color} = [$rn,$gn,$bn];
$obj{command} = "color"; $obj{command} = "color";
$obj{priority} = $priority * 1; $obj{priority} = $priority * 1;
$obj{duration} = $duration * 1000 if ($duration > 0); $obj{duration} = $duration * 1000
if ($duration > 0);
} }
elsif ($cmd eq "dimUp" || $cmd eq "dimDown") elsif ($cmd eq "dimUp" || $cmd eq "dimDown")
{ {
return "Value of $cmd has to be between 1 and 99" if (defined($value) && $value =~ /°(\d+)$/ && int($1) < 1 && int($1) > 99); return "Value of $cmd has to be between 1 and 99"
if (defined($value) && $value =~ /°(\d+)$/ && int($1) < 1 && int($1) > 99);
my $dim = int ReadingsVal($name,"dim",100); my $dim = int ReadingsVal($name,"dim",100);
my $dimStep = (defined $value) ? int $value : int AttrVal($name,"hyperionDimStep",5); my $dimStep = (defined $value) ? int $value : int AttrVal($name,"hyperionDimStep",5);
my $dimUp = ($dim + $dimStep < 100) ? $dim + $dimStep : 100; my $dimUp = ($dim + $dimStep < 100) ? $dim + $dimStep : 100;
my $dimDown = ($dim - $dimStep > 0) ? $dim - $dimStep : 0; my $dimDown = ($dim - $dimStep > 0) ? $dim - $dimStep : 0;
fhem "set $name dim $dimUp" if ($cmd eq "dimUp"); fhem "set $name dim $dimUp"
fhem "set $name dim $dimDown" if ($cmd eq "dimDown"); if ($cmd eq "dimUp");
fhem "set $name dim $dimDown"
if ($cmd eq "dimDown");
return undef; return undef;
} }
elsif ($cmd eq "effect") elsif ($cmd eq "effect")
{ {
return "Effect $value is not available in the effect list of $name!" if ($value !~ /^(\w+)?((_)\w+){0,}$/ || index(ReadingsVal($name,".effects",""),$value) == -1); return "Effect $value is not available in the effect list of $name!"
if ($value !~ /^(\w+)?((_)\w+){0,}$/ || index(ReadingsVal($name,".effects",""),$value) == -1);
$value =~ s/_/ /g; $value =~ s/_/ /g;
my %ef = ("name" => $value); my %ef = ("name" => $value);
$obj{effect} = \%ef; $obj{effect} = \%ef;
$obj{command} = "effect"; $obj{command} = "effect";
$obj{priority} = $priority * 1; $obj{priority} = $priority * 1;
$obj{duration} = $duration * 1000 if ($duration > 0); $obj{duration} = $duration * 1000
if ($duration > 0);
} }
elsif ($cmd eq "clearall") 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; $obj{command} = $cmd;
} }
elsif ($cmd eq "clear") elsif ($cmd eq "clear")
{ {
return "Value of $cmd has to be between 0 and 65536 in steps of 1" if ($value !~ /^(\d+)$/ || int $1 < 0 || int $1 > 65536); return "Value of $cmd has to be between 0 and 65536 in steps of 1"
if ($value !~ /^(\d+)$/ || int $1 < 0 || int $1 > 65536);
$value = int $value; $value = int $value;
$obj{command} = $cmd; $obj{command} = $cmd;
$obj{priority} = $value * 1; $obj{priority} = $value * 1;
} }
elsif ($cmd eq "off") 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{command} = "color";
$obj{color} = [0,0,0]; $obj{color} = [0,0,0];
$obj{priority} = 0; $obj{priority} = 0;
} }
elsif ($cmd eq "on") 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 $rmode = ReadingsVal($name,"mode_before_off","rgb");
my $rrgb = ReadingsVal($name,"rgb",""); my $rrgb = ReadingsVal($name,"rgb","");
my $reffect = ReadingsVal($name,"effect",""); my $reffect = ReadingsVal($name,"effect","");
@ -618,21 +676,16 @@ sub Hyperion_Set($@)
} }
elsif ($cmd eq "toggle") 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); my $rstate = Value($name);
if ($rstate ne "off") ($rstate ne "off") ? fhem "set ".$name." off" : fhem "set ".$name." on";
{
fhem "set ".$name." off";
}
else
{
fhem "set ".$name." on";
}
return undef; return undef;
} }
elsif ($cmd eq "mode") 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"; Log3 $name,4,"$name: cmd: $cmd, value: $value";
my $rmode = $value; my $rmode = $value;
my $rrgb = ReadingsVal($name,"rgb",""); my $rrgb = ReadingsVal($name,"rgb","");
@ -663,7 +716,8 @@ sub Hyperion_Set($@)
$cmd eq "valueGain" $cmd eq "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); 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; $value = sprintf("%.3f",$value) * 1;
my %tr = ($cmd => $value); my %tr = ($cmd => $value);
$obj{command} = "transform"; $obj{command} = "transform";
@ -675,7 +729,8 @@ sub Hyperion_Set($@)
$cmd eq "whitelevel" $cmd eq "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); 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"); my $arr = Hyperion_list2array($value,"%.3f");
my %ar = ($cmd => $arr); my %ar = ($cmd => $arr);
$obj{command} = "transform"; $obj{command} = "transform";
@ -684,7 +739,8 @@ sub Hyperion_Set($@)
elsif ($cmd eq "correction" || $cmd eq "colorTemperature") elsif ($cmd eq "correction" || $cmd eq "colorTemperature")
{ {
$cmd = "temperature" if ($cmd eq "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); 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);
my $arr = Hyperion_list2array($value,"%d"); my $arr = Hyperion_list2array($value,"%d");
my %ar = ("correctionValues" => $arr); my %ar = ("correctionValues" => $arr);
$obj{command} = $cmd; $obj{command} = $cmd;
@ -695,7 +751,8 @@ sub Hyperion_Set($@)
$cmd eq "adjustBlue" $cmd eq "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); 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"); $cmd = "redAdjust" if ($cmd eq "adjustRed");
$cmd = "greenAdjust" if ($cmd eq "adjustGreen"); $cmd = "greenAdjust" if ($cmd eq "adjustGreen");
$cmd = "blueAdjust" if ($cmd eq "adjustBlue"); $cmd = "blueAdjust" if ($cmd eq "adjustBlue");
@ -753,15 +810,18 @@ sub Hyperion_Attr(@)
} }
elsif ($attr_name eq "hyperionDefaultPriority" || $attr_name eq "hyperionDefaultDuration") elsif ($attr_name eq "hyperionDefaultPriority" || $attr_name eq "hyperionDefaultDuration")
{ {
$err = "Invalid value $attr_value for attribute $attr_name. Must be a number between 0 and 65536." if ($attr_value !~ /^(\d+)$/ || $1 < 0 || $1 > 65536); $err = "Invalid value $attr_value for attribute $attr_name. Must be a number between 0 and 65536."
if ($attr_value !~ /^(\d+)$/ || $1 < 0 || $1 > 65536);
} }
elsif ($attr_name eq "hyperionDimStep") elsif ($attr_name eq "hyperionDimStep")
{ {
$err = "Invalid value $attr_value for attribute $attr_name. Must be between 1 and 50 in steps of 1, default is 5." if ($attr_value !~ /^(\d+)$/ || $1 < 1 || $1 > 50); $err = "Invalid value $attr_value for attribute $attr_name. Must be between 1 and 50 in steps of 1, default is 5."
if ($attr_value !~ /^(\d+)$/ || $1 < 1 || $1 > 50);
} }
elsif ($attr_name eq "hyperionNoSudo") elsif ($attr_name eq "hyperionNoSudo")
{ {
$err = "Invalid value $attr_value for attribute $attr_name. Can only be value 1." if ($attr_value !~ /^1$/); $err = "Invalid value $attr_value for attribute $attr_name. Can only be value 1."
if ($attr_value !~ /^1$/);
} }
elsif ($attr_name eq "hyperionSshUser") elsif ($attr_name eq "hyperionSshUser")
{ {
@ -777,7 +837,8 @@ sub Hyperion_Attr(@)
} }
elsif ($attr_name eq "hyperionVersionCheck") elsif ($attr_name eq "hyperionVersionCheck")
{ {
$err = "Invalid value $attr_value for attribute $attr_name. Can only be value 0." if ($attr_value !~ /^0$/); $err = "Invalid value $attr_value for attribute $attr_name. Can only be value 0."
if ($attr_value !~ /^0$/);
} }
elsif ($attr_name eq "queryAfterSet") elsif ($attr_name eq "queryAfterSet")
{ {
@ -821,17 +882,24 @@ sub Hyperion_devStateIcon($;$)
my $rgb = ReadingsVal($name,"rgb",""); my $rgb = ReadingsVal($name,"rgb","");
my $dim = ReadingsVal($name,"dim",10); my $dim = ReadingsVal($name,"dim",10);
my $ico = (int($dim / 10) * 10 < 10) ? 10 : int($dim / 10) * 10; my $ico = (int($dim / 10) * 10 < 10) ? 10 : int($dim / 10) * 10;
return ".*:off:toggle" if (Value($name) eq "off"); return ".*:off:toggle"
return ".*:light_exclamation" if (Value($name) eq "ERROR"); if (Value($name) eq "off");
return ".*:light_question" if (Value($name) eq "Initialized"); return ".*:light_exclamation"
return ".*:light_light_dim_$ico@#".$rgb.":toggle" if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "rgb"); if (Value($name) eq "ERROR");
return ".*:light_led_stripe_rgb@#FFFF00:toggle" if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "effect"); return ".*:light_question"
return ".*:it_television@#0000FF:toggle" if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "clearall"); if (Value($name) eq "Initialized");
return ".*:light_light_dim_$ico@#".$rgb.":toggle"
if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "rgb");
return ".*:light_led_stripe_rgb@#FFFF00:toggle"
if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "effect");
return ".*:it_television@#0000FF:toggle"
if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "clearall");
} }
sub Hyperion_readingsBulkUpdateIfChanged($$$) { sub Hyperion_readingsBulkUpdateIfChanged($$$) {
my ($hash,$read,$value) = @_; my ($hash,$read,$value) = @_;
readingsBulkUpdate($hash,$read,$value) if ReadingsVal($hash->{NAME},$read,"SomeThingTotallyCrazy") ne $value; readingsBulkUpdate($hash,$read,$value)
if ReadingsVal($hash->{NAME},$read,"SomeThingTotallyCrazy") ne $value;
} }
1; 1;
@ -987,7 +1055,8 @@ sub Hyperion_readingsBulkUpdateIfChanged($$$) {
<ul> <ul>
<li> <li>
<i>configFiles</i><br> <i>configFiles</i><br>
get the available config files in directory from attribute hyperionConfigDir get the available config files in directory from attribute hyperionConfigDir<br>
will only work properly if at least two config files are found
</li> </li>
<li> <li>
<i>devStateIcon</i><br> <i>devStateIcon</i><br>