1
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-07 22:29:19 +00:00

75_MSG: add support for ReplaceSetMagic

git-svn-id: https://svn.fhem.de/fhem/trunk@13278 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-01-29 23:47:30 +00:00
parent 8d18a49780
commit 05a8a9faf1
2 changed files with 94 additions and 19 deletions

View File

@ -1,5 +1,8 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: 75_MSG: support for ReplaceSetMagic; msg command may now be used
with texts containing [device:reading] to replace with
found readings
- feature: 98_weekprofile: attributes for temperature 'on' and 'off' - feature: 98_weekprofile: attributes for temperature 'on' and 'off'
- feature: 98_BOSEST: NEW REQUIREMENT sox, libsox-fmt-mp3 for TTS - feature: 98_BOSEST: NEW REQUIREMENT sox, libsox-fmt-mp3 for TTS
- feature: 98_BOSEST: support more than 100 chars for TTS - feature: 98_BOSEST: support more than 100 chars for TTS

View File

@ -22,14 +22,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with fhem. If not, see <http://www.gnu.org/licenses/>. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
# #
#
# Version: 1.0.0
#
# Major Version History:
#
# - 1.0.0 - 2015-11-01
# -- First release
#
############################################################################## ##############################################################################
package main; package main;
@ -1903,6 +1895,67 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
next; next;
} }
# ReplaceSetMagic
#
my $replaceError;
if ( $featurelevel >= 5.7 ) {
my %dummy;
my ( $err, @a );
# MSG
( $err, @a ) =
ReplaceSetMagic( \%dummy, 0, ($loopMsg) );
$replaceError .=
"ReplaceSetMagic failed for MSG: $err\n"
if ($err);
$loopMsg = join( " ", @a )
unless ($err);
# DEVICE
( $err, @a ) =
ReplaceSetMagic( \%dummy, 0, ($gatewayDev) );
$replaceError .=
"ReplaceSetMagic failed for DEVICE: $err\n"
if ($err);
$gatewayDev = join( " ", @a )
unless ($err);
# TITLE
( $err, @a ) =
ReplaceSetMagic( \%dummy, 0, ($loopTitle) );
$replaceError .=
"ReplaceSetMagic failed for TITLE: $err\n"
if ($err);
$loopTitle = join( " ", @a )
unless ($err);
# RECIPIENT
if ( $subRecipient ne "" ) {
( $err, @a ) =
ReplaceSetMagic( \%dummy, 0,
($subRecipient) );
$replaceError .=
"ReplaceSetMagic failed "
. "for RECIPIENT: $err\n"
if ($err);
$subRecipient = join( " ", @a )
unless ($err);
}
# TERMINAL
if ( $subRecipient ne "" ) {
( $err, @a ) =
ReplaceSetMagic( \%dummy, 0,
($termRecipient) );
$replaceError .=
"ReplaceSetMagic failed "
. "for TERMINAL: $err\n"
if ($err);
$termRecipient = join( " ", @a )
unless ($err);
}
}
$cmd =~ s/%DEVICE%/$gatewayDev/gi; $cmd =~ s/%DEVICE%/$gatewayDev/gi;
$cmd =~ s/%PRIORITY%/$loopPriority/gi; $cmd =~ s/%PRIORITY%/$loopPriority/gi;
$cmd =~ s/%TITLE%/$loopTitle/gi; $cmd =~ s/%TITLE%/$loopTitle/gi;
@ -1972,9 +2025,25 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
my $error = 0; my $error = 0;
# ReplaceSetMagic
#
if ( $featurelevel >= 5.7 && !$replaceError ) {
my %dummy;
my ( $err, @a ) =
ReplaceSetMagic( \%dummy, 0, ($cmd) );
$replaceError .=
"ReplaceSetMagic failed for CMD: $err\n"
if ($err);
$cmd = join( " ", @a )
unless ($err);
}
# run command # run command
undef $@; if ($replaceError) {
if ( $cmd =~ s/^[ \t]*\{|\}[ \t]*$//gi ) { $error = 2;
$return .= $replaceError;
}
elsif ( $cmd =~ /^\s*\{.*\}\s*$/ ) {
Log3 $logDevice, 5, Log3 $logDevice, 5,
"msg $device: $type[$i] route command (Perl): $cmd"; "msg $device: $type[$i] route command (Perl): $cmd";
eval $cmd; eval $cmd;
@ -1993,22 +2062,25 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
} }
} }
$routeStatus = "ERROR" if ( $error == 1 ); $routeStatus = "ERROR"
if ( $error == 1 );
$routeStatus = "ERROR_EVAL"
if ( $error == 2 );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority($priorityCat) TITLE='$loopTitle' MSG='$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority($priorityCat) TITLE='$loopTitle' MSG='$loopMsg'"
if ( $priorityCat ne "" if ( $priorityCat ne ""
&& $subRecipient ne "" ); && $subRecipient ne "" );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' MSG='$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' MSG='$loopMsg'"
if ( $priorityCat eq "" if ( $priorityCat eq ""
&& $subRecipient ne "" ); && $subRecipient ne "" );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority($priorityCat) TITLE='$loopTitle' MSG='$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority($priorityCat) TITLE='$loopTitle' MSG='$loopMsg'"
if ( $priorityCat ne "" if ( $priorityCat ne ""
&& $subRecipient eq "" ); && $subRecipient eq "" );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' MSG='$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' MSG='$loopMsg'"
if ( $priorityCat eq "" if ( $priorityCat eq ""
&& $subRecipient eq "" ); && $subRecipient eq "" );
@ -2033,10 +2105,10 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
|| $routeStatus eq "UNDEFINED" ) || $routeStatus eq "UNDEFINED" )
{ {
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$loopMsg'"
if ( $subRecipient ne "" ); if ( $subRecipient ne "" );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$loopMsg'"
if ( $subRecipient eq "" ); if ( $subRecipient eq "" );
$gatewaysStatus{$gatewayDev} = $routeStatus $gatewaysStatus{$gatewayDev} = $routeStatus
if ( $globalDevName ne $gatewayDev ); if ( $globalDevName ne $gatewayDev );
@ -2045,10 +2117,10 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
} }
else { else {
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev RECIPIENT=$subRecipient STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$loopMsg'"
if ( $subRecipient ne "" ); if ( $subRecipient ne "" );
Log3 $logDevice, 3, Log3 $logDevice, 3,
"msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$msg'" "msg $device: ID=$msgID.$sentCounter TYPE=$type[$i] ROUTE=$gatewayDev STATUS=$routeStatus PRIORITY=$loopPriority TITLE='$loopTitle' '$loopMsg'"
if ( $subRecipient eq "" ); if ( $subRecipient eq "" );
$msgSent = 2 if ( $msgSent != 1 ); $msgSent = 2 if ( $msgSent != 1 );
$msgSentDev = 2 if ( $msgSentDev != 1 ); $msgSentDev = 2 if ( $msgSentDev != 1 );