lib/Power/Outlet.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 90.0% 54 / 60 CC 4 SCAR 6.6
CC
4
Cov
91%
new
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« lib/Power/Outlet/OpenBeken.pm ↑ Summary lib/Power/Outlet/Common/IP/HTTPS.pm »
1 package Power::Outlet;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 our $VERSION = '0.54';
6  
7 =head1 NAME
8  
9 Power::Outlet - Control and query network attached power outlets
10  
11 =head1 SYNOPSIS
12  
13 Command Line
14  
15 power-outlet Config ON section "My Section"
16 power-outlet iBoot ON host mylamp
17 power-outlet Hue ON host mybridge id 1 username myuser
18 power-outlet Shelly ON host myshelly
19 power-outlet SonoffDiy ON host mysonoff
20 power-outlet Tasmota ON host mytasmota
21 power-outlet WeMo ON host mywemo
22  
23 Perl Object API
24  
25 my $outlet=Power::Outlet->new( #sane defaults from manufactures spec
26 type => "iBoot",
27 host => "mylamp",
28 );
29 print $outlet->query, "\n";
30 print $outlet->on, "\n";
31 print $outlet->off, "\n";
32  
33 =head1 DESCRIPTION
34  
35 Power::Outlet is a package for controlling and querying network attached power outlets. Individual hardware drivers in this name space must provide a common object interface for the controlling and querying of an outlet. Common methods that every network attached power outlet must know are on, off, query, switch and cycle. Optional methods might be implemented in some drivers like amps and volts.
36  
37 =head2 SCOPE
38  
39 The current scope of these packages is network attached power outlets. I started with iBoot and iBootBar since I had the hardware. Hardware configuration is beyond the scope of this group of packages as most power outlets have functional web based or command line configuration tools.
40  
41 =head2 Home Assistant
42  
43 Integration with Home Assistant L<https://home-assistant.io/> can be accomplished by configuring a Command Line Switch.
44  
45 switch:
46 - platform: command_line
47 switches:
48 ibootbar_1:
49 command_on: /usr/bin/power-outlet iBootBar ON host mybar.local outlet 1
50 command_off: /usr/bin/power-outlet iBootBar OFF host mybar.local outlet 1
51 command_state: /usr/bin/power-outlet iBootBar QUERY host mybar.local outlet 1 | /bin/grep -q ON
52 friendly_name: My iBootBar Outlet 1
53  
54 See L<https://home-assistant.io/components/switch.command_line/>
55  
56 =head2 Node Red
57  
58 Integration with Node Red L<https://nodered.org/> can be accomplished with the included JSON web API power-outlet-json.cgi. The power-outlet-json.cgi script is a layer on top of L<Power::Outlet::Config> where the "name" parameter maps to the section in the /etc/power-outlet.ini INI file.
59  
60 To access all of these devices use an http request node with a URL https://127.0.0.1/cgi-bin/power-outlet-json.cgi?name={{topic}};action={{payload}} then simply set the topic to the INI section and the action to either ON or OFF.
61  
62 =head1 USAGE
63  
64 The Perl one liner
65  
66 perl -MPower::Outlet -e 'print Power::Outlet->new(type=>"Tasmota", host=>shift)->switch, "\n"' myhost
67  
68 The included command line script
69  
70 power-outlet Shelly ON host myshelly
71  
72 =head1 CONSTRUCTOR
73  
74 =head2 new
75  
76 my $outlet = Power::Outlet->new(type=>"WeMo", host=>"mywemo");
77  
78 =cut
79  
80 13 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
81 13 my $this = shift;
82 13 ▶ my $base = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0130
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
83 13 my %data = @_;
84 13 ▶ my $type = $data{"type"} or die("Error: the type parameter is required.");
Branch: 1 branch
BranchTrueFalseTotal
my $type = $data{"type"} or die "Error: the type parameter is required." 13 0 13
85 13 my $class = join("::", $base, $type);
86 13 local $@;
87 5 ▶ eval "use $class";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
88 13 my $error = $@;
89 13 ▶ die(qq{Errot: Cannot find package "$class" for outlet type "$type"\n}) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 13 13
90 13 my $outlet = $class->new(%data);
91 13 return $outlet;
92 }
93  
94 =head1 BUGS
95  
96 Please open an issue on github
97  
98 =head1 SUPPORT
99  
100 DavisNetworks.com supports all Perl applications including this package.
101  
102 =head1 AUTHOR
103  
104 Michael R. Davis
105 CPAN ID: MRDVT
106 DavisNetworks.com
107  
108 =head1 COPYRIGHT
109  
110 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
111  
112 The full text of the license can be found in the LICENSE file included with this module.
113  
114 =head1 SEE ALSO
115  
116 L<Power::Outlet::iBoot>, L<Power::Outlet::iBootBar>, L<Power::Outlet::WeMo>, L<Power::Outlet::Hue>
117  
118 =cut
119  
120 7 1;
« lib/Power/Outlet/OpenBeken.pm ↑ Summary lib/Power/Outlet/Common/IP/HTTPS.pm »