Skip to content

Commit

Permalink
Merge pull request #4 from krkeegan/insteon_device_log_verbosity
Browse files Browse the repository at this point in the history
Whoah, you were busy! It looks good to me, based on my quick review. I think you caught a few things that I missed, like selecting the correct object, rather than $self all the time. Thanks!
  • Loading branch information
pmatis committed Nov 10, 2013
2 parents c35756b + 02d7680 commit a1ead97
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 282 deletions.
18 changes: 18 additions & 0 deletions lib/Generic_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,24 @@ sub user_data {
return \%{$$self{user_data}};
}

=item C<debuglevel([level], [debug_group])>
Returns 1 if debug_group or this device is at least debug level 'level', otherwise returns 0.
=cut

sub debuglevel
{
my ($object, $debug_level, $debug_group) = @_;
$debug_level = 1 unless $debug_level;
my $objname;
$objname = lc $object->get_object_name if defined $object;
::print_log("[Generic_Item] debuglevel: Processing debug for object $objname ... " . $main::Debug{$objname}) if $main::Debug{$debug_group} >= 5;
return 1 if $main::Debug{$debug_group} >= $debug_level;
return 1 if defined $objname && $main::Debug{$objname} >= $debug_level;
return 0;
}

=back
=head2 PACKAGE FUNCTIONS
Expand Down
53 changes: 9 additions & 44 deletions lib/Insteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ sub scan_all_linktables
push @_scan_devices, $candidate_object;
&main::print_log("[Scan all linktables] INFO1: "
. $candidate_object->get_object_name
. " will be scanned.") if $candidate_object->debuglevel(1);
. " will be scanned.") if $candidate_object->debuglevel(1, 'insteon');
}
else
{
Expand Down Expand Up @@ -906,28 +906,6 @@ sub init {

}

=item C<debuglevel([level])>
Returns 1 if Insteon or this device is at least debug level 'level', otherwise returns 0.
=cut

sub debuglevel
{
my ($object, $debug_level) = @_;
$debug_level = 1 unless $debug_level;
my $objname;
#try {
$objname = lc $object->get_object_name if defined $object;
#} catch {
# &::print_log("$object doesn't have a get_object_name function.") if $main::Debug{insteon} >= 2;
#}
&::print_log("Insteon::debuglevel: Processing debug for object $objname ... " . $main::Debug{$objname}) if $main::Debug{insteon} >= 5;
return 1 if $main::Debug{insteon} >= $debug_level;
return 1 if defined $objname && $main::Debug{$objname} >= $debug_level;
return 0;
}

=item C<generate_voice_commands()>
Generates and sets the voice commands for all Insteon devices.
Expand Down Expand Up @@ -1083,7 +1061,7 @@ Walks through every Insteon device and checks the aldb object version for I1 vs.

sub check_all_aldb_versions
{
main::print_log("[Insteon] DEBUG4 Checking aldb version of all devices") if Insteon::debuglevel(undef,4);
main::print_log("[Insteon] DEBUG4 Checking aldb version of all devices") if ($main::Debug{insteon} >= 4);

my @ALDB_devices = ();
push @ALDB_devices, Insteon::find_members("Insteon::BaseDevice");
Expand All @@ -1097,21 +1075,21 @@ sub check_all_aldb_versions
{
main::print_log("[Insteon] DEBUG4 Checking aldb version for "
. $ALDB_device->get_object_name()
. " ($count of $ALDB_cnt)") if ($ALDB_device->debuglevel(4));
. " ($count of $ALDB_cnt)") if ($ALDB_device->debuglevel(4, 'insteon'));
$ALDB_device->check_aldb_version();
} else
{
main::print_log("[Insteon] DEBUG4 " . $ALDB_device->get_object_name
. " does not have its own aldb ($count of $ALDB_cnt)")
if ($ALDB_device->debuglevel(4));
if ($ALDB_device->debuglevel(4, 'insteon'));
}
}
main::print_log("[Insteon] DEBUG4 Checking aldb version of all devices completed") if Insteon::debuglevel(undef,4);
main::print_log("[Insteon] DEBUG4 Checking aldb version of all devices completed") if ($main::Debug{insteon} >= 4);
}

sub check_thermo_versions
{
main::print_log("[Insteon] DEBUG4 Initializing thermostat versions") if Insteon::debuglevel(undef,4);
main::print_log("[Insteon] DEBUG4 Initializing thermostat versions") if ($main::Debug{insteon} >= 4);

my @thermo_devices = ();
push @thermo_devices, Insteon::find_members("Insteon::Thermostat");
Expand All @@ -1121,18 +1099,17 @@ sub check_thermo_versions
$thermo_device->get_root()->engine_version eq "I2CS"){
main::print_log("[Insteon] DEBUG4 Setting thermostat "
. $thermo_device->get_object_name() . " to i2CS")
if ($thermo_device->debuglevel(4));
if ($thermo_device->debuglevel(4, 'insteon'));
bless $thermo_device, 'Insteon::Thermo_i2CS';
$thermo_device->init();
}
else {
main::print_log("[Insteon] DEBUG4 Setting thermostat "
. $thermo_device->get_object_name() . " to i1")
if ($thermo_device->debuglevel(4));
if ($thermo_device->debuglevel(4, 'insteon'));
bless $thermo_device, 'Insteon::Thermo_i1';
}
}
#main::print_log("[Insteon] DEBUG4 Checking thermostat version of all devices completed") if ($self->debuglevel(4));
}

=back
Expand Down Expand Up @@ -1208,7 +1185,7 @@ sub _active_interface
my ($self, $interface) = @_;
# setup hooks the first time that an interface is made active
if (!($$self{active_interface}) and $interface) {
&main::print_log("[Insteon] Setting up initialization hooks") if $self->debuglevel();
&main::print_log("[Insteon] Setting up initialization hooks") if $main::Debug{insteon};
&main::MainLoop_pre_add_hook(\&Insteon::BaseInterface::check_for_data, 1);
&main::Reload_post_add_hook(\&Insteon::check_all_aldb_versions, 1);
&main::Reload_post_add_hook(\&Insteon::BaseInterface::poll_all, 1);
Expand All @@ -1221,18 +1198,6 @@ sub _active_interface
return $$self{active_interface};
}

=item C<debuglevel([level])>
Returns 1 if Insteon or this device is at least debug level 'level', otherwise returns 0.
=cut

sub debuglevel
{
my ($self, $debug_level) = @_;
return Insteon::debuglevel(undef, $debug_level);
}

=item C<add()>
Adds a list of objects to be tracked.
Expand Down
Loading

0 comments on commit a1ead97

Please sign in to comment.