mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
30_HUEBridge.pm, 31_HUEDevice.pm: handle duplicate group names in fhemweb dropdown, show group names in light list if possible
git-svn-id: https://svn.fhem.de/fhem/trunk@19478 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e7765ddb60
commit
7debdb9be8
@ -488,6 +488,10 @@ HUEBridge_scene2id($$)
|
||||
$hash = $defs{$hash} if( ref($hash) ne 'HASH' );
|
||||
return undef if( !$hash );
|
||||
|
||||
if( $id =~ m/\[id=(.*)\]$/ ) {
|
||||
$id = $1;
|
||||
}
|
||||
|
||||
if( $hash->{helper}{scenes} ) {
|
||||
return $id if( defined($hash->{helper}{scenes}{$id}) );
|
||||
$id = lc($id);
|
||||
@ -497,14 +501,35 @@ HUEBridge_scene2id($$)
|
||||
my $scene = $hash->{helper}{scenes}{$key};
|
||||
|
||||
return $key if( lc($key) eq $id );
|
||||
return $key if( lc($scene->{name}) =~ m/^$id$/ );
|
||||
return $key if( lc("$scene->{name} ($key)") =~ m/^$id$/ );
|
||||
#return $key if( $scene->{name} eq $id );
|
||||
return $key if( lc($scene->{name}) =~ m/^$id$/ );
|
||||
}
|
||||
}
|
||||
|
||||
return '<unknown>';
|
||||
}
|
||||
sub
|
||||
HUEbridge_groupOfLights($$)
|
||||
{
|
||||
my ($hash,$lights) = @_;
|
||||
$hash = $defs{$hash} if( ref($hash) ne 'HASH' );
|
||||
return undef if( !$hash );
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $group;
|
||||
foreach my $chash ( values %{$modules{HUEDevice}{defptr}} ) {
|
||||
next if( !$chash->{IODev} );
|
||||
next if( !$chash->{lights} );
|
||||
next if( $chash->{IODev}{NAME} ne $name );
|
||||
next if( $chash->{helper}{devtype} ne 'G' );
|
||||
next if( $chash->{lights} ne $lights );
|
||||
|
||||
$group .= ',' if( $group );
|
||||
$group .= AttrVal($chash->{NAME}, 'alias', $chash->{NAME});
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
sub HUEBridge_Set($@);
|
||||
sub
|
||||
@ -901,7 +926,23 @@ HUEBridge_Set($@)
|
||||
my $list = "active inactive delete creategroup deletegroup savescene deletescene modifyscene";
|
||||
|
||||
if( my $scenes = $hash->{helper}{scenes} ) {
|
||||
$list .= " scene:". join(",", sort map { my $scene = $scenes->{$_}{name}; $scene =~ s/ /#/g ;$scene} keys %{$scenes} );
|
||||
my %count;
|
||||
map { $count{$scenes->{$_}{name}}++ } keys %{$scenes};
|
||||
$list .= " scene:". join(",", sort map { my $scene = $scenes->{$_}{name};
|
||||
my $group = '';
|
||||
if( $count{$scene} > 1 ) {
|
||||
my $lights = join( ",", @{$scenes->{$_}{lights}} );
|
||||
$group = HUEbridge_groupOfLights($hash,$lights);
|
||||
$group = join( ";", map { my $l = $hash->{helper}{lights}{$_}{name}; $l?$l:$_;} @{$scenes->{$_}{lights}} ) if( !$group && $hash->{helper}{lights} );
|
||||
$group = $lights if( !$group );
|
||||
$group =~ s/,/;/g;
|
||||
$group = '' if( $group =~ /,/ );
|
||||
$group = $_ if( !$group );
|
||||
|
||||
$scene .= " ($group)";
|
||||
$scene .= " [id=$_]" if( 1 || $group =~ /;/ );;
|
||||
}
|
||||
$scene =~ s/ /#/g; $scene;} keys %{$scenes} );
|
||||
} else {
|
||||
$list .= " scene";
|
||||
}
|
||||
@ -969,10 +1010,16 @@ HUEBridge_Get($@)
|
||||
foreach my $key ( sort {$result->{$a}{name} cmp $result->{$b}{name}} keys %{$result} ) {
|
||||
$ret .= sprintf( "%-20s %-20s", $key, $result->{$key}{name} );
|
||||
$ret .= sprintf( "%i %i %i %-40s %-20s", $result->{$key}{recycle}, $result->{$key}{locked},$result->{$key}{version}, $result->{$key}{owner}, $result->{$key}{lastupdated}?$result->{$key}{lastupdated}:'' ) if( $arg && $arg eq 'detail' );
|
||||
if( !$arg && $hash->{helper}{lights} ) {
|
||||
my $lights = join( ",", @{$result->{$key}{lights}} );
|
||||
my $group = HUEbridge_groupOfLights($hash,$lights);
|
||||
|
||||
if( !$arg && $group ) {
|
||||
$ret .= sprintf( " %s\n", $group );
|
||||
|
||||
} elsif( !$arg && $hash->{helper}{lights} ) {
|
||||
$ret .= sprintf( " %s\n", join( ",", map { my $l = $hash->{helper}{lights}{$_}{name}; $l?$l:$_;} @{$result->{$key}{lights}} ) );
|
||||
} else {
|
||||
$ret .= sprintf( " %s\n", join( ",", @{$result->{$key}{lights}} ) );
|
||||
$ret .= sprintf( " %s\n", $lights );
|
||||
}
|
||||
}
|
||||
if( $ret ) {
|
||||
|
@ -1283,8 +1283,9 @@ HUEDevice_Parse($$)
|
||||
$hash->{sensitivitymax} = $config->{sensitivitymax} if( defined ($config->{sensitivitymax}) );
|
||||
}
|
||||
|
||||
my $lastupdated;
|
||||
my $lastupdated_local;
|
||||
my $lastupdated = '';
|
||||
my $lastupdated_local = '';
|
||||
my $offset = 0;
|
||||
if( my $state = $result->{state} ) {
|
||||
$lastupdated = $state->{lastupdated};
|
||||
|
||||
@ -1293,7 +1294,6 @@ HUEDevice_Parse($$)
|
||||
|
||||
substr( $lastupdated, 10, 1, ' ' ) if($lastupdated);
|
||||
|
||||
my $offset = 0;
|
||||
if( my $iohash = $hash->{IODev} ) {
|
||||
substr( $lastupdated, 10, 1, '_' );
|
||||
my $sec = SVG_time_to_sec($lastupdated);
|
||||
@ -1317,13 +1317,6 @@ HUEDevice_Parse($$)
|
||||
$lastupdated_local = $lastupdated;
|
||||
}
|
||||
|
||||
$hash->{lastupdated} = ReadingsVal( $name, '.lastupdated', undef ) if( !$hash->{lastupdated} );
|
||||
$hash->{lastupdated_local} = ReadingsVal( $name, '.lastupdated_local', undef ) if( !$hash->{lastupdated_local} );
|
||||
return undef if( $hash->{lastupdated} && $hash->{lastupdated} eq $lastupdated );
|
||||
|
||||
Log3 $name, 4, "$name: lastupdated: $lastupdated, hash->{lastupdated}: $hash->{lastupdated}, lastupdated_local: $lastupdated_local, offsetUTC: $offset";
|
||||
Log3 $name, 5, "$name: ". Dumper $result if($HUEDevice_hasDataDumper);
|
||||
|
||||
$hash->{lastupdated} = $lastupdated;
|
||||
$hash->{lastupdated_local} = $lastupdated_local;
|
||||
|
||||
@ -1358,6 +1351,15 @@ HUEDevice_Parse($$)
|
||||
$readings{vibrationstrength} = $state->{vibrationstrength} if( defined ($state->{vibrationstrength}) );
|
||||
}
|
||||
|
||||
$hash->{lastupdated} = ReadingsVal( $name, '.lastupdated', undef ) if( !$hash->{lastupdated} );
|
||||
$hash->{lastupdated_local} = ReadingsVal( $name, '.lastupdated_local', undef ) if( !$hash->{lastupdated_local} );
|
||||
return undef if( $hash->{lastupdated}
|
||||
&& $hash->{lastupdated} eq $lastupdated
|
||||
&& (!$readings{state} || $readings{state} eq ReadingsVal( $name, 'state', '' )) );
|
||||
|
||||
Log3 $name, 4, "$name: lastupdated: $lastupdated, hash->{lastupdated}: $hash->{lastupdated}, lastupdated_local: $lastupdated_local, offsetUTC: $offset";
|
||||
Log3 $name, 5, "$name: ". Dumper $result if($HUEDevice_hasDataDumper);
|
||||
|
||||
if( scalar keys %readings ) {
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
@ -1390,7 +1392,6 @@ HUEDevice_Parse($$)
|
||||
}
|
||||
|
||||
return undef;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user