diff --git a/lib/Insteon/Controller.pm b/lib/Insteon/Controller.pm index 45b77b9ad..263d96f28 100755 --- a/lib/Insteon/Controller.pm +++ b/lib/Insteon/Controller.pm @@ -9,7 +9,8 @@ use Insteon::BaseInsteon; my %message_types = ( %Insteon::BaseDevice::message_types, bright => 0x15, - dim => 0x16 + dim => 0x16, + extended_set_get => 0x2e ); sub new @@ -49,6 +50,65 @@ sub set return; } +sub set_awake_time { + my ($self, $awake) = @_; + $awake = sprintf("%02x", $awake); + my $root = $self->get_root(); + my $extra = '000102' . $awake . '0000000000000000000000'; + $$root{_ext_set_get_action} = "set"; + my $message = new Insteon::InsteonMessage('insteon_ext_send', $root, 'extended_set_get', $extra); + $root->_send_cmd($message); + return; +} + +sub get_extended_info { + my ($self) = @_; + my $root = $self->get_root(); + my $extra = '000100000000000000000000000000'; + $$root{_ext_set_get_action} = "get"; + my $message = new Insteon::InsteonMessage('insteon_ext_send', $root, 'extended_set_get', $extra); + $root->_send_cmd($message); + return; +} + +sub _process_message { + my ($self,$p_setby,%msg) = @_; + my $clear_message = 0; + if ($msg{command} eq 'link_cleanup_report'){ + #Queue an get_extended_info request + $self->get_extended_info(); + } + if ($msg{command} eq "extended_set_get" && $msg{is_ack}){ + $self->default_hop_count($msg{maxhops}-$msg{hopsleft}); + #If this was a get request don't clear until data packet received + main::print_log("[Insteon::RemoteLinc] Extended Set/Get ACK Received for " . $self->get_object_name) if $main::Debug{insteon}; + if ($$self{_ext_set_get_action} eq 'set'){ + main::print_log("[Insteon::RemoteLinc] Clearing active message") if $main::Debug{insteon}; + $clear_message = 1; + $$self{_ext_set_get_action} = undef; + $self->_process_command_stack(%msg); + } + } + elsif ($msg{command} eq "extended_set_get" && $msg{is_extended}) { + if (substr($msg{extra},0,6) eq "000001") { + $self->default_hop_count($msg{maxhops}-$msg{hopsleft}); + #D10 = Battery; + main::print_log("[Insteon::RemoteLinc] The battery level ". + "for device ". $self->get_object_name . " is: ". + hex(substr($msg{extra}, 20, 2))); + $clear_message = 1; + $self->_process_command_stack(%msg); + } else { + main::print_log("[Insteon::RemoteLinc] WARN: Corrupt Extended " + ."Set/Get Data Received for ". $self->get_object_name) if $main::Debug{insteon}; + } + } + else { + $clear_message = $self->SUPER::_process_message($p_setby,%msg); + } + return $clear_message; +} + sub is_responder { return 0;