Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insteon: Set Send Timeout on a Per Device Basis #165

Merged
merged 5 commits into from
Jul 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ sub new
$$self{_onlevel} = undef;
$$self{is_responder} = 1;
$$self{default_hop_count} = 0;
$$self{timeout_factor} = 1.0;

&Insteon::add($self);
return $self;
Expand Down Expand Up @@ -198,6 +199,24 @@ sub group
return $$self{m_group};
}

=item C<timeout_factor($float)>

Changes the amount of time MH will wait to receive a response from a device before
resending the message. The value set will be multiplied by the predefined value
in MH. $float can be set to any positive decimal number. For example using 1.0
will not change the preset values; 1.1 will increase the time MH waits by 10%; and
0.9 will force MH to wait for only 90% of the predefined time.

This value is NOT saved on reboot, as such likely should be called in a $Reload loop.

=cut

sub timeout_factor {
my ($self, $factor) = @_;
$$self{timeout_factor} = $factor if $factor;
return $$self{timeout_factor};
}

=item C<max_hops($int)>

Sets the maximum number of hops that may be used in a message sent to the device.
Expand Down
27 changes: 16 additions & 11 deletions lib/Insteon/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -527,53 +527,58 @@ sub send_timeout
my ($self, $ignore) = @_;
my $hop_count = (ref $self->setby and $self->setby->isa('Insteon::BaseObject')) ?
$self->setby->default_hop_count : $self->send_attempts;
my $timeout = 1400;
if($self->command eq 'peek' || $self->command eq 'set_address_msb')
{
return 4000;
$timeout = 4000;
}
if ($self->command_type eq 'all_link_send')
elsif ($self->command_type eq 'all_link_send')
{
# note, the following was set to 2000 and that was insufficient
return 3000;
$timeout = 3000;
}
elsif ($self->command_type eq 'insteon_ext_send')
{
if ($hop_count == 0)
{
return 2220;
$timeout = 2220;
}
elsif ($hop_count == 1)
{
return 2690;
$timeout = 2690;
}
elsif ($hop_count == 2)
{
return 3000;
$timeout = 3000;
}
elsif ($hop_count >= 3)
{
return 3170;
$timeout = 3170;
}
}
else
{
if ($hop_count == 0)
{
return 1400;
$timeout = 1400;
}
elsif ($hop_count == 1)
{
return 1700;
$timeout = 1700;
}
elsif ($hop_count == 2)
{
return 1900;
$timeout = 1900;
}
elsif ($hop_count >= 3)
{
return 2000;
$timeout = 2000;
}
}
if (ref $self->setby and $self->setby->isa('Insteon::BaseObject')){
$timeout = int($timeout * $self->setby->timeout_factor);
}
return $timeout;
}

=item C<to_string()>
Expand Down