2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

PHTV: simplify code and add new attributes device_id and auth_key

git-svn-id: https://svn.fhem.de/fhem/trunk@13390 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-02-11 14:02:45 +00:00
parent 420ade4a4a
commit 7d579dd715

View File

@ -60,7 +60,7 @@ sub PHTV_Initialize($) {
$hash->{UndefFn} = "PHTV_Undefine"; $hash->{UndefFn} = "PHTV_Undefine";
$hash->{AttrList} = $hash->{AttrList} =
"disable:0,1 timeout sequentialQuery:0,1 drippyFactor:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 inputs ambiHueLeft ambiHueRight ambiHueTop ambiHueBottom ambiHueLatency:150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 jsversion:1,5,6 macaddr:textField model wakeupCmd:textField channelsMax:slider,30,1,200 " "disable:0,1 timeout sequentialQuery:0,1 drippyFactor:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 inputs ambiHueLeft ambiHueRight ambiHueTop ambiHueBottom ambiHueLatency:150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 jsversion:1,5,6 macaddr:textField model wakeupCmd:textField channelsMax:slider,30,1,200 device_id auth_key "
. $readingFnAttributes; . $readingFnAttributes;
$data{RC_layout}{PHTV_SVG} = "PHTV_RClayout_SVG"; $data{RC_layout}{PHTV_SVG} = "PHTV_RClayout_SVG";
@ -95,8 +95,7 @@ sub PHTV_GetStatus($;$) {
my ( $hash, $update ) = @_; my ( $hash, $update ) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $interval = $hash->{INTERVAL}; my $interval = $hash->{INTERVAL};
my $sequential = ( defined( $attr{$name}{sequentialQuery} ) my $sequential = AttrVal( $name, "sequentialQuery", 0 );
&& $attr{$name}{sequentialQuery} == 1 ) ? 1 : 0;
my $querySent = 0; my $querySent = 0;
Log3 $name, 5, "PHTV $name: called function PHTV_GetStatus()"; Log3 $name, 5, "PHTV $name: called function PHTV_GetStatus()";
@ -108,7 +107,7 @@ sub PHTV_GetStatus($;$) {
InternalTimer( gettimeofday() + $interval, "PHTV_GetStatus", $hash, 0 ); InternalTimer( gettimeofday() + $interval, "PHTV_GetStatus", $hash, 0 );
return return
if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} == 1 ); if ( IsDisabled($name) );
# try to fetch only some information to check device availability # try to fetch only some information to check device availability
if ( !$update ) { if ( !$update ) {
@ -198,8 +197,8 @@ sub PHTV_GetStatus($;$) {
# Input alias handling # Input alias handling
# #
if ( defined( $attr{$name}{inputs} ) ) { if ( AttrVal( $name, "inputs", "" ) ne "" ) {
my @inputs = split( ':', $attr{$name}{inputs} ); my @inputs = split( ':', AttrVal( $name, "inputs", ":" ) );
if (@inputs) { if (@inputs) {
foreach (@inputs) { foreach (@inputs) {
@ -253,7 +252,7 @@ sub PHTV_Set($@) {
Log3 $name, 5, "PHTV $name: called function PHTV_Set()"; Log3 $name, 5, "PHTV $name: called function PHTV_Set()";
return "No Argument given" if ( !defined( $a[1] ) ); return "No Argument given" unless ( defined( $a[1] ) );
# depending on current FHEMWEB instance's allowedCommands, # depending on current FHEMWEB instance's allowedCommands,
# restrict set commands if there is "set-user" in it # restrict set commands if there is "set-user" in it
@ -268,8 +267,8 @@ sub PHTV_Set($@) {
} }
# Input alias handling # Input alias handling
if ( defined( $attr{$name}{inputs} ) && $attr{$name}{inputs} ne "" ) { if ( AttrVal( $name, "inputs", "" ) ne "" ) {
my @inputs = split( ':', $attr{$name}{inputs} ); my @inputs = split( ':', AttrVal( $name, "inputs", ":" ) );
$inputs_txt = "-," if ( $state ne "on" ); $inputs_txt = "-," if ( $state ne "on" );
if (@inputs) { if (@inputs) {
@ -434,7 +433,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "ambihue" ) { elsif ( lc( $a[1] ) eq "ambihue" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0 if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
@ -446,10 +445,10 @@ sub PHTV_Set($@) {
if ( lc( $a[2] ) eq "on" ) { if ( lc( $a[2] ) eq "on" ) {
return return
"No configuration found. Please set ambiHue attributes first." "No configuration found. Please set ambiHue attributes first."
if ( !defined( $attr{$name}{ambiHueLeft} ) unless ( AttrVal( $name, "ambiHueLeft", undef )
&& !defined( $attr{$name}{ambiHueRight} ) && AttrVal( $name, "ambiHueRight", undef )
&& !defined( $attr{$name}{ambiHueTop} ) && AttrVal( $name, "ambiHueTop", undef )
&& !defined( $attr{$name}{ambiHueBottom} ) ); && AttrVal( $name, "ambiHueBottom", undef ) );
# enable internal Ambilight color # enable internal Ambilight color
PHTV_SendCommand( $hash, "ambilight/mode", PHTV_SendCommand( $hash, "ambilight/mode",
@ -476,7 +475,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "ambimode" ) { elsif ( lc( $a[1] ) eq "ambimode" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0 if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
@ -509,7 +508,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "ambipreset" ) { elsif ( lc( $a[1] ) eq "ambipreset" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0 if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
@ -683,7 +682,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "rgb" ) { elsif ( lc( $a[1] ) eq "rgb" ) {
Log3 $name, 4, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 4, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0 if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
@ -838,7 +837,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "hue" ) { elsif ( lc( $a[1] ) eq "hue" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0 if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
@ -846,19 +845,17 @@ sub PHTV_Set($@) {
&& ReadingsVal( $name, "ambiLEDRight", 0 ) == 0 && ReadingsVal( $name, "ambiLEDRight", 0 ) == 0
&& ReadingsVal( $name, "ambiLEDTop", 0 ) == 0 ); && ReadingsVal( $name, "ambiLEDTop", 0 ) == 0 );
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( defined( $hash->{READINGS}{rgb}{VAL} ) if ( ReadingsVal( $name, "rgb", "" ) ne "" ) {
&& $hash->{READINGS}{rgb}{VAL} ne "" )
{
my $hsb; my $hsb;
my $hex; my $hex;
if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 65535 ) { if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 65535 ) {
$hsb = PHTV_hex2hsb( $hash->{READINGS}{rgb}{VAL} ); $hsb = PHTV_hex2hsb( ReadingsVal( $name, "rgb", "" ) );
$hex = PHTV_hsb2hex( $a[2], $hsb->{s}, $hsb->{b} ); $hex = PHTV_hsb2hex( $a[2], $hsb->{s}, $hsb->{b} );
Log3 $name, 4, Log3 $name, 4,
"PHTV $name hue - old: " "PHTV $name hue - old: "
. $hash->{READINGS}{rgb}{VAL} . ReadingsVal( $name, "rgb", "" )
. " new: $hex(h=" . " new: $hex(h="
. $a[2] . " s=" . $a[2] . " s="
. $hsb->{s} . " b=" . $hsb->{s} . " b="
@ -881,43 +878,25 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "sat" ) { elsif ( lc( $a[1] ) eq "sat" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
( && ReadingsVal( $name, "ambiLEDLeft", 0 ) == 0
!defined( $hash->{READINGS}{ambiLEDBottom}{VAL} ) && ReadingsVal( $name, "ambiLEDRight", 0 ) == 0
&& !defined( $hash->{READINGS}{ambiLEDLeft}{VAL} ) && ReadingsVal( $name, "ambiLEDTop", 0 ) == 0 );
&& !defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& !defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
)
|| (
(
defined( $hash->{READINGS}{ambiLEDBottom}{VAL} )
&& $hash->{READINGS}{ambiLEDBottom}{VAL} == 0
)
&& ( defined( $hash->{READINGS}{ambiLEDLeft}{VAL} )
&& $hash->{READINGS}{ambiLEDLeft}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& $hash->{READINGS}{ambiLEDRight}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
&& $hash->{READINGS}{ambiLEDTop}{VAL} == 0 )
)
);
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( defined( $hash->{READINGS}{rgb}{VAL} ) if ( ReadingsVal( $name, "rgb", "" ) ne "" ) {
&& $hash->{READINGS}{rgb}{VAL} ne "" )
{
my $hsb; my $hsb;
my $hex; my $hex;
if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 255 ) { if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 255 ) {
$hsb = PHTV_hex2hsb( $hash->{READINGS}{rgb}{VAL} ); $hsb = PHTV_hex2hsb( ReadingsVal( $name, "rgb", "" ) );
$hex = PHTV_hsb2hex( $hsb->{h}, $a[2], $hsb->{b} ); $hex = PHTV_hsb2hex( $hsb->{h}, $a[2], $hsb->{b} );
Log3 $name, 4, Log3 $name, 4,
"PHTV $name sat - old: " "PHTV $name sat - old: "
. $hash->{READINGS}{rgb}{VAL} . ReadingsVal( $name, "rgb", "" )
. " new: $hex(h=" . " new: $hex(h="
. $hsb->{h} . " s=" . $hsb->{h} . " s="
. $a[2] . " b=" . $a[2] . " b="
@ -940,43 +919,25 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "bri" ) { elsif ( lc( $a[1] ) eq "bri" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
( && ReadingsVal( $name, "ambiLEDLeft", 0 ) == 0
!defined( $hash->{READINGS}{ambiLEDBottom}{VAL} ) && ReadingsVal( $name, "ambiLEDRight", 0 ) == 0
&& !defined( $hash->{READINGS}{ambiLEDLeft}{VAL} ) && ReadingsVal( $name, "ambiLEDTop", 0 ) == 0 );
&& !defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& !defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
)
|| (
(
defined( $hash->{READINGS}{ambiLEDBottom}{VAL} )
&& $hash->{READINGS}{ambiLEDBottom}{VAL} == 0
)
&& ( defined( $hash->{READINGS}{ambiLEDLeft}{VAL} )
&& $hash->{READINGS}{ambiLEDLeft}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& $hash->{READINGS}{ambiLEDRight}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
&& $hash->{READINGS}{ambiLEDTop}{VAL} == 0 )
)
);
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( defined( $hash->{READINGS}{rgb}{VAL} ) if ( ReadingsVal( $name, "rgb", "" ) ne "" ) {
&& $hash->{READINGS}{rgb}{VAL} ne "" )
{
my $hsb; my $hsb;
my $hex; my $hex;
if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 255 ) { if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 255 ) {
$hsb = PHTV_hex2hsb( $hash->{READINGS}{rgb}{VAL} ); $hsb = PHTV_hex2hsb( ReadingsVal( $name, "rgb", "" ) );
$hex = PHTV_hsb2hex( $hsb->{h}, $hsb->{s}, $a[2] ); $hex = PHTV_hsb2hex( $hsb->{h}, $hsb->{s}, $a[2] );
Log3 $name, 4, Log3 $name, 4,
"PHTV $name bri - old: " "PHTV $name bri - old: "
. $hash->{READINGS}{rgb}{VAL} . ReadingsVal( $name, "rgb", "" )
. " new: $hex(h=" . " new: $hex(h="
. $hsb->{h} . " s=" . $hsb->{h} . " s="
. $hsb->{s} . " b=" . $hsb->{s} . " b="
@ -999,45 +960,27 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "pct" ) { elsif ( lc( $a[1] ) eq "pct" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
return "Device does not seem to support Ambilight" return "Device does not seem to support Ambilight"
if ( if ( ReadingsVal( $name, "ambiLEDBottom", 0 ) == 0
( && ReadingsVal( $name, "ambiLEDLeft", 0 ) == 0
!defined( $hash->{READINGS}{ambiLEDBottom}{VAL} ) && ReadingsVal( $name, "ambiLEDRight", 0 ) == 0
&& !defined( $hash->{READINGS}{ambiLEDLeft}{VAL} ) && ReadingsVal( $name, "ambiLEDTop", 0 ) == 0 );
&& !defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& !defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
)
|| (
(
defined( $hash->{READINGS}{ambiLEDBottom}{VAL} )
&& $hash->{READINGS}{ambiLEDBottom}{VAL} == 0
)
&& ( defined( $hash->{READINGS}{ambiLEDLeft}{VAL} )
&& $hash->{READINGS}{ambiLEDLeft}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDRight}{VAL} )
&& $hash->{READINGS}{ambiLEDRight}{VAL} == 0 )
&& ( defined( $hash->{READINGS}{ambiLEDTop}{VAL} )
&& $hash->{READINGS}{ambiLEDTop}{VAL} == 0 )
)
);
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( defined( $hash->{READINGS}{rgb}{VAL} ) if ( ReadingsVal( $name, "rgb", "" ) ne "" ) {
&& $hash->{READINGS}{rgb}{VAL} ne "" )
{
my $hsb; my $hsb;
my $bri; my $bri;
my $hex; my $hex;
if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 100 ) { if ( $a[2] =~ m/^\d+$/ && $a[2] >= 0 && $a[2] <= 100 ) {
$hsb = PHTV_hex2hsb( $hash->{READINGS}{rgb}{VAL} ); $hsb = PHTV_hex2hsb( ReadingsVal( $name, "rgb", "" ) );
$bri = PHTV_pct2bri( $a[2] ); $bri = PHTV_pct2bri( $a[2] );
$hex = PHTV_hsb2hex( $hsb->{h}, $hsb->{s}, $bri ); $hex = PHTV_hsb2hex( $hsb->{h}, $hsb->{s}, $bri );
Log3 $name, 4, Log3 $name, 4,
"PHTV $name pct - old: " "PHTV $name pct - old: "
. $hash->{READINGS}{rgb}{VAL} . ReadingsVal( $name, "rgb", "" )
. " new: $hex(h=" . " new: $hex(h="
. $hsb->{h} . " s=" . $hsb->{h} . " s="
. $hsb->{s} . $hsb->{s}
@ -1060,10 +1003,10 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "volume" ) { elsif ( lc( $a[1] ) eq "volume" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
my $vol; my $vol;
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( $a[2] =~ m/^\d+$/ && $a[2] >= 1 && $a[2] <= 100 ) { if ( $a[2] =~ m/^\d+$/ && $a[2] >= 1 && $a[2] <= 100 ) {
if ( defined( $hash->{helper}{audio}{min} ) if ( defined( $hash->{helper}{audio}{min} )
&& defined( $hash->{helper}{audio}{max} ) ) && defined( $hash->{helper}{audio}{max} ) )
@ -1097,10 +1040,10 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "volumestraight" ) { elsif ( lc( $a[1] ) eq "volumestraight" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
return "No argument given" if ( !defined( $a[2] ) ); return "No argument given" unless ( defined( $a[2] ) );
my $vol; my $vol;
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( $a[2] =~ m/^\d+$/ if ( $a[2] =~ m/^\d+$/
&& $a[2] >= $hash->{helper}{audio}{min} && $a[2] >= $hash->{helper}{audio}{min}
&& $a[2] <= $hash->{helper}{audio}{max} ) && $a[2] <= $hash->{helper}{audio}{max} )
@ -1131,7 +1074,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) =~ /^(volumeup|volumedown)$/ ) { elsif ( lc( $a[1] ) =~ /^(volumeup|volumedown)$/ ) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( lc( $a[1] ) eq "volumeup" ) { if ( lc( $a[1] ) eq "volumeup" ) {
$cmd = PHTV_GetRemotecontrolCommand("VOLUP"); $cmd = PHTV_GetRemotecontrolCommand("VOLUP");
} }
@ -1155,25 +1098,25 @@ sub PHTV_Set($@) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
} }
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( !defined( $a[2] ) || $a[2] eq "toggle" ) { if ( !defined( $a[2] ) || $a[2] eq "toggle" ) {
if ( $hash->{READINGS}{mute}{VAL} eq "off" ) { if ( ReadingsVal( $name, "mute", "" ) eq "off" ) {
$cmd = '"muted": true'; $cmd = '"muted": true';
readingsSingleUpdate( $hash, "mute", "on", 1 ); readingsSingleUpdate( $hash, "mute", "on", 1 );
} }
elsif ( $hash->{READINGS}{mute}{VAL} eq "on" ) { elsif ( ReadingsVal( $name, "mute", "" ) eq "on" ) {
$cmd = '"muted": false'; $cmd = '"muted": false';
readingsSingleUpdate( $hash, "mute", "off", 1 ); readingsSingleUpdate( $hash, "mute", "off", 1 );
} }
} }
elsif ( lc( $a[2] ) eq "off" ) { elsif ( lc( $a[2] ) eq "off" ) {
if ( $hash->{READINGS}{mute}{VAL} ne "off" ) { if ( ReadingsVal( $name, "mute", "" ) ne "off" ) {
$cmd = '"muted": false'; $cmd = '"muted": false';
readingsSingleUpdate( $hash, "mute", "off", 1 ); readingsSingleUpdate( $hash, "mute", "off", 1 );
} }
} }
elsif ( lc( $a[2] ) eq "on" ) { elsif ( lc( $a[2] ) eq "on" ) {
if ( $hash->{READINGS}{mute}{VAL} ne "on" ) { if ( ReadingsVal( $name, "mute", "" ) ne "on" ) {
$cmd = '"muted": true'; $cmd = '"muted": true';
readingsSingleUpdate( $hash, "mute", "on", 1 ); readingsSingleUpdate( $hash, "mute", "on", 1 );
} }
@ -1193,8 +1136,8 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "remotecontrol" ) { elsif ( lc( $a[1] ) eq "remotecontrol" ) {
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
if ( $hash->{READINGS}{state}{VAL} ne "absent" ) { if ( ReadingsVal( $name, "state", "absent" ) ne "absent" ) {
if ( !defined( $a[2] ) ) { unless ( defined( $a[2] ) ) {
my $commandKeys = ""; my $commandKeys = "";
for ( for (
sort keys %{ sort keys %{
@ -1248,8 +1191,8 @@ sub PHTV_Set($@) {
# channel # channel
elsif ( lc( $a[1] ) eq "channel" ) { elsif ( lc( $a[1] ) eq "channel" ) {
if ( defined( $a[2] ) if ( defined( $a[2] )
&& $hash->{READINGS}{presence}{VAL} eq "present" && ReadingsVal( $name, "presence", "absent" ) eq "present"
&& $hash->{READINGS}{state}{VAL} ne "on" ) && ReadingsVal( $name, "state", "off" ) ne "on" )
{ {
Log3 $name, 4, "PHTV $name: indirect switching request to ON"; Log3 $name, 4, "PHTV $name: indirect switching request to ON";
PHTV_Set( $hash, $name, "on" ); PHTV_Set( $hash, $name, "on" );
@ -1259,9 +1202,9 @@ sub PHTV_Set($@) {
return return
"No argument given, choose one of channel presetNumber channelName " "No argument given, choose one of channel presetNumber channelName "
if ( !defined( $a[2] ) ); unless ( defined( $a[2] ) );
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
my $channelName = $a[2]; my $channelName = $a[2];
if ( if (
defined( $hash->{helper}{device}{channelID}{$channelName}{id} ) defined( $hash->{helper}{device}{channelID}{$channelName}{id} )
@ -1269,9 +1212,8 @@ sub PHTV_Set($@) {
{ {
$cmd = $hash->{helper}{device}{channelID}{$channelName}{id}; $cmd = $hash->{helper}{device}{channelID}{$channelName}{id};
if ( $hash->{READINGS}{channel}{VAL} ne $channelName ) { readingsSingleUpdate( $hash, "channel", $channelName, 1 )
readingsSingleUpdate( $hash, "channel", $channelName, 1 ); if ( ReadingsVal( $name, "channel", "" ) ne $channelName );
}
} }
elsif ( elsif (
$channelName =~ /^(\d+):(.*):$/ $channelName =~ /^(\d+):(.*):$/
@ -1301,7 +1243,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) =~ /^(channelup|channeldown)$/ ) { elsif ( lc( $a[1] ) =~ /^(channelup|channeldown)$/ ) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
if ( lc( $a[1] ) eq "channelup" ) { if ( lc( $a[1] ) eq "channelup" ) {
$cmd = PHTV_GetRemotecontrolCommand("CHANUP"); $cmd = PHTV_GetRemotecontrolCommand("CHANUP");
} }
@ -1319,14 +1261,14 @@ sub PHTV_Set($@) {
# input # input
elsif ( lc( $a[1] ) eq "input" ) { elsif ( lc( $a[1] ) eq "input" ) {
if ( defined( $a[2] ) if ( defined( $a[2] )
&& $hash->{READINGS}{presence}{VAL} eq "present" && ReadingsVal( $name, "presence", "absent" ) eq "present"
&& $hash->{READINGS}{state}{VAL} ne "on" ) && ReadingsVal( $name, "state", "off" ) ne "on" )
{ {
Log3 $name, 4, "PHTV $name: indirect switching request to ON"; Log3 $name, 4, "PHTV $name: indirect switching request to ON";
PHTV_Set( $hash, $name, "on" ); PHTV_Set( $hash, $name, "on" );
} }
return "No 2nd argument given" if ( !defined( $a[2] ) ); return "No 2nd argument given" unless ( defined( $a[2] ) );
Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2]; Log3 $name, 3, "PHTV set $name " . $a[1] . " " . $a[2];
@ -1346,13 +1288,12 @@ sub PHTV_Set($@) {
return "Unknown source input '" . $a[2] . "' on that device."; return "Unknown source input '" . $a[2] . "' on that device.";
} }
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
PHTV_SendCommand( $hash, "sources/current", PHTV_SendCommand( $hash, "sources/current",
'"id": "' . $input_id . '"', $input_id ); '"id": "' . $input_id . '"', $input_id );
if ( $hash->{READINGS}{input}{VAL} ne $a[2] ) { readingsSingleUpdate( $hash, "input", $a[2], 1 )
readingsSingleUpdate( $hash, "input", $a[2], 1 ); if ( ReadingsVal( $name, "input", "" ) ne $a[2] );
}
} }
else { else {
return "Device needs to be reachable to switch input."; return "Device needs to be reachable to switch input.";
@ -1363,7 +1304,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) =~ /^(play|pause)$/ ) { elsif ( lc( $a[1] ) =~ /^(play|pause)$/ ) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
$cmd = PHTV_GetRemotecontrolCommand("PLAYPAUSE"); $cmd = PHTV_GetRemotecontrolCommand("PLAYPAUSE");
PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' ); PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' );
} }
@ -1376,7 +1317,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "stop" ) { elsif ( lc( $a[1] ) eq "stop" ) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
$cmd = PHTV_GetRemotecontrolCommand("STOP"); $cmd = PHTV_GetRemotecontrolCommand("STOP");
PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' ); PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' );
} }
@ -1389,7 +1330,7 @@ sub PHTV_Set($@) {
elsif ( lc( $a[1] ) eq "record" ) { elsif ( lc( $a[1] ) eq "record" ) {
Log3 $name, 3, "PHTV set $name " . $a[1]; Log3 $name, 3, "PHTV set $name " . $a[1];
if ( $hash->{READINGS}{state}{VAL} eq "on" ) { if ( ReadingsVal( $name, "state", "off" ) eq "on" ) {
$cmd = PHTV_GetRemotecontrolCommand("RECORD"); $cmd = PHTV_GetRemotecontrolCommand("RECORD");
PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' ); PHTV_SendCommand( $hash, "input/key", '"key": "' . $cmd . '"' );
} }
@ -1438,21 +1379,20 @@ sub PHTV_Define($$) {
$hash->{INTERVAL} = $interval; $hash->{INTERVAL} = $interval;
readingsSingleUpdate( $hash, "ambiHue", "off", 0 ) readingsSingleUpdate( $hash, "ambiHue", "off", 0 )
if ( defined( $hash->{READINGS}{ambiHue}{VAL} ) if ( ReadingsVal( $name, "ambiHue", "" ) ne "off" );
&& $hash->{READINGS}{ambiHue}{VAL} ne "off" );
$hash->{model} = $hash->{READINGS}{model}{VAL} $hash->{model} = ReadingsVal( $name, "model", undef )
if ( defined( $hash->{READINGS}{model}{VAL} ) ); if ( ReadingsVal( $name, "model", undef ) );
$hash->{swversion} = $hash->{READINGS}{softwareversion}{VAL} $hash->{swversion} = ReadingsVal( $name, "softwareversion", undef )
if ( defined( $hash->{READINGS}{softwareversion}{VAL} ) ); if ( ReadingsVal( $name, "softwareversion", undef ) );
# set default settings on first define # set default settings on first define
if ( $init_done && !defined( $hash->{OLDDEF} ) ) { if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
$attr{$name}{webCmd} = 'volume:input:rgb'; fhem 'attr ' . $name . ' webCmd volume:input:rgb';
$attr{$name}{devStateIcon} = fhem 'attr ' . $name
'on:rc_GREEN:off off:rc_YELLOW:on absent:rc_STOP:on'; . ' devStateIcon on:rc_GREEN:off off:rc_YELLOW:on absent:rc_STOP:on';
$attr{$name}{icon} = 'it_television'; fhem 'attr ' . $name . ' icon it_television';
} }
# start the status update timer # start the status update timer
@ -1487,6 +1427,8 @@ sub PHTV_SendCommand($$;$$$) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS}; my $address = $hash->{helper}{ADDRESS};
my $protoV = AttrVal( $name, "jsversion", 1 ); my $protoV = AttrVal( $name, "jsversion", 1 );
my $device_id = AttrVal( $name, "device_id", undef );
my $auth_key = AttrVal( $name, "auth_key", undef );
my $timestamp = gettimeofday(); my $timestamp = gettimeofday();
my $data; my $data;
my $timeout; my $timeout;
@ -1539,16 +1481,11 @@ sub PHTV_SendCommand($$;$$$) {
$URL = "http://"; $URL = "http://";
$URL = "https://" if ( $protoV > 5 ); $URL = "https://" if ( $protoV > 5 );
$URL .= "$device_id:$auth_key@" if ( $device_id && $auth_key );
$URL .= $address . "/" . $protoV . "/" . $service; $URL .= $address . "/" . $protoV . "/" . $service;
if ( defined( $attr{$name}{timeout} ) $timeout = AttrVal( $name, "timeout", 7 );
&& $attr{$name}{timeout} =~ /^\d+$/ ) $timeout = 7 unless ( $timeout =~ /^\d+$/ );
{
$timeout = $attr{$name}{timeout};
}
else {
$timeout = 7;
}
# send request via HTTP-POST method # send request via HTTP-POST method
Log3 $name, 5, "PHTV $name: GET " . $URL . " (" . urlDecode($data) . ")" Log3 $name, 5, "PHTV $name: GET " . $URL . " (" . urlDecode($data) . ")"
@ -1556,7 +1493,7 @@ sub PHTV_SendCommand($$;$$$) {
Log3 $name, 5, "PHTV $name: GET " . $URL . " (#HASH)" Log3 $name, 5, "PHTV $name: GET " . $URL . " (#HASH)"
if ( defined($data) && ref($cmd) eq "HASH" ); if ( defined($data) && ref($cmd) eq "HASH" );
Log3 $name, 5, "PHTV $name: GET " . $URL Log3 $name, 5, "PHTV $name: GET " . $URL
if ( !defined($data) ); unless ( defined($data) );
HttpUtils_NonblockingGet( HttpUtils_NonblockingGet(
{ {
@ -1569,6 +1506,7 @@ sub PHTV_SendCommand($$;$$$) {
cmd => $cmd, cmd => $cmd,
type => $type, type => $type,
timestamp => $timestamp, timestamp => $timestamp,
httpversion => "1.1",
callback => \&PHTV_ReceiveCommand, callback => \&PHTV_ReceiveCommand,
} }
); );
@ -1583,13 +1521,9 @@ sub PHTV_ReceiveCommand($$$) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $service = $param->{service}; my $service = $param->{service};
my $cmd = $param->{cmd}; my $cmd = $param->{cmd};
my $sequential = ( defined( $attr{$name}{sequentialQuery} ) my $sequential = AttrVal( $name, "sequentialQuery", 0 );
&& $attr{$name}{sequentialQuery} == 1 ) ? 1 : 0;
my $state = my $state = ReadingsVal( $name, "state", "" );
( $hash->{READINGS}{state}{VAL} )
? $hash->{READINGS}{state}{VAL}
: "";
my $newstate; my $newstate;
my $type = ( $param->{type} ) ? $param->{type} : ""; my $type = ( $param->{type} ) ? $param->{type} : "";
my $return; my $return;
@ -1632,7 +1566,7 @@ sub PHTV_ReceiveCommand($$$) {
$newstate = "on"; $newstate = "on";
# because it does not seem to support the command # because it does not seem to support the command
if ( !defined( $hash->{helper}{supportedAPIcmds}{$service} ) ) { unless ( defined( $hash->{helper}{supportedAPIcmds}{$service} ) ) {
$hash->{helper}{supportedAPIcmds}{$service} = 0; $hash->{helper}{supportedAPIcmds}{$service} = 0;
Log3 $name, 4, Log3 $name, 4,
"PHTV $name: API command '" "PHTV $name: API command '"
@ -1675,9 +1609,10 @@ sub PHTV_ReceiveCommand($$$) {
} }
$hash->{helper}{supportedAPIcmds}{$service} = 1 $hash->{helper}{supportedAPIcmds}{$service} = 1
if ( !defined( $hash->{helper}{supportedAPIcmds}{$service} ) unless (
&& $service !~ /^channels\/.*/ defined( $hash->{helper}{supportedAPIcmds}{$service} )
&& $service !~ /^channellists\/.*/ ); && $service =~ /^channels\/.*/
&& $service =~ /^channellists\/.*/ );
$return = decode_json( Encode::encode_utf8($data) ); $return = decode_json( Encode::encode_utf8($data) );
} }
@ -1694,9 +1629,10 @@ sub PHTV_ReceiveCommand($$$) {
} }
$hash->{helper}{supportedAPIcmds}{$service} = 1 $hash->{helper}{supportedAPIcmds}{$service} = 1
if ( !defined( $hash->{helper}{supportedAPIcmds}{$service} ) unless (
&& $service !~ /^channels\/.*/ defined( $hash->{helper}{supportedAPIcmds}{$service} )
&& $service !~ /^channellists\/.*/ ); && $service =~ /^channels\/.*/
&& $service =~ /^channellists\/.*/ );
$return = "ok"; $return = "ok";
} }
@ -1712,7 +1648,9 @@ sub PHTV_ReceiveCommand($$$) {
. $data; . $data;
} }
if ( !defined( $hash->{helper}{supportedAPIcmds}{$service} ) ) { unless (
defined( $hash->{helper}{supportedAPIcmds}{$service} ) )
{
$hash->{helper}{supportedAPIcmds}{$service} = 0; $hash->{helper}{supportedAPIcmds}{$service} = 0;
Log3 $name, 4, Log3 $name, 4,
"PHTV $name: API command '" "PHTV $name: API command '"
@ -1791,14 +1729,14 @@ sub PHTV_ReceiveCommand($$$) {
# and user set attribut for lazy devices # and user set attribut for lazy devices
if ( $newstate eq "on" if ( $newstate eq "on"
&& $newstate ne $state && $newstate ne $state
&& defined( $attr{$name}{drippyFactor} ) && AttrVal( $name, "drippyFactor", -1 ) ge 0 )
&& $attr{$name}{drippyFactor} ne ""
&& $attr{$name}{drippyFactor} ge 0 )
{ {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
InternalTimer( InternalTimer(
gettimeofday() + $attr{$name}{drippyFactor}, gettimeofday() +
"PHTV_GetStatus", $hash, 1 ); AttrVal( $name, "drippyFactor", 0 ),
"PHTV_GetStatus", $hash, 1
);
} }
else { else {
PHTV_GetStatus( $hash, 1 ); PHTV_GetStatus( $hash, 1 );
@ -1873,7 +1811,7 @@ sub PHTV_ReceiveCommand($$$) {
$hash->{helper}{device}{sourceID}{$input_name} = $input; $hash->{helper}{device}{sourceID}{$input_name} = $input;
$inputs .= $input_name . ":"; $inputs .= $input_name . ":";
} }
if ( !defined( $attr{$name}{inputs} ) ) { unless ( defined( AttrVal( $name, "inputs", undef ) ) ) {
$inputs = substr( $inputs, 0, -1 ); $inputs = substr( $inputs, 0, -1 );
$attr{$name}{inputs} = $inputs; $attr{$name}{inputs} = $inputs;
} }
@ -2098,7 +2036,7 @@ sub PHTV_ReceiveCommand($$$) {
} }
# read all channellists if not existing # read all channellists if not existing
if ( !defined( $hash->{helper}{device}{channellists} ) ) { unless ( defined( $hash->{helper}{device}{channellists} ) ) {
PHTV_SendCommand( $hash, "channellists" ); PHTV_SendCommand( $hash, "channellists" );
$hash->{helper}{sequentialQueryCounter}++ if $sequential; $hash->{helper}{sequentialQueryCounter}++ if $sequential;
} }
@ -2268,7 +2206,7 @@ sub PHTV_ReceiveCommand($$$) {
} }
elsif ( $return eq "ok" ) { elsif ( $return eq "ok" ) {
if ( $type =~ /^(..)(..)(..)$/ if ( $type =~ /^(..)(..)(..)$/
&& defined( $hash->{READINGS}{ambiLEDLayers}{VAL} ) ) && ReadingsVal( $name, "ambiLEDLayers", undef ) )
{ {
my $hsb = PHTV_hex2hsb($type); my $hsb = PHTV_hex2hsb($type);
my $hue = $hsb->{h}; my $hue = $hsb->{h};
@ -2283,10 +2221,10 @@ sub PHTV_ReceiveCommand($$$) {
readingsBulkUpdateIfChanged( $hash, "pct", $pct ); readingsBulkUpdateIfChanged( $hash, "pct", $pct );
readingsBulkUpdateIfChanged( $hash, "level", $pct . " %" ); readingsBulkUpdateIfChanged( $hash, "level", $pct . " %" );
if ( defined( $hash->{READINGS}{ambiLEDLayers}{VAL} ) ) { if ( ReadingsVal( $name, "ambiLEDLayers", undef ) ) {
my $layer = 1; my $layer = 1;
while ( while ( $layer <=
$layer <= $hash->{READINGS}{ambiLEDLayers}{VAL} ) ReadingsVal( $name, "ambiLEDLayers", undef ) )
{ {
foreach foreach
@ -2302,13 +2240,11 @@ sub PHTV_ReceiveCommand($$$) {
$s =~ s/right/R/ if ( $side eq "right" ); $s =~ s/right/R/ if ( $side eq "right" );
$s =~ s/bottom/B/ if ( $side eq "bottom" ); $s =~ s/bottom/B/ if ( $side eq "bottom" );
if ( defined( $hash->{READINGS}{$ambiLED}{VAL} ) if ( ReadingsVal( $name, $ambiLED, 0 ) > 0 ) {
&& $hash->{READINGS}{$ambiLED}{VAL} > 0 )
{
my $led = 0; my $led = 0;
while ( $led <= while ( $led <=
$hash->{READINGS}{$ambiLED}{VAL} - 1 ) ReadingsVal( $name, $ambiLED, 0 ) - 1 )
{ {
my $readingname = my $readingname =
"rgb_" . $l . $s . $led; "rgb_" . $l . $s . $led;
@ -2338,21 +2274,18 @@ sub PHTV_ReceiveCommand($$$) {
# run ambiHue # run ambiHue
if ( if (
( (
$hash->{READINGS}{ambiHue}{VAL} eq "on" ReadingsVal( $name, "ambiHue", "off" ) eq "on"
|| $type eq "init" || $type eq "init"
) )
&& ( defined( $attr{$name}{ambiHueLeft} ) && ( defined( AttrVal( $name, "ambiHueLeft", undef ) )
|| defined( $attr{$name}{ambiHueRight} ) || defined( AttrVal( $name, "ambiHueRight", undef ) )
|| defined( $attr{$name}{ambiHueTop} ) || defined( AttrVal( $name, "ambiHueTop", undef ) )
|| defined( $attr{$name}{ambiHueBottom} ) ) || defined( AttrVal( $name, "ambiHueBottom", undef ) ) )
) )
{ {
my $transitiontime = my $transitiontime = int(
( $attr{$name}{ambiHueLatency} ) AttrVal( $name, "ambiHueLatency", 300 ) / 100 + 0.5 );
? int( $attr{$name}{ambiHueLatency} / 100 + 0.5 )
: 3;
$transitiontime = 3 if ( $transitiontime < 3 ); $transitiontime = 3 if ( $transitiontime < 3 );
foreach my $side ( 'Left', 'Top', 'Right', 'Bottom' ) { foreach my $side ( 'Left', 'Top', 'Right', 'Bottom' ) {
@ -2361,15 +2294,13 @@ sub PHTV_ReceiveCommand($$$) {
my $s = lc($side); my $s = lc($side);
# $ambiHue # $ambiHue
if ( defined( $attr{$name}{$ambiHue} ) if ( AttrVal( $name, $ambiHue, "" ) ne ""
&& $attr{$name}{$ambiHue} ne ""
&& defined( $return->{layer1}->{$s} ) && defined( $return->{layer1}->{$s} )
&& ref( $return->{layer1}->{$s} ) eq "HASH" && ref( $return->{layer1}->{$s} ) eq "HASH"
&& defined( $hash->{READINGS}{$ambiLED}{VAL} ) && ReadingsVal( $name, $ambiLED, 0 ) > 0 )
&& $hash->{READINGS}{$ambiLED}{VAL} > 0 )
{ {
my @devices = my @devices =
split( " ", $attr{$name}{$ambiHue} ); split( " ", AttrVal( $name, $ambiHue, "" ) );
Log3 $name, 5, Log3 $name, 5,
"PHTV $name: processing devices from attribute $ambiHue"; "PHTV $name: processing devices from attribute $ambiHue";
@ -2393,7 +2324,7 @@ sub PHTV_ReceiveCommand($$$) {
if ( !defined( $defs{$dev} ) if ( !defined( $defs{$dev} )
|| !defined( $defs{$dev}{TYPE} ) || !defined( $defs{$dev}{TYPE} )
|| $defs{$dev}{TYPE} ne "HUEDevice" || $defs{$dev}{TYPE} ne "HUEDevice"
|| $defs{$dev}{READINGS}{reachable}{VAL} ne || ReadingsVal( $dev, "reachable", 0 ) ne
"1" ) "1" )
{ {
Log3 $name, 5, Log3 $name, 5,
@ -2404,7 +2335,7 @@ sub PHTV_ReceiveCommand($$$) {
# determine reference LEDs # determine reference LEDs
if ( !defined($led) || $led eq "" ) { if ( !defined($led) || $led eq "" ) {
my $led_middle = int( my $led_middle = int(
$hash->{READINGS}{$ambiLED}{VAL} / 2 + ReadingsVal( $name, $ambiLED, 0 ) / 2 +
0.5 ) - 1; 0.5 ) - 1;
# take the middle LED and # take the middle LED and
@ -2532,12 +2463,9 @@ sub PHTV_ReceiveCommand($$$) {
} }
# temp. disable event triggers for HUEDevice # temp. disable event triggers for HUEDevice
if ( unless (
!defined( AttrVal( $dev, "event-on-change-reading",
$attr{$dev}{"event-on-change-reading"} "" ) eq "none"
)
|| $attr{$dev}{"event-on-change-reading"}
ne "none"
) )
{ {
$attr{$dev}{"event-on-change-reading"} = $attr{$dev}{"event-on-change-reading"} =
@ -2633,9 +2561,7 @@ sub PHTV_ReceiveCommand($$$) {
my $duration = gettimeofday() - $param->{timestamp}; my $duration = gettimeofday() - $param->{timestamp};
my $minLatency = my $minLatency =
( $attr{$name}{ambiHueLatency} ) AttrVal( $name, "ambiHueLatency", 200 ) / 1000;
? $attr{$name}{ambiHueLatency} / 1000
: 0.20;
my $waittime = $minLatency - $duration; my $waittime = $minLatency - $duration;
# latency compensation # latency compensation
@ -2654,11 +2580,12 @@ sub PHTV_ReceiveCommand($$$) {
# cleanup after stopping ambiHue # cleanup after stopping ambiHue
elsif ( elsif (
$hash->{READINGS}{ambiHue}{VAL} eq "off" ReadingsVal( $name, "ambiHue", "off" ) eq "off"
|| ( !defined( $attr{$name}{ambiHueLeft} ) || ( !defined( AttrVal( $name, "ambiHueLeft", undef ) )
&& !defined( $attr{$name}{ambiHueRight} ) && !defined( AttrVal( $name, "ambiHueRight", undef ) )
&& !defined( $attr{$name}{ambiHueTop} ) && !defined( AttrVal( $name, "ambiHueTop", undef ) )
&& !defined( $attr{$name}{ambiHueBottom} ) ) && !defined( AttrVal( $name, "ambiHueBottom", undef ) )
)
) )
{ {
delete $hash->{helper}{ambiHueDelay}; delete $hash->{helper}{ambiHueDelay};
@ -2667,11 +2594,9 @@ sub PHTV_ReceiveCommand($$$) {
readingsBulkUpdateIfChanged( $hash, "ambiHue", "off" ); readingsBulkUpdateIfChanged( $hash, "ambiHue", "off" );
# ambiHueLeft # ambiHueLeft
if ( defined( $attr{$name}{ambiHueLeft} ) if ( AttrVal( $name, "ambiHueLeft", "" ) ne "" ) {
&& $attr{$name}{ambiHueLeft} ne "" )
{
my @devices = my @devices =
split( " ", $attr{$name}{ambiHueLeft} ); split( " ", AttrVal( $name, "ambiHueLeft", "" ) );
foreach (@devices) { foreach (@devices) {
my ( $dev, $led ) = split( /:/, $_ ); my ( $dev, $led ) = split( /:/, $_ );
@ -2684,11 +2609,9 @@ sub PHTV_ReceiveCommand($$$) {
} }
# ambiHueTop # ambiHueTop
if ( defined( $attr{$name}{ambiHueTop} ) if ( AttrVal( $name, "ambiHueTop", "" ) ne "" ) {
&& $attr{$name}{ambiHueTop} ne "" )
{
my @devices = my @devices =
split( " ", $attr{$name}{ambiHueTop} ); split( " ", AttrVal( $name, "ambiHueTop", "" ) );
foreach (@devices) { foreach (@devices) {
my ( $dev, $led ) = split( /:/, $_ ); my ( $dev, $led ) = split( /:/, $_ );
@ -2701,11 +2624,9 @@ sub PHTV_ReceiveCommand($$$) {
} }
# ambiHueRight # ambiHueRight
if ( defined( $attr{$name}{ambiHueRight} ) if ( AttrVal( $name, "ambiHueRight", "" ) ne "" ) {
&& $attr{$name}{ambiHueRight} ne "" )
{
my @devices = my @devices =
split( " ", $attr{$name}{ambiHueRight} ); split( " ", AttrVal( $name, "ambiHueRight", "" ) );
foreach (@devices) { foreach (@devices) {
my ( $dev, $led ) = split( /:/, $_ ); my ( $dev, $led ) = split( /:/, $_ );
@ -2718,9 +2639,7 @@ sub PHTV_ReceiveCommand($$$) {
} }
# ambiHueBottom # ambiHueBottom
if ( defined( $attr{$name}{ambiHueBottom} ) if ( AttrVal( $name, "ambiHueBottom", "" ) ne "" ) {
&& $attr{$name}{ambiHueBottom} ne "" )
{
my @devices = my @devices =
split( " ", $attr{$name}{ambiHueBottom} ); split( " ", $attr{$name}{ambiHueBottom} );
@ -2786,9 +2705,9 @@ sub PHTV_ReceiveCommand($$$) {
readingsBulkUpdateIfChanged( $hash, "pct", "0" ); readingsBulkUpdateIfChanged( $hash, "pct", "0" );
readingsBulkUpdateIfChanged( $hash, "level", "0 %" ); readingsBulkUpdateIfChanged( $hash, "level", "0 %" );
if ( defined( $hash->{READINGS}{ambiLEDLayers}{VAL} ) ) { if ( ReadingsVal( $name, "ambiLEDLayers", undef ) ) {
my $layer = 1; my $layer = 1;
while ( $layer <= $hash->{READINGS}{ambiLEDLayers}{VAL} ) { while ( $layer <= ReadingsVal( $name, "ambiLEDLayers", undef ) ) {
foreach my $side ( 'Left', 'Top', 'Right', 'Bottom' ) { foreach my $side ( 'Left', 'Top', 'Right', 'Bottom' ) {
my $ambiLED = "ambiLED$side"; my $ambiLED = "ambiLED$side";
@ -2801,12 +2720,11 @@ sub PHTV_ReceiveCommand($$$) {
$s =~ s/right/R/ if ( $side eq "right" ); $s =~ s/right/R/ if ( $side eq "right" );
$s =~ s/bottom/B/ if ( $side eq "bottom" ); $s =~ s/bottom/B/ if ( $side eq "bottom" );
if ( defined( $hash->{READINGS}{$ambiLED}{VAL} ) if ( ReadingsVal( $name, $ambiLED, 0 ) > 0 ) {
&& $hash->{READINGS}{$ambiLED}{VAL} > 0 )
{
my $led = 0; my $led = 0;
while ( $led <= $hash->{READINGS}{$ambiLED}{VAL} - 1 ) { while ( $led <= ReadingsVal( $name, $ambiLED, 0 ) - 1 )
{
my $readingname = "rgb_" . $l . $s . $led; my $readingname = "rgb_" . $l . $s . $led;
readingsBulkUpdateIfChanged( $hash, readingsBulkUpdateIfChanged( $hash,
@ -2872,10 +2790,7 @@ sub PHTV_GetStateAV($) {
sub PHTV_wake ($) { sub PHTV_wake ($) {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $mac_addr = my $mac_addr = AttrVal( $name, "macaddr", "-" );
( defined( $attr{$name}{macaddr} ) )
? $attr{$name}{macaddr}
: "-";
my $address = '255.255.255.255'; my $address = '255.255.255.255';
my $port = 9; my $port = 9;