-
Notifications
You must be signed in to change notification settings - Fork 4
/
97_PAClient.pm
executable file
·109 lines (88 loc) · 2.72 KB
/
97_PAClient.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main;
use strict;
use warnings;
my $PAClient_LogLevelDebug = 1;
my $PAClient_LogLevelNormal = 1;
my $PAClient_LogLevelCritical =1;
my $PAClient_standard_interval = 10;
my %PAClient_gets = (
"tbd" => "x"
);
my %PAClient_sets = (
"desired-master" => ""
);
sub PAClient_Initialize($) {
my ($hash) = @_;
$hash->{DefFn} = 'PAClient_Define';
$hash->{UndefFn} = 'PAClient_Undef';
$hash->{SetFn} = 'PAClient_Set';
$hash->{GetFn} = 'PAClient_Get';
$hash->{AttrFn} = 'PAClient_Attr';
$hash->{ReadFn} = 'PAClient_Read';
$hash->{Match} = ".*";
$hash->{AttrList} =
"IODev startcmd stopcmd interval "
. $readingFnAttributes;
}
sub PAClient_Define($$) {
my ($hash, $def) = @_;
my @a = split('[ \t]+', $def);
if (@a != 3) {
my $msg = "wrong syntax: define <name> PAClient <host/ip>";
Log3 undef, 2, $msg;
return $msg;
}
$hash->{name} = $a[0];
$hash->{ip} = $a[2];
Log $PAClient_LogLevelNormal, "PAClient: Device $a[0] defined.";
readingsSingleUpdate($hash,"state","defined",1);
RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+5, "PAServer_processCmd", $hash, 0); # initiate the regular update process
AssignIoPort($hash);
return undef;
}
sub PAClient_Undef($$) {
my ($hash, $arg) = @_;
# TODO: delete modules combined and tunnels
RemoveInternalTimer($hash);
BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));
IOWrite ($hash, $hash->{name},"deleted");
return undef;
}
sub PAClient_Get($@) {
my ($hash, @param) = @_;
return '"get PAClient" needs at least one argument' if (int(@param) < 2);
my $name = shift @param;
my $opt = shift @param;
if(!$PAClient_gets{$opt}) {
my @cList = keys %PAClient_gets;
return "Unknown argument $opt, choose one of " . join(" ", @cList);
}
return "to be defined";
}
sub PAClient_Set($@) {
my ($hash, @param) = @_;
return '"set PAClient" needs at least one argument' if (int(@param) < 2);
my $name = shift @param;
my $opt = shift @param;
my $value = join("", @param);
if(!defined($PAClient_sets{$opt})) {
my @cList = keys %PAClient_sets;
return "Unknown argument $name $opt $value, choose one of " . join(" ", @cList);
}
if($opt eq "desired-master"){
if($value eq $name){
return "Cant set master to self";
}
if($value eq "none"){
delete $hash->{DESIRED_MASTER};
IOWrite ($hash, $hash->{name},"DESIRED_MASTER none");
return undef;
}
$hash->{DESIRED_MASTER}=$value;
IOWrite ($hash, $hash->{name},"DESIRED_MASTER $value");
return undef;
}
return "not yet implemented";
}
1;