File Coverage

blib/lib/Device/RFXCOM/Decoder/Electrisave.pm
Criterion Covered Total %
statement 38 38 100.0
branch 8 8 100.0
condition 6 6 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 61 61 100.0


line stmt bran cond sub pod time code
1 3     3   2883 use strict;
  3         7  
  3         113  
2 3     3   19 use warnings;
  3         7  
  3         140  
3             package Device::RFXCOM::Decoder::Electrisave;
4             $Device::RFXCOM::Decoder::Electrisave::VERSION = '1.142010';
5             # ABSTRACT: Device::RFXCOM::Decoder::Electrisave decode Electrisave RF messages
6              
7              
8 3     3   56 use 5.006;
  3         10  
  3         137  
9 3     3   16 use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_ELECTRISAVE_DEBUG};
  3         5  
  3         167  
10 3     3   14 use Carp qw/croak/;
  3         8  
  3         176  
11 3     3   14 use base 'Device::RFXCOM::Decoder';
  3         7  
  3         368  
12 3     3   18 use Device::RFXCOM::Response::Sensor;
  3         17  
  3         1032  
13              
14              
15             sub decode {
16 83     83 1 168 my ($self, $parent, $message, $bytes, $bits, $result) = @_;
17 83 100       391 $bits == 120 or return;
18              
19 8 100 100     71 ($bytes->[0]==0xea && $bytes->[9]==0xff && $bytes->[10]==0x5f) or return;
      100        
20              
21 2         9 my $device = sprintf "%02x", $bytes->[2];
22 2         4 my @ct = ();
23 2         8 $ct[1] = ( (($bytes->[3] ) )+(($bytes->[4]&0x3 )<<8) ) / 10;
24 2         8 $ct[2] = ( (($bytes->[4]&0xFC)>>2)+(($bytes->[5]&0xF )<<6) ) / 10;
25 2         5 $ct[3] = ( (($bytes->[5]&0xF0)>>4)+(($bytes->[6]&0x3F)<<4) ) / 10;
26 2         9 $ct[0] = $ct[1] + $ct[2] + $ct[3];
27 2         6 foreach my $index (0..3) {
28 8 100       22 my $dev = $device.($index ? '.'.$index : '');
29 8         8 printf "electrisave d=%s current=%.2f\n", $dev, $ct[$index] if DEBUG;
30 8         8 push @{$result->{messages}},
  8         47  
31             Device::RFXCOM::Response::Sensor->new(device => 'electrisave.'.$dev,
32             measurement => 'current',
33             value => $ct[$index]);
34             }
35 2 100       3 push @{$result->{messages}},
  2         19  
36             Device::RFXCOM::Response::Sensor->new(device => 'electrisave.'.$device,
37             measurement => 'battery',
38             value => (($bytes->[1]&0x10)
39             ? 10 : 90),
40             units => '%');
41 2         12 return 1;
42             }
43              
44             1;
45              
46             __END__