Merge branch 'master' into devel
This commit is contained in:
commit
ed83bf0775
@ -2,7 +2,7 @@
|
||||
#
|
||||
# Developed with Kate
|
||||
#
|
||||
# (c) 2016-2017 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
||||
# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
||||
# All rights reserved
|
||||
#
|
||||
# This script is free software; you can redistribute it and/or modify
|
||||
@ -47,7 +47,7 @@ use JSON;
|
||||
use Blocking;
|
||||
|
||||
|
||||
my $version = "2.0.0";
|
||||
my $version = "2.0.5";
|
||||
|
||||
|
||||
|
||||
@ -195,6 +195,7 @@ sub XiaomiBTLESens_Attr(@) {
|
||||
if( $attrName eq "disable" ) {
|
||||
if( $cmd eq "set" and $attrVal eq "1" ) {
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||
Log3 $name, 3, "XiaomiBTLESens ($name) - disabled";
|
||||
}
|
||||
@ -219,6 +220,8 @@ sub XiaomiBTLESens_Attr(@) {
|
||||
}
|
||||
|
||||
elsif( $attrName eq "interval" ) {
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
if( $cmd eq "set" ) {
|
||||
if( $attrVal < 300 ) {
|
||||
Log3 $name, 3, "XiaomiBTLESens ($name) - interval too small, please use something >= 300 (sec), default is 3600 (sec)";
|
||||
@ -324,15 +327,7 @@ sub XiaomiBTLESens_stateRequestTimer($) {
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
if( $init_done and not IsDisabled($name) ) {
|
||||
|
||||
XiaomiBTLESens_stateRequest($hash);
|
||||
|
||||
} else {
|
||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||
}
|
||||
XiaomiBTLESens_stateRequest($hash) if( $init_done );
|
||||
|
||||
InternalTimer( gettimeofday()+$hash->{INTERVAL}+int(rand(600)), "XiaomiBTLESens_stateRequestTimer", $hash );
|
||||
|
||||
@ -442,9 +437,8 @@ 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) {
|
||||
if(defined($gatttool) and ($gatttool)) {
|
||||
|
||||
my $cmd;
|
||||
my $loop;
|
||||
@ -633,12 +627,10 @@ sub XiaomiBTLESens_FlowerSensHandle0x38($$) {
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - FlowerSens Handle0x38";
|
||||
|
||||
my @dataBatFw = split(" ",$notification);
|
||||
my $blevel = hex("0x".$dataBatFw[0]);
|
||||
my $fw = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30);
|
||||
|
||||
$readings{'batteryLevel'} = $blevel;
|
||||
$readings{'battery'} = ($blevel > 20?"ok":"low");
|
||||
$readings{'firmware'} = $fw;
|
||||
$readings{'batteryLevel'} = hex("0x".$dataBatFw[0]);
|
||||
$readings{'battery'} = (hex("0x".$dataBatFw[0]) > 20?"ok":"low");
|
||||
$readings{'firmware'} = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30);
|
||||
|
||||
$hash->{helper}{CallBattery} = 1;
|
||||
XiaomiBTLESens_CallBattery_Timestamp($hash);
|
||||
@ -661,23 +653,15 @@ sub XiaomiBTLESens_FlowerSensHandle0x35($$) {
|
||||
return XiaomiBTLESens_stateRequest($hash)
|
||||
unless( $dataSensor[0] ne "aa" and $dataSensor[1] ne "bb" and $dataSensor[2] ne "cc" and $dataSensor[3] ne "dd" and $dataSensor[4] ne "ee" and $dataSensor[5] ne "ff");
|
||||
|
||||
|
||||
my $temp;
|
||||
|
||||
if( $dataSensor[1] eq "ff" ) {
|
||||
$temp = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff");
|
||||
$readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff") / 10;
|
||||
} else {
|
||||
$temp = hex("0x".$dataSensor[1].$dataSensor[0]);
|
||||
$readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) / 10;
|
||||
}
|
||||
|
||||
my $lux = hex("0x".$dataSensor[4].$dataSensor[3]);
|
||||
my $moisture = hex("0x".$dataSensor[7]);
|
||||
my $fertility = hex("0x".$dataSensor[9].$dataSensor[8]);
|
||||
|
||||
$readings{'temperature'} = $temp/10;
|
||||
$readings{'lux'} = $lux;
|
||||
$readings{'moisture'} = $moisture;
|
||||
$readings{'fertility'} = $fertility;
|
||||
$readings{'lux'} = hex("0x".$dataSensor[4].$dataSensor[3]);
|
||||
$readings{'moisture'} = hex("0x".$dataSensor[7]);
|
||||
$readings{'fertility'} = hex("0x".$dataSensor[9].$dataSensor[8]);
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
return \%readings;
|
||||
@ -693,10 +677,10 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x18($$) {
|
||||
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x18";
|
||||
|
||||
my $blevel = hex("0x".$notification);
|
||||
chomp($notification);
|
||||
|
||||
$readings{'batteryLevel'} = $blevel;
|
||||
$readings{'battery'} = ($blevel > 20?"ok":"low");
|
||||
$readings{'batteryLevel'} = hex("0x".$notification);
|
||||
$readings{'battery'} = (hex("0x".$notification) > 20?"ok":"low");
|
||||
|
||||
$hash->{helper}{CallBattery} = 1;
|
||||
XiaomiBTLESens_CallBattery_Timestamp($hash);
|
||||
@ -714,12 +698,9 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x10($$) {
|
||||
Log3 $name, 5, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10";
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
# 54 3d 31 37 2e 33 20 48 3d 35 32 2e 35 00
|
||||
my $temp = pack('H*',substr($notification,4,8)); # 31 37 2e 33
|
||||
my $hum = pack('H*',substr($notification,18,8)); # 35 32 2e 35
|
||||
|
||||
$readings{'temperature'} = $temp;
|
||||
$readings{'humidity'} = $hum;
|
||||
$readings{'temperature'} = pack('H*',substr($notification,4,8));
|
||||
$readings{'humidity'} = pack('H*',substr($notification,18,8));
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
return \%readings;
|
||||
@ -737,9 +718,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x24($$) {
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
|
||||
my $fw = pack('H*',$notification);
|
||||
|
||||
$readings{'firmware'} = $fw;
|
||||
$readings{'firmware'} = pack('H*',$notification);
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
return \%readings;
|
||||
@ -757,9 +736,7 @@ sub XiaomiBTLESens_ThermoHygroSensHandle0x3($$) {
|
||||
|
||||
$notification =~ s/\s+//g;
|
||||
|
||||
my $devname = pack('H*',$notification);
|
||||
|
||||
$readings{'devicename'} = $devname;
|
||||
$readings{'devicename'} = pack('H*',$notification);
|
||||
|
||||
$hash->{helper}{CallBattery} = 0;
|
||||
return \%readings;
|
||||
|
Loading…
Reference in New Issue
Block a user