File Coverage

blib/lib/Device/RFXCOM/Decoder/Digimax.pm
Criterion Covered Total %
statement 41 41 100.0
branch 8 8 100.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 59 59 100.0


line stmt bran cond sub pod time code
1 3     3   2770 use strict;
  3         8  
  3         120  
2 3     3   16 use warnings;
  3         6  
  3         138  
3             package Device::RFXCOM::Decoder::Digimax;
4             $Device::RFXCOM::Decoder::Digimax::VERSION = '1.142010';
5             # ABSTRACT: Device::RFXCOM::Decoder::Digimax decode Digimax RF messages
6              
7              
8 3     3   65 use 5.006;
  3         11  
  3         150  
9 3     3   22 use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_DIGIMAX_DEBUG};
  3         5  
  3         209  
10 3     3   17 use Carp qw/croak/;
  3         6  
  3         148  
11 3     3   16 use base 'Device::RFXCOM::Decoder';
  3         6  
  3         284  
12 3     3   2136 use Device::RFXCOM::Response::Thermostat;
  3         9  
  3         104  
13 3     3   194 use Device::RFXCOM::Decoder qw/hi_nibble lo_nibble nibble_sum/;
  3         8  
  3         1242  
14              
15              
16             sub decode {
17 86     86 1 184 my ($self, $parent, $message, $bytes, $bits, $result) = @_;
18 86 100       444 return unless ($bits == 44);
19 5         33 my $p =
20             hi_nibble($bytes->[0]) + lo_nibble($bytes->[0]) +
21             hi_nibble($bytes->[1]) + lo_nibble($bytes->[1]) +
22             hi_nibble($bytes->[2]) + lo_nibble($bytes->[2]);
23 5         7 $p &= 0xf;
24 5 100       14 return unless ($p == 0xf);
25              
26 4         11 $p =
27             hi_nibble($bytes->[3]) + lo_nibble($bytes->[3]) +
28             hi_nibble($bytes->[4]) + lo_nibble($bytes->[4]) +
29             hi_nibble($bytes->[5]);
30 4         6 $p &= 0xf;
31 4 100       13 return unless ($p == 0xf);
32              
33 3         12 my $state =
34             [
35             'undef', 'demand', 'satisfied', 'init'
36             ]->[hi_nibble($bytes->[2])&0x3];
37              
38 3         5 my $temp = $bytes->[3];
39 3         5 my $set = $bytes->[4]&0x3f;
40 3 100       6 my $mode = $bytes->[4]&0x40 ? 'cool' : 'heat';
41 3         27 my $device = sprintf 'digimax.%02x%02x', $bytes->[0], $bytes->[1];
42 3         9 printf STDERR "Thermostat: $device $state $temp $set $mode\n" if DEBUG;
43 3         3 push @{$result->{messages}},
  3         20  
44             Device::RFXCOM::Response::Thermostat->new(device => $device,
45             temp => $temp,
46             set => $set,
47             mode => $mode,
48             state => $state);
49 3         14 return 1;
50             }
51              
52             1;
53              
54             __END__