2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

74_XiaomiBTLESens: better timer logic

git-svn-id: https://svn.fhem.de/fhem/trunk@15933 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2018-01-20 05:59:24 +00:00
parent 78f921e6d9
commit fa4ca91c17
2 changed files with 13 additions and 22 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- change: 74_XiaomiBTLESens: better timer logic
- feature: 20_FRM_AD: analog resolution now depending on device capability - feature: 20_FRM_AD: analog resolution now depending on device capability
- change: 93_DbLog: V3.6.5, avoid shutdown problem if database is too slow, - change: 93_DbLog: V3.6.5, avoid shutdown problem if database is too slow,
extend configCheck with shutdown preparation check, extend configCheck with shutdown preparation check,

View File

@ -2,7 +2,7 @@
# #
# Developed with Kate # 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 # All rights reserved
# #
# This script is free software; you can redistribute it and/or modify # This script is free software; you can redistribute it and/or modify
@ -47,7 +47,7 @@ use JSON;
use Blocking; use Blocking;
my $version = "2.0.3"; my $version = "2.0.4";
@ -195,6 +195,7 @@ sub XiaomiBTLESens_Attr(@) {
if( $attrName eq "disable" ) { if( $attrName eq "disable" ) {
if( $cmd eq "set" and $attrVal eq "1" ) { if( $cmd eq "set" and $attrVal eq "1" ) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
readingsSingleUpdate ( $hash, "state", "disabled", 1 ); readingsSingleUpdate ( $hash, "state", "disabled", 1 );
Log3 $name, 3, "XiaomiBTLESens ($name) - disabled"; Log3 $name, 3, "XiaomiBTLESens ($name) - disabled";
} }
@ -219,6 +220,8 @@ sub XiaomiBTLESens_Attr(@) {
} }
elsif( $attrName eq "interval" ) { elsif( $attrName eq "interval" ) {
RemoveInternalTimer($hash);
if( $cmd eq "set" ) { if( $cmd eq "set" ) {
if( $attrVal < 300 ) { if( $attrVal < 300 ) {
Log3 $name, 3, "XiaomiBTLESens ($name) - interval too small, please use something >= 300 (sec), default is 3600 (sec)"; Log3 $name, 3, "XiaomiBTLESens ($name) - interval too small, please use something >= 300 (sec), default is 3600 (sec)";
@ -323,17 +326,9 @@ sub XiaomiBTLESens_stateRequestTimer($) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
RemoveInternalTimer($hash); XiaomiBTLESens_stateRequest($hash) if( $init_done );
if( $init_done and not IsDisabled($name) ) {
XiaomiBTLESens_stateRequest($hash);
} else {
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
}
InternalTimer( gettimeofday()+$hash->{INTERVAL}+int(rand(600)), "XiaomiBTLESens_stateRequestTimer", $hash ); InternalTimer( gettimeofday()+$hash->{INTERVAL}+int(rand(600)), "XiaomiBTLESens_stateRequestTimer", $hash );
Log3 $name, 4, "XiaomiBTLESens ($name) - stateRequestTimer: Call Request Timer"; Log3 $name, 4, "XiaomiBTLESens ($name) - stateRequestTimer: Call Request Timer";
@ -632,12 +627,10 @@ sub XiaomiBTLESens_FlowerSensHandle0x38($$) {
Log3 $name, 5, "XiaomiBTLESens ($name) - FlowerSens Handle0x38"; Log3 $name, 5, "XiaomiBTLESens ($name) - FlowerSens Handle0x38";
my @dataBatFw = split(" ",$notification); my @dataBatFw = split(" ",$notification);
my $blevel = hex("0x".$dataBatFw[0]);
my $fw = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30); $readings{'batteryLevel'} = hex("0x".$dataBatFw[0]);
$readings{'battery'} = (hex("0x".$dataBatFw[0]) > 20?"ok":"low");
$readings{'batteryLevel'} = $blevel; $readings{'firmware'} = ($dataBatFw[2]-30).".".($dataBatFw[4]-30).".".($dataBatFw[6]-30);
$readings{'battery'} = ($blevel > 20?"ok":"low");
$readings{'firmware'} = $fw;
$hash->{helper}{CallBattery} = 1; $hash->{helper}{CallBattery} = 1;
XiaomiBTLESens_CallBattery_Timestamp($hash); XiaomiBTLESens_CallBattery_Timestamp($hash);
@ -659,9 +652,6 @@ sub XiaomiBTLESens_FlowerSensHandle0x35($$) {
return XiaomiBTLESens_stateRequest($hash) 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"); 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" ) { if( $dataSensor[1] eq "ff" ) {
$readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff") / 10; $readings{'temperature'} = hex("0x".$dataSensor[1].$dataSensor[0]) - hex("0xffff") / 10;