2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

75_MSG: add support for PostMe module

git-svn-id: https://svn.fhem.de/fhem/trunk@13817 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-03-27 13:19:43 +00:00
parent eb86e242e3
commit 77041f1b7e
4 changed files with 130 additions and 19 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: 75_MSG: add support for PostMe module
- feature: 74_XiaomiFlowerSens: 1.0.1 new Attributs minLux and maxLux
- feature: 98_monitoring: blacklist attribute is now a space seperated list
of devspecs instead a comma seperated list of devices

View File

@ -30,6 +30,7 @@
# reachable via msg
# - implement default messages in RESIDENTS using msg command
# - queue message until recipient is available again (e.g. when absent)
# also see https://forum.fhem.de/index.php/topic,69683.0.html
#
package main;
@ -55,7 +56,7 @@ sub MSG_Initialize($$) {
########################################
sub MSG_FindAttrVal($$$$) {
my ( $d, $n, $msgType, $default ) = @_;
$msgType = ucfirst($msgType);
$msgType = ucfirst($msgType) if ($msgType);
$n .= $msgType if ( $n =~ /^msg(Contact|Priority)$/ );
my $g = (
@ -78,7 +79,7 @@ sub MSG_FindAttrVal($$$$) {
AttrVal( $d, "msgRecipient$msgType", "" ),
$n,
# look for indirect general
# look for indirect, type-independent
AttrVal(
AttrVal( $d, "msgRecipient", "" ),
$n,
@ -92,7 +93,7 @@ sub MSG_FindAttrVal($$$$) {
AttrVal( $g, "msgRecipient$msgType", "" ),
$n,
# look for global indirect general
# look for global indirect, type-independent
AttrVal(
AttrVal( $g, "msgRecipient", "" ),
$n,
@ -110,7 +111,7 @@ sub MSG_FindAttrVal($$$$) {
########################################
sub MSG_FindReadingsVal($$$$) {
my ( $d, $n, $msgType, $default ) = @_;
$msgType = ucfirst($msgType);
$msgType = ucfirst($msgType) if ($msgType);
return
@ -123,7 +124,7 @@ sub MSG_FindReadingsVal($$$$) {
AttrVal( $d, "msgRecipient$msgType", "" ),
$n,
# look for indirect general
# look for indirect, type-independent
ReadingsVal(
AttrVal( $d, "msgRecipient", "" ),
$n,
@ -366,6 +367,7 @@ s/^[\s\t]*([!]?(([A-Za-z0-9%+._-])*@([%+a-z0-9A-Z.-]+))[\w,@.!|:]*)[\s\t]+//
my %sentTypesPerDevice;
my $sentCounter = 0;
my $msgID = time();
my $msgDateTime = TimeNow();
my $isTypeOr = 1;
my $isRecipientOr = 1;
my $hasTypeOr = 0;
@ -743,7 +745,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
my $loopPriority = $priority;
$loopPriority =
MSG_FindAttrVal( $device, "msgPriority", $typeUc, 0 )
unless ( defined($priority) );
if ( $priority eq "" );
# check for available routes
#
@ -1473,14 +1475,90 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
}
}
$cmd =~ s/%DEVICE%/$gatewayDev/gi;
$cmd =~ s/%PRIORITY%/$loopPriority/gi;
$cmd =~ s/%TITLE%/$loopTitle/gi;
$cmd =~ s/%PRIOCAT%/$priorityCat/gi;
$cmd =~ s/%MSG%/$loopMsg/gi;
$cmd =~ s/%MSGID%/$msgID.$sentCounter/gi;
$cmd =~ s/%TITLE%/$loopTitle/gi;
my $loopTitle2 = $loopTitle;
$loopTitle2 = substr( $loopTitle2, 0, 27 ) . "..."
if ( length($loopTitle2) > 30 );
$cmd =~ s/%TITLESHRT%/$loopTitle2/gi;
$loopTitle2 =~ s/^([\s\t ]*\w+).*/$1/g;
$loopTitle2 = substr( $loopTitle2, 0, 17 ) . "..."
if ( length($loopTitle2) > 20 );
$cmd =~ s/%TITLESHRT2%/$loopTitle2/gi;
my $deviceName = AttrVal(
$device,
AttrVal(
$device,
"rg_realname",
AttrVal( $device, "rr_realname", "group" )
),
AttrVal( $device, "alias", $device )
);
my $deviceName2 = $deviceName;
$deviceName2 =~ s/ /_/;
$cmd =~ s/%SOURCE%/$device/gi;
$cmd =~ s/%SRCALIAS%/$deviceName/gi;
$cmd =~ s/%SRCALIAS2%/$deviceName2/gi;
my $gatewayDevName = AttrVal(
$gatewayDev,
AttrVal(
$gatewayDev,
"rg_realname",
AttrVal(
$gatewayDev, "rr_realname", "group"
)
),
AttrVal( $gatewayDev, "alias", $gatewayDev )
);
my $gatewayDevName2 = $gatewayDevName;
$gatewayDevName2 =~ s/ /_/;
$cmd =~ s/%DEVICE%/$gatewayDev/gi;
$cmd =~ s/%DEVALIAS%/$gatewayDevName/gi;
$cmd =~ s/%DEVALIAS2%/$gatewayDevName2/gi;
my $loopMsgDateTime = $msgDateTime;
$loopMsgDateTime .= ".$sentCounter"
if ($sentCounter);
my $loopMsgDateTime2 = $loopMsgDateTime;
$loopMsgDateTime2 =~ s/ /_/;
$cmd =~ s/%MSGDATETIME%/$loopMsgDateTime/gi;
$cmd =~ s/%MSGDATETIME2%/$loopMsgDateTime2/gi;
my $subRecipientName =
$subRecipient eq ""
? ""
: AttrVal(
$subRecipient,
AttrVal(
$subRecipient,
"rg_realname",
AttrVal(
$subRecipient, "rr_realname",
"group"
)
),
AttrVal(
$subRecipient, "alias", $subRecipient
)
);
my $subRecipientName2 = $subRecipientName;
$subRecipientName2 =~ s/ /_/;
$cmd =~ s/%RECIPIENT%/$subRecipient/gi
if ( $subRecipient ne "" );
$cmd =~ s/%RCPTNAME%/$subRecipientName/gi
if ( $subRecipientName ne "" );
$cmd =~ s/%RCPTNAME2%/$subRecipientName2/gi
if ( $subRecipientName2 ne "" );
$cmd =~ s/%TERMINAL%/$termRecipient/gi
if ( $termRecipient ne "" );
@ -1584,6 +1662,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
my ( $a, $h ) = parseParams($cmd);
keys %$params;
while ( ( my $key, my $value ) =
each %$params )
{
@ -1730,6 +1809,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
my $gwStates = "-";
keys %gatewaysStatus;
while ( ( my $gwName, my $gwState ) = each %gatewaysStatus )
{
$gwStates = "" if $gwStates eq "-";
@ -1938,6 +2018,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
}
# finalize device readings
keys %sentTypesPerDevice;
while ( ( my $device, my $types ) = each %sentTypesPerDevice ) {
$device = $globalDevName
if ( $device =~ /^(([A-Za-z0-9%+._-])+[@]+([%+a-z0-9A-Z.-]*))$/ );

View File

@ -22,13 +22,6 @@
# You should have received a copy of the GNU General Public License
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
#
#
# Version: 1.0.0
#
# Major Version History:
# - 1.0.0 - 2015-10-18
# -- First release
#
##############################################################################
package main;
@ -115,7 +108,7 @@ sub msgConfig_Initialize($) {
msgTitleText
msgTitleTextHigh
msgTitleTextLow
msgType
msgType:text,push,mail,screen,light,audio
);
use warnings 'qw';
$hash->{AttrList} = join( " ", @attrList ) . " " . $readingFnAttributes;
@ -161,6 +154,7 @@ sub msgConfig_Define($$) {
$attr{$name}{room} = $room if ( $room ne "" );
$attr{$name}{comment} = "FHEM Global Configuration for command 'msg'";
$attr{$name}{stateFormat} = "fhemMsgState";
$attr{$name}{msgType} = "text";
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "fhemMsgState", "initialized" );

View File

@ -374,6 +374,41 @@ my $db = {
},
},
'PostMe' => {
'Normal' =>
'set %DEVICE% create %RCPTNAME2%; set %DEVICE% add %RCPTNAME2% %MSGDATETIME2%_%TITLESHRT2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%TITLESHRT2% %PostMe_TO% %SRCALIAS2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%TITLESHRT2% %PostMe_SUB% %TITLE%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%TITLESHRT2% %PostMe_MSG% %MSG%',
'High' =>
'set %DEVICE% create %RCPTNAME2%; set %DEVICE% add %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_PRIO% %PRIOCAT%/%PRIORITY%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_TO% %SRCALIAS2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_SUB% %TITLE%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_MSG% %MSG%',
'Low' =>
'set %DEVICE% create %RCPTNAME2%; set %DEVICE% add %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_PRIO% %PRIOCAT%/%PRIORITY%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_TO% %SRCALIAS2%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_SUB% %TITLE%; set %DEVICE% modify %RCPTNAME2% %MSGDATETIME2%_%PRIOCAT%__%TITLESHRT2% %PostMe_MSG% %MSG%',
'defaultValues' => {
'Normal' => {
'RCPTNAME2' => 'Notifications',
'TITLE' => 'Info',
'PostMe_TO' => 'To',
'PostMe_PRIO' => 'Priority',
'PostMe_SUB' => 'Subject',
'PostMe_MSG' => 'Message',
},
'High' => {
'RCPTNAME2' => 'Notifications',
'TITLE' => 'Warning',
'PostMe_TO' => 'To',
'PostMe_PRIO' => 'Priority',
'PostMe_SUB' => 'Subject',
'PostMe_MSG' => 'Message',
},
'Low' => {
'RCPTNAME2' => 'Notifications',
'TITLE' => 'Notice',
'PostMe_TO' => 'To',
'PostMe_PRIO' => 'Priority',
'PostMe_SUB' => 'Subject',
'PostMe_MSG' => 'Message',
},
},
},
'XBMC' => {
'Normal' =>
'{ my $d=\'%DEVICE%\'; my $msg=\'%MSG%\'; my $title=\'%TITLE%\'; my $timeout=%TIMEOUT%*1000; fhem "set $d msg \'$title\' \'$msg\' $timeout %XBMC_ICON%"; }',