From 8e1602cb15c66fc6cfb3486e773dd8f58ec7c8a6 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Fri, 11 Oct 2013 18:48:41 -0700 Subject: [PATCH 1/5] Insteon: Add Is Deaf Routine for Battery Devices Closed #279 --- lib/Insteon/AllLinkDatabase.pm | 8 ++++---- lib/Insteon/BaseInsteon.pm | 18 ++++++++++++++++++ lib/Insteon/Controller.pm | 1 + lib/Insteon/Security.pm | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Insteon/AllLinkDatabase.pm b/lib/Insteon/AllLinkDatabase.pm index aa47c807b..8d2ff2926 100644 --- a/lib/Insteon/AllLinkDatabase.pm +++ b/lib/Insteon/AllLinkDatabase.pm @@ -421,7 +421,7 @@ sub delete_orphan_links # first, make sure that the health of ALDB is ok if ($self->health ne 'good') { - if ($$self{device}->isa('Insteon::RemoteLinc') or $$self{device}->isa('Insteon::MotionSensor')) + if (!$self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] Delete orphan links: ignoring link from deaf device: $selfname"); @@ -588,7 +588,7 @@ sub delete_orphan_links } else # is a non-PLM device { - if ($linked_device->isa('Insteon::RemoteLinc') or $linked_device->isa('Insteon::MotionSensor')) + if (!$self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] Delete orphan links: ignoring link from $selfname to 'deaf' device: " . $linked_device->get_object_name); } @@ -754,7 +754,7 @@ sub delete_orphan_links { $member = $member->get_root; } - if ($member->isa('Insteon::RemoteLinc') or $member->isa('Insteon::MotionSensor')) + if (!$self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] ignoring link from " . $link->get_object_name . " to " . $member->get_object_name); @@ -2830,7 +2830,7 @@ sub delete_orphan_links } if ($member->isa('Insteon::BaseDevice')) { - if ($member->isa('Insteon::RemoteLinc') or $member->isa('Insteon::MotionSensor')) + if (!$self->is_deaf) { &::print_log("[Insteon::ALDB_PLM] ignoring link from PLM to " . $member->get_object_name); diff --git a/lib/Insteon/BaseInsteon.pm b/lib/Insteon/BaseInsteon.pm index 43717c4ca..9c6250448 100644 --- a/lib/Insteon/BaseInsteon.pm +++ b/lib/Insteon/BaseInsteon.pm @@ -1260,6 +1260,7 @@ sub new $$self{hops_left_count} = 0; $$self{max_hops_count} = 0; $$self{outgoing_hop_count} = 0; + $$self{is_deaf} = 0; return $self; } @@ -1308,6 +1309,23 @@ sub set_receive $self->SUPER::set_receive($p_state, $p_setby, $p_response); } +=item C + +Returns true if the device must be awake in order to respond to messages. Most +devices are not deaf, currently devices that are deaf are battery operated +devices such as the Motion Sensor, RemoteLinc and TriggerLinc. + +At the BaseObject level all devices are defined as deaf. Objects which inherit +BaseObject should redefine is_deaf as necessary. + +=cut + +sub is_deaf +{ + my ($self) = @_; + return $$self{is_deaf}; +} + =item C Returns true if the device is a controller. diff --git a/lib/Insteon/Controller.pm b/lib/Insteon/Controller.pm index 871ed28b6..1d2e18299 100644 --- a/lib/Insteon/Controller.pm +++ b/lib/Insteon/Controller.pm @@ -79,6 +79,7 @@ sub new $$self{queue_timer} = new Timer; } bless $self,$class; + $$self{is_deaf} = 1; return $self; } diff --git a/lib/Insteon/Security.pm b/lib/Insteon/Security.pm index fe97e4014..65f4d3484 100644 --- a/lib/Insteon/Security.pm +++ b/lib/Insteon/Security.pm @@ -126,6 +126,7 @@ sub new $$self{queue_timer} = new Timer; } bless $self,$class; + $$self{is_deaf} = 1; return $self; } @@ -775,6 +776,7 @@ sub new my $self = new Insteon::BaseDevice($p_deviceid,$p_interface); $$self{message_types} = \%message_types; bless $self,$class; + $$self{is_deaf} = 1; return $self; } From 4b7e268950740e16453f0712ca8d31cc1f3bc182 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Fri, 11 Oct 2013 18:55:35 -0700 Subject: [PATCH 2/5] Insteon: Add is_deaf Check to Sync Links, Fix Dumb Typo Fix Delete Orphans Logic, had that backwards. --- lib/Insteon.pm | 7 +++---- lib/Insteon/AllLinkDatabase.pm | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Insteon.pm b/lib/Insteon.pm index fa01d60d6..0a5afe9a1 100755 --- a/lib/Insteon.pm +++ b/lib/Insteon.pm @@ -400,9 +400,8 @@ sub scan_all_linktables { my $candidate_object = $_; if ($candidate_object->is_root and - !($candidate_object->isa('Insteon::RemoteLinc') - or $candidate_object->isa('Insteon::InterfaceController') - or $candidate_object->isa('Insteon::MotionSensor'))) + !($self->is_deaf + or $candidate_object->isa('Insteon::InterfaceController'))) { push @_scan_devices, $candidate_object; &main::print_log("[Scan all linktables] INFO1: " @@ -511,7 +510,7 @@ sub sync_all_links # iterate over all registered objects and compare whether the link tables match defined scene linkages in known Insteon_Links for my $obj (&Insteon::find_members('Insteon::BaseController')) { - if ($obj->isa('Insteon::RemoteLinc') or $obj->isa('Insteon::MotionSensor')) + if ($self->is_deaf) { &main::print_log("[Sync all links] Ignoring links from 'deaf' device: " . $obj->get_object_name); } diff --git a/lib/Insteon/AllLinkDatabase.pm b/lib/Insteon/AllLinkDatabase.pm index 8d2ff2926..9d35b4005 100644 --- a/lib/Insteon/AllLinkDatabase.pm +++ b/lib/Insteon/AllLinkDatabase.pm @@ -421,7 +421,7 @@ sub delete_orphan_links # first, make sure that the health of ALDB is ok if ($self->health ne 'good') { - if (!$self->is_deaf) + if ($self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] Delete orphan links: ignoring link from deaf device: $selfname"); @@ -588,7 +588,7 @@ sub delete_orphan_links } else # is a non-PLM device { - if (!$self->is_deaf) + if ($self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] Delete orphan links: ignoring link from $selfname to 'deaf' device: " . $linked_device->get_object_name); } @@ -754,7 +754,7 @@ sub delete_orphan_links { $member = $member->get_root; } - if (!$self->is_deaf) + if ($self->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] ignoring link from " . $link->get_object_name . " to " . $member->get_object_name); @@ -2830,7 +2830,7 @@ sub delete_orphan_links } if ($member->isa('Insteon::BaseDevice')) { - if (!$self->is_deaf) + if ($self->is_deaf) { &::print_log("[Insteon::ALDB_PLM] ignoring link from PLM to " . $member->get_object_name); From 726997a580288967850fc9cd316d9a0760771ed3 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Fri, 11 Oct 2013 19:01:16 -0700 Subject: [PATCH 3/5] Insteon: Not All References are to Self Reminder to self: don't use find and replace --- lib/Insteon.pm | 2 +- lib/Insteon/AllLinkDatabase.pm | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Insteon.pm b/lib/Insteon.pm index 0a5afe9a1..ced96dbdb 100755 --- a/lib/Insteon.pm +++ b/lib/Insteon.pm @@ -510,7 +510,7 @@ sub sync_all_links # iterate over all registered objects and compare whether the link tables match defined scene linkages in known Insteon_Links for my $obj (&Insteon::find_members('Insteon::BaseController')) { - if ($self->is_deaf) + if ($obj->is_deaf) { &main::print_log("[Sync all links] Ignoring links from 'deaf' device: " . $obj->get_object_name); } diff --git a/lib/Insteon/AllLinkDatabase.pm b/lib/Insteon/AllLinkDatabase.pm index 9d35b4005..003db8636 100644 --- a/lib/Insteon/AllLinkDatabase.pm +++ b/lib/Insteon/AllLinkDatabase.pm @@ -588,7 +588,7 @@ sub delete_orphan_links } else # is a non-PLM device { - if ($self->is_deaf) + if ($linked_device->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] Delete orphan links: ignoring link from $selfname to 'deaf' device: " . $linked_device->get_object_name); } @@ -754,7 +754,7 @@ sub delete_orphan_links { $member = $member->get_root; } - if ($self->is_deaf) + if ($member->is_deaf) { &::print_log("[Insteon::AllLinkDatabase] ignoring link from " . $link->get_object_name . " to " . $member->get_object_name); @@ -2830,7 +2830,7 @@ sub delete_orphan_links } if ($member->isa('Insteon::BaseDevice')) { - if ($self->is_deaf) + if ($member->is_deaf) { &::print_log("[Insteon::ALDB_PLM] ignoring link from PLM to " . $member->get_object_name); From f6762440a0796149ecad68fdd94cef6147bad24a Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Fri, 11 Oct 2013 19:03:32 -0700 Subject: [PATCH 4/5] Insteon: One More Typo --- lib/Insteon.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Insteon.pm b/lib/Insteon.pm index ced96dbdb..e55ee7961 100755 --- a/lib/Insteon.pm +++ b/lib/Insteon.pm @@ -400,7 +400,7 @@ sub scan_all_linktables { my $candidate_object = $_; if ($candidate_object->is_root and - !($self->is_deaf + !($candidate_object->is_deaf or $candidate_object->isa('Insteon::InterfaceController'))) { push @_scan_devices, $candidate_object; From efdefe437194057d8df984ad465bf912da15b85d Mon Sep 17 00:00:00 2001 From: Pmatis Date: Thu, 17 Oct 2013 20:03:55 -0400 Subject: [PATCH 5/5] Fix typo in description of base device's is_deaf default. --- lib/Insteon/BaseInsteon.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Insteon/BaseInsteon.pm b/lib/Insteon/BaseInsteon.pm index 9c6250448..18c5e18f5 100644 --- a/lib/Insteon/BaseInsteon.pm +++ b/lib/Insteon/BaseInsteon.pm @@ -1315,8 +1315,8 @@ Returns true if the device must be awake in order to respond to messages. Most devices are not deaf, currently devices that are deaf are battery operated devices such as the Motion Sensor, RemoteLinc and TriggerLinc. -At the BaseObject level all devices are defined as deaf. Objects which inherit -BaseObject should redefine is_deaf as necessary. +At the BaseObject level all devices are defined as not deaf. Objects which +inherit BaseObject should redefine is_deaf as necessary. =cut