remove all prototyps, change code PBP conform
This commit is contained in:
parent
4789870ad7
commit
765a923f46
@ -197,16 +197,15 @@ my %CallBatteryAge = (
|
||||
'48h' => 172800
|
||||
);
|
||||
|
||||
sub Initialize($) {
|
||||
sub Initialize {
|
||||
my $hash = shift;
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{SetFn} = "FHEM::XiaomiBTLESens::Set";
|
||||
$hash->{GetFn} = "FHEM::XiaomiBTLESens::Get";
|
||||
$hash->{DefFn} = "FHEM::XiaomiBTLESens::Define";
|
||||
$hash->{NotifyFn} = "FHEM::XiaomiBTLESens::Notify";
|
||||
$hash->{UndefFn} = "FHEM::XiaomiBTLESens::Undef";
|
||||
$hash->{AttrFn} = "FHEM::XiaomiBTLESens::Attr";
|
||||
$hash->{SetFn} = \&Set;
|
||||
$hash->{GetFn} = \&Get;
|
||||
$hash->{DefFn} = \&Define;
|
||||
$hash->{NotifyFn} = \&Notify;
|
||||
$hash->{UndefFn} = \&Undef;
|
||||
$hash->{AttrFn} = \&Attr;
|
||||
$hash->{AttrList} =
|
||||
"interval "
|
||||
. "disable:1 "
|
||||
@ -226,29 +225,26 @@ sub Initialize($) {
|
||||
. "model:flowerSens,thermoHygroSens,clearGrassSens "
|
||||
. "blockingCallLoglevel:2,3,4,5 "
|
||||
. $readingFnAttributes;
|
||||
$hash->{parseParams} = 1;
|
||||
|
||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||
}
|
||||
|
||||
# declare prototype
|
||||
sub ExecGatttool_Run($);
|
||||
|
||||
sub Define($$) {
|
||||
|
||||
my ( $hash, $def ) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def );
|
||||
sub Define {
|
||||
my $hash = shift;
|
||||
my $a = shift;
|
||||
|
||||
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
||||
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
||||
|
||||
return "too few parameters: define <name> XiaomiBTLESens <BTMAC>"
|
||||
if ( @a != 3 );
|
||||
if ( scalar( @{$a} ) != 3 );
|
||||
return
|
||||
"Cannot define XiaomiBTLESens device. Perl modul ${missingModul}is missing."
|
||||
if ($missingModul);
|
||||
|
||||
my $name = $a[0];
|
||||
my $mac = $a[2];
|
||||
my $name = $a->[0];
|
||||
my $mac = $a->[2];
|
||||
|
||||
$hash->{BTMAC} = $mac;
|
||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||
@ -262,15 +258,17 @@ sub Define($$) {
|
||||
CommandAttr( undef, $name . ' room XiaomiBTLESens' )
|
||||
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
|
||||
|
||||
Log3($name, 3, "XiaomiBTLESens ($name) - defined with BTMAC $hash->{BTMAC}");
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - defined with BTMAC $hash->{BTMAC}" );
|
||||
|
||||
$modules{XiaomiBTLESens}{defptr}{ $hash->{BTMAC} } = $hash;
|
||||
return undef;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Undef($$) {
|
||||
|
||||
my ( $hash, $arg ) = @_;
|
||||
sub Undef {
|
||||
my $hash = shift;
|
||||
my $arg = shift;
|
||||
|
||||
my $mac = $hash->{BTMAC};
|
||||
my $name = $hash->{NAME};
|
||||
@ -281,11 +279,11 @@ sub Undef($$) {
|
||||
|
||||
delete( $modules{XiaomiBTLESens}{defptr}{$mac} );
|
||||
Log3( $name, 3, "Sub XiaomiBTLESens_Undef ($name) - delete device $name" );
|
||||
return undef;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Attr(@) {
|
||||
|
||||
sub Attr {
|
||||
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
||||
my $hash = $defs{$name};
|
||||
|
||||
@ -323,7 +321,8 @@ sub Attr(@) {
|
||||
if ( $cmd eq "set" ) {
|
||||
if ( $attrVal < 120 ) {
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - interval too small, please use something >= 120 (sec), default is 300 (sec)");
|
||||
"XiaomiBTLESens ($name) - interval too small, please use something >= 120 (sec), default is 300 (sec)"
|
||||
);
|
||||
return
|
||||
"interval too small, please use something >= 120 (sec), default is 300 (sec)";
|
||||
}
|
||||
@ -336,7 +335,8 @@ sub Attr(@) {
|
||||
|
||||
elsif ( $cmd eq "del" ) {
|
||||
$hash->{INTERVAL} = 300;
|
||||
Log3($name, 3, "XiaomiBTLESens ($name) - set interval to default");
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - set interval to default" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,22 +344,25 @@ sub Attr(@) {
|
||||
if ( $cmd eq "set" ) {
|
||||
$hash->{loglevel} = $attrVal;
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - set blockingCallLoglevel to $attrVal");
|
||||
"XiaomiBTLESens ($name) - set blockingCallLoglevel to $attrVal"
|
||||
);
|
||||
}
|
||||
|
||||
elsif ( $cmd eq "del" ) {
|
||||
$hash->{loglevel} = 4;
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - set blockingCallLoglevel to default");
|
||||
"XiaomiBTLESens ($name) - set blockingCallLoglevel to default"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
sub Notify($$) {
|
||||
sub Notify {
|
||||
my $hash = shift;
|
||||
my $dev = shift;
|
||||
|
||||
my ( $hash, $dev ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
return stateRequestTimer($hash) if ( IsDisabled($name) );
|
||||
|
||||
@ -419,9 +422,9 @@ sub Notify($$) {
|
||||
return;
|
||||
}
|
||||
|
||||
sub stateRequest($) {
|
||||
sub stateRequest {
|
||||
my $hash = shift;
|
||||
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
|
||||
@ -481,11 +484,12 @@ sub stateRequest($) {
|
||||
else {
|
||||
readingsSingleUpdate( $hash, "state", "disabled", 1 );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub stateRequestTimer($) {
|
||||
|
||||
my ($hash) = @_;
|
||||
sub stateRequestTimer {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -497,28 +501,30 @@ sub stateRequestTimer($) {
|
||||
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - stateRequestTimer: Call Request Timer" );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Set($$@) {
|
||||
|
||||
my ( $hash, $name, @aa ) = @_;
|
||||
my ( $cmd, @args ) = @aa;
|
||||
my $hash = shift;
|
||||
my $a = shift;
|
||||
my $name = shift @$a;
|
||||
my $cmd = shift @$a // return qq{"set $name" needs at least one argument};
|
||||
|
||||
my $mod;
|
||||
my $handle;
|
||||
my $value = 'write';
|
||||
|
||||
if ( $cmd eq 'devicename' ) {
|
||||
return "usage: devicename <name>" if ( @args < 1 );
|
||||
return "usage: devicename <name>" if ( scalar( @{$a} ) < 1 );
|
||||
|
||||
my $devicename = join( " ", @args );
|
||||
$mod = 'write';
|
||||
$handle = $XiaomiModels{ AttrVal( $name, 'model', '' ) }{devicename};
|
||||
$value = CreateDevicenameHEX( makeDeviceName($devicename) );
|
||||
$value = CreateDevicenameHEX( makeDeviceName( $a->[0] ) );
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'resetBatteryTimestamp' ) {
|
||||
return "usage: resetBatteryTimestamp" if ( @args != 0 );
|
||||
return "usage: resetBatteryTimestamp" if ( scalar( @{$a} ) != 0 );
|
||||
|
||||
$hash->{helper}{updateTimeCallBattery} = 0;
|
||||
return;
|
||||
@ -538,32 +544,33 @@ sub Set($$@) {
|
||||
|
||||
CreateParamGatttool( $hash, $mod, $handle, $value );
|
||||
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
sub Get($$@) {
|
||||
|
||||
my ( $hash, $name, @aa ) = @_;
|
||||
my ( $cmd, @args ) = @aa;
|
||||
sub Get {
|
||||
my $hash = shift;
|
||||
my $a = shift;
|
||||
my $name = shift @$a;
|
||||
my $cmd = shift @$a // return qq{"set $name" needs at least one argument};
|
||||
|
||||
my $mod = 'read';
|
||||
my $handle;
|
||||
|
||||
if ( $cmd eq 'sensorData' ) {
|
||||
return "usage: sensorData" if ( @args != 0 );
|
||||
return "usage: sensorData" if ( scalar( @{$a} ) != 0 );
|
||||
|
||||
stateRequest($hash);
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'firmware' ) {
|
||||
return "usage: firmware" if ( @args != 0 );
|
||||
return "usage: firmware" if ( scalar( @{$a} ) != 0 );
|
||||
|
||||
$mod = 'read';
|
||||
$handle = $XiaomiModels{ AttrVal( $name, 'model', '' ) }{firmware};
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'devicename' ) {
|
||||
return "usage: devicename" if ( @args != 0 );
|
||||
return "usage: devicename" if ( scalar( @{$a} ) != 0 );
|
||||
|
||||
$mod = 'read';
|
||||
$handle = $XiaomiModels{ AttrVal( $name, 'model', '' ) }{devicename};
|
||||
@ -582,12 +589,12 @@ sub Get($$@) {
|
||||
|
||||
CreateParamGatttool( $hash, $mod, $handle ) if ( $cmd ne 'sensorData' );
|
||||
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
sub CreateParamGatttool($@) {
|
||||
|
||||
sub CreateParamGatttool {
|
||||
my ( $hash, $mod, $handle, $value ) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $mac = $hash->{BTMAC};
|
||||
|
||||
@ -607,7 +614,8 @@ sub CreateParamGatttool($@) {
|
||||
readingsSingleUpdate( $hash, "state", "read sensor data", 1 );
|
||||
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle");
|
||||
"XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle"
|
||||
);
|
||||
|
||||
}
|
||||
elsif ( $mod eq 'write' ) {
|
||||
@ -628,17 +636,19 @@ sub CreateParamGatttool($@) {
|
||||
readingsSingleUpdate( $hash, "state", "write sensor data", 1 );
|
||||
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value");
|
||||
}
|
||||
"XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value"
|
||||
);
|
||||
}
|
||||
|
||||
sub Gatttool_executeCommand($) {
|
||||
return;
|
||||
}
|
||||
|
||||
sub Gatttool_executeCommand {
|
||||
my $command = join( ' ', @_ );
|
||||
return ( $_ = qx{$command 2>&1}, $? >> 8 );
|
||||
}
|
||||
|
||||
sub ExecGatttool_Run($) {
|
||||
|
||||
sub ExecGatttool_Run {
|
||||
my $string = shift;
|
||||
|
||||
my ( $name, $mac, $gattCmd, $handle, $value, $listen ) =
|
||||
@ -686,7 +696,8 @@ sub ExecGatttool_Run($) {
|
||||
BTLE_CmdlinePreventGrepFalsePositive("gatttool -i $hci -b $mac");
|
||||
my $psCommand = AttrVal( $name, 'psCommand', 'ps ax' );
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: Execute Command $psCommand | grep -E $gatttoolCmdlineStaticEscaped");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: Execute Command $psCommand | grep -E $gatttoolCmdlineStaticEscaped"
|
||||
);
|
||||
|
||||
# $grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\')
|
||||
$grepGatttool =
|
||||
@ -700,7 +711,8 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||
|
||||
if ( not $grepGatttool =~ /^\s*$/ ) {
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting...");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting..."
|
||||
);
|
||||
sleep(1);
|
||||
}
|
||||
else {
|
||||
@ -714,7 +726,8 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||
do {
|
||||
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop"
|
||||
);
|
||||
|
||||
( $returnString, $returnCode ) = Gatttool_executeCommand($cmd);
|
||||
@gtResult = split( ": ", $returnString );
|
||||
@ -731,8 +744,8 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||
$loop++;
|
||||
} while ( $loop < 5 and ( $returnCode != 0 and $returnCode != 124 ) );
|
||||
Log3( $name, 3,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\"")
|
||||
if ( $returnCode != 0 and $returnCode != 124 );
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\""
|
||||
) if ( $returnCode != 0 and $returnCode != 124 );
|
||||
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result "
|
||||
@ -778,11 +791,13 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"')
|
||||
);
|
||||
return "$name|$mac|error|$gattCmd|$handle|$json_notification";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ExecGatttool_Done($) {
|
||||
|
||||
sub ExecGatttool_Done {
|
||||
my $string = shift;
|
||||
|
||||
my ( $name, $mac, $respstate, $gattCmd, $handle, $json_notification ) =
|
||||
split( "\\|", $string );
|
||||
|
||||
@ -791,17 +806,19 @@ sub ExecGatttool_Done($) {
|
||||
delete( $hash->{helper}{RUNNING_PID} );
|
||||
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: Helper is disabled. Stop processing")
|
||||
if ( $hash->{helper}{DISABLED} );
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: Helper is disabled. Stop processing"
|
||||
) if ( $hash->{helper}{DISABLED} );
|
||||
return if ( $hash->{helper}{DISABLED} );
|
||||
|
||||
Log3( $name, 5,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string"
|
||||
);
|
||||
|
||||
my $decode_json = eval { decode_json($json_notification) };
|
||||
if ($@) {
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@"
|
||||
);
|
||||
}
|
||||
|
||||
if ( $respstate eq 'ok'
|
||||
@ -820,11 +837,13 @@ sub ExecGatttool_Done($) {
|
||||
else {
|
||||
ProcessingErrors( $hash, $decode_json->{gtResult} );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ExecGatttool_Aborted($) {
|
||||
sub ExecGatttool_Aborted {
|
||||
my $hash = shift;
|
||||
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
|
||||
@ -836,11 +855,13 @@ sub ExecGatttool_Aborted($) {
|
||||
WriteReadings( $hash, \%readings );
|
||||
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Aborted: The BlockingCall Process terminated unexpectedly. Timedout");
|
||||
"XiaomiBTLESens ($name) - ExecGatttool_Aborted: The BlockingCall Process terminated unexpectedly. Timedout"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ProcessingNotification($@) {
|
||||
|
||||
sub ProcessingNotification {
|
||||
my ( $hash, $gattCmd, $handle, $notification ) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
@ -852,7 +873,8 @@ sub ProcessingNotification($@) {
|
||||
if ( $handle eq '0x38' ) {
|
||||
### Flower Sens - Read Firmware and Battery Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x38");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x38"
|
||||
);
|
||||
|
||||
$readings = FlowerSensHandle0x38( $hash, $notification );
|
||||
|
||||
@ -860,7 +882,8 @@ sub ProcessingNotification($@) {
|
||||
elsif ( $handle eq '0x35' ) {
|
||||
### Flower Sens - Read Sensor Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x35");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x35"
|
||||
);
|
||||
|
||||
$readings = FlowerSensHandle0x35( $hash, $notification );
|
||||
}
|
||||
@ -870,21 +893,24 @@ sub ProcessingNotification($@) {
|
||||
if ( $handle eq '0x18' ) {
|
||||
### Thermo/Hygro Sens - Read Battery Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x18");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x18"
|
||||
);
|
||||
|
||||
$readings = ThermoHygroSensHandle0x18( $hash, $notification );
|
||||
}
|
||||
elsif ( $handle eq '0x10' ) {
|
||||
### Thermo/Hygro Sens - Read Sensor Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x10");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x10"
|
||||
);
|
||||
|
||||
$readings = ThermoHygroSensHandle0x10( $hash, $notification );
|
||||
}
|
||||
elsif ( $handle eq '0x24' ) {
|
||||
### Thermo/Hygro Sens - Read Firmware Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x24");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x24"
|
||||
);
|
||||
|
||||
$readings = ThermoHygroSensHandle0x24( $hash, $notification );
|
||||
}
|
||||
@ -903,21 +929,24 @@ sub ProcessingNotification($@) {
|
||||
if ( $handle eq '0x3b' ) {
|
||||
### Clear Grass Sens - Read Battery Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3b");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3b"
|
||||
);
|
||||
|
||||
$readings = ClearGrassSensHandle0x3b( $hash, $notification );
|
||||
}
|
||||
elsif ( $handle eq '0x1e' ) {
|
||||
### Clear Grass Sens - Read Sensor Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x1e");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x1e"
|
||||
);
|
||||
|
||||
$readings = ClearGrassSensHandle0x1e( $hash, $notification );
|
||||
}
|
||||
elsif ( $handle eq '0x2a' ) {
|
||||
### Clear Grass Sens - Read Firmware Data
|
||||
Log3( $name, 4,
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x2a");
|
||||
"XiaomiBTLESens ($name) - ProcessingNotification: handle 0x2a"
|
||||
);
|
||||
|
||||
$readings = ClearGrassSensHandle0x2a( $hash, $notification );
|
||||
}
|
||||
@ -933,12 +962,13 @@ sub ProcessingNotification($@) {
|
||||
}
|
||||
}
|
||||
|
||||
WriteReadings( $hash, $readings );
|
||||
return WriteReadings( $hash, $readings );
|
||||
}
|
||||
|
||||
sub FlowerSensHandle0x38($$) {
|
||||
sub FlowerSensHandle0x38 {
|
||||
### FlowerSens - Read Firmware and Battery Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -959,12 +989,14 @@ sub FlowerSensHandle0x38($$) {
|
||||
|
||||
$hash->{helper}{CallBattery} = 1;
|
||||
CallBattery_Timestamp($hash);
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub FlowerSensHandle0x35($$) {
|
||||
sub FlowerSensHandle0x35 {
|
||||
### Flower Sens - Read Sensor Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1004,12 +1036,14 @@ sub FlowerSensHandle0x35($$) {
|
||||
. $readings{fertility} );
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ThermoHygroSensHandle0x18($$) {
|
||||
sub ThermoHygroSensHandle0x18 {
|
||||
### Thermo/Hygro Sens - Battery Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1026,12 +1060,14 @@ sub ThermoHygroSensHandle0x18($$) {
|
||||
|
||||
$hash->{helper}{CallBattery} = 1;
|
||||
CallBattery_Timestamp($hash);
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ThermoHygroSensHandle0x10($$) {
|
||||
sub ThermoHygroSensHandle0x10 {
|
||||
### Thermo/Hygro Sens - Read Sensor Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1062,12 +1098,14 @@ sub ThermoHygroSensHandle0x10($$) {
|
||||
);
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ThermoHygroSensHandle0x24($$) {
|
||||
sub ThermoHygroSensHandle0x24 {
|
||||
### Thermo/Hygro Sens - Read Firmware Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1079,12 +1117,14 @@ sub ThermoHygroSensHandle0x24($$) {
|
||||
$readings{'firmware'} = pack( 'H*', $notification );
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ThermoHygroSensHandle0x3($$) {
|
||||
sub ThermoHygroSensHandle0x3 {
|
||||
### Thermo/Hygro Sens - Read and Write Devicename
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1096,12 +1136,14 @@ sub ThermoHygroSensHandle0x3($$) {
|
||||
$readings{'devicename'} = pack( 'H*', $notification );
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ClearGrassSensHandle0x3b($$) {
|
||||
sub ClearGrassSensHandle0x3b {
|
||||
### Clear Grass Sens - Battery Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1118,12 +1160,14 @@ sub ClearGrassSensHandle0x3b($$) {
|
||||
|
||||
$hash->{helper}{CallBattery} = 1;
|
||||
CallBattery_Timestamp($hash);
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ClearGrassSensHandle0x1e($$) {
|
||||
sub ClearGrassSensHandle0x1e {
|
||||
### Clear Grass Sens - Read Sensor Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1143,12 +1187,14 @@ sub ClearGrassSensHandle0x1e($$) {
|
||||
10;
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ClearGrassSensHandle0x2a($$) {
|
||||
sub ClearGrassSensHandle0x2a {
|
||||
### Clear Grass Sens - Read Firmware Data
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1160,12 +1206,14 @@ sub ClearGrassSensHandle0x2a($$) {
|
||||
$readings{'firmware'} = pack( 'H*', $notification );
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub ClearGrassSensHandle0x3($$) {
|
||||
sub ClearGrassSensHandle0x3 {
|
||||
### Clear Grass Sens - Read and Write Devicename
|
||||
my ( $hash, $notification ) = @_;
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1177,12 +1225,13 @@ sub ClearGrassSensHandle0x3($$) {
|
||||
$readings{'devicename'} = pack( 'H*', $notification );
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
|
||||
return \%readings;
|
||||
}
|
||||
|
||||
sub WriteReadings($$) {
|
||||
|
||||
my ( $hash, $readings ) = @_;
|
||||
sub WriteReadings {
|
||||
my $hash = shift;
|
||||
my $readings = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1296,11 +1345,13 @@ sub WriteReadings($$) {
|
||||
|
||||
$hash->{helper}{CallSensDataCounter} = 0;
|
||||
stateRequest($hash) if ( $hash->{helper}{CallBattery} == 1 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ProcessingErrors($$) {
|
||||
|
||||
my ( $hash, $notification ) = @_;
|
||||
sub ProcessingErrors {
|
||||
my $hash = shift;
|
||||
my $notification = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my %readings;
|
||||
@ -1308,12 +1359,11 @@ sub ProcessingErrors($$) {
|
||||
Log3( $name, 4, "XiaomiBTLESens ($name) - ProcessingErrors" );
|
||||
$readings{'lastGattError'} = $notification;
|
||||
|
||||
WriteReadings( $hash, \%readings );
|
||||
return WriteReadings( $hash, \%readings );
|
||||
}
|
||||
|
||||
#### my little Helper
|
||||
sub encodeJSON($) {
|
||||
|
||||
sub encodeJSON {
|
||||
my $gtResult = shift;
|
||||
|
||||
chomp($gtResult);
|
||||
@ -1324,8 +1374,7 @@ sub encodeJSON($) {
|
||||
}
|
||||
|
||||
## Routinen damit Firmware und Batterie nur alle X male statt immer aufgerufen wird
|
||||
sub CallBattery_Timestamp($) {
|
||||
|
||||
sub CallBattery_Timestamp {
|
||||
my $hash = shift;
|
||||
|
||||
# get timestamp
|
||||
@ -1334,8 +1383,7 @@ sub CallBattery_Timestamp($) {
|
||||
$hash->{helper}{updateTimestampCallBattery} = FmtDateTime( gettimeofday() );
|
||||
}
|
||||
|
||||
sub CallBattery_UpdateTimeAge($) {
|
||||
|
||||
sub CallBattery_UpdateTimeAge {
|
||||
my $hash = shift;
|
||||
|
||||
$hash->{helper}{updateTimeCallBattery} = 0
|
||||
@ -1345,15 +1393,14 @@ sub CallBattery_UpdateTimeAge($) {
|
||||
return $UpdateTimeAge;
|
||||
}
|
||||
|
||||
sub CallBattery_IsUpdateTimeAgeToOld($$) {
|
||||
|
||||
my ( $hash, $maxAge ) = @_;
|
||||
sub CallBattery_IsUpdateTimeAgeToOld {
|
||||
my $hash = shift;
|
||||
my $maxAge = shift;
|
||||
|
||||
return ( CallBattery_UpdateTimeAge($hash) > $maxAge ? 1 : 0 );
|
||||
}
|
||||
|
||||
sub CreateDevicenameHEX($) {
|
||||
|
||||
sub CreateDevicenameHEX {
|
||||
my $devicename = shift;
|
||||
|
||||
my $devicenameHex = unpack( "H*", $devicename );
|
||||
@ -1361,15 +1408,15 @@ sub CreateDevicenameHEX($) {
|
||||
return $devicenameHex;
|
||||
}
|
||||
|
||||
sub BTLE_CmdlinePreventGrepFalsePositive($) {
|
||||
sub BTLE_CmdlinePreventGrepFalsePositive {
|
||||
|
||||
# https://stackoverflow.com/questions/9375711/more-elegant-ps-aux-grep-v-grep
|
||||
# Given abysmal (since external-command-based) performance in the first place, we'd better
|
||||
# avoid an *additional* grep process plus pipe...
|
||||
|
||||
my $cmdline = shift;
|
||||
|
||||
$cmdline =~ s/(.)(.*)/[$1]$2/;
|
||||
|
||||
return $cmdline;
|
||||
}
|
||||
|
||||
@ -1562,7 +1609,7 @@ sub BTLE_CmdlinePreventGrepFalsePositive($) {
|
||||
],
|
||||
"release_status": "stable",
|
||||
"license": "GPL_2",
|
||||
"version": "v2.8.2",
|
||||
"version": "v2.9.1",
|
||||
"author": [
|
||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user