Skip to content

Commit

Permalink
Insteon: Revert Including Deaf Devices in Batch Commands
Browse files Browse the repository at this point in the history
- On further thought, including deaf devices in batch commands is a bad idea.  Many deaf devices are rarely contacted, yet a user may run the batch commands frequently.  This may result in a TON of queued messages for a deaf device, which may result in too much traffic when the device is finally contacted.

- The better course of action seems to be to force users to run these same commands on the specific deaf devices.
  • Loading branch information
krkeegan committed Apr 18, 2014
1 parent 20b85c8 commit a9bae32
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 59 deletions.
70 changes: 22 additions & 48 deletions lib/Insteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Resets the message stats back to 0 for this device.

my (@_insteon_plm,@_insteon_device,@_insteon_link,@_scannable_link,$_scan_cnt,$_sync_cnt,$_sync_failure_cnt);
my $init_complete;
my (@_scan_devices,@_scan_deaf_devices,@_scan_device_failures,$current_scan_device);
my (@_scan_devices,@_scan_device_failures,$current_scan_device);
my (@_sync_devices,@_sync_device_failures,$current_sync_device);
my ($_stress_test_count, $_stress_test_one_pass, @_stress_test_devices);
my ($_ping_count, @_ping_devices);
Expand Down Expand Up @@ -386,7 +386,6 @@ sub scan_all_linktables
my @candidate_devices = ();
# clear @_scan_devices
@_scan_devices = ();
@_scan_deaf_devices = ();
@_scan_device_failures = ();
$current_scan_device = undef;
# alwayws include the active interface (e.g., plm)
Expand All @@ -395,29 +394,32 @@ sub scan_all_linktables
push @candidate_devices, &Insteon::find_members("Insteon::BaseDevice");

