lib/Power/Outlet/OpenBeken.pm untested

filter: Statementstmt 0.0% 0 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 16 CC 1 SCAR 6.9
CC
1
Cov
0%
_host_default
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Power::Outlet::OpenBeken;
2 use strict;
3 use warnings;
4 use base qw{Power::Outlet::Tasmota};
5  
6 #See Power::Outlet::Tasmota for code but use OpenBeken in case we need to tweak any operations for OpenBeken in the future.
7  
8 our $VERSION = '0.54';
9  
10 =head1 NAME
11  
12 Power::Outlet::OpenBeken - Control and query an OpenBeken configured device
13  
14 =head1 SYNOPSIS
15  
16 my $outlet = Power::Outlet::OpenBeken->new(host => "myhost", relay => "POWER1");
17 print $outlet->query, "\n";
18 print $outlet->on, "\n";
19 print $outlet->off, "\n";
20  
21 =head1 DESCRIPTION
22  
23 Power::Outlet::OpenBeken is a package for controlling and querying OpenBeken flashed hardware over the exposed HTTP interface. OpenBeken supports multiple chipsets, including ESWIN, Transa Semi, Lightning Semi, Espressif, Beken, WinnerMicro, Xradiotech/Allwinner, Realtek, and Bouffalo Lab.
24  
25 The OpenBeken project adopted the HTTP command interface from the Tasmota project as defined at L<https://tasmota.github.io/docs/#/Commands>
26  
27 Commands can be executed via web (HTTP) requests, for example:
28  
29 http://<ip>/cm?cmnd=Power%20TOGGLE
30 http://<ip>/cm?cmnd=Power%20On
31 http://<ip>/cm?cmnd=Power%20off
32 http://<ip>/cm?user=foo&password=bar&cmnd=Power%20Toggle
33  
34 Examples:
35  
36 Query default relay
37  
38 $ curl http://myhost/cm?cmnd=POWER1
39 {"POWER1":"ON"}
40  
41 Toggle (Switch) relay 4
42  
43 $ curl http://myhost/cm?user=foo;password=bar;cmnd=POWER4+TOGGLE
44 {"POWER4":"OFF"}
45  
46 Turn ON relay 2
47  
48 $ curl http://myhost/cm?user=foo;password=bar;cmnd=POWER2+ON
49 {"POWER2":"ON"}
50  
51 =head1 USAGE
52  
53 use Power::Outlet::OpenBeken;
54 my $relay = Power::Outlet::OpenBeken->new(host=>"myhost", relay=>"POWER1");
55 print $relay->on, "\n";
56  
57 =head1 CONSTRUCTOR
58  
59 =head2 new
60  
61 my $outlet = Power::Outlet->new(type=>"OpenBeken", host=>"myhost", relay=>"POWER2");
62 my $outlet = Power::Outlet::OpenBeken->new(host=>"myhost", relay=>"POWER2");
63  
64 =head1 PROPERTIES
65  
66 =head2 relay
67  
68 Relays map to the relay tokens "POWER1", "POWER2", ... "POWER8". With "POWER" being the default relay name for the first relay defined in the configuration.
69  
70 Default: POWER1
71  
72 =head2 host
73  
74 Sets and returns the hostname or IP address.
75  
76 Default: openbeken
77  
78 =cut
79  
80 sub _host_default {'openbeken'};
81  
82 =head2 port
83  
84 Sets and returns the port number.
85  
86 Default: 80
87  
88 =head2 http_path
89  
90 Sets and returns the http_path.
91  
92 Default: /cm
93  
94 =head2 user
95  
96 Sets and returns the user used for authentication with the OpenBeken hardware
97  
98 my $outlet = Power::Outlet::OpenBeken->new(host=>"myhost", relay=>"POWER1", user=>"mylogin", password=>"mypassword");
99 print $outlet->query, "\n";
100  
101 Default: undef() #which is only passed on the url when defined
102  
103 =head2 password
104  
105 Sets and returns the password used for authentication with the OpenBeken hardware
106  
107 Default: "" #which is only passed on the url when user property is defined
108  
109 =head1 METHODS
110  
111 =head2 name
112  
113 Returns the FriendlyName from the OpenBeken hardware.
114  
115 Note: The FriendlyName is cached for the life of the object.
116  
117 =head2 query
118  
119 Sends an HTTP message to the device to query the current state
120  
121 =head2 on
122  
123 Sends a message to the device to Turn Power ON
124  
125 =head2 off
126  
127 Sends a message to the device to Turn Power OFF
128  
129 =head2 switch
130  
131 Sends a message to the device to toggle the power
132  
133 =head2 cycle
134  
135 Sends messages to the device to Cycle Power (ON-OFF-ON or OFF-ON-OFF).
136  
137 =cut
138  
139 #see Power::Outlet::Common->cycle
140  
141 =head1 BUGS and SUPPORT
142  
143 Please use GitHub
144  
145 =head1 AUTHOR
146  
147 Michael R. Davis
148 CPAN ID: MRDVT
149  
150 =head1 COPYRIGHT
151  
152 Copyright (c) 2025 Michael R. Davis
153  
154 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
155  
156 The full text of the license can be found in the LICENSE file included with this module.
157  
158 =head1 SEE ALSO
159  
160 L<https://github.com/openshwprojects/OpenBK7231T_App>
161 L<https://tasmota.github.io/docs/#/Commands>
162  
163 =cut
164  
165 1;