mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
76_MSGMail: tidy up code
git-svn-id: https://svn.fhem.de/fhem/trunk@8536 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2f105a421c
commit
fa8429adaf
@ -1,6 +1,17 @@
|
|||||||
########################################################
|
########################################################
|
||||||
# $Id$
|
# $Id$
|
||||||
########################################################
|
########################################################
|
||||||
|
#
|
||||||
|
# Created 2012 by rbente
|
||||||
|
#
|
||||||
|
########################################################
|
||||||
|
#
|
||||||
|
# History:
|
||||||
|
#
|
||||||
|
# 2015-05-06: tidy up code for restructuring
|
||||||
|
# 2015-05-05: remove dependency on Switch
|
||||||
|
#
|
||||||
|
#
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
@ -10,6 +21,7 @@ my %sets = (
|
|||||||
"clear" => "MSGMail",
|
"clear" => "MSGMail",
|
||||||
"list" => "MSGMail"
|
"list" => "MSGMail"
|
||||||
);
|
);
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Initialize Function
|
# Initialize Function
|
||||||
# Attributes are:
|
# Attributes are:
|
||||||
@ -23,8 +35,7 @@ my %sets = (
|
|||||||
# CR 0 = no CR added to the end of the line
|
# CR 0 = no CR added to the end of the line
|
||||||
# 1 = CR added to the end of the line
|
# 1 = CR added to the end of the line
|
||||||
##############################################
|
##############################################
|
||||||
sub
|
sub MSGMail_Initialize($)
|
||||||
MSGMail_Initialize($)
|
|
||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
@ -39,8 +50,7 @@ MSGMail_Initialize($)
|
|||||||
# all the data are stored in the global array @data
|
# all the data are stored in the global array @data
|
||||||
# as counter we use a READING named msgcount
|
# as counter we use a READING named msgcount
|
||||||
##############################################
|
##############################################
|
||||||
sub
|
sub MSGMail_Set($@)
|
||||||
MSGMail_Set($@)
|
|
||||||
{
|
{
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
return "Unknown argument $a[1], choose one of -> " . join(" ", sort keys %sets)
|
return "Unknown argument $a[1], choose one of -> " . join(" ", sort keys %sets)
|
||||||
@ -48,21 +58,22 @@ MSGMail_Set($@)
|
|||||||
my $name = shift @a;
|
my $name = shift @a;
|
||||||
|
|
||||||
return "no set value specified" if (int(@a) < 1);
|
return "no set value specified" if (int(@a) < 1);
|
||||||
|
|
||||||
# return "Unknown argument ?" if($a[0] eq "?");
|
# return "Unknown argument ?" if($a[0] eq "?");
|
||||||
my $v = join(" ", @a);
|
my $v = join(" ", @a);
|
||||||
##### we like to add another line of data
|
# we like to add another line of data
|
||||||
if ($a[0] eq "add")
|
if ($a[0] eq "add")
|
||||||
{
|
{
|
||||||
##### split the line in command and data
|
# split the line in command and data
|
||||||
my $mx = shift @a;
|
my $mx = shift @a;
|
||||||
my $my = join(" ", @a);
|
my $my = join(" ", @a);
|
||||||
##### check if we like to have and CR at the end of the line
|
# check if we like to have and CR at the end of the line
|
||||||
if (AttrVal($name, "CR", "0") eq "1")
|
if (AttrVal($name, "CR", "0") eq "1")
|
||||||
{
|
{
|
||||||
$my = $my . "\n";
|
$my = $my . "\n";
|
||||||
}
|
}
|
||||||
##### get the highest number of lines, stored the line in @data and increase
|
# get the highest number of lines, stored the line in @data and increase
|
||||||
##### the counter, at the end set the status
|
# the counter, at the end set the status
|
||||||
my $count = $hash->{READINGS}{msgcount}{VAL};
|
my $count = $hash->{READINGS}{msgcount}{VAL};
|
||||||
$data{$name}{$count} = $my;
|
$data{$name}{$count} = $my;
|
||||||
$hash->{READINGS}{msgcount}{TIME} = TimeNow();
|
$hash->{READINGS}{msgcount}{TIME} = TimeNow();
|
||||||
@ -70,8 +81,8 @@ MSGMail_Set($@)
|
|||||||
$hash->{STATE} = "addmsg";
|
$hash->{STATE} = "addmsg";
|
||||||
|
|
||||||
}
|
}
|
||||||
##### we like to clear our buffer, first clear all lines of @data
|
# we like to clear our buffer, first clear all lines of @data
|
||||||
##### and then set the counter to 0 and the status to clear
|
# and then set the counter to 0 and the status to clear
|
||||||
|
|
||||||
elsif ($a[0] eq "clear")
|
elsif ($a[0] eq "clear")
|
||||||
{
|
{
|
||||||
@ -86,7 +97,7 @@ MSGMail_Set($@)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##### we like to see the buffer
|
# we like to see the buffer
|
||||||
|
|
||||||
elsif ($a[0] eq "list")
|
elsif ($a[0] eq "list")
|
||||||
{
|
{
|
||||||
@ -111,8 +122,7 @@ MSGMail_Set($@)
|
|||||||
# Define Function
|
# Define Function
|
||||||
# set the counter to 0
|
# set the counter to 0
|
||||||
##############################################
|
##############################################
|
||||||
sub
|
sub MSGMail_Define($$)
|
||||||
MSGMail_Define($$)
|
|
||||||
{
|
{
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
@ -120,7 +130,7 @@ MSGMail_Define($$)
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
return $errmsg if (@a != 6);
|
return $errmsg if (@a != 6);
|
||||||
##### set all the Attributes
|
# set all the Attributes
|
||||||
$attr{$name}{from} = $a[2];
|
$attr{$name}{from} = $a[2];
|
||||||
$attr{$name}{to} = $a[3];
|
$attr{$name}{to} = $a[3];
|
||||||
$attr{$name}{smtphost} = $a[4];
|
$attr{$name}{smtphost} = $a[4];
|
||||||
@ -128,23 +138,22 @@ MSGMail_Define($$)
|
|||||||
$attr{$name}{subject} = "FHEM ";
|
$attr{$name}{subject} = "FHEM ";
|
||||||
$attr{$name}{CR} = "1";
|
$attr{$name}{CR} = "1";
|
||||||
|
|
||||||
|
|
||||||
$hash->{STATE} = "ready";
|
$hash->{STATE} = "ready";
|
||||||
$hash->{TYPE} = "MSGMail";
|
$hash->{TYPE} = "MSGMail";
|
||||||
$hash->{READINGS}{msgcount}{TIME} = TimeNow();
|
$hash->{READINGS}{msgcount}{TIME} = TimeNow();
|
||||||
$hash->{READINGS}{msgcount}{VAL} = 0;
|
$hash->{READINGS}{msgcount}{VAL} = 0;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Undefine Function
|
# Undefine Function
|
||||||
# flush all lines of data
|
# flush all lines of data
|
||||||
##############################################
|
##############################################
|
||||||
sub
|
sub MSGMail_Undef($$)
|
||||||
MSGMail_Undef($$)
|
|
||||||
{
|
{
|
||||||
my ($hash, $name) = @_;
|
my ($hash, $name) = @_;
|
||||||
my $i;
|
my $i;
|
||||||
############ flush the data
|
# flush the data
|
||||||
for ($i = 0 ; $i < ReadingsVal($name, "msgcount", 0) ; $i++)
|
for ($i = 0 ; $i < ReadingsVal($name, "msgcount", 0) ; $i++)
|
||||||
{
|
{
|
||||||
$data{$name}{$i} = "";
|
$data{$name}{$i} = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user