2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

73_GasCalculator: feature: "set" and "get" - command in GUI implemented.

git-svn-id: https://svn.fhem.de/fhem/trunk@11720 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
sailor-fhem 2016-06-27 12:15:07 +00:00
parent d36706c557
commit 5f8de9055b

View File

@ -44,16 +44,19 @@
package main;
use strict;
use warnings;
my %GasCalculator_gets;
my %GasCalculator_sets;
###START###### Initialize module ##############################################################################START####
sub GasCalculator_Initialize($)
{
my ($hash) = @_;
$hash->{STATE} = "Init";
$hash->{DefFn} = "GasCalculator_Define";
$hash->{UndefFn} = "GasCalculator_Undefine";
$hash->{SetFn} = "GasCalculator_Set";
$hash->{GetFn} = "GasCalculator_Get";
$hash->{SetFn} = "GasCalculator_Set";
$hash->{AttrFn} = "GasCalculator_Attr";
$hash->{NotifyFn} = "GasCalculator_Notify";
$hash->{NotifyOrderPrefix} = "10-"; # Want to be called before the rest
@ -140,6 +143,47 @@ sub GasCalculator_Attr(@)
}
####END####### Handle attributes after changes via fhem GUI ####################################################END#####
###START###### Manipulate reading after "set" command by fhem #################################################START####
sub GasCalculator_Get($@)
{
my ( $hash, @a ) = @_;
### If not enough arguments have been provided
if ( @a < 2 )
{
return "\"get GasCalculator\" needs at least one argument";
}
my $GasCalcName = shift @a;
my $reading = shift @a;
my $value;
my $ReturnMessage;
if(!defined($GasCalculator_gets{$reading}))
{
my @cList = keys %GasCalculator_sets;
return "Unknown argument $reading, choose one of " . join(" ", @cList);
### Create Log entries for debugging
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - get list: " . join(" ", @cList);
}
if ( $reading ne "?")
{
### Create Log entries for debugging
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - get " . $reading . " with value: " . $value;
### Write current value
$value = ReadingsVal($GasCalcName, $reading, undef);
### Create ReturnMessage
$ReturnMessage = $value;
}
return($ReturnMessage);
}
####END####### Manipulate reading after "set" command by fhem ##################################################END#####
###START###### Manipulate reading after "set" command by fhem #################################################START####
sub GasCalculator_Set($@)
{
@ -156,6 +200,15 @@ sub GasCalculator_Set($@)
my $value = join(" ", @a);
my $ReturnMessage;
if(!defined($GasCalculator_sets{$reading}))
{
my @cList = keys %GasCalculator_sets;
return "Unknown argument $reading, choose one of " . join(" ", @cList);
### Create Log entries for debugging
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - set list: " . join(" ", @cList);
}
if ( $reading ne "?")
{
### Create Log entries for debugging
@ -189,8 +242,6 @@ sub GasCalculator_Notify($$)
return "";
}
### Check whether all required attributes has been provided and if not, create them with standard values
if(!defined($attr{$GasCalcName}{BasicPricePerAnnum}))
{
@ -679,7 +730,15 @@ sub GasCalculator_Notify($$)
### Create Log entries for debugging
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator End_________________________________________________________________________________________________________________________________";
}
### Update list of available readings
%GasCalculator_gets = %{$GasCalcDev->{READINGS}};
%GasCalculator_sets = %{$GasCalcDev->{READINGS}};
### Create Log entries for debugging
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - notify x_sets list: " . join(" ", (keys %GasCalculator_sets));
return undef;
}
####END####### Calculate gas meter values on changed events ####################################################END#####