line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::AquariumHive::Plugin::GemBird::Socket; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
31
|
$App::AquariumHive::Plugin::GemBird::Socket::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
$App::AquariumHive::Plugin::GemBird::Socket::VERSION = '0.003'; |
6
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with qw( |
9
|
|
|
|
|
|
|
App::AquariumHive::Role |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
265
|
use String::Trim; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
280
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has socket_id => ( |
15
|
|
|
|
|
|
|
is => 'lazy', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_socket_id { |
19
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
20
|
0
|
|
|
|
|
|
my $socket_id = $self->serial_number; |
21
|
0
|
|
|
|
|
|
$socket_id =~ s/://g; |
22
|
0
|
|
|
|
|
|
return $socket_id; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has serial_number => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
required => 1, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has device_type => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
required => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub set { |
36
|
0
|
|
|
0
|
0
|
|
my ( $self, $no, $state ) = @_; |
37
|
0
|
0
|
|
|
|
|
my $function = $state ? 'o' : 'f'; |
38
|
0
|
|
|
|
|
|
my $cmd = 'sudo sispmctl -D'.$self->serial_number.' -'.$function.$no; |
39
|
0
|
|
|
|
|
|
$self->run_cmd($cmd); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub state { |
43
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
44
|
0
|
|
|
|
|
|
my @lines = $self->run_cmd('sudo sispmctl -D'.$self->serial_number.' -gall'); |
45
|
0
|
|
|
|
|
|
my %state; |
46
|
0
|
|
|
|
|
|
for (@lines) { |
47
|
0
|
0
|
|
|
|
|
if ($_ =~ m/^Status of outlet (\d+):(.+)$/) { |
48
|
0
|
|
|
|
|
|
my $no = $1; |
49
|
0
|
|
|
|
|
|
my $onoff = trim($2); |
50
|
0
|
0
|
|
|
|
|
$state{$no} = $onoff eq 'on' ? 1 : 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
return \%state; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
App::AquariumHive::Plugin::GemBird::Socket |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.003 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
B<IN DEVELOPMENT, DO NOT USE YET> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
See L<http://aquariumhive.com/> for now. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SUPPORT |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
IRC |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Join #AquariumHive on irc.freenode.net. Highlight Getty for fast reaction :). |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Repository |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
https://github.com/homehivelab/aquariumhive |
85
|
|
|
|
|
|
|
Pull request and additional contributors are welcome |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Issue Tracker |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
https://github.com/homehivelab/aquariumhive/issues |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Torsten Raudssus <torsten@raudss.us> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Torsten Raudssus. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
100
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |