mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
73_GasCalculator: feature: "set" and "get" - command in GUI implemented.
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@11720 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ccfc3bcfb6
commit
79a89f8c3a
@ -44,6 +44,8 @@
|
|||||||
package main;
|
package main;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
my %GasCalculator_gets;
|
||||||
|
my %GasCalculator_sets;
|
||||||
|
|
||||||
###START###### Initialize module ##############################################################################START####
|
###START###### Initialize module ##############################################################################START####
|
||||||
sub GasCalculator_Initialize($)
|
sub GasCalculator_Initialize($)
|
||||||
@ -53,6 +55,7 @@ sub GasCalculator_Initialize($)
|
|||||||
$hash->{STATE} = "Init";
|
$hash->{STATE} = "Init";
|
||||||
$hash->{DefFn} = "GasCalculator_Define";
|
$hash->{DefFn} = "GasCalculator_Define";
|
||||||
$hash->{UndefFn} = "GasCalculator_Undefine";
|
$hash->{UndefFn} = "GasCalculator_Undefine";
|
||||||
|
$hash->{GetFn} = "GasCalculator_Get";
|
||||||
$hash->{SetFn} = "GasCalculator_Set";
|
$hash->{SetFn} = "GasCalculator_Set";
|
||||||
$hash->{AttrFn} = "GasCalculator_Attr";
|
$hash->{AttrFn} = "GasCalculator_Attr";
|
||||||
$hash->{NotifyFn} = "GasCalculator_Notify";
|
$hash->{NotifyFn} = "GasCalculator_Notify";
|
||||||
@ -140,6 +143,47 @@ sub GasCalculator_Attr(@)
|
|||||||
}
|
}
|
||||||
####END####### Handle attributes after changes via fhem GUI ####################################################END#####
|
####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####
|
###START###### Manipulate reading after "set" command by fhem #################################################START####
|
||||||
sub GasCalculator_Set($@)
|
sub GasCalculator_Set($@)
|
||||||
{
|
{
|
||||||
@ -156,6 +200,15 @@ sub GasCalculator_Set($@)
|
|||||||
my $value = join(" ", @a);
|
my $value = join(" ", @a);
|
||||||
my $ReturnMessage;
|
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 "?")
|
if ( $reading ne "?")
|
||||||
{
|
{
|
||||||
### Create Log entries for debugging
|
### Create Log entries for debugging
|
||||||
@ -189,8 +242,6 @@ sub GasCalculator_Notify($$)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Check whether all required attributes has been provided and if not, create them with standard values
|
### Check whether all required attributes has been provided and if not, create them with standard values
|
||||||
if(!defined($attr{$GasCalcName}{BasicPricePerAnnum}))
|
if(!defined($attr{$GasCalcName}{BasicPricePerAnnum}))
|
||||||
{
|
{
|
||||||
@ -680,6 +731,14 @@ sub GasCalculator_Notify($$)
|
|||||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator End_________________________________________________________________________________________________________________________________";
|
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;
|
return undef;
|
||||||
}
|
}
|
||||||
####END####### Calculate gas meter values on changed events ####################################################END#####
|
####END####### Calculate gas meter values on changed events ####################################################END#####
|
||||||
|
Loading…
x
Reference in New Issue
Block a user