diff --git a/lib/Insteon/BaseInsteon.pm b/lib/Insteon/BaseInsteon.pm index ea17ae646..0462b5721 100644 --- a/lib/Insteon/BaseInsteon.pm +++ b/lib/Insteon/BaseInsteon.pm @@ -545,7 +545,7 @@ sub derive_message if (!(defined $p_extra)) { if ($command eq 'on') { - if ($self->isa('Insteon::BaseDevice') && defined $self->local_onlevel) { + if ($self->can('local_onlevel') && defined $self->local_onlevel) { $level = 2.55 * $self->local_onlevel; $command = 'on_fast'; } else { @@ -1186,6 +1186,7 @@ our %message_types = ( peek => 0x2b, peek_internal => 0x2c, poke_internal => 0x2d, + extended_set_get => 0x2e, read_write_aldb => 0x2f, ); @@ -1929,42 +1930,6 @@ sub states } -=item C - -Sets and returns the local onlevel for the device in MH only. Level is a -percentage from 0%-100% - -=cut - -sub local_onlevel -{ - my ($self, $p_onlevel) = @_; - if (defined $p_onlevel) - { - my ($onlevel) = $p_onlevel =~ /(\d+)%?/; - $$self{_onlevel} = $onlevel; - } - return $$self{_onlevel}; -} - -=item C - -Sets and returns the local ramp rate for the device in MH only. Rate is a time -between .1 and 540 seconds. Only 32 rate steps exist, to MH will pick a time -equal to of the closest below this time. - -=cut - -sub local_ramprate -{ - my ($self, $p_ramprate) = @_; - if (defined $p_ramprate) { - $$self{_ramprate} = &Insteon::DimmableLight::convert_ramp($p_ramprate); - } - return $$self{_ramprate}; - -} - =item C Reviews the cached version of all of the ALDBs and based on this review removes @@ -2001,27 +1966,6 @@ sub log_alllink_table $self->_aldb->log_alllink_table if $self->_aldb; } -=item C - -Pushes the values set in C and C to the device. -The device will only reread these values when it is power-cycled. This can be -done by pulling the air-gap for 4 seconds or unplugging the device. - -=cut - -sub update_local_properties -{ - my ($self) = @_; - if ($self->isa('Insteon::DimmableLight')) - { - $self->_aldb->update_local_properties() if $self->_aldb; - } - else - { - &::print_log("[Insteon::BaseDevice] update_local_properties may only be applied to dimmable devices!"); - } -} - =item C Sets or gets the device object engine version. If setting the engine version, diff --git a/lib/Insteon/Controller.pm b/lib/Insteon/Controller.pm index 573439dc9..20b081bcb 100644 --- a/lib/Insteon/Controller.pm +++ b/lib/Insteon/Controller.pm @@ -59,8 +59,7 @@ use Insteon::BaseInsteon; my %message_types = ( %Insteon::BaseDevice::message_types, bright => 0x15, - dim => 0x16, - extended_set_get => 0x2e + dim => 0x16 ); =item C diff --git a/lib/Insteon/IOLinc.pm b/lib/Insteon/IOLinc.pm index 084a6c5ba..2983a61b9 100755 --- a/lib/Insteon/IOLinc.pm +++ b/lib/Insteon/IOLinc.pm @@ -122,11 +122,6 @@ my %operating_flags = ( 'momentary_c_off' => '15', ); -my %message_types = ( - %Insteon::BaseDevice::message_types, - extended_set_get => 0x2e -); - =item C Instantiates a new object. @@ -138,7 +133,6 @@ sub new my ($class, $p_deviceid, $p_interface) = @_; my $self = new Insteon::BaseDevice($p_deviceid, $p_interface); $$self{operating_flags} = \%operating_flags; - $$self{message_types} = \%message_types; bless $self, $class; $self->restore_data('momentary_time'); $$self{momentary_timer} = new Timer; diff --git a/lib/Insteon/Lighting.pm b/lib/Insteon/Lighting.pm index 304631bbd..fd33381f1 100644 --- a/lib/Insteon/Lighting.pm +++ b/lib/Insteon/Lighting.pm @@ -243,12 +243,98 @@ sub new return $self; } +=item C + +Sets and returns the local onlevel for the device in MH only. Level is a +percentage from 0%-100%. + +This setting can be pushed to the device using C. + +Parameters: level [0-100] + +Returns: [0-100] + +=cut + +sub local_onlevel +{ + my ($self, $p_onlevel) = @_; + if (defined $p_onlevel) + { + my ($onlevel) = $p_onlevel =~ /(\d+)%?/; + $$self{_onlevel} = $onlevel; + } + return $$self{_onlevel}; +} + +=item C + +Sets and returns the local ramp rate for the device in MH only. Rate is a time +between .1 and 540 seconds. Only 32 rate steps exist, to MH will pick a time +equal to of the closest below this time. + +This setting can be pushed to the device using C. + +Parameters: rate = ramp rate [.1s - 540s] see C for valid values + +Returns: hexadecimal representation of the ramprate. + +=cut + +sub local_ramprate +{ + my ($self, $p_ramprate) = @_; + if (defined $p_ramprate) { + $$self{_ramprate} = &Insteon::DimmableLight::convert_ramp($p_ramprate); + } + return $$self{_ramprate}; + +} + +=item C + +Pushes the values set in C and C to the device. + +I1 Devices: + +The device will only reread these values when it is power-cycled. This can be +done by pulling the air-gap for 4 seconds or unplugging the device. + +I2 & I2CS Devices + +The device will immediately read and update the values. + +=cut + +sub update_local_properties +{ + my ($self) = @_; + if ($self->engine_version eq 'I1'){ + $self->_aldb->update_local_properties() if $self->_aldb; + } + else { + #Queue Ramp Rate First + my $extra = '000005' . $self->local_ramprate(); + $extra .= '0' x (30 - length $extra); + my $message = new Insteon::InsteonMessage('insteon_ext_send', $self, 'extended_set_get', $extra); + $self->_send_cmd($message); + + #Now queue on level + $extra = '000006' . ::Insteon::DimmableLight::convert_level($self->local_onlevel()); + $extra .= '0' x (30 - length $extra); + $message = new Insteon::InsteonMessage('insteon_ext_send', $self, 'extended_set_get', $extra); + $self->_send_cmd($message); + } +} + =item C -Takes the p_level, and stores it as a numeric level in memory. If the p_level +Stores and returns the objects current on_level as a percentage. If p_level is ON and the device has a defined local_onlevel, the local_onlevel is stored as the numeric level in memory. +Returns [0-100] + =cut sub level @@ -681,6 +767,21 @@ use Insteon::BaseInsteon; @Insteon::KeyPadLincRelay::ISA = ('Insteon::BaseLight','Insteon::DeviceController'); +our %operating_flags = ( + 'program_lock_on' => '00', + 'program_lock_off' => '01', + 'led_on_during_tx' => '02', + 'led_off_during_tx' => '03', + 'resume_dim_on' => '04', + 'resume_dim_off' => '05', + '8_key_mode' => '06', + '6_key_mode' => '07', + 'led_off' => '08', + 'led_enabled' => '09', + 'key_beep_enabled' => '0a', + 'key_beep_off' => '0b' +); + =item C Instantiates a new object. @@ -690,8 +791,8 @@ Instantiates a new object. sub new { my ($class,$p_deviceid,$p_interface) = @_; - my $self = new Insteon::BaseLight($p_deviceid,$p_interface); + $$self{operating_flags} = \%operating_flags; bless $self,$class; return $self; } @@ -731,6 +832,7 @@ sub set } else { + $link_state = $p_state if $self->can('level'); return $self->Insteon::DeviceController::set($link_state, $p_setby, $p_respond); } @@ -755,9 +857,31 @@ options include: sub update_flags { - my ($self, $flags) = @_; + my ($self, $flags) = @_; return unless defined $flags; - $self->_aldb->update_flags($flags) if $self->_aldb; + if ($self->engine_version eq 'I1') { + $self->_aldb->update_flags($flags) if $self->_aldb; + } + else { + if ($flags & 0x02) { + $self->set_operating_flag('8_key_mode'); + } + else { + $self->set_operating_flag('6_key_mode'); + } + if ($flags & 0x04) { + $self->set_operating_flag('led_off'); + } + else { + $self->set_operating_flag('led_enabled'); + } + if ($flags & 0x08) { + $self->set_operating_flag('resume_dim_on'); + } + else { + $self->set_operating_flag('resume_dim_off'); + } + } } =item C @@ -847,7 +971,7 @@ package Insteon::KeyPadLinc; use strict; use Insteon::BaseInsteon; -@Insteon::KeyPadLinc::ISA = ('Insteon::DimmableLight','Insteon::DeviceController'); +@Insteon::KeyPadLinc::ISA = ('Insteon::KeyPadLincRelay', 'Insteon::DimmableLight','Insteon::DeviceController'); =item C @@ -858,79 +982,12 @@ Instantiates a new object. sub new { my ($class,$p_deviceid,$p_interface) = @_; - my $self = new Insteon::DimmableLight($p_deviceid,$p_interface); + $$self{operating_flags} = \%Insteon::KeyPadLincRelay::operating_flags; bless $self,$class; return $self; } -=item C - -Handles setting and receiving states from the device and specifically its -subordinate buttons. - -NOTE: This could be merged somehow with the set() function in -C - -=cut - -sub set -{ - my ($self, $p_state, $p_setby, $p_respond) = @_; - - if (!($self->is_root)) - { - my $rslt_code = $self->Insteon::BaseController::set($p_state, $p_setby, $p_respond); - return $rslt_code if $rslt_code; - - my $link_state = &Insteon::BaseObject::derive_link_state($p_state); - - if (ref $p_setby and $p_setby->isa('Insteon::BaseDevice')) - { - $self->Insteon::BaseObject::set($p_state, $p_setby, $p_respond); - } - elsif (ref $$self{surrogate} && ($$self{surrogate}->isa('Insteon::InterfaceController'))) - { - $$self{surrogate}->set($link_state, $p_setby, $p_respond) - unless ref $p_setby and $p_setby eq $self; - } - else - { - &::print_log("[Insteon::KeyPadLinc] You may not directly attempt to set a keypadlinc's button " - . "unless you have defined a reverse link with the \"surrogate\" keyword"); - } - } - else - { - return $self->Insteon::DeviceController::set($p_state, $p_setby, $p_respond); - } - - return 0; - -} - -=item C - -Can be used to set the button layout and light level on a keypadlinc. Flag -options include: - - '0a' - 8 button; backlighting dim - '06' - 8 button; backlighting off - '02' - 8 button; backlighting normal - - '08' - 6 button; backlighting dim - '04' - 6 button; backlighting off - '00' - 6 button; backlighting normal - -=cut - -sub update_flags -{ - my ($self, $flags) = @_; - return unless defined $flags; - $self->_aldb->update_flags($flags) if $self->_aldb; -} - =item C Returns a hash of voice commands where the key is the voice command name and the @@ -1178,4 +1235,4 @@ You should have received a copy of the GNU General Public License along with thi =cut -1 \ No newline at end of file +1 diff --git a/lib/Insteon/Security.pm b/lib/Insteon/Security.pm index 0af6cf4b9..ede4466e3 100644 --- a/lib/Insteon/Security.pm +++ b/lib/Insteon/Security.pm @@ -110,11 +110,6 @@ use Insteon::BaseInsteon; @Insteon::MotionSensor::ISA = ('Insteon::DeviceController','Insteon::BaseDevice'); -my %message_types = ( - %Insteon::BaseDevice::message_types, - extended_set_get => 0x2e -); - =item C Instantiates a new object. @@ -126,7 +121,6 @@ sub new my ($class,$p_deviceid,$p_interface) = @_; my $self = new Insteon::BaseDevice($p_deviceid,$p_interface); - $$self{message_types} = \%message_types; if ($self->is_root){ $self->restore_data('query_timer', 'last_query_time'); $$self{queue_timer} = new Timer;