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

All my modules: use IsDevice() and GetType()

git-svn-id: https://svn.fhem.de/fhem/trunk@13899 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-04 18:01:08 +00:00
parent dcb0ce6e5e
commit eedc05ffab
10 changed files with 149 additions and 177 deletions

View File

@ -212,7 +212,7 @@ sub RESIDENTS_Notify($$) {
return unless ( $devName ne $hashName ); # only foreign events return unless ( $devName ne $hashName ); # only foreign events
return if ( IsDisabled($hashName) or IsDisabled($devName) ); return if ( IsDisabled($hashName) or IsDisabled($devName) );
return return
unless ( RESIDENTStk_IsDevice( $devName, "ROOMMATE|GUEST|dummy" ) ); unless ( IsDevice( $devName, "ROOMMATE|GUEST|dummy" ) );
my @registeredRoommates = my @registeredRoommates =
split( /,/, $hash->{ROOMMATES} ) split( /,/, $hash->{ROOMMATES} )
@ -461,11 +461,11 @@ sub RESIDENTS_Set($@) {
# define roommate # define roommate
fhem( "define " . $rr_name . " ROOMMATE " . $name ) fhem( "define " . $rr_name . " ROOMMATE " . $name )
unless ( RESIDENTStk_IsDevice($rr_name) ); unless ( IsDevice($rr_name) );
if ( RESIDENTStk_IsDevice($rr_name) ) { if ( IsDevice($rr_name) ) {
return "Can't create, device $rr_name already existing." return "Can't create, device $rr_name already existing."
unless ( RESIDENTStk_IsDevice( $rr_name, "ROOMMATE" ) ); unless ( IsDevice( $rr_name, "ROOMMATE" ) );
my $lang = my $lang =
$a[3] $a[3]
@ -497,7 +497,7 @@ sub RESIDENTS_Set($@) {
my $rr_name = $a[2]; my $rr_name = $a[2];
# delete roommate # delete roommate
if ( RESIDENTStk_IsDevice($rr_name) ) { if ( IsDevice($rr_name) ) {
Log3 $name, 3, "RESIDENTS $name: deleted device $rr_name" Log3 $name, 3, "RESIDENTS $name: deleted device $rr_name"
if fhem( "delete " . $rr_name ); if fhem( "delete " . $rr_name );
} }
@ -521,11 +521,11 @@ sub RESIDENTS_Set($@) {
# define guest # define guest
fhem( "define " . $rg_name . " GUEST " . $name ) fhem( "define " . $rg_name . " GUEST " . $name )
unless ( RESIDENTStk_IsDevice($rg_name) ); unless ( IsDevice($rg_name) );
if ( RESIDENTStk_IsDevice($rg_name) ) { if ( IsDevice($rg_name) ) {
return "Can't create, device $rg_name already existing." return "Can't create, device $rg_name already existing."
unless ( RESIDENTStk_IsDevice( $rg_name, "GUEST" ) ); unless ( IsDevice( $rg_name, "GUEST" ) );
my $lang = my $lang =
$a[3] $a[3]
@ -557,7 +557,7 @@ sub RESIDENTS_Set($@) {
my $rg_name = $a[2]; my $rg_name = $a[2];
# delete guest # delete guest
if ( RESIDENTStk_IsDevice($rg_name) ) { if ( IsDevice($rg_name) ) {
Log3 $name, 3, "RESIDENTS $name: deleted device $rg_name" Log3 $name, 3, "RESIDENTS $name: deleted device $rg_name"
if fhem( "delete " . $rg_name ); if fhem( "delete " . $rg_name );
} }
@ -575,7 +575,7 @@ sub RESIDENTS_Set($@) {
my $created = 0; my $created = 0;
until ($created) { until ($created) {
if ( RESIDENTStk_IsDevice($wakeuptimerName) ) { if ( IsDevice($wakeuptimerName) ) {
$i++; $i++;
$wakeuptimerName = $name . "_wakeuptimer" . $i; $wakeuptimerName = $name . "_wakeuptimer" . $i;
} }
@ -1414,7 +1414,7 @@ sub RESIDENTS_UpdateReadings (@) {
for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
next if !$wakeupDevice; next if !$wakeupDevice;
if ( RESIDENTStk_IsDevice( $wakeupDevice, "dummy" ) ) { if ( IsDevice( $wakeupDevice, "dummy" ) ) {
# forced-stop only if resident is not present anymore # forced-stop only if resident is not present anymore
if ( $newpresence eq "present" ) { if ( $newpresence eq "present" ) {

View File

@ -73,7 +73,7 @@ sub GUEST_Define($$) {
if ( defined( $hash->{RESIDENTGROUPS} ) ) { if ( defined( $hash->{RESIDENTGROUPS} ) ) {
foreach ( split( /,/, $hash->{RESIDENTGROUPS} ) ) { foreach ( split( /,/, $hash->{RESIDENTGROUPS} ) ) {
RESIDENTStk_findResidentSlaves( $defs{$_} ) RESIDENTStk_findResidentSlaves( $defs{$_} )
if ( RESIDENTStk_IsDevice( $_, "RESIDENTS" ) ); if ( IsDevice( $_, "RESIDENTS" ) );
} }
} }
@ -213,7 +213,7 @@ sub GUEST_Undefine($$) {
delete $hash->{RESIDENTGROUPS}; delete $hash->{RESIDENTGROUPS};
foreach ( split( /,/, $old ) ) { foreach ( split( /,/, $old ) ) {
RESIDENTStk_findResidentSlaves( $defs{$_} ) RESIDENTStk_findResidentSlaves( $defs{$_} )
if ( RESIDENTStk_IsDevice( $_, "RESIDENTS" ) ); if ( IsDevice( $_, "RESIDENTS" ) );
} }
} }
@ -247,7 +247,7 @@ sub GUEST_Notify($$) {
# make sure computeAfterInit is set at at-device # make sure computeAfterInit is set at at-device
# and re-calculate on our own this time # and re-calculate on our own this time
if ( RESIDENTStk_IsDevice( $wakeupAtdevice, "at" ) if ( IsDevice( $wakeupAtdevice, "at" )
&& AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne && AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne
"1" ) "1" )
{ {
@ -578,7 +578,7 @@ sub GUEST_Set($@) {
for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
next if !$wakeupDevice; next if !$wakeupDevice;
if ( RESIDENTStk_IsDevice( $wakeupDevice, "dummy" ) ) { if ( IsDevice( $wakeupDevice, "dummy" ) ) {
# forced-stop only if resident is not present anymore # forced-stop only if resident is not present anymore
if ( $newpresence eq "present" ) { if ( $newpresence eq "present" ) {
@ -694,7 +694,7 @@ sub GUEST_Set($@) {
split( ' ', $attr{$name}{"rg_passPresenceTo"} ); split( ' ', $attr{$name}{"rg_passPresenceTo"} );
foreach my $object (@linkedObjects) { foreach my $object (@linkedObjects) {
if ( RESIDENTStk_IsDevice( $object, "ROOMMATE|GUEST" ) if ( IsDevice( $object, "ROOMMATE|GUEST" )
&& $defs{$object} ne $name && $defs{$object} ne $name
&& ReadingsVal( $object, "state", "" ) ne "gone" && ReadingsVal( $object, "state", "" ) ne "gone"
&& ReadingsVal( $object, "state", "" ) ne "none" ) && ReadingsVal( $object, "state", "" ) ne "none" )
@ -867,7 +867,7 @@ sub GUEST_Set($@) {
my $created = 0; my $created = 0;
until ($created) { until ($created) {
if ( RESIDENTStk_IsDevice($wakeuptimerName) ) { if ( IsDevice($wakeuptimerName) ) {
$i++; $i++;
$wakeuptimerName = $name . "_wakeuptimer" . $i; $wakeuptimerName = $name . "_wakeuptimer" . $i;
} }
@ -920,7 +920,7 @@ sub GUEST_Set($@) {
elsif ( lc( $a[2] ) eq "locationmap" ) { elsif ( lc( $a[2] ) eq "locationmap" ) {
my $locationmapName = $name . "_map"; my $locationmapName = $name . "_map";
if ( RESIDENTStk_IsDevice($locationmapName) ) { if ( IsDevice($locationmapName) ) {
return return
"Device $locationmapName existing already, delete it first to have it re-created."; "Device $locationmapName existing already, delete it first to have it re-created.";
} }

View File

@ -74,7 +74,7 @@ sub ROOMMATE_Define($$) {
if ( defined( $hash->{RESIDENTGROUPS} ) ) { if ( defined( $hash->{RESIDENTGROUPS} ) ) {
foreach ( split( /,/, $hash->{RESIDENTGROUPS} ) ) { foreach ( split( /,/, $hash->{RESIDENTGROUPS} ) ) {
RESIDENTStk_findResidentSlaves( $defs{$_} ) RESIDENTStk_findResidentSlaves( $defs{$_} )
if ( RESIDENTStk_IsDevice( $_, "RESIDENTS" ) ); if ( IsDevice( $_, "RESIDENTS" ) );
} }
} }
@ -216,7 +216,7 @@ sub ROOMMATE_Undefine($$) {
delete $hash->{RESIDENTGROUPS}; delete $hash->{RESIDENTGROUPS};
foreach ( split( /,/, $old ) ) { foreach ( split( /,/, $old ) ) {
RESIDENTStk_findResidentSlaves( $defs{$_} ) RESIDENTStk_findResidentSlaves( $defs{$_} )
if ( RESIDENTStk_IsDevice( $_, "RESIDENTS" ) ); if ( IsDevice( $_, "RESIDENTS" ) );
} }
} }
@ -250,7 +250,7 @@ sub ROOMMATE_Notify($$) {
# make sure computeAfterInit is set at at-device # make sure computeAfterInit is set at at-device
# and re-calculate on our own this time # and re-calculate on our own this time
if ( RESIDENTStk_IsDevice( $wakeupAtdevice, "at" ) if ( IsDevice( $wakeupAtdevice, "at" )
&& AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne && AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne
"1" ) "1" )
{ {
@ -580,7 +580,7 @@ sub ROOMMATE_Set($@) {
for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
next if !$wakeupDevice; next if !$wakeupDevice;
if ( RESIDENTStk_IsDevice( $wakeupDevice, "dummy" ) ) { if ( IsDevice( $wakeupDevice, "dummy" ) ) {
# forced-stop only if resident is not present anymore # forced-stop only if resident is not present anymore
if ( $newpresence eq "present" ) { if ( $newpresence eq "present" ) {
@ -696,7 +696,7 @@ sub ROOMMATE_Set($@) {
split( ' ', $attr{$name}{"rr_passPresenceTo"} ); split( ' ', $attr{$name}{"rr_passPresenceTo"} );
foreach my $object (@linkedObjects) { foreach my $object (@linkedObjects) {
if ( RESIDENTStk_IsDevice( $object, "ROOMMATE|GUEST" ) if ( IsDevice( $object, "ROOMMATE|GUEST" )
&& $defs{$object} ne $name && $defs{$object} ne $name
&& ReadingsVal( $object, "state", "" ) ne "gone" && ReadingsVal( $object, "state", "" ) ne "gone"
&& ReadingsVal( $object, "state", "" ) ne "none" ) && ReadingsVal( $object, "state", "" ) ne "none" )
@ -849,7 +849,7 @@ sub ROOMMATE_Set($@) {
my $created = 0; my $created = 0;
until ($created) { until ($created) {
if ( RESIDENTStk_IsDevice($wakeuptimerName) ) { if ( IsDevice($wakeuptimerName) ) {
$i++; $i++;
$wakeuptimerName = $name . "_wakeuptimer" . $i; $wakeuptimerName = $name . "_wakeuptimer" . $i;
} }
@ -902,7 +902,7 @@ sub ROOMMATE_Set($@) {
elsif ( lc( $a[2] ) eq "locationmap" ) { elsif ( lc( $a[2] ) eq "locationmap" ) {
my $locationmapName = $name . "_map"; my $locationmapName = $name . "_map";
if ( RESIDENTStk_IsDevice($locationmapName) ) { if ( IsDevice($locationmapName) ) {
return return
"Device $locationmapName existing already, delete it first to have it re-created."; "Device $locationmapName existing already, delete it first to have it re-created.";
} }

View File

@ -136,7 +136,7 @@ sub ONKYO_AVR_removeExtension($) {
my $url = "?/$link"; my $url = "?/$link";
my $name = $data{FWEXT}{$url}{deviceName}; my $name = $data{FWEXT}{$url}{deviceName};
Log3 $name, 2, Log3 $name, 2,
"ONKYO_AVR $name: Unregistering ONKYO_AVR for webhook URL $url..."; "ONKYO_AVR $name: Unregistering ONKYO_AVR for webhook URI $url...";
delete $data{FWEXT}{$url}; delete $data{FWEXT}{$url};
} }

View File

@ -2652,9 +2652,7 @@ m/^\s*(([{\[][\s\S]+[}\]])|(<html>\s*<head>\s*<title>\s*Ok\s*<\/title>\s*<\/head
Log3 $name, 5, $logtext; Log3 $name, 5, $logtext;
# next for if HUE device is not ready # next for if HUE device is not ready
if ( !defined( $defs{$dev} ) if ( !IsDevice( $dev, "HUEDevice" )
|| !defined( $defs{$dev}{TYPE} )
|| $defs{$dev}{TYPE} ne "HUEDevice"
|| ReadingsVal( $dev, "reachable", 0 ) ne || ReadingsVal( $dev, "reachable", 0 ) ne
"1" ) "1" )
{ {

View File

@ -1030,7 +1030,7 @@ sub THINKINGCLEANER_removeExtension($) {
my $url = "?/$link"; my $url = "?/$link";
my $name = $data{FWEXT}{$url}{deviceName}; my $name = $data{FWEXT}{$url}{deviceName};
Log3 $name, 2, Log3 $name, 2,
"THINKINGCLEANER $name: Unregistering THINKINGCLEANER for webhook URL $url..."; "THINKINGCLEANER $name: Unregistering THINKINGCLEANER for webhook URI $url...";
delete $data{FWEXT}{$url}; delete $data{FWEXT}{$url};
} }

View File

@ -255,9 +255,10 @@ sub msgConfig_Set($@) {
$device =~ s/[\s\t-]+/_/g; $device =~ s/[\s\t-]+/_/g;
return "Device $device is already existing but not a dummy device" return "Device $device is already existing but not a dummy device"
if ( msgConfig_IsDevice($device) && msgConfig_GetType($device) ne "dummy" ); if ( IsDevice($device)
&& GetType($device) ne "dummy" );
if ( !msgConfig_IsDevice($device) ) { if ( !IsDevice($device) ) {
$return = fhem( "define $device dummy", 1 ); $return = fhem( "define $device dummy", 1 );
$return .= "Device $device was created" $return .= "Device $device was created"
if ( $return eq "" ); if ( $return eq "" );
@ -302,9 +303,10 @@ sub msgConfig_Set($@) {
if ( defined( $a[0] ) && $a[0] eq "de" ); if ( defined( $a[0] ) && $a[0] eq "de" );
return "Device $device is already existing but not a dummy device" return "Device $device is already existing but not a dummy device"
if ( msgConfig_IsDevice($device) && msgConfig_GetType($device) ne "dummy" ); if ( IsDevice($device)
&& GetType($device) ne "dummy" );
if ( !msgConfig_IsDevice($device) ) { if ( !IsDevice($device) ) {
$return = fhem( "define $device dummy", 1 ); $return = fhem( "define $device dummy", 1 );
$return .= "Device $device was created" $return .= "Device $device was created"
if ( $return eq "" ); if ( $return eq "" );
@ -361,19 +363,17 @@ sub msgConfig_Set($@) {
return return
"Device $device is already existing but not a RESIDENTS or ROOMMATE device" "Device $device is already existing but not a RESIDENTS or ROOMMATE device"
if ( msgConfig_IsDevice($device) if ( IsDevice($device)
&& !msgConfig_IsDevice( $device, "RESIDENTS|ROOMMATE" ) ); && !IsDevice( $device, "RESIDENTS|ROOMMATE" ) );
if ( !msgConfig_IsDevice($device) ) { if ( !IsDevice($device) ) {
$return = fhem( "define $device RESIDENTS", 1 ); $return = fhem( "define $device RESIDENTS", 1 );
$return .= "RESIDENTS device $device was created." $return .= "RESIDENTS device $device was created."
if ( $return eq "" ); if ( $return eq "" );
} }
else { else {
$return = $return =
"Existing " "Existing " . GetType($device) . " device $device was updated.";
. msgConfig_GetType($device)
. " device $device was updated.";
} }
my $txt = fhem("attr $device rgr_lang $lang") my $txt = fhem("attr $device rgr_lang $lang")
@ -426,12 +426,12 @@ sub msgConfig_Get($@) {
# Check device # Check device
if ( $devicesReq ne "" ) { if ( $devicesReq ne "" ) {
foreach my $device ( split( /,/, $devicesReq ) ) { foreach my $device ( split( /,/, $devicesReq ) ) {
if ( msgConfig_IsDevice($device) ) { if ( IsDevice($device) ) {
$UserDeviceTypes .= "," . msgConfig_GetType($device) $UserDeviceTypes .= "," . GetType($device)
if ( $UserDeviceTypes ne "" if ( $UserDeviceTypes ne ""
&& $msgType ne "mail" && $msgType ne "mail"
&& $device ne $name ); && $device ne $name );
$UserDeviceTypes = msgConfig_GetType($device) $UserDeviceTypes = GetType($device)
if ( $UserDeviceTypes eq "" if ( $UserDeviceTypes eq ""
&& $msgType ne "mail" && $msgType ne "mail"
&& $device ne $name ); && $device ne $name );
@ -470,7 +470,7 @@ sub msgConfig_Get($@) {
if ( $output == 0 ); if ( $output == 0 );
$return .= $return .=
" $device (DEVICE TYPE: " " $device (DEVICE TYPE: "
. msgConfig_GetType($device) . ")\n" . GetType($device) . ")\n"
if ( $output == 0 ); if ( $output == 0 );
$output = 1 if ( $output == 0 ); $output = 1 if ( $output == 0 );
@ -665,38 +665,62 @@ sub msgConfig_FindReadingsVal($$$$) {
} }
######################################## ########################################
sub msgConfig_IsDevice($;$) { sub msgConfig_QueueAdd(@) {
my $devname = shift; my (
my $devtype = shift; $msgA, $params, $datetime, $msgID,
$devtype = ".*" unless ( $devtype && $devtype ne "" ); $minorID, $type, $recipient, $subRecipient,
$termRecipient, $priority, $title, $msg
) = @_;
return 1 my $name = $modules{msgConfig}{defptr}{NAME};
if ( defined($devname)
&& defined( $defs{$devname} )
&& ref( $defs{$devname} ) eq "HASH"
&& defined( $defs{$devname}{NAME} )
&& $defs{$devname}{NAME} eq $devname
&& defined( $defs{$devname}{TYPE} )
&& $defs{$devname}{TYPE} =~ m/^$devtype$/
&& defined( $modules{ $defs{$devname}{TYPE} } )
&& defined( $modules{ $defs{$devname}{TYPE} }{LOADED} )
&& $modules{ $defs{$devname}{TYPE} }{LOADED} );
delete $defs{$devname} return 0 if ( $defs{$name}{queue}{$recipient}{"$msgID.$minorID"} );
if ( defined($devname)
&& defined( $defs{$devname} )
&& $devtype eq ".*" );
return 0; $defs{$name}{queue}{$recipient}{"$msgID.$minorID"} = {
msgOrig => $msgA,
msgOrigParams => $params,
datetime => $datetime,
majorId => $msgID,
minorId => $minorID,
type => $type,
recipient => $recipient,
subRecipient => $subRecipient,
terminalRecipient => $termRecipient,
priority => $priority,
title => $title,
message => $msg,
};
delete $defs{$name}{queue}{$recipient}{"$msgID.$minorID"}{msgOrigParams}
{msgQID};
readingsSingleUpdate(
$defs{$name},
"Q_" . $recipient,
scalar keys %{ $defs{$name}{queue}{$recipient} }, 1
);
return 1;
} }
######################################## ########################################
sub msgConfig_GetType($;$) { sub msgConfig_QueueReleaseMsgId($$) {
my $devname = shift; my ( $recipient, $msgID ) = @_;
my $default = shift;
return $default unless ( msgConfig_IsDevice($devname) ); my $name = $modules{msgConfig}{defptr}{NAME};
return $defs{$devname}{TYPE};
return 0
unless ( $defs{$name}{queue}
&& $defs{$name}{queue}{$recipient}
&& $defs{$name}{queue}{$recipient}{$msgID} );
delete $defs{$name}{queue}{$recipient}{$msgID};
my $c = scalar keys %{ $defs{$name}{queue}{$recipient} };
delete $defs{$name}{queue}{$recipient} unless ($c);
readingsSingleUpdate( $defs{$name}, "Q_" . $recipient, $c, 1 );
return 1;
} }
1; 1;

View File

@ -845,45 +845,45 @@ sub powerMap_AttrVal($$$$) {
# $defs{device}{TYPE}{attribute} # $defs{device}{TYPE}{attribute}
return $defs{$d}{$TYPE}{$n} return $defs{$d}{$TYPE}{$n}
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{$TYPE} ) && defined( $defs{$d}{$TYPE} )
&& defined( $defs{$d}{$TYPE}{$n} ) ); && defined( $defs{$d}{$TYPE}{$n} ) );
# $defs{device}{.TYPE}{attribute} # $defs{device}{.TYPE}{attribute}
return $defs{$d}{".$TYPE"}{$n} return $defs{$d}{".$TYPE"}{$n}
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{".$TYPE"} ) && defined( $defs{$d}{".$TYPE"} )
&& defined( $defs{$d}{".$TYPE"}{$n} ) ); && defined( $defs{$d}{".$TYPE"}{$n} ) );
# $defs{device}{TYPE_attribute} # $defs{device}{TYPE_attribute}
return $defs{$d}{ $TYPE . "_" . $n } return $defs{$d}{ $TYPE . "_" . $n }
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{ $TYPE . "_" . $n } ) ); && defined( $defs{$d}{ $TYPE . "_" . $n } ) );
# $defs{device}{attribute} # $defs{device}{attribute}
return $defs{$d}{$n} return $defs{$d}{$n}
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{$n} ) ); && defined( $defs{$d}{$n} ) );
# $defs{device}{.TYPE_attribute} # $defs{device}{.TYPE_attribute}
return $defs{$d}{ "." . $TYPE . "_" . $n } return $defs{$d}{ "." . $TYPE . "_" . $n }
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{ "." . $TYPE . "_" . $n } ) ); && defined( $defs{$d}{ "." . $TYPE . "_" . $n } ) );
# $defs{device}{.attribute} # $defs{device}{.attribute}
return $defs{$d}{".$n"} return $defs{$d}{".$n"}
if ( $d if ( $d
&& defined( $defs{$d} ) && IsDevice($d)
&& defined( $defs{$d}{".$n"} ) ); && defined( $defs{$d}{".$n"} ) );
# module HASH # module HASH
# #
my $t = $defs{$d}{TYPE}; my $t = GetType($d);
# $modules{module}{TYPE}{attribute} # $modules{module}{TYPE}{attribute}
return $modules{$t}{$TYPE}{$n} return $modules{$t}{$TYPE}{$n}
@ -1024,8 +1024,7 @@ sub powerMap_findPowerMaps($;$) {
# directly return any existing device specific definition # directly return any existing device specific definition
if ( $dev && $dev !~ /^:/ ) { if ( $dev && $dev !~ /^:/ ) {
return {} return {}
unless ( defined( $defs{$dev} ) unless ( IsDevice($dev) );
&& defined( $defs{$dev}{TYPE} ) );
return $defs{$dev}{powerMap}{map} return $defs{$dev}{powerMap}{map}
if ( if (

View File

@ -87,7 +87,7 @@ m/^(off|nextrun|trigger|start|stop|end|reset|auto|[\+\-][1-9]*[0-9]*|[\+\-]?[0-9
my $wakeupUserdeviceRealname = "Bewohner"; my $wakeupUserdeviceRealname = "Bewohner";
if ( RESIDENTStk_IsDevice( $wakeupUserdevice, "ROOMMATE" ) ) { if ( IsDevice( $wakeupUserdevice, "ROOMMATE" ) ) {
$wakeupUserdeviceRealname = AttrVal( $wakeupUserdeviceRealname = AttrVal(
AttrVal( $NAME, "wakeupUserdevice", "" ), AttrVal( $NAME, "wakeupUserdevice", "" ),
AttrVal( AttrVal(
@ -97,7 +97,7 @@ m/^(off|nextrun|trigger|start|stop|end|reset|auto|[\+\-][1-9]*[0-9]*|[\+\-]?[0-9
$wakeupUserdeviceRealname $wakeupUserdeviceRealname
); );
} }
elsif ( RESIDENTStk_IsDevice( $wakeupUserdevice, "GUEST" ) ) { elsif ( IsDevice( $wakeupUserdevice, "GUEST" ) ) {
$wakeupUserdeviceRealname = AttrVal( $wakeupUserdeviceRealname = AttrVal(
AttrVal( $NAME, "wakeupUserdevice", "" ), AttrVal( $NAME, "wakeupUserdevice", "" ),
AttrVal( AttrVal(
@ -122,13 +122,11 @@ m/^(off|nextrun|trigger|start|stop|end|reset|auto|[\+\-][1-9]*[0-9]*|[\+\-]?[0-9
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: WARNING - set attribute wakeupUserdevice before running wakeup function!"; "RESIDENTStk $NAME: WARNING - set attribute wakeupUserdevice before running wakeup function!";
} }
elsif ( !RESIDENTStk_IsDevice($wakeupUserdevice) ) { elsif ( !IsDevice($wakeupUserdevice) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: WARNING - user device $wakeupUserdevice does not exist!"; "RESIDENTStk $NAME: WARNING - user device $wakeupUserdevice does not exist!";
} }
elsif ( elsif ( !IsDevice( $wakeupUserdevice, "RESIDENTS|ROOMMATE|GUEST" ) ) {
!RESIDENTStk_IsDevice( $wakeupUserdevice, "RESIDENTS|ROOMMATE|GUEST" ) )
{
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: WARNING - defined user device '$wakeupUserdevice' is not a RESIDENTS, ROOMMATE or GUEST device!"; "RESIDENTStk $NAME: WARNING - defined user device '$wakeupUserdevice' is not a RESIDENTS, ROOMMATE or GUEST device!";
} }
@ -140,7 +138,7 @@ m/^(off|nextrun|trigger|start|stop|end|reset|auto|[\+\-][1-9]*[0-9]*|[\+\-]?[0-9
fhem "attr $NAME wakeupMacro $macroName"; fhem "attr $NAME wakeupMacro $macroName";
$wakeupMacro = $macroName; $wakeupMacro = $macroName;
} }
if ( !RESIDENTStk_IsDevice($wakeupMacro) ) { if ( !IsDevice($wakeupMacro) ) {
my $wakeUpMacroTemplate = "{\ my $wakeUpMacroTemplate = "{\
##=============================================================================\ ##=============================================================================\
## This is an example wake-up program running within a period of 30 minutes:\ ## This is an example wake-up program running within a period of 30 minutes:\
@ -232,7 +230,7 @@ if (\$EVTPART0 eq \"stop\") {\
fhem "attr $wakeupMacro room $room" fhem "attr $wakeupMacro room $room"
if ($room); if ($room);
} }
elsif ( RESIDENTStk_GetType($wakeupMacro) ne "notify" ) { elsif ( GetType($wakeupMacro) ne "notify" ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: WARNING - defined macro device '$wakeupMacro' is not a notify device!"; "RESIDENTStk $NAME: WARNING - defined macro device '$wakeupMacro' is not a notify device!";
} }
@ -244,7 +242,7 @@ if (\$EVTPART0 eq \"stop\") {\
fhem "attr $NAME wakeupAtdevice $atName"; fhem "attr $NAME wakeupAtdevice $atName";
$wakeupAtdevice = $atName; $wakeupAtdevice = $atName;
} }
if ( !RESIDENTStk_IsDevice($wakeupAtdevice) ) { if ( !IsDevice($wakeupAtdevice) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new at-device $wakeupAtdevice created"; "RESIDENTStk $NAME: new at-device $wakeupAtdevice created";
fhem fhem
@ -260,8 +258,8 @@ if (\$EVTPART0 eq \"stop\") {\
# for ROOMMATE or GUEST devices # for ROOMMATE or GUEST devices
# macro: gotosleep # macro: gotosleep
if ( RESIDENTStk_GetType($wakeupUserdevice) ne "RESIDENTS" if ( GetType($wakeupUserdevice) ne "RESIDENTS"
&& !RESIDENTStk_IsDevice($macroNameGotosleep) ) && !IsDevice($macroNameGotosleep) )
{ {
my $templateGotosleep = "{\ my $templateGotosleep = "{\
##=============================================================================\ ##=============================================================================\
@ -326,7 +324,7 @@ return;;\
} }
# wd: gotosleep # wd: gotosleep
if ( !RESIDENTStk_IsDevice($wdNameGotosleep) ) { if ( !IsDevice($wdNameGotosleep) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdNameGotosleep created"; "RESIDENTStk $NAME: new watchdog device $wdNameGotosleep created";
fhem fhem
@ -339,8 +337,8 @@ return;;\
} }
# macro: asleep # macro: asleep
if ( RESIDENTStk_GetType($wakeupUserdevice) ne "RESIDENTS" if ( GetType($wakeupUserdevice) ne "RESIDENTS"
&& !RESIDENTStk_IsDevice($macroNameAsleep) ) && !IsDevice($macroNameAsleep) )
{ {
my $templateAsleep = "{\ my $templateAsleep = "{\
##=============================================================================\ ##=============================================================================\
@ -401,7 +399,7 @@ return;;\
} }
# wd: asleep # wd: asleep
if ( !RESIDENTStk_IsDevice($wdNameAsleep) ) { if ( !IsDevice($wdNameAsleep) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdNameAsleep created"; "RESIDENTStk $NAME: new watchdog device $wdNameAsleep created";
fhem fhem
@ -414,8 +412,8 @@ return;;\
} }
# macro: awoken # macro: awoken
if ( RESIDENTStk_GetType($wakeupUserdevice) ne "RESIDENTS" if ( GetType($wakeupUserdevice) ne "RESIDENTS"
&& !RESIDENTStk_IsDevice($macroNameAwoken) ) && !IsDevice($macroNameAwoken) )
{ {
my $templateAwoken = "{\ my $templateAwoken = "{\
##=============================================================================\ ##=============================================================================\
@ -472,7 +470,7 @@ return;;\
} }
# wd: awoken # wd: awoken
if ( !RESIDENTStk_IsDevice($wdNameAwoken) ) { if ( !IsDevice($wdNameAwoken) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdNameAwoken created"; "RESIDENTStk $NAME: new watchdog device $wdNameAwoken created";
fhem fhem
@ -490,10 +488,10 @@ return;;\
# #
my $RESIDENTGROUPS = ""; my $RESIDENTGROUPS = "";
if ( RESIDENTStk_IsDevice( $wakeupUserdevice, "RESIDENTS" ) ) { if ( IsDevice( $wakeupUserdevice, "RESIDENTS" ) ) {
$RESIDENTGROUPS = $wakeupUserdevice; $RESIDENTGROUPS = $wakeupUserdevice;
} }
elsif ( RESIDENTStk_IsDevice($wakeupUserdevice) elsif ( IsDevice($wakeupUserdevice)
&& defined( $defs{$wakeupUserdevice}{RESIDENTGROUPS} ) ) && defined( $defs{$wakeupUserdevice}{RESIDENTGROUPS} ) )
{ {
$RESIDENTGROUPS = $defs{$wakeupUserdevice}{RESIDENTGROUPS}; $RESIDENTGROUPS = $defs{$wakeupUserdevice}{RESIDENTGROUPS};
@ -508,7 +506,7 @@ return;;\
my $wdRNameAwoken = "wd_" . $deviceName . "_awoken"; my $wdRNameAwoken = "wd_" . $deviceName . "_awoken";
# macro: gotosleep # macro: gotosleep
if ( !RESIDENTStk_IsDevice($macroRNameGotosleep) ) { if ( !IsDevice($macroRNameGotosleep) ) {
my $templateGotosleep = "{\ my $templateGotosleep = "{\
##=============================================================================\ ##=============================================================================\
## This is an example macro when all residents are gettin' ready for bed.\ ## This is an example macro when all residents are gettin' ready for bed.\
@ -554,7 +552,7 @@ return;;\
} }
# wd: gotosleep # wd: gotosleep
if ( !RESIDENTStk_IsDevice($wdRNameGotosleep) ) { if ( !IsDevice($wdRNameGotosleep) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdRNameGotosleep created"; "RESIDENTStk $NAME: new watchdog device $wdRNameGotosleep created";
fhem fhem
@ -567,7 +565,7 @@ return;;\
} }
# macro: asleep # macro: asleep
if ( !RESIDENTStk_IsDevice($macroRNameAsleep) ) { if ( !IsDevice($macroRNameAsleep) ) {
my $templateAsleep = "{\ my $templateAsleep = "{\
##=============================================================================\ ##=============================================================================\
## This is an example macro when all residents are in their beds.\ ## This is an example macro when all residents are in their beds.\
@ -613,7 +611,7 @@ return;;\
} }
# wd: asleep # wd: asleep
if ( !RESIDENTStk_IsDevice($wdRNameAsleep) ) { if ( !IsDevice($wdRNameAsleep) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdNameAsleep created"; "RESIDENTStk $NAME: new watchdog device $wdNameAsleep created";
fhem fhem
@ -626,7 +624,7 @@ return;;\
} }
# macro: awoken # macro: awoken
if ( !RESIDENTStk_IsDevice($macroRNameAwoken) ) { if ( !IsDevice($macroRNameAwoken) ) {
my $templateAwoken = "{\ my $templateAwoken = "{\
##=============================================================================\ ##=============================================================================\
## This is an example macro when the first resident has confirmed to be awake\ ## This is an example macro when the first resident has confirmed to be awake\
@ -675,7 +673,7 @@ return;;\
} }
# wd: awoken # wd: awoken
if ( !RESIDENTStk_IsDevice($wdRNameAwoken) ) { if ( !IsDevice($wdRNameAwoken) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new watchdog device $wdNameAwoken created"; "RESIDENTStk $NAME: new watchdog device $wdNameAwoken created";
fhem fhem
@ -690,7 +688,7 @@ return;;\
} }
} }
elsif ( RESIDENTStk_GetType($wakeupAtdevice) ne "at" ) { elsif ( GetType($wakeupAtdevice) ne "at" ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: WARNING - defined at-device '$wakeupAtdevice' is not an at-device!"; "RESIDENTStk $NAME: WARNING - defined at-device '$wakeupAtdevice' is not an at-device!";
} }
@ -708,13 +706,13 @@ return;;\
return return
"ERROR: wakeupHolidays set in this alarm clock but global attribute holiday2we not set!"; "ERROR: wakeupHolidays set in this alarm clock but global attribute holiday2we not set!";
} }
elsif ( !RESIDENTStk_IsDevice($holidayDevice) ) { elsif ( !IsDevice($holidayDevice) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: ERROR - global attribute holiday2we has reference to non-existing device $holidayDevice"; "RESIDENTStk $NAME: ERROR - global attribute holiday2we has reference to non-existing device $holidayDevice";
return return
"ERROR: global attribute holiday2we has reference to non-existing device $holidayDevice"; "ERROR: global attribute holiday2we has reference to non-existing device $holidayDevice";
} }
elsif ( RESIDENTStk_GetType($holidayDevice) ne "holiday" ) { elsif ( GetType($holidayDevice) ne "holiday" ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: ERROR - global attribute holiday2we seems to have invalid device reference - $holidayDevice is not of type 'holiday'"; "RESIDENTStk $NAME: ERROR - global attribute holiday2we seems to have invalid device reference - $holidayDevice is not of type 'holiday'";
return return
@ -746,11 +744,11 @@ return;;\
if ( !$wakeupMacro ) { if ( !$wakeupMacro ) {
Log3 $NAME, 2, "RESIDENTStk $NAME: missing attribute wakeupMacro"; Log3 $NAME, 2, "RESIDENTStk $NAME: missing attribute wakeupMacro";
} }
elsif ( !RESIDENTStk_IsDevice($wakeupMacro) ) { elsif ( !IsDevice($wakeupMacro) ) {
Log3 $NAME, 2, Log3 $NAME, 2,
"RESIDENTStk $NAME: notify macro $wakeupMacro not found - no wakeup actions defined!"; "RESIDENTStk $NAME: notify macro $wakeupMacro not found - no wakeup actions defined!";
} }
elsif ( RESIDENTStk_GetType($wakeupMacro) ne "notify" ) { elsif ( GetType($wakeupMacro) ne "notify" ) {
Log3 $NAME, 2, Log3 $NAME, 2,
"RESIDENTStk $NAME: device $wakeupMacro is not of type notify"; "RESIDENTStk $NAME: device $wakeupMacro is not of type notify";
} }
@ -784,7 +782,7 @@ return;;\
} }
my $wakeupStopAtdevice = $wakeupAtdevice . "_stop"; my $wakeupStopAtdevice = $wakeupAtdevice . "_stop";
if ( RESIDENTStk_IsDevice($wakeupStopAtdevice) ) { if ( IsDevice($wakeupStopAtdevice) ) {
fhem "delete $wakeupStopAtdevice"; fhem "delete $wakeupStopAtdevice";
} }
} }
@ -826,7 +824,7 @@ return;;\
|| $VALUE =~ /^[\+\-][1-9]*[0-9]*$/ || $VALUE =~ /^[\+\-][1-9]*[0-9]*$/
|| $VALUE =~ /^[\+\-]?([0-9]{2}):([0-9]{2})$/ || $VALUE =~ /^[\+\-]?([0-9]{2}):([0-9]{2})$/
) )
&& RESIDENTStk_GetType($wakeupAtdevice) eq "at" && GetType($wakeupAtdevice) eq "at"
) )
{ {
@ -901,17 +899,17 @@ sub RESIDENTStk_wakeupGetBegin($;$) {
# just give any valuable return to at-device # just give any valuable return to at-device
# if wakeuptimer device does not exit anymore # if wakeuptimer device does not exit anymore
# and run self-destruction to clean up # and run self-destruction to clean up
if ( !RESIDENTStk_IsDevice($NAME) ) { if ( !IsDevice($NAME) ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: this wake-up timer device does not exist anymore"; "RESIDENTStk $NAME: this wake-up timer device does not exist anymore";
my $atName = "at_" . $NAME; my $atName = "at_" . $NAME;
if ( RESIDENTStk_GetType($wakeupAtdevice) eq "at" ) { if ( GetType($wakeupAtdevice) eq "at" ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: Cleaning up at-device $wakeupAtdevice (self-destruction)"; "RESIDENTStk $NAME: Cleaning up at-device $wakeupAtdevice (self-destruction)";
fhem "sleep 1; delete $wakeupAtdevice"; fhem "sleep 1; delete $wakeupAtdevice";
} }
elsif ( RESIDENTStk_GetType($atName) eq "at" ) { elsif ( GetType($atName) eq "at" ) {
Log3 $NAME, 3, "RESIDENTStk $NAME: Cleaning up at-device $atName"; Log3 $NAME, 3, "RESIDENTStk $NAME: Cleaning up at-device $atName";
fhem "sleep 1; delete $atName"; fhem "sleep 1; delete $atName";
} }
@ -983,7 +981,7 @@ sub RESIDENTStk_wakeupRun($;$) {
my $holidayToday = ""; my $holidayToday = "";
if ( $wakeupHolidays if ( $wakeupHolidays
&& RESIDENTStk_GetType($holidayDevice) eq "holiday" ) && GetType($holidayDevice) eq "holiday" )
{ {
my $hdayTod = ReadingsVal( $holidayDevice, "state", "" ); my $hdayTod = ReadingsVal( $holidayDevice, "state", "" );
@ -1035,7 +1033,7 @@ sub RESIDENTStk_wakeupRun($;$) {
if ( $wakeupResetdays ne "" ); if ( $wakeupResetdays ne "" );
my %rdays = map { $_ => 1 } @rdays; my %rdays = map { $_ => 1 } @rdays;
if ( !RESIDENTStk_IsDevice($NAME) ) { if ( !IsDevice($NAME) ) {
return "$NAME: Non existing device"; return "$NAME: Non existing device";
} }
elsif ( lc($nextRun) eq "off" && !$forceRun ) { elsif ( lc($nextRun) eq "off" && !$forceRun ) {
@ -1045,16 +1043,14 @@ sub RESIDENTStk_wakeupRun($;$) {
elsif ( !$wakeupUserdevice ) { elsif ( !$wakeupUserdevice ) {
return "$NAME: missing attribute wakeupUserdevice"; return "$NAME: missing attribute wakeupUserdevice";
} }
elsif ( !RESIDENTStk_IsDevice($wakeupUserdevice) ) { elsif ( !IsDevice($wakeupUserdevice) ) {
return "$NAME: Non existing wakeupUserdevice $wakeupUserdevice"; return "$NAME: Non existing wakeupUserdevice $wakeupUserdevice";
} }
elsif ( elsif ( !IsDevice( $wakeupUserdevice, "RESIDENTS|ROOMMATE|GUEST" ) ) {
!RESIDENTStk_IsDevice( $wakeupUserdevice, "RESIDENTS|ROOMMATE|GUEST" ) )
{
return return
"$NAME: device $wakeupUserdevice is not of type RESIDENTS, ROOMMATE or GUEST"; "$NAME: device $wakeupUserdevice is not of type RESIDENTS, ROOMMATE or GUEST";
} }
elsif ( RESIDENTStk_GetType($wakeupUserdevice) eq "GUEST" elsif ( GetType($wakeupUserdevice) eq "GUEST"
&& $wakeupUserdeviceState eq "none" ) && $wakeupUserdeviceState eq "none" )
{ {
Log3 $NAME, 4, Log3 $NAME, 4,
@ -1134,11 +1130,11 @@ sub RESIDENTStk_wakeupRun($;$) {
if ( !$wakeupMacro ) { if ( !$wakeupMacro ) {
return "$NAME: missing attribute wakeupMacro"; return "$NAME: missing attribute wakeupMacro";
} }
elsif ( !RESIDENTStk_IsDevice($wakeupMacro) ) { elsif ( !IsDevice($wakeupMacro) ) {
return return
"$NAME: notify macro $wakeupMacro not found - no wakeup actions defined!"; "$NAME: notify macro $wakeupMacro not found - no wakeup actions defined!";
} }
elsif ( RESIDENTStk_GetType($wakeupMacro) ne "notify" ) { elsif ( GetType($wakeupMacro) ne "notify" ) {
return "$NAME: device $wakeupMacro is not of type notify"; return "$NAME: device $wakeupMacro is not of type notify";
} }
elsif ($wakeupUserdeviceWakeup) { elsif ($wakeupUserdeviceWakeup) {
@ -1189,7 +1185,7 @@ sub RESIDENTStk_wakeupRun($;$) {
if ( $wakeupOffset > 0 ) { if ( $wakeupOffset > 0 ) {
my $wakeupStopAtdevice = $wakeupAtdevice . "_stop"; my $wakeupStopAtdevice = $wakeupAtdevice . "_stop";
if ( RESIDENTStk_IsDevice($wakeupStopAtdevice) ) { if ( IsDevice($wakeupStopAtdevice) ) {
fhem "delete $wakeupStopAtdevice"; fhem "delete $wakeupStopAtdevice";
} }
@ -1231,7 +1227,7 @@ sub RESIDENTStk_wakeupRun($;$) {
my $doReset = 1; my $doReset = 1;
if ( $wakeupResetSwitcher if ( $wakeupResetSwitcher
&& RESIDENTStk_GetType($wakeupResetSwitcher) eq "dummy" && GetType($wakeupResetSwitcher) eq "dummy"
&& ReadingsVal( $wakeupResetSwitcher, "state", 0 ) eq "off" ) && ReadingsVal( $wakeupResetSwitcher, "state", 0 ) eq "off" )
{ {
$doReset = 0; $doReset = 0;
@ -1266,7 +1262,7 @@ sub RESIDENTStk_AttrFnDummy(@) {
# wakeupResetSwitcher # wakeupResetSwitcher
if ( $aName eq "wakeupResetSwitcher" ) { if ( $aName eq "wakeupResetSwitcher" ) {
if ( !RESIDENTStk_IsDevice($aVal) ) { if ( !IsDevice($aVal) ) {
my $alias = AttrVal( $name, "alias", 0 ); my $alias = AttrVal( $name, "alias", 0 );
my $group = AttrVal( $name, "group", 0 ); my $group = AttrVal( $name, "group", 0 );
my $room = AttrVal( $name, "room", 0 ); my $room = AttrVal( $name, "room", 0 );
@ -1294,7 +1290,7 @@ sub RESIDENTStk_AttrFnDummy(@) {
Log3 $name, 3, Log3 $name, 3,
"RESIDENTStk $name: new slave dummy device $aVal created"; "RESIDENTStk $name: new slave dummy device $aVal created";
} }
elsif ( RESIDENTStk_GetType($aVal) ne "dummy" ) { elsif ( GetType($aVal) ne "dummy" ) {
Log3 $name, 3, Log3 $name, 3,
"RESIDENTStk $name: Defined device name in attr $aName is not a dummy device"; "RESIDENTStk $name: Defined device name in attr $aName is not a dummy device";
return "Existing device $aVal is not a dummy!"; return "Existing device $aVal is not a dummy!";
@ -1346,7 +1342,7 @@ sub RESIDENTStk_wakeupGetNext($) {
for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
next if !$wakeupDevice; next if !$wakeupDevice;
if ( !RESIDENTStk_IsDevice($wakeupDevice) ) { if ( !IsDevice($wakeupDevice) ) {
Log3 $name, 4, Log3 $name, 4,
"RESIDENTStk $name: 00 - ignoring reference to non-existing wakeupDevice $wakeupDevice"; "RESIDENTStk $name: 00 - ignoring reference to non-existing wakeupDevice $wakeupDevice";
@ -1371,7 +1367,7 @@ sub RESIDENTStk_wakeupGetNext($) {
my $wakeupAtdevice = AttrVal( $wakeupDevice, "wakeupAtdevice", 0 ); my $wakeupAtdevice = AttrVal( $wakeupDevice, "wakeupAtdevice", 0 );
my $wakeupOffset = AttrVal( $wakeupDevice, "wakeupOffset", 0 ); my $wakeupOffset = AttrVal( $wakeupDevice, "wakeupOffset", 0 );
my $wakeupAtNTM = ( my $wakeupAtNTM = (
RESIDENTStk_IsDevice($wakeupAtdevice) IsDevice($wakeupAtdevice)
&& defined( $defs{$wakeupAtdevice}{NTM} ) && defined( $defs{$wakeupAtdevice}{NTM} )
? substr( $defs{$wakeupAtdevice}{NTM}, 0, -3 ) ? substr( $defs{$wakeupAtdevice}{NTM}, 0, -3 )
: 0 : 0
@ -1384,7 +1380,7 @@ sub RESIDENTStk_wakeupGetNext($) {
# get holiday status for today and tomorrow # get holiday status for today and tomorrow
if ( $wakeupHolidays if ( $wakeupHolidays
&& $holidayDevice && $holidayDevice
&& RESIDENTStk_GetType($holidayDevice) eq "holiday" ) && GetType($holidayDevice) eq "holiday" )
{ {
if ( $hdayTod ne "none" && $hdayTod ne "" ) { if ( $hdayTod ne "none" && $hdayTod ne "" ) {
$holidayToday = 1; $holidayToday = 1;
@ -1779,31 +1775,4 @@ sub RESIDENTStk_findResidentSlaves($) {
} }
} }
sub RESIDENTStk_IsDevice($;$) {
my $devname = shift;
my $devtype = shift;
return 1
if ( defined($devname)
&& defined( $defs{$devname} )
&& ( !$devtype || $devtype eq "" ) );
return 1
if ( defined($devname)
&& defined( $defs{$devname} )
&& defined( $defs{$devname}{TYPE} )
&& $defs{$devname}{TYPE} =~ m/^$devtype$/ );
return 0;
}
sub RESIDENTStk_GetType($;$) {
my $devname = shift;
my $default = shift;
return $default
unless ( RESIDENTStk_IsDevice($devname) && $defs{$devname}{TYPE} );
return $defs{$devname}{TYPE};
}
1; 1;

View File

@ -4458,7 +4458,7 @@ sub CommandSetReadingDesc($@) {
my @rets; my @rets;
my $last; my $last;
foreach my $name ( devspec2array( $a->[0], $cl ) ) { foreach my $name ( devspec2array( $a->[0], $cl ) ) {
unless ( Unit_IsDevice($name) ) { unless ( IsDevice($name) ) {
push @rets, "Please define $name first"; push @rets, "Please define $name first";
next; next;
} }
@ -4524,7 +4524,7 @@ sub CommandDeleteReadingDesc($@) {
my @rets; my @rets;
my $last; my $last;
foreach my $name ( devspec2array( $a->[0], $cl ) ) { foreach my $name ( devspec2array( $a->[0], $cl ) ) {
unless ( Unit_IsDevice($name) ) { unless ( IsDevice($name) ) {
push @rets, "Please define $name first"; push @rets, "Please define $name first";
next; next;
} }
@ -4549,22 +4549,4 @@ sub CommandDeleteReadingDesc($@) {
return join( "\n", @rets ); return join( "\n", @rets );
} }
sub Unit_IsDevice($;$) {
my $devname = shift;
my $devtype = shift;
return 1
if ( defined($devname)
&& defined( $defs{$devname} )
&& ( !$devtype || $devtype eq "" ) );
return 1
if ( defined($devname)
&& defined( $defs{$devname} )
&& defined( $defs{$devname}{TYPE} )
&& $defs{$devname}{TYPE} =~ m/^$devtype$/ );
return 0;
}
1; 1;