Skip to content

Commit

Permalink
Merge pull request #782 from mhgithub20/led_level
Browse files Browse the repository at this point in the history
led_level
  • Loading branch information
hplato authored Dec 7, 2019
2 parents 23b7039 + 30a101c commit dbc269c
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions lib/Insteon/Lighting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ sub get_voice_cmds {
return \%voice_cmds;
}

=item C<led_level([0-100])>
Sets the LED to brightness percentage.
=cut

sub led_level {
my ( $self, $level ) = @_;
return unless defined $level;
my $name = $self->get_object_name;

::print_log( "[Insteon::BaseLight] Setting LED level of $name to" . " $level." )
if $self->debuglevel( 1, 'insteon' );


#For whatever reason 100% = 127 and 50% = 64
$level = $level * 1.28;
$level = 127 if $level > 127;
$level = 0 if $level < 0;

my $extra = '000107' . sprintf( '%02X', $level );
$extra .= '0' x ( 30 - length $extra );
my $message = new Insteon::InsteonMessage( 'insteon_ext_send', $self, 'extended_set_get', $extra );
$self->_send_cmd($message);
}

=back
=head2 AUTHOR
Expand Down Expand Up @@ -1385,30 +1411,6 @@ sub enable_beep_button {
}
}

=item C<led_level([0-100])>
Sets the LED to brightness percentage.
=cut

sub led_level {
my ( $self, $level ) = @_;
return unless defined $level;
my $name = $self->get_object_name;

::print_log( "[Insteon::MicroSwitch] Setting LED level of $name to" . " $level." );

#For whatever reason 100% = 127 and 50% = 64
$level = $level * 1.28;
$level = 127 if $level > 127;
$level = 0 if $level < 0;

my $extra = '000107' . sprintf( '%02X', $level );
$extra .= '0' x ( 30 - length $extra );
my $message = new Insteon::InsteonMessage( 'insteon_ext_send', $self, 'extended_set_get', $extra );
$self->_send_cmd($message);
}

=item C<get_voice_cmds>
Returns a hash of voice commands where the key is the voice command name and the
Expand Down

0 comments on commit dbc269c

Please sign in to comment.