From 30a101c11094e919cb7f800fa876113aafe9ca18 Mon Sep 17 00:00:00 2001 From: Brian M Date: Thu, 23 May 2019 09:04:02 -0700 Subject: [PATCH] Move led_level from Insteon::MicroSwitch to Insteon::BaseLight, as it is also works for 2476x/2477x switches and probably other devices --- lib/Insteon/Lighting.pm | 50 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/Insteon/Lighting.pm b/lib/Insteon/Lighting.pm index 7d730bb4d..ca179c2b3 100644 --- a/lib/Insteon/Lighting.pm +++ b/lib/Insteon/Lighting.pm @@ -83,6 +83,32 @@ sub get_voice_cmds { return \%voice_cmds; } +=item C + +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 @@ -1367,30 +1393,6 @@ sub enable_beep_button { } } -=item C - -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 Returns a hash of voice commands where the key is the voice command name and the