2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-05 18:16:44 +00:00

98_Hyperion: fix dimUp/dimDown bug, extend use of regex, remove Hyperion_readingsBulkUpdateIfChanged and change to readingsBulkUpdate

git-svn-id: https://svn.fhem.de/fhem/trunk@12313 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
deespe 2016-10-10 19:38:58 +00:00
parent df87e5452b
commit d66affdb2f

View File

@ -243,8 +243,8 @@ sub Hyperion_Read($)
Log3 $name, 1, $error; Log3 $name, 1, $error;
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash,"serverResponse","ERROR"); readingsBulkUpdate($hash,"serverResponse","ERROR");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","ERROR"); readingsBulkUpdate($hash,"state","ERROR");
Hyperion_readingsBulkUpdateIfChanged($hash,"lastError",$error); readingsBulkUpdate($hash,"lastError",$error);
readingsEndUpdate($hash,1); readingsEndUpdate($hash,1);
return undef; return undef;
} }
@ -320,34 +320,32 @@ sub Hyperion_Read($)
$hash->{build_time} = $data->{hyperion_build}->[0]->{time} $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})); 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); readingsBulkUpdate($hash,"adjustRed",$adjR);
Hyperion_readingsBulkUpdateIfChanged($hash,"adjustGreen",$adjG); readingsBulkUpdate($hash,"adjustGreen",$adjG);
Hyperion_readingsBulkUpdateIfChanged($hash,"adjustBlue",$adjB); readingsBulkUpdate($hash,"adjustBlue",$adjB);
Hyperion_readingsBulkUpdateIfChanged($hash,"blacklevel",$blkL); readingsBulkUpdate($hash,"blacklevel",$blkL);
Hyperion_readingsBulkUpdateIfChanged($hash,"colorTemperature",$temP); readingsBulkUpdate($hash,"colorTemperature",$temP);
Hyperion_readingsBulkUpdateIfChanged($hash,"correction",$corS); readingsBulkUpdate($hash,"correction",$corS);
Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0]) readingsBulkUpdate($hash,"effect",(split(",",$effectList))[0])
if (!defined ReadingsVal($name,"effect",undef)); if (!defined ReadingsVal($name,"effect",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,"effect",(split(",",$effectList))[0]) readingsBulkUpdate($hash,".effects", $effectList)
if (!defined ReadingsVal($name,"effect",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,".effects", $effectList)
if ($effectList); if ($effectList);
Hyperion_readingsBulkUpdateIfChanged($hash,"duration",$duration); readingsBulkUpdate($hash,"duration",$duration);
Hyperion_readingsBulkUpdateIfChanged($hash,"gamma",$gamM); readingsBulkUpdate($hash,"gamma",$gamM);
Hyperion_readingsBulkUpdateIfChanged($hash,"id",$id); readingsBulkUpdate($hash,"id",$id);
Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceGain",$lumG); readingsBulkUpdate($hash,"luminanceGain",$lumG);
Hyperion_readingsBulkUpdateIfChanged($hash,"luminanceMinimum",$lumM) readingsBulkUpdate($hash,"luminanceMinimum",$lumM)
if ($lumM); if ($lumM);
Hyperion_readingsBulkUpdateIfChanged($hash,"priority",$prio) readingsBulkUpdate($hash,"priority",$prio)
if (defined $prio); if (defined $prio);
Hyperion_readingsBulkUpdateIfChanged($hash,"rgb","ff0d0d") readingsBulkUpdate($hash,"rgb","ff0d0d")
if (!defined ReadingsVal($name,"rgb",undef)); if (!defined ReadingsVal($name,"rgb",undef));
Hyperion_readingsBulkUpdateIfChanged($hash,"saturationGain",$satG); readingsBulkUpdate($hash,"saturationGain",$satG);
Hyperion_readingsBulkUpdateIfChanged($hash,"saturationLGain",$satL) readingsBulkUpdate($hash,"saturationLGain",$satL)
if ($satL); if ($satL);
Hyperion_readingsBulkUpdateIfChanged($hash,"threshold",$thrE); readingsBulkUpdate($hash,"threshold",$thrE);
Hyperion_readingsBulkUpdateIfChanged($hash,"valueGain",$valG); readingsBulkUpdate($hash,"valueGain",$valG);
Hyperion_readingsBulkUpdateIfChanged($hash,"whitelevel",$whiL); readingsBulkUpdate($hash,"whitelevel",$whiL);
if ($script) if ($script)
{ {
my $args = $data->{activeEffects}->[0]->{args}; my $args = $data->{activeEffects}->[0]->{args};
@ -363,10 +361,10 @@ sub Hyperion_Read($)
{ {
my $en = $e->{name}; my $en = $e->{name};
$en =~ s/ /_/g; $en =~ s/ /_/g;
Hyperion_readingsBulkUpdateIfChanged($hash,"effect",$en); readingsBulkUpdate($hash,"effect",$en);
Hyperion_readingsBulkUpdateIfChanged($hash,"mode","effect"); readingsBulkUpdate($hash,"mode","effect");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","effect $en"); readingsBulkUpdate($hash,"state","effect $en");
Hyperion_readingsBulkUpdateIfChanged($hash,"mode_before_off","effect"); readingsBulkUpdate($hash,"mode_before_off","effect");
Log3 $name,4,"$name: effect $en"; Log3 $name,4,"$name: effect $en";
} }
} }
@ -379,26 +377,26 @@ sub Hyperion_Read($)
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 $dim = int($v * 100); my $dim = int($v * 100);
Hyperion_readingsBulkUpdateIfChanged($hash,"rgb",$rgb); readingsBulkUpdate($hash,"rgb",$rgb);
Hyperion_readingsBulkUpdateIfChanged($hash,"dim",$dim); readingsBulkUpdate($hash,"dim",$dim);
Hyperion_readingsBulkUpdateIfChanged($hash,"mode","rgb"); readingsBulkUpdate($hash,"mode","rgb");
Hyperion_readingsBulkUpdateIfChanged($hash,"mode_before_off","rgb"); readingsBulkUpdate($hash,"mode_before_off","rgb");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","rgb $rgb"); readingsBulkUpdate($hash,"state","rgb $rgb");
Log3 $name,4,"$name: rgb $rgb"; Log3 $name,4,"$name: rgb $rgb";
} }
else else
{ {
if ($prio) if ($prio)
{ {
Hyperion_readingsBulkUpdateIfChanged($hash,"mode","clearall"); readingsBulkUpdate($hash,"mode","clearall");
Hyperion_readingsBulkUpdateIfChanged($hash,"mode_before_off","clearall"); readingsBulkUpdate($hash,"mode_before_off","clearall");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","clearall"); readingsBulkUpdate($hash,"state","clearall");
Log3 $name,4,"$name: clearall"; Log3 $name,4,"$name: clearall";
} }
else else
{ {
Hyperion_readingsBulkUpdateIfChanged($hash,"mode","off"); readingsBulkUpdate($hash,"mode","off");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","off"); readingsBulkUpdate($hash,"state","off");
Log3 $name,4,"$name: off"; Log3 $name,4,"$name: off";
} }
} }
@ -409,9 +407,9 @@ sub Hyperion_Read($)
{ {
Log3 $name,4,"$name: error while requesting ".$hash->{DeviceName}." - $result"; Log3 $name,4,"$name: error while requesting ".$hash->{DeviceName}." - $result";
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
Hyperion_readingsBulkUpdateIfChanged($hash,"lastError","error while requesting ".$hash->{DeviceName}); readingsBulkUpdate($hash,"lastError","error while requesting ".$hash->{DeviceName});
readingsBulkUpdate($hash,"serverResponse","ERROR"); readingsBulkUpdate($hash,"serverResponse","ERROR");
Hyperion_readingsBulkUpdateIfChanged($hash,"state","ERROR") readingsBulkUpdate($hash,"state","ERROR")
if (Value($name) ne "ERROR"); if (Value($name) ne "ERROR");
} }
return undef; return undef;
@ -595,10 +593,10 @@ sub Hyperion_Set($@)
$obj{duration} = $duration * 1000 $obj{duration} = $duration * 1000
if ($duration > 0); if ($duration > 0);
} }
elsif ($cmd eq "dimUp" || $cmd eq "dimDown") elsif ($cmd =~ /^(dimUp|dimDown)$/)
{ {
return "Value of $cmd has to be between 1 and 99" return "Value of $cmd has to be between 1 and 99"
if (defined($value) && $value =~ /°(\d+)$/ && int($1) < 1 && int($1) > 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;
@ -700,12 +698,7 @@ sub Hyperion_Set($@)
} }
return undef; return undef;
} }
elsif ( $cmd eq "luminanceGain" || elsif ($cmd =~ /^(luminanceGain|luminanceMinimum|saturationGain|saturationLGain|valueGain)$/)
$cmd eq "luminanceMinimum" ||
$cmd eq "saturationGain" ||
$cmd eq "saturationLGain" ||
$cmd eq "valueGain"
)
{ {
return "The value of $cmd has to be between 0.000 an 1.999 in steps of 0.001." 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); if ($value !~ /^(\d)(\.\d)?(\d{1,2})?$/ || int $1 > 1);
@ -714,11 +707,7 @@ sub Hyperion_Set($@)
$obj{command} = "transform"; $obj{command} = "transform";
$obj{transform} = \%tr; $obj{transform} = \%tr;
} }
elsif ( $cmd eq "blacklevel" || elsif ($cmd =~ /^(blacklevel|gamma|threshold|whitelevel)$/)
$cmd eq "gamma" ||
$cmd eq "threshold" ||
$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" 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); if ($value !~ /^((\d)\.(\d){1,3}),((\d)\.(\d){1,3}),((\d)\.(\d){1,3})$/ || int $1 > 9 || int $4 > 9 || int $7 > 9);
@ -727,9 +716,10 @@ sub Hyperion_Set($@)
$obj{command} = "transform"; $obj{command} = "transform";
$obj{transform} = \%ar; $obj{transform} = \%ar;
} }
elsif ($cmd eq "correction" || $cmd eq "colorTemperature") elsif ($cmd =~ /^(correction|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" 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); 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");
@ -737,10 +727,7 @@ sub Hyperion_Set($@)
$obj{command} = $cmd; $obj{command} = $cmd;
$obj{$cmd} = \%ar; $obj{$cmd} = \%ar;
} }
elsif ( $cmd eq "adjustRed" || elsif ( $cmd =~ /^(adjustRed|adjustGreen|adjustBlue)$/)
$cmd eq "adjustGreen" ||
$cmd eq "adjustBlue"
)
{ {
return "Each of the three comma separated values of $cmd has to be between 0 an 255 in steps of 1" 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); if ($value !~ /^(\d{1,3})?,(\d{1,3})?,(\d{1,3})?$/ || int $1 > 255 || int $2 > 255 || int $3 > 255);
@ -886,12 +873,6 @@ sub Hyperion_devStateIcon($;$)
if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "clearall"); if (Value($name) ne "off" && ReadingsVal($name,"mode","") eq "clearall");
} }
sub Hyperion_readingsBulkUpdateIfChanged($$$) {
my ($hash,$read,$value) = @_;
readingsBulkUpdate($hash,$read,$value)
if ReadingsVal($hash->{NAME},$read,"SomeThingTotallyCrazy") ne $value;
}
1; 1;
=pod =pod