From 9cde59da81cca09a29252b8c5d058b1818c72476 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 15 Jan 2018 07:44:58 +0100 Subject: [PATCH] add set and get devicename, fix bugfix for which is gatttool only ssh host installed --- 74_XiaomiBTLESens.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/74_XiaomiBTLESens.pm b/74_XiaomiBTLESens.pm index 18663d7..0ac513b 100644 --- a/74_XiaomiBTLESens.pm +++ b/74_XiaomiBTLESens.pm @@ -362,6 +362,8 @@ sub XiaomiBTLESens_ReadFirmware($) { $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|read|".$XiaomiModels{$attr{$name}{model}}{firmware}, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless(exists($hash->{helper}{RUNNING_PID})); + readingsSingleUpdate($hash,"state","fetch firmware data",1); + Log3 $name, 4, "XiaomiBTLESens ($name) - CallFirmware: call function ExecGatttool_Run"; } @@ -375,6 +377,8 @@ sub XiaomiBTLESens_ReadDeviceName($) { $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|read|".$XiaomiModels{$attr{$name}{model}}{devicename}, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless(exists($hash->{helper}{RUNNING_PID})); + readingsSingleUpdate($hash,"state","fetch devicename data",1); + Log3 $name, 4, "XiaomiBTLESens ($name) - CallDeviceName: call function ExecGatttool_Run"; } @@ -414,6 +418,8 @@ sub XiaomiBTLESens_WriteDeviceName($$) { $hash->{helper}{RUNNING_PID} = BlockingCall("XiaomiBTLESens_ExecGatttool_Run", $name."|".$mac."|write|".$XiaomiModels{$attr{$name}{model}}{devicename}."|".$value, "XiaomiBTLESens_ExecGatttool_Done", 60, "XiaomiBTLESens_ExecGatttool_Aborted", $hash) unless(exists($hash->{helper}{RUNNING_PID})); + readingsSingleUpdate($hash,"state","write devicename data",1); + Log3 $name, 4, "XiaomiBTLESens ($name) - WriteDeviceName: call function ExecGatttool_Run"; } @@ -449,8 +455,19 @@ sub XiaomiBTLESens_Get($$@) { XiaomiBTLESens_stateRequest($hash); + } elsif( $cmd eq 'firmware' ) { + return "usage: firmware" if( @args != 0 ); + + XiaomiBTLESens_ReadFirmware($hash); + + } elsif( $cmd eq 'devicename' ) { + return "usage: devicename" if( @args != 0 ); + + XiaomiBTLESens_ReadDeviceName($hash); + } else { - my $list = "sensorData:noArg"; + my $list = "sensorData:noArg firmware:noArg"; + $list .= " devicename:noArg" if( AttrVal($name,'model','thermoHygroSens') eq 'thermoHygroSens' ); return "Unknown argument $cmd, choose one of $list"; } @@ -469,6 +486,7 @@ sub XiaomiBTLESens_ExecGatttool_Run($) { $gatttool = qx(which gatttool) if($sshHost eq 'none'); $gatttool = qx(ssh $sshHost 'which gatttool') if($sshHost ne 'none'); chomp $gatttool; + $gatttool = "ssh $sshHost \'$gatttool\'" if($sshHost ne 'none'); if(-x $gatttool) {