mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +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:
parent
eb86e242e3
commit
77041f1b7e
@ -1,5 +1,6 @@
|
|||||||
# 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: add support for PostMe module
|
||||||
- feature: 74_XiaomiFlowerSens: 1.0.1 new Attributs minLux and maxLux
|
- feature: 74_XiaomiFlowerSens: 1.0.1 new Attributs minLux and maxLux
|
||||||
- feature: 98_monitoring: blacklist attribute is now a space seperated list
|
- feature: 98_monitoring: blacklist attribute is now a space seperated list
|
||||||
of devspecs instead a comma seperated list of devices
|
of devspecs instead a comma seperated list of devices
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
# reachable via msg
|
# reachable via msg
|
||||||
# - implement default messages in RESIDENTS using msg command
|
# - implement default messages in RESIDENTS using msg command
|
||||||
# - queue message until recipient is available again (e.g. when absent)
|
# - 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;
|
package main;
|
||||||
@ -55,7 +56,7 @@ sub MSG_Initialize($$) {
|
|||||||
########################################
|
########################################
|
||||||
sub MSG_FindAttrVal($$$$) {
|
sub MSG_FindAttrVal($$$$) {
|
||||||
my ( $d, $n, $msgType, $default ) = @_;
|
my ( $d, $n, $msgType, $default ) = @_;
|
||||||
$msgType = ucfirst($msgType);
|
$msgType = ucfirst($msgType) if ($msgType);
|
||||||
$n .= $msgType if ( $n =~ /^msg(Contact|Priority)$/ );
|
$n .= $msgType if ( $n =~ /^msg(Contact|Priority)$/ );
|
||||||
|
|
||||||
my $g = (
|
my $g = (
|
||||||
@ -78,7 +79,7 @@ sub MSG_FindAttrVal($$$$) {
|
|||||||
AttrVal( $d, "msgRecipient$msgType", "" ),
|
AttrVal( $d, "msgRecipient$msgType", "" ),
|
||||||
$n,
|
$n,
|
||||||
|
|
||||||
# look for indirect general
|
# look for indirect, type-independent
|
||||||
AttrVal(
|
AttrVal(
|
||||||
AttrVal( $d, "msgRecipient", "" ),
|
AttrVal( $d, "msgRecipient", "" ),
|
||||||
$n,
|
$n,
|
||||||
@ -87,12 +88,12 @@ sub MSG_FindAttrVal($$$$) {
|
|||||||
AttrVal(
|
AttrVal(
|
||||||
$g, $n,
|
$g, $n,
|
||||||
|
|
||||||
#look for global indirect
|
# look for global indirect
|
||||||
AttrVal(
|
AttrVal(
|
||||||
AttrVal( $g, "msgRecipient$msgType", "" ),
|
AttrVal( $g, "msgRecipient$msgType", "" ),
|
||||||
$n,
|
$n,
|
||||||
|
|
||||||
# look for global indirect general
|
# look for global indirect, type-independent
|
||||||
AttrVal(
|
AttrVal(
|
||||||
AttrVal( $g, "msgRecipient", "" ),
|
AttrVal( $g, "msgRecipient", "" ),
|
||||||
$n,
|
$n,
|
||||||
@ -110,7 +111,7 @@ sub MSG_FindAttrVal($$$$) {
|
|||||||
########################################
|
########################################
|
||||||
sub MSG_FindReadingsVal($$$$) {
|
sub MSG_FindReadingsVal($$$$) {
|
||||||
my ( $d, $n, $msgType, $default ) = @_;
|
my ( $d, $n, $msgType, $default ) = @_;
|
||||||
$msgType = ucfirst($msgType);
|
$msgType = ucfirst($msgType) if ($msgType);
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -118,12 +119,12 @@ sub MSG_FindReadingsVal($$$$) {
|
|||||||
ReadingsVal(
|
ReadingsVal(
|
||||||
$d, $n,
|
$d, $n,
|
||||||
|
|
||||||
#look for indirect
|
# look for indirect
|
||||||
ReadingsVal(
|
ReadingsVal(
|
||||||
AttrVal( $d, "msgRecipient$msgType", "" ),
|
AttrVal( $d, "msgRecipient$msgType", "" ),
|
||||||
$n,
|
$n,
|
||||||
|
|
||||||
# look for indirect general
|
# look for indirect, type-independent
|
||||||
ReadingsVal(
|
ReadingsVal(
|
||||||
AttrVal( $d, "msgRecipient", "" ),
|
AttrVal( $d, "msgRecipient", "" ),
|
||||||
$n,
|
$n,
|
||||||
@ -366,6 +367,7 @@ s/^[\s\t]*([!]?(([A-Za-z0-9%+._-])*@([%+a-z0-9A-Z.-]+))[\w,@.!|:]*)[\s\t]+//
|
|||||||
my %sentTypesPerDevice;
|
my %sentTypesPerDevice;
|
||||||
my $sentCounter = 0;
|
my $sentCounter = 0;
|
||||||
my $msgID = time();
|
my $msgID = time();
|
||||||
|
my $msgDateTime = TimeNow();
|
||||||
my $isTypeOr = 1;
|
my $isTypeOr = 1;
|
||||||
my $isRecipientOr = 1;
|
my $isRecipientOr = 1;
|
||||||
my $hasTypeOr = 0;
|
my $hasTypeOr = 0;
|
||||||
@ -743,7 +745,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
|
|||||||
my $loopPriority = $priority;
|
my $loopPriority = $priority;
|
||||||
$loopPriority =
|
$loopPriority =
|
||||||
MSG_FindAttrVal( $device, "msgPriority", $typeUc, 0 )
|
MSG_FindAttrVal( $device, "msgPriority", $typeUc, 0 )
|
||||||
unless ( defined($priority) );
|
if ( $priority eq "" );
|
||||||
|
|
||||||
# check for available routes
|
# 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/%PRIORITY%/$loopPriority/gi;
|
||||||
$cmd =~ s/%TITLE%/$loopTitle/gi;
|
$cmd =~ s/%PRIOCAT%/$priorityCat/gi;
|
||||||
$cmd =~ s/%MSG%/$loopMsg/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
|
$cmd =~ s/%RECIPIENT%/$subRecipient/gi
|
||||||
if ( $subRecipient ne "" );
|
if ( $subRecipient ne "" );
|
||||||
|
$cmd =~ s/%RCPTNAME%/$subRecipientName/gi
|
||||||
|
if ( $subRecipientName ne "" );
|
||||||
|
$cmd =~ s/%RCPTNAME2%/$subRecipientName2/gi
|
||||||
|
if ( $subRecipientName2 ne "" );
|
||||||
$cmd =~ s/%TERMINAL%/$termRecipient/gi
|
$cmd =~ s/%TERMINAL%/$termRecipient/gi
|
||||||
if ( $termRecipient ne "" );
|
if ( $termRecipient ne "" );
|
||||||
|
|
||||||
@ -1584,6 +1662,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
|
|||||||
|
|
||||||
my ( $a, $h ) = parseParams($cmd);
|
my ( $a, $h ) = parseParams($cmd);
|
||||||
|
|
||||||
|
keys %$params;
|
||||||
while ( ( my $key, my $value ) =
|
while ( ( my $key, my $value ) =
|
||||||
each %$params )
|
each %$params )
|
||||||
{
|
{
|
||||||
@ -1730,6 +1809,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
|
|||||||
|
|
||||||
my $gwStates = "-";
|
my $gwStates = "-";
|
||||||
|
|
||||||
|
keys %gatewaysStatus;
|
||||||
while ( ( my $gwName, my $gwState ) = each %gatewaysStatus )
|
while ( ( my $gwName, my $gwState ) = each %gatewaysStatus )
|
||||||
{
|
{
|
||||||
$gwStates = "" if $gwStates eq "-";
|
$gwStates = "" if $gwStates eq "-";
|
||||||
@ -1938,6 +2018,7 @@ m/^(absent|disappeared|unauthorized|disconnected|unreachable)$/i
|
|||||||
}
|
}
|
||||||
|
|
||||||
# finalize device readings
|
# finalize device readings
|
||||||
|
keys %sentTypesPerDevice;
|
||||||
while ( ( my $device, my $types ) = each %sentTypesPerDevice ) {
|
while ( ( my $device, my $types ) = each %sentTypesPerDevice ) {
|
||||||
$device = $globalDevName
|
$device = $globalDevName
|
||||||
if ( $device =~ /^(([A-Za-z0-9%+._-])+[@]+([%+a-z0-9A-Z.-]*))$/ );
|
if ( $device =~ /^(([A-Za-z0-9%+._-])+[@]+([%+a-z0-9A-Z.-]*))$/ );
|
||||||
|
@ -22,13 +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-10-18
|
|
||||||
# -- First release
|
|
||||||
#
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
@ -115,7 +108,7 @@ sub msgConfig_Initialize($) {
|
|||||||
msgTitleText
|
msgTitleText
|
||||||
msgTitleTextHigh
|
msgTitleTextHigh
|
||||||
msgTitleTextLow
|
msgTitleTextLow
|
||||||
msgType
|
msgType:text,push,mail,screen,light,audio
|
||||||
);
|
);
|
||||||
use warnings 'qw';
|
use warnings 'qw';
|
||||||
$hash->{AttrList} = join( " ", @attrList ) . " " . $readingFnAttributes;
|
$hash->{AttrList} = join( " ", @attrList ) . " " . $readingFnAttributes;
|
||||||
@ -161,6 +154,7 @@ sub msgConfig_Define($$) {
|
|||||||
$attr{$name}{room} = $room if ( $room ne "" );
|
$attr{$name}{room} = $room if ( $room ne "" );
|
||||||
$attr{$name}{comment} = "FHEM Global Configuration for command 'msg'";
|
$attr{$name}{comment} = "FHEM Global Configuration for command 'msg'";
|
||||||
$attr{$name}{stateFormat} = "fhemMsgState";
|
$attr{$name}{stateFormat} = "fhemMsgState";
|
||||||
|
$attr{$name}{msgType} = "text";
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate( $hash, "fhemMsgState", "initialized" );
|
readingsBulkUpdate( $hash, "fhemMsgState", "initialized" );
|
||||||
|
@ -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' => {
|
'XBMC' => {
|
||||||
'Normal' =>
|
'Normal' =>
|
||||||
'{ my $d=\'%DEVICE%\'; my $msg=\'%MSG%\'; my $title=\'%TITLE%\'; my $timeout=%TIMEOUT%*1000; fhem "set $d msg \'$title\' \'$msg\' $timeout %XBMC_ICON%"; }',
|
'{ my $d=\'%DEVICE%\'; my $msg=\'%MSG%\'; my $title=\'%TITLE%\'; my $timeout=%TIMEOUT%*1000; fhem "set $d msg \'$title\' \'$msg\' $timeout %XBMC_ICON%"; }',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user