add oldTimeStampAge for Call BatteryFirmware Function
This commit is contained in:
parent
4a74bb89ec
commit
2a7bad25a2
@ -219,6 +219,11 @@ sub XiaomiFlowerSens_stateRequest($) {
|
|||||||
|
|
||||||
if( !IsDisabled($name) ) {
|
if( !IsDisabled($name) ) {
|
||||||
if( ReadingsVal($name,'firmware','none') ne 'none') {
|
if( ReadingsVal($name,'firmware','none') ne 'none') {
|
||||||
|
|
||||||
|
return XiaomiFlowerSens_CallBatteryFirmware($hash)
|
||||||
|
if( XiaomiFlowerSens_CallBatteryFirmware_IsUpdateTimeAgeToOld($hash,'90000') );
|
||||||
|
|
||||||
|
|
||||||
if( ReadingsVal($name, 'firmware', '') eq '2.6.2') {
|
if( ReadingsVal($name, 'firmware', '') eq '2.6.2') {
|
||||||
|
|
||||||
XiaomiFlowerSens_CallSensData($hash);
|
XiaomiFlowerSens_CallSensData($hash);
|
||||||
@ -458,14 +463,13 @@ sub XiaomiFlowerSens_ProcessingNotification($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub XiaomiFlowerSens_Handle0x38($$) {
|
sub XiaomiFlowerSens_Handle0x38($$) {
|
||||||
|
### Read Firmware and Battery Data
|
||||||
my ($hash,$notification) = @_;
|
my ($hash,$notification) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
Log3 $name, 5, "XiaomiFlowerSens ($name) - Handle0x38";
|
Log3 $name, 5, "XiaomiFlowerSens ($name) - Handle0x38";
|
||||||
### Read Firmware and Battery Data
|
|
||||||
|
|
||||||
my @dataBatFw = split(" ",$notification);
|
my @dataBatFw = split(" ",$notification);
|
||||||
my $blevel = hex("0x".$dataBatFw[0]);
|
my $blevel = hex("0x".$dataBatFw[0]);
|
||||||
@ -477,10 +481,12 @@ sub XiaomiFlowerSens_Handle0x38($$) {
|
|||||||
|
|
||||||
$hash->{helper}{CallBatteryFirmware} = 1;
|
$hash->{helper}{CallBatteryFirmware} = 1;
|
||||||
XiaomiFlowerSens_WriteReadings($hash);
|
XiaomiFlowerSens_WriteReadings($hash);
|
||||||
|
|
||||||
|
XiaomiFlowerSens_CallBatteryFirmware_Timestamp($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub XiaomiFlowerSens_Handle0x35($$) {
|
sub XiaomiFlowerSens_Handle0x35($$) {
|
||||||
|
### Read Sensor Data
|
||||||
my ($hash,$notification) = @_;
|
my ($hash,$notification) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -569,7 +575,7 @@ sub XiaomiFlowerSens_ProcessingErrors($$) {
|
|||||||
XiaomiFlowerSens_WriteReadings($hash);
|
XiaomiFlowerSens_WriteReadings($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
### my little Helper
|
#### my little Helper
|
||||||
sub XiaomiFlowerSens_encodeJSON($) {
|
sub XiaomiFlowerSens_encodeJSON($) {
|
||||||
|
|
||||||
my $gtResult = shift;
|
my $gtResult = shift;
|
||||||
@ -581,6 +587,34 @@ sub XiaomiFlowerSens_encodeJSON($) {
|
|||||||
return encode_json \%response;
|
return encode_json \%response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Routinen damit Firmware und Batterie nur alle X male statt immer aufgerufen wird
|
||||||
|
sub XiaomiFlowerSens_CallBatteryFirmware_Timestamp($) {
|
||||||
|
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
|
|
||||||
|
# get timestamp
|
||||||
|
$hash->{helper}{updateTimeCallBatteryFirmware} = gettimeofday(); # in seconds since the epoch
|
||||||
|
$hash->{helper}{updateTimestampCallBatteryFirmware} = FmtDateTime(gettimeofday());
|
||||||
|
}
|
||||||
|
|
||||||
|
sub XiaomiFlowerSens_CallBatteryFirmware_UpdateTimeAge($) {
|
||||||
|
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
|
my $UpdateTimeAge = gettimeofday() - $hash->{helper}{updateTimeCallBatteryFirmware};
|
||||||
|
|
||||||
|
|
||||||
|
return $UpdateTimeAge;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub XiaomiFlowerSens_CallBatteryFirmware_IsUpdateTimeAgeToOld($$) {
|
||||||
|
|
||||||
|
my ($hash,$maxAge) = @_;;
|
||||||
|
|
||||||
|
|
||||||
|
return (XiaomiFlowerSens_CallBatteryFirmware_UpdateTimeAge($hash)>$maxAge ? 1:0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user