Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added converter BoolDisplay #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions FHEM/fhconverter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,59 @@ sub NumDisplay(@)
return undef;
}

###############################################################################
#
# converts reading to bool (1|0), one way fhem->fronthem
#
###############################################################################
sub BoolDisplay(@)
{
my ($param) = @_;
my $cmd = $param->{cmd};
my $gad = $param->{gad};
my $gadval = $param->{gadval};

my $device = $param->{device};
my $reading = $param->{reading};
my $event = $param->{event};

my @args = @{$param->{args}};

if ($param->{cmd} eq 'get')
{
$event = ($reading eq 'state') ? main::Value($device) : main::ReadingsVal($device, $reading, '0');
$param->{cmd} = 'send';
}

if ($param->{cmd} eq 'send')
{
if ($event =~ /\D*([+-]{0,1}\d+[.]{0,1}\d*).*?/)
{
# numeric: greater than thresh -> 1, less or equal -> 0
$event = $1;
my $thresh = (@args) ? $args[0] : 0;
$param->{gadval} = ($event > $thresh) ? 1 : 0;
}
else
{
# string: we convert on/off to 1/0
$param->{gadval} = ($event eq "off") ? 0 : 1;
}
$param->{gad} = $gad;
$param->{gads} = [];
return undef;
}
elsif ($param->{cmd} eq 'rcv')
{
return 'done'; # only a display, no set
}
elsif ($param->{cmd} eq '?')
{
return 'usage: TBD!!!';
}
return undef;
}

###############################################################################
#
# RGB device, param: gad_r, gad_g, gad_b
Expand Down