Skip to content

Commit

Permalink
Override set_label and set_states Reload restriction
Browse files Browse the repository at this point in the history
Addes the ability to specify $obj->set_label("label",1) and $obj->set_states("on","maybe","off","override=1") to allow these functions to work outside the $Main::Reload loop
  • Loading branch information
hplato authored Jun 30, 2024
1 parent ec97038 commit f3aabab
Showing 1 changed file with 63 additions and 8 deletions.
71 changes: 63 additions & 8 deletions lib/Generic_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ sub new {
if ( defined $main::config_parms{object_logger_enable} );
$self->{logger_mintime} = 1;
$self->{logger_updatetime} = 0;
$self->{rrdfile} = undef; #if an rrdfile is attached to the object, then it can be displayed in the ia7 interface
$self->restore_data( 'active_state', 'schedule_count' );

for my $index ( 1 .. 20 ) {
Expand Down Expand Up @@ -254,6 +255,7 @@ sub _set_process {

# Override any set_by_timer requests
if ( $$self{timer} ) {
print "deleting timer due to set call\n" if $::Debug{set};
&Timer::unset( $$self{timer} );
delete $$self{timer};
}
Expand All @@ -280,7 +282,7 @@ sub _set_process {
else {
$state = ( $state_current eq 'on' ) ? 'off' : 'on';
}
&main::print_log( "Toggling $self->{object_name} from $state_current " . "to $state" );
# &main::print_log( "Toggling $self->{object_name} from $state_current " . "to $state" );
}

# Respond_Target is write-only from here (and its use for speech chimes
Expand Down Expand Up @@ -861,9 +863,12 @@ Specify a text label, useful for creating touch screen interfaces. Can only be
=cut

sub set_label {
return unless $main::Reload;
my ( $self, $label ) = @_;

#return unless $main::Reload;
#add in the ability to override this limitation, used in HA_Item
my ( $self, $label, $override ) = @_;
$override = 0 unless (defined $override);
return unless ( $main::Reload or $override);

# Set it
if ( defined $label ) {
$self->{label} = $label;
Expand Down Expand Up @@ -1015,12 +1020,18 @@ sub get_fp_icon_set {
=item C<set_states(states)>
Sets valid states to states, which is a list or array. Can only be run at startup or reload. TODO
Since set_states is an array, if the last element is override=1, then this can override states only being created at reload
Used in HA_Item for states that come back from the webapi
=cut

sub set_states {
return unless $main::Reload;
my ( $self, @states ) = @_;
my ( $self, @states) = @_;
my $override;
my $last_element = $states[-1];
($override) = $last_element =~ m/override=(\d)/;
pop(@states) if (defined $override);
$override = 0 unless (defined $override);
return unless ( $main::Reload or $override);
@{ $$self{states} } = @states;
}

Expand Down Expand Up @@ -1167,6 +1178,49 @@ sub logger {
$self->{logger_updatetime} = $tickcount;
}

=item C<set_rrd()>
Attach a rrd filename, and data source (ds) names to the object. Used to display a graph in the IA7 interface
=cut

sub set_rrd {
my ( $self, $rrdfile, $ds) = @_;

$self->{rrdfile} = $rrdfile;
$self->{rrdds} = $ds;

}

=item C<get_rrd()>
Get the rrd filename attached to the object.
=cut

sub get_rrd {
my ( $self) = @_;

return $self->{rrdfile};

}

=item C<get_rrd()>
Get the rrd datasources attached to the object.
=cut

sub get_rrd_ds {
my ( $self) = @_;

return $self->{rrdds};

}


=item C<reset_states2()>
TODO
Expand Down Expand Up @@ -2003,7 +2057,8 @@ sub check_date {
. " schedule is "
. $self->{ 'schedule_' . $index }
. " time_cron return "
. &main::time_cron( $self->{ 'schedule_' . $index } ) );
. &main::time_cron( $self->{ 'schedule_' . $index } ) )
if $main::Debug{'schedule'};
if ( &main::time_cron( $self->{ 'schedule_' . $index } ) ) {
$self->set_action( $self->{ 'schedule_label_' . $index } );
}
Expand Down

0 comments on commit f3aabab

Please sign in to comment.