Skip to content

Commit

Permalink
Merge pull request #1 from brainwarr/iEngine_n_nacks
Browse files Browse the repository at this point in the history
Provide human readable NACK messages.  Implement Insteon get_engine_vers...
  • Loading branch information
hollie committed Nov 3, 2012
2 parents 7e24c76 + cc7053d commit 04bcb73
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
8 changes: 5 additions & 3 deletions lib/Insteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ sub generate_voice_commands
$cmd_states .= ",link to interface,unlink with interface";
}
if ($object->is_root and !($object->isa('Insteon::InterfaceController'))) {
$cmd_states .= ",status,scan link table,log links";
$cmd_states .= ",status,get engine version,scan link table,log links";
push @_scannable_link, $object_name;
}
$object_string .= "$object_name_v = new Voice_Cmd '$command [$cmd_states]';\n";
$object_string .= "$object_name_v -> tie_event('$object_name->initiate_linking_as_controller(\"$group\")', 'initiate linking as controller');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->interface()->cancel_linking','cancel linking');\n\n";
if ($object->is_root and !($object->isa('Insteon::InterfaceController'))) {
$object_string .= "$object_name_v -> tie_event('$object_name->request_status','status');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->get_engine_version','get engine version');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->scan_link_table(\"" . '\$self->log_alllink_table' . "\")','scan link table');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->log_alllink_table()','log links');\n\n";
}
Expand All @@ -272,14 +273,15 @@ sub generate_voice_commands
} elsif ($object->isa('Insteon::BaseDevice')) {
$states = $insteon_menu_states if $insteon_menu_states
&& ($object->can('is_dimmable') && $object->is_dimmable);
my $cmd_states = "$states,status,scan link table,log links,update onlevel/ramprate"; #,on level,ramp rate";
my $cmd_states = "$states,status,get engine version,scan link table,log links,update onlevel/ramprate"; #,on level,ramp rate";
$cmd_states .= ",link to interface,unlink with interface" if $object->isa("Insteon::BaseController") || $object->is_controller;
$object_string .= "$object_name_v = new Voice_Cmd '$command [$cmd_states]';\n";
foreach my $state (split(/,/,$states)) {
$object_string .= "$object_name_v -> tie_items($object_name, '$state');\n\n";
}
$object_string .= "$object_name_v -> tie_event('$object_name->log_alllink_table()','log links');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->request_status','status');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->get_engine_version','get engine version');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->update_local_properties','update onlevel/ramprate');\n\n";
$object_string .= "$object_name_v -> tie_event('$object_name->scan_link_table(\"" . '\$self->log_alllink_table' . "\")','scan link table');\n\n";
if ($object->isa("Insteon::BaseController") || $object->is_controller) {
Expand Down Expand Up @@ -504,4 +506,4 @@ sub find_members {
return @l_found;
}

1
1
57 changes: 48 additions & 9 deletions lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ our %message_types = (
off => 0x13
);

our %nack_messages = (
fb => 'illegal_value_in_cmd',
fc => 'pre_nak_long_db_search',
fd => 'bad_checksum_or_unknown_cmd',
fe => 'load_sense_detects_no_load',
ff => 'sender_id_not_in_responder_aldb',
);

sub derive_link_state
{
my ($p_state) = @_;
Expand Down Expand Up @@ -435,6 +443,19 @@ sub _is_info_request
}
# if this were a scene controller, then also propogate the result to all members
}
elsif ( $cmd eq 'get_engine_version' ) {
my $version = $msg{extra};
$version++; # version retuned in cmd2 is 0 indexed
if ( $version == 3 ) {
$version = 'I2CS';
}
else {
$version = 'I'. sprintf( "%1d",$version);
}
&::print_log("[Insteon::BaseObject] received engine version for "
. $self->{object_name} . " of $version.");
}

return $is_info_request;

}
Expand Down Expand Up @@ -503,16 +524,21 @@ sub _process_message
# }
# else
# {
if ($self->isa('Insteon::BaseLight'))
{
&::print_log("[Insteon::BaseObject] WARN!! encountered a nack message for " . $self->{object_name}
if ($self->isa('Insteon::BaseLight')) {

&::print_log("[Insteon::BaseObject] WARN!! encountered a nack message ("
. $self->get_nack_msg_for( $msg{extra} )
.") for "
. $self->{object_name}
. ". It may be unplugged or have a burned out bulb") if $main::Debug{insteon};
}
else
{
&::print_log("[Insteon::BaseObject] WARN!! encountered a nack message for " . $self->{object_name}
}
else {
&::print_log("[Insteon::BaseObject] WARN!! encountered a nack message ("
. $self->get_nack_msg_for( $msg{extra} )
.") for "
. $self->{object_name}
. " ... skipping");
}
}
$self->is_acknowledged(0);
$self->_process_command_stack(%msg);
# }
Expand Down Expand Up @@ -635,6 +661,11 @@ sub _is_valid_state
}
}

# Provide human readable nack message.
sub get_nack_msg_for {
my ($self,$msg) = @_;
return $nack_messages{ $msg };
}

####################################
### #####################
Expand All @@ -656,6 +687,7 @@ our %message_types = (
delete_from_group => 0x02,
linking_mode => 0x09,
unlinking_mode => 0x0A,
get_engine_version => 0x0D,
ping => 0x10,
on_fast => 0x12,
off_fast => 0x14,
Expand Down Expand Up @@ -1020,6 +1052,13 @@ sub request_status
# $self->_send_cmd('command' => 'status_request', 'is_synchronous' => 1);
}

sub get_engine_version {
my ($self, $requestor) = @_;

my $message = new Insteon::InsteonMessage('insteon_send', $self, 'get_engine_version');
$self->_send_cmd($message);
}

sub ping
{
my ($self) = @_;
Expand Down Expand Up @@ -1815,4 +1854,4 @@ sub is_root
return 0;
}

1;
1;

0 comments on commit 04bcb73

Please sign in to comment.