Skip to content

Commit

Permalink
Update Venstar_Colortouch.pm for new perl version. Add parameter to g…
Browse files Browse the repository at this point in the history
…et_temp to allow for obtaining temp for index other than 0.
  • Loading branch information
pmatis committed Dec 6, 2020
1 parent ec395d3 commit e15d74d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Venstar_Colortouch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sub _init {
$self->{active} = 1;
$self->{previous}->{tempunits} = $self->{data}->{tempunits};
$self->{previous}->{name} = $self->{data}->{name};
foreach my $key1 ( keys $self->{data}->{info} ) {
foreach my $key1 ( keys %{$self->{data}->{info}} ) {
$self->{previous}->{info}->{$key1} = $self->{data}->{info}->{$key1};
}
$self->{previous}->{sensors}->{sensors}[0]->{temp} = $self->{data}->{sensors}->{sensors}[0]->{temp};
Expand Down Expand Up @@ -270,7 +270,7 @@ sub process_check {
$file_data = "" unless ($file_data); #just to prevent warning messages
#for some reason get_url adds garbage to the output. Clean out the characters before and after the json
print "debug: file_data=$file_data\n" if ( $self->{debug} );
my ($json_data) = $file_data =~ /({.*})/;
my ($json_data) = $file_data =~ /(\{.*\})/;
$json_data = "" unless ($json_data); #just to prevent warning messages
print "debug: json_data=$json_data\n" if ( $self->{debug} );
unless ( ($file_data) and ($json_data) ) {
Expand All @@ -288,7 +288,7 @@ sub process_check {
$com_status = "offline";
}
else {
if ( keys $data ) {
if ( keys %{$data} ) {
$self->{poll_data_timestamp} = &main::get_tickcount();
if ( $self->{poll_process_mode} eq "info" ) {
$self->{data}->{tempunits} = $data->{tempunits};
Expand Down Expand Up @@ -345,7 +345,7 @@ sub process_check {
}
#for some reason get_url adds garbage to the output. Clean out the characters before and after the json
my ($json_data) = $file_data =~ /({.*})/;
my ($json_data) = $file_data =~ /(\{.*\})/;
my $data;
eval { $data = JSON::XS->new->decode($json_data); };

Expand All @@ -356,7 +356,7 @@ sub process_check {

}
else {
if ( keys $data ) {
if ( keys %{$data} ) {
if ( $data->{success} eq "true" ) {
shift @{ $self->{cmd_queue} }; #remove the command from queue since it was successful
$self->{cmd_process_retry} = 0;
Expand Down Expand Up @@ -1586,11 +1586,14 @@ sub get_units {
}

sub get_temp {
my ($self) = @_;
my ($self, $index) = @_;

$index=0 unless ( defined $index );


# my ($isSuccessResponse) = $self->poll;
# if ($isSuccessResponse) {
return ( $self->{data}->{sensors}->{sensors}[0]->{temp} );
return ( $self->{data}->{sensors}->{sensors}[$index]->{temp} );

# } else {
# return ("unknown");
Expand Down

0 comments on commit e15d74d

Please sign in to comment.