# don't try to scan devices that are not responders
if (@candidate_devices)
{
foreach (@candidate_devices)
{
if (@candidate_devices) {
foreach (@candidate_devices) {
my $candidate_object = $_;
if ($candidate_object->is_root and
if ($candidate_object->is_deaf){
::print_log("[Scan all linktables] INFO: !!! "
. $candidate_object->get_object_name
. " is deaf. To scan this object you"
. " must run 'Scan Link Table' on it"
. " directly.");
}
elsif ($candidate_object->is_root and
!($candidate_object->isa('Insteon::InterfaceController')))
{
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, 'insteon');
}
else
{
else {
&main::print_log("[Scan all linktables] INFO: !!! "
. $candidate_object->get_object_name
. " is NOT a candidate for scanning.");
}
}
}
else
{
else {
&main::print_log("[Scan all linktables] WARN: No insteon devices could be found");
}
$_scan_cnt = scalar @_scan_devices;
Expand Down Expand Up @@ -453,22 +455,15 @@ sub _get_next_linkscan
my($skip_unchanged, $changed_device) = @_;
$current_scan_device = shift @_scan_devices;
if ($current_scan_device) {
if ($current_scan_device->is_deaf){
# Store deaf devices for scanning at the end
push(@_scan_deaf_devices, $current_scan_device);
&Insteon::_get_next_linkscan($skip_unchanged);
}
else {
::print_log("[Scan all link tables] Now scanning: "
. $current_scan_device->get_object_name . " ("
. ($_scan_cnt - scalar @_scan_devices)
. " of $_scan_cnt)");
# pass first the success callback followed by the failure callback
$current_scan_device->scan_link_table(
'&Insteon::_get_next_linkscan('.$skip_unchanged.')',
'&Insteon::_get_next_linkscan_failure('.$skip_unchanged.')',
$skip_unchanged);
}
::print_log("[Scan all link tables] Now scanning: "
. $current_scan_device->get_object_name . " ("
. ($_scan_cnt - scalar @_scan_devices)
. " of $_scan_cnt)");
# pass first the success callback followed by the failure callback
$current_scan_device->scan_link_table(
'&Insteon::_get_next_linkscan('.$skip_unchanged.')',
'&Insteon::_get_next_linkscan_failure('.$skip_unchanged.')',
$skip_unchanged);
}
else {
::print_log("[Scan all link tables] Completed scanning of all regular items.");
Expand All @@ -480,27 +475,6 @@ sub _get_next_linkscan
::print_log("[Scan all link tables] WARN, unable to "
." complete a scan of the following devices: $obj_list");
}
if (scalar @_scan_deaf_devices){
my $obj_list;
for my $deaf_obj (@_scan_deaf_devices){
$obj_list .= $deaf_obj->get_object_name .", ";
}
::print_log("[Scan all link tables] Will attempt to scan"
." the following deaf devices the next time they"
." wakeup: $obj_list");
for my $deaf_obj (@_scan_deaf_devices){
my $success_callback = "::print_log(qq|[Scan all".
" link tables] Delayed scan successfully".
" completed for: " .
$deaf_obj->get_object_name . "|)";
my $failure_callback = "::print_log(qq|[Scan all".
" link tables] WARN: The delayed scan ".
" failed for: " .
$deaf_obj->get_object_name . "|)";
$deaf_obj->scan_link_table($success_callback,
$failure_callback,$skip_unchanged);
}
}
}
}

Expand Down
29 changes: 18 additions & 11 deletions lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,13 @@ sub sync_links

# Warn if device is deaf or ALDB out of sync
my $insteon_object_is_syncable = 1;
if ($insteon_object->_aldb->health ne 'good' && $insteon_object->_aldb->health ne 'empty'){
if ($insteon_object->is_deaf && $skip_deaf) {
::print_log("[Insteon::BaseController] $self_link_name is deaf, only responder links will be added to devices "
."controlled by this device. To sync links on this device, put it in awake mode and run the 'Sync Links' "
."command on this specific device.");
$insteon_object_is_syncable = 0;
}
elsif ($insteon_object->_aldb->health ne 'good' && $insteon_object->_aldb->health ne 'empty'){
::print_log("[Insteon::BaseController] WARN! The ALDB of $self_link_name is ".$insteon_object->_aldb->health
.", links will be added to devices "
."linked to this device, but no links will be added to $self_link_name. Please rescan this device and attempt "
Expand Down Expand Up @@ -3368,6 +3374,12 @@ sub _process_sync_queue {
} else {
::print_log("[Insteon::BaseController] Completed sync links for: "
.$self->get_object_name);
if ($$self{deaf_sync_queue_flag}){
::print_log("[Insteon::BaseController] Links on "
.$self->get_object_name . " will sync the next "

This comment has been minimized.

Copy link
@JaredF

JaredF May 10, 2014

Collaborator

I seem to receive a gratuitous "will sync the next time the device is awake" message when syncing a single link on a deaf device that is set as manually awake:

05/09/2014 23:42:52  Running: Living Room Remote 1 mark as manually awake
05/09/2014 23:42:59  Running: Living Room Remote 1 sync links
05/09/2014 23:42:59  [Insteon::BaseController]  Adding controller record to $Living_Room_Remote_1 for $Living_Room_Floor_Lamp
group = 01; data3 = 01; cmd = add; is_controller = 1;
05/09/2014 23:42:59  [Insteon::BaseController] Completed sync links for: $Living_Room_Remote_1
05/09/2014 23:42:59  [Insteon::BaseController] Links on $Living_Room_Remote_1 will sync the next time the device is awake.

This comment has been minimized.

Copy link
@krkeegan

krkeegan May 14, 2014

Author Collaborator

Hmm, that shouldn't be happening.

This comment has been minimized.

Copy link
@JaredF

JaredF May 14, 2014

Collaborator

It's no big deal; more cosmetic than anything else, but I wanted to report it. All of these extra features for the Insteon 'deaf' devices are really great, BTW! Thanks as always for the hard work!

This comment has been minimized.

Copy link
@krkeegan

krkeegan May 15, 2014

Author Collaborator

OK, I submitted a pull request that should fix this issue as well as the PLM Enable Monitor mode issue. Let me know if they work for you.

This comment has been minimized.

Copy link
@JaredF

JaredF May 15, 2014

Collaborator

Thanks! Will test tonight.

This comment has been minimized.

Copy link
@JaredF

JaredF May 16, 2014

Collaborator

Just tested this pull; both features now work as expected--thanks!

."time the device is awake.");
$self->_process_deaf_sync_queue();
}
}
}

Expand All @@ -3382,21 +3394,16 @@ sub _build_deaf_sync_queue {
my ($self, $link_req_ptr) = @_;
my %link_req = %$link_req_ptr;
my $self_link_name = $self->get_object_name;
$$self{deaf_sync_queue_flag} = 1; #Sync requests are pending
%link_req = ( callback => "$self_link_name->_process_deaf_sync_queue()",
failure_callback => "$self_link_name->_process_deaf_sync_queue_failure()");
push @{$$self{deaf_sync_queue}}, \%link_req;
if (!$$self{deaf_sync_queue_flag}){
::print_log("[Insteon::BaseController] Sync requests for "
.$self_link_name. " will not be processed until it is awake.");
$self->_process_deaf_sync_queue();
}
}

sub _process_deaf_sync_queue {
my ($self) = @_;
my $num_sync_queue = @{$$self{deaf_sync_queue}};
if ($num_sync_queue) {
$$self{deaf_sync_queue_flag} = 1; #Sync requests are pending
my $link_req_ptr = shift(@{$$self{deaf_sync_queue}});
my %link_req = %$link_req_ptr;
my $link_member = $link_req{member};
Expand All @@ -3408,11 +3415,11 @@ sub _process_deaf_sync_queue {
}
}
else {
::print_log($self->get_object_name." completed the delayed "
."sync links request");
::print_log("[Insteon::BaseController] Completed the delayed "
."sync links request on " . $self->get_object_name);
if ($$self{deaf_sync_queue_failure}) {
::print_log("However, some failures occured while "
."syncing links on " . $self->get_object_name);
::print_log("[Insteon::BaseController] However, some "
."failures occured.");
}
$$self{deaf_sync_queue_flag} = 0;
$$self{deaf_sync_queue_failure} = 0;
Expand Down

0 comments on commit a9bae32

Please sign in to comment.