Power/Outlet/Osram.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 65 CC 7 SCAR 21.3
CC
7
Cov
0%
_call
20.0
BEGIN
6.0
name
6.0
CRAP 8.4
1 package Power::Outlet::Osram;
2  
3 use strict;
4 use warnings;
5  
6 use Device::Osram::Lightify::Hub;
7  
8 BEGIN
9 {
10  
11 my $base = "use base qw{Power::Outlet::Common::IP};";
12 eval($base);
13 if ($@)
14 {
15 warn "Base-class Power::Outlet::Common::IP not found.\n";
16 }
17 }
18  
19 our $VERSION = '0.6';
20  
21 =head1 NAME
22  
23 Power::Outlet::Osram - Control and query an Osram Lightify light
24  
25 =head1 SYNOPSIS
26  
27 Using power-outlet shell script from Power::Outlet distribution
28  
29 power-outlet Osram ON host 192.168.1.10 name hall
30  
31 Using Power::Outlet API
32  
33 my $outlet=Power::Outlet->new(type=>"Osram", host => "192.168.1.10", name=>"hall");
34 print $outlet->on, "\n";
35  
36 Using Power::Outlet::Osram directly
37  
38 my $outlet=Power::Outlet::Osram->new(host => "192.168.1.10", name=>"hall");
39 print $outlet->query, "\n";
40 print $outlet->on, "\n";
41 print $outlet->off, "\n";
42  
43 =head1 DESCRIPTION
44  
45 Power::Outlet::Osram is a package for controlling and querying a light on an Osram Lightify network attached bridge.
46  
47 =head1 USAGE
48  
49 use Power::Outlet::Osram;
50 my $lamp=Power::Outlet::Osram->new(host=>"mybridge", name=>"hall");
51 print $lamp->on, "\n";
52  
53 =head1 CONSTRUCTOR
54  
55 =head2 new
56  
57 my $outlet=Power::Outlet->new(type=>"Osram", host=>"192.168.10.136", name => "Hall" );
58 my $outlet=Power::Outlet::Osram->new(host=>"mybridge", name="kitchen");
59  
60 =head1 PROPERTIES
61  
62 =head2 name
63  
64 Name for the particular light as configured on the Osram Lightify bridge.
65  
66 =cut
67  
68 sub name
69 {
70 my $self = shift;
71 $self->{ "name" } = shift if @_;
72 return $self->{ "name" };
73 }
74  
75  
76 =head1 METHODS
77  
78 =head2 query
79  
80 Return the current state of the specified device, as a string.
81  
82 =cut
83  
84 sub query
85 {
86 my $self = shift;
87  
88 my $x = Device::Osram::Lightify::Hub->new( host => $self->host() );
89 foreach my $device ( $x->lights() )
90 {
91 if ( $device->name() eq $self->name() )
92 {
93 return ( $device->stringify() );
94 }
95 }
96  
97 }
98  
99 =head2 on
100  
101 Sends a message to the device to Turn Power ON
102  
103 =cut
104  
105 sub on
106 {
107 my $self = shift;
108 return $self->_call("on");
109 }
110  
111 =head2 off
112  
113 Sends a message to the device to Turn Power OFF
114  
115 =cut
116  
117 sub off
118 {
119 my $self = shift;
120 return $self->_call("off");
121 }
122  
123  
124 =head2 _call
125  
126 Implementation method to send an on/off message to the given device.
127  
128 =cut
129  
130 sub _call
131 {
132 my $self = shift;
133 my $state = shift;
134  
135 my $x = Device::Osram::Lightify::Hub->new( host => $self->host() );
136 foreach my $device ( $x->lights() )
137 {
138 if ( $device->name() eq $self->name() )
139 {
140 if ( $state =~ /on/i )
141 {
142 $device->set_on();
143 return 1;
144 }
145 if ( $state =~ /off/i )
146 {
147 $device->set_off();
148 return 1;
149 }
150 }
151 }
152 return 0;
153 }
154  
155 =head2 switch
156  
157 Queries the device for the current status and then requests the opposite.
158  
159 =cut
160  
161 #see Power::Outlet::Common->switch
162  
163 =head2 cycle
164  
165 Sends messages to the device to Cycle Power (ON-OFF-ON or OFF-ON-OFF).
166  
167 =cut
168  
169 #see Power::Outlet::Common->cycle
170  
171 =head1 AUTHOR
172  
173 Steve Kemp <steve@steve.org.uk>
174  
175 =cut
176  
177 =head1 COPYRIGHT AND LICENSE
178  
179 Copyright (C) 2016 Steve Kemp <steve@steve.org.uk>.
180  
181 This library is free software. You can modify and or distribute it under
182 the same terms as Perl itself.
183  
184 =cut
185  
186 1;