Skip to content

Instantly share code, notes, and snippets.

@krkeegan
Created July 24, 2014 21:21
Show Gist options
  • Save krkeegan/5f485e83d73389a8e7f4 to your computer and use it in GitHub Desktop.
Save krkeegan/5f485e83d73389a8e7f4 to your computer and use it in GitHub Desktop.
Example of possible Psuedo-Code for Table A Validation
#This would be called inside each definition, this is using SCENE_BUILD as an example:
validate_def(['name,1','name,1', 'boolean,0','boolean,0','insteon_on_level,0','insteon_ramp_rate,0'], \@item_info);
#Global validation routine:
sub validate_def {
my ($req_array, $passed_values);
my $i = 0;
for my $req_line (@{$req_array}){
my ($type, $req) = split(',',$req_line);
if ($type eq 'boolean'){
::print_log("Error item $i in definition, should be 0 or 1") unless ($$passed_values[$i] =~ /^(0|1)$/);
}
elsif ($type eq 'name'){
::print_log("Error item $i in definition, can only use characters A-z and _") unless ($$passed_values[$i] =~ /^[\w_]*$/);
}
elsif ($type eq 'insteon_on_level'){
...
}
elsif ($type eq 'insteon_ramp_rate'){
...
}
if ($req and ($$passed_values[$i] eq '')){
::print_log("Error, item $1 is required in the definition");
}
$i++;
}
}
@krkeegan
Copy link
Author

Another thing that would be nice, although may not fit in this design, is a unified method for returning the descriptions of each of the fields. While I don't think many people use is, the web/bin/items.pl page does offer a user interface for editing items. But in order to have the definitions and proper descriptions appear on that page, you need to edit the web/bin/items.pl code. I have been, and I think many others as well, completely overlooking the additions to that file. It would be much better for developers if there was only one place to edit these things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment