2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +00:00

31_HUEDevice.pm: handle IODev rename

git-svn-id: https://svn.fhem.de/fhem/trunk@20492 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2019-11-11 09:45:09 +00:00
parent e4c5e5b8b9
commit 77603c7c04
5 changed files with 90 additions and 12 deletions

View File

@ -1,5 +1,6 @@
# 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.
- feature: 31_HUEDevice: handle IODev rename
- bugfix: 73_PRESENCE: add missing attributes retryCount and retryInterval
to AttrList
- change: 93_DbRep: commandref revised

View File

@ -31,6 +31,7 @@ sub HUEBridge_Initialize($)
#Consumer
$hash->{DefFn} = "HUEBridge_Define";
$hash->{RenameFn} = "HUEBridge_Rename";
$hash->{NotifyFn} = "HUEBridge_Notify";
$hash->{SetFn} = "HUEBridge_Set";
$hash->{GetFn} = "HUEBridge_Get";
@ -257,6 +258,18 @@ HUEBridge_Define($$)
return undef;
}
sub
HUEBridge_Rename($$$)
{
my ($new,$old) = @_;
foreach my $chash ( values %{$modules{HUEDevice}{defptr}} ) {
next if( !$chash->{IODev} );
next if( $chash->{IODev}{NAME} ne $new );
HUEDevice_IODevChanged($chash, $old, $new);
}
}
sub
HUEBridge_Notify($$)
{
my ($hash,$dev) = @_;

View File

@ -51,7 +51,7 @@ LIGHTIFY_Initialize($)
$hash->{Clients} = ":HUEDevice:";
$hash->{DefFn} = "LIGHTIFY_Define";
$hash->{NOTIFYDEV} = "global";
$hash->{RenameFn} = "LIGHTIFY_Rename";
$hash->{NotifyFn} = "LIGHTIFY_Notify";
$hash->{UndefFn} = "LIGHTIFY_Undefine";
$hash->{SetFn} = "LIGHTIFY_Set";
@ -80,6 +80,8 @@ LIGHTIFY_Define($$)
$hash->{INTERVAL} = 60;
$hash->{NOTIFYDEV} = "global";
if( $init_done ) {
LIGHTIFY_Disconnect($hash);
LIGHTIFY_Connect($hash);
@ -91,7 +93,18 @@ LIGHTIFY_Define($$)
return undef;
}
sub
LIGHTIFY_Rename($$$)
{
my ($new,$old) = @_;
foreach my $chash ( values %{$modules{HUEDevice}{defptr}} ) {
next if( !$chash->{IODev} );
next if( $chash->{IODev}{NAME} ne $new );
HUEDevice_IODevChanged($chash, $old, $new);
}
}
sub
LIGHTIFY_Notify($$)
{

View File

@ -35,6 +35,7 @@ tradfri_Initialize($)
$hash->{WriteFn} = "tradfri_Write";
$hash->{DefFn} = "tradfri_Define";
$hash->{RenameFn} = "tradfri_Rename";
$hash->{NotifyFn} = "tradfri_Notify";
$hash->{UndefFn} = "tradfri_Undefine";
$hash->{DelayedShutdownFn} = "tradfri_DelayedShutdown";
@ -106,7 +107,18 @@ tradfri_Define($$)
return undef;
}
sub
tradfri_Rename($$$)
{
my ($new,$old) = @_;
foreach my $chash ( values %{$modules{HUEDevice}{defptr}} ) {
next if( !$chash->{IODev} );
next if( $chash->{IODev}{NAME} ne $new );
HUEDevice_IODevChanged($chash, $old, $new);
}
}
sub
tradfri_Notify($$)
{

View File

@ -267,6 +267,51 @@ HUEDevice_summaryFn($$$$)
return HUEDevice_devStateIcon($hash);
}
sub
HUEDevice_IODevChanged($$$)
{
my ($hash,$old,$new) = @_;
$hash = $defs{$hash} if( ref($hash) ne 'HASH' );
my $name = $hash->{NAME};
if( $hash->{TYPE} ne 'HUEDevice' ) {
Log3 $name, 1, "$name: can't change IODev for TYPE $hash->{TYPE}";
return undef;
}
$old = AttrVal($name, "IODev", undef) if( !$old );
my $code = $hash->{ID};
$code = $old ."-". $code if( $old );
delete $modules{HUEDevice}{defptr}{$code};
AssignIoPort($hash,$new);
if( defined($hash->{IODev}) ) {
Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME};
} else {
Log3 $name, 1, "$name: no I/O device";
}
$new = $hash->{IODev}->{NAME} if( defined($hash->{IODev}) );
$code = $hash->{ID};
$code = $new ."-". $code if( $new );
$modules{HUEDevice}{defptr}{$code} = $hash;
if( $old ) {
if( $new ) {
$hash->{DEF} =~ s/IODev=$old/IODev=$new/;
} else {
$hash->{DEF} =~ s/IODev=$old//;
}
} elsif( $new ) {
$hash->{DEF} .= " IODev=$new"
}
$hash->{DEF} =~ s/ / /g;
return $new;
}
sub HUEDevice_Define($$)
{
my ($hash, $def) = @_;
@ -305,13 +350,7 @@ sub HUEDevice_Define($$)
$hash->{ID} = $hash->{helper}->{devtype}.$id;
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
if(defined($hash->{IODev})) {
Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME};
} else {
Log3 $name, 1, "$name: no I/O device";
}
$iodev = $hash->{IODev}->{NAME} if( defined($hash->{IODev}) );
$iodev = HUEDevice_IODevChanged( $hash, undef, $iodev ) if( !$hash->{IODev} );
my $code = $hash->{ID};
$code = $iodev ."-". $code if( defined($iodev) );
@ -403,7 +442,7 @@ sub HUEDevice_Undefine($$)
RemoveInternalTimer($hash);
my $code = $hash->{ID};
$code = $hash->{IODev}->{NAME} ."-". $code if( defined($hash->{IODev}->{NAME}) );
$code = $hash->{IODev}->{NAME} ."-". $code if( defined($hash->{IODev}) );
delete($modules{HUEDevice}{defptr}{$code});
@ -443,7 +482,7 @@ HUEDevice_SetParam($$@)
} elsif($cmd eq 'down' ) {
$cmd = 'pct';
$value = 0;
} if($cmd eq "pct" && $value == 0 && $subtype ne 'blind' ) {
$cmd = "off";
$value = $value2;