Skip to content

Commit

Permalink
Modified the compare since it seems like JSON_prev sometime has a met…
Browse files Browse the repository at this point in the history
…adata entry.
  • Loading branch information
hplato committed Oct 18, 2015
1 parent cc57af6 commit deca7b0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Nest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,15 @@ sub parse_data {
#This is the first JSON packet received after connecting
$$self{prev_JSON} = $$self{JSON};
$$self{JSON} = decode_json $data;
if (!defined $$self{prev_JSON}){
if (!defined $$self{prev_JSON}{data}{devices}){
#this is the first run so convert the names to ids
$self->convert_to_ids($$self{monitor});
}
$self->compare_json($$self{JSON}, $$self{prev_JSON}, $$self{monitor});
#print "*** Object *** " . Data::Dumper::Dumper( \$self);

#print "*** Object *** \n";
#print Data::Dumper::Dumper( \$self);
#print Data::Dumper::Dumper( \$self->{monitor});
#print "*** Object *** \n";
}
elsif ($event =~ /auth_revoked/){
# Sent when auth parameter is no longer valid
Expand Down Expand Up @@ -597,6 +599,7 @@ sub convert_to_ids {
my ($self) = @_;
for my $array_ref (@{$$self{register}}){
my ($parent, $value, $action) = @{$array_ref};
$self->debug("Nest Initial data load convert_to_ids " . $value);
my $device_id = $parent->device_id();
if ($$parent{type} ne '') {
push(@{$$self{monitor}{data}{$$parent{class}}{$$parent{type}}{$device_id}{$value}},$action);
Expand All @@ -610,14 +613,14 @@ sub convert_to_ids {

=item C<client_version()>
Prints the Misterhouse Client Version. Client version of 2 is required for humidity and hvac_state
Prints the Misterhouse Client Version. Client version of 2 is required for humidity and hvac_state. Returns -1 if unknown version, or if the data hasn't been parsed yet
=cut

sub client_version {
my ($self) = @_;
my $version = 0;
$version = $$self{JSON}{data}{metadata}{client_version};
my $version = -1;
$version = $$self{JSON}{data}{metadata}{client_version} if defined ($$self{JSON}{data}{metadata}{client_version});
return ($version);

}
Expand Down Expand Up @@ -1740,4 +1743,4 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
=cut
=cut

0 comments on commit deca7b0

Please sign in to comment.