Enhancements to Current Implementation of X10_Switchlinc:

1)    Reports the state, level, and state_level appropriately

2)    0% to 100% are represented correctly

3)    Supports response from status request (2-way only)

4)    Sets state/level when switch is pressed (2-way only)

 

NOTES:

The old version overrode set(…), but did not work well with the two way X10 Switchlinc devices.  The changes are pretty simple and utilize the infrastructure already provided by MH.

 

Since I am new to MH and Perl programming, suggestions/corrections are welcome.

 

 

############### NEW CODE

 

package X10_Switchlinc;

@X10_Switchlinc::ISA = ('X10_Item');

 

@preset_dim_levels = qw(M  N  O  P  C  D  A  B  E  F  G  H  K  L  I  J);

                       

sub new {

    my $self = &X10_Item::new(@_);

    my $id = $self->{x10_id};

 

    $self-> add ('XOGNGMGPGMG', 'clear');

    $self-> add ('XOGPGNGMGMG', 'setramprate');

    $self-> add ('XPGNGMGOGMG', 'setonlevel');

    $self-> add ('XMGNGOGPG',   'addscenemembership');

    $self-> add ('XOGPGMGNG',   'deletescenemembership');

    $self-> add ('XNGOGPGMG',   'setsceneramprate');

    $self-> add ('XMGNGPGOGPG', 'disablex10transmit');

    $self-> add ('XOGMGNGPGPG', 'enablex10transmit');

 

    # 0% is MPRESET_DIM1

    $self-> add( $id . $preset_dim_levels[0] . 'PRESET_DIM1', "0%" );

 

    # 100% is JPRESET_DIM2

    $self-> add( $id . $preset_dim_levels[15] . 'PRESET_DIM2', "100%" );

   

    # 30 levels, 1% to 99%

    for (my $percent=1; $percent<=99; $percent++)

    {

      my $index = int(($percent - 1) * 30 / 99) + 1;

      my $state2  = $id . ( ($index < 16 ) ?

                  $preset_dim_levels[$index] . 'PRESET_DIM1' :

                  $preset_dim_levels[$index - 16] . 'PRESET_DIM2');

                   

      $self-> add( $state2, $percent . "%" );

    }

 

 

    return $self;

}

 

# SET METHOD REMOVED

 

 

 

############### CURRENT CODE FOR v2.86 of MH

 

package X10_Switchlinc;

@X10_Switchlinc::ISA = ('X10_Item');

 

sub new {

    my $self = &X10_Item::new(@_);

    my $id = $self->{x10_id};

 

    $self-> add ('XOGNGMGPGMG', 'clear');

    $self-> add ('XOGPGNGMGMG', 'setramprate');

    $self-> add ('XPGNGMGOGMG', 'setonlevel');

    $self-> add ('XMGNGOGPG',   'addscenemembership');

    $self-> add ('XOGPGMGNG',   'deletescenemembership');

    $self-> add ('XNGOGPGMG',   'setsceneramprate');

    $self-> add ('XMGNGPGOGPG', 'disablex10transmit');

    $self-> add ('XOGMGNGPGPG', 'enablex10transmit');

 

    return $self;

}

 

@preset_dim_levels = qw(M  N  O  P  C  D  A  B  E  F  G  H  K  L  I  J

                        M  N  O  P  C  D  A  B  E  F  G  H  K  L  I  J);

sub set {

    my ($self, $state, $set_by) = @_;

 

                                # Use preset_dims for ##% data

    if ($state =~ /^(\d+)\%/) {

        my $index = int(.5 + $1 * 32 / 100) - 1;   # 32 levels, 100% -> 31

        my $state2  = $self->{x10_id} . $preset_dim_levels[$index];

        $state2 .= ($index < 16) ? 'PRESET_DIM1' : 'PRESET_DIM2';

        print "Switchlink X10 dim: $state -> $state2\n" if $main::Debug{x10};

 

        $state = $state2;

    }

    $self->SUPER::set($state, $set_by);

}

 

Thanks,

-Steven