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

Add Support for Update_Flags and Update_OnLevel/RampRate for I2 Devices #242

Merged
merged 6 commits into from
Aug 9, 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
60 changes: 2 additions & 58 deletions lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1186,6 +1186,7 @@ our %message_types = (
peek => 0x2b,
peek_internal => 0x2c,
poke_internal => 0x2d,
extended_set_get => 0x2e,
read_write_aldb => 0x2f,
);

Expand Down Expand Up @@ -1929,42 +1930,6 @@ sub states

}

=item C<local_onlevel(level)>

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<local_ramprate(rate)>

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<delete_orphan_links(audit_mode)>

Reviews the cached version of all of the ALDBs and based on this review removes
Expand Down Expand Up @@ -2001,27 +1966,6 @@ sub log_alllink_table
$self->_aldb->log_alllink_table if $self->_aldb;
}

=item C<update_local_properties()>

Pushes the values set in C<local_onlevel()> and C<local_ramprate()> 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<engine_version>

Sets or gets the device object engine version. If setting the engine version,
Expand Down
3 changes: 1 addition & 2 deletions lib/Insteon/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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<new()>
Expand Down
6 changes: 0 additions & 6 deletions lib/Insteon/IOLinc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ my %operating_flags = (
'momentary_c_off' => '15',
);

my %message_types = (
%Insteon::BaseDevice::message_types,
extended_set_get => 0x2e
);

=item C<new()>

Instantiates a new object.
Expand All @@ -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;
Expand Down
205 changes: 131 additions & 74 deletions lib/Insteon/Lighting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,98 @@ sub new
return $self;
}

=item C<local_onlevel(level)>

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<update_local_properties>.

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<local_ramprate(rate)>

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<update_local_properties>.

Parameters: rate = ramp rate [.1s - 540s] see C<convert_ramp> 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<update_local_properties()>

Pushes the values set in C<local_onlevel()> and C<local_ramprate()> 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<level(p_level)>

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
Expand Down Expand Up @@ -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<new()>

Instantiates a new object.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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<get_voice_cmds>
Expand Down Expand Up @@ -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<new()>

Expand All @@ -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<set(state[,setby,response])>

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<Insteon::KeyPadLincRelay>

=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<update_flags(flags)>

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<get_voice_cmds>

Returns a hash of voice commands where the key is the voice command name and the
Expand Down Expand Up @@ -1178,4 +1235,4 @@ You should have received a copy of the GNU General Public License along with thi

=cut

1
1
Loading