Add missing Round pressure, Fix something

-added: missing round pressure
-added: round to zero decimal places
-added: helper list connected sensors
-change: reading battery_level to  batteryLevel
-fix: multigwsupport sensorreadings are now to correct gw associated
This commit is contained in:
2017-12-18 14:20:48 +01:00
parent 672521a4aa
commit a11d334298
3 changed files with 28 additions and 15 deletions

View File

@@ -52,7 +52,7 @@ sub XiaomiSmartHome_Notify($$);
sub XiaomiSmartHome_updateSingleReading($$);
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
my $version = "1.20";
my $version = "1.21";
my %XiaomiSmartHome_gets = (
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
@@ -146,8 +146,16 @@ sub XiaomiSmartHome_Read($) {
Log3 $name, 5, "$name: Read> " . $buf;
my $rsid = $decoded->{'sid'};
if ($decoded->{'cmd'} eq 'read_ack' || $decoded->{'cmd'} eq 'report' && $decoded->{'model'} ne 'gateway'|| $decoded->{'cmd'} eq 'heartbeat' && $decoded->{'model'} ne 'gateway' || $decoded->{'cmd'} eq 'write_ack' && $decoded->{'model'} ne 'gateway') {
if ( $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{SID} = $rsid ){
Log3 $name, 5, "$name: Read> Dispatch " . $buf;
my $devhash = $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{IODev};
Dispatch($devhash, $buf, undef);
}
else {
Log3 $name, 5, "$name: Read> Dispatch " . $buf;
Dispatch($hash, $buf, undef);
}
}
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
@@ -244,11 +252,14 @@ sub XiaomiSmartHome_Reading ($@) {
Log3 $name, 1, "$name: Reading> Error while request: $@";
return;
}
my $all_sensors = "";
foreach my $sensor (@sensors)
{
Log3 $name, 4, "$name: Reading> PushRead:" . $sensor;
XiaomiSmartHome_Write($hash, 'read', $sensor );
$all_sensors = $all_sensors . $sensor . ",";
}
$hash->{helper}{sensors} = $all_sensors;
return;
}
}

View File

@@ -27,7 +27,7 @@ use warnings;
my $version = "1.20";
my $version = "1.21";
sub XiaomiSmartHome_Device_updateSReading($);
@@ -44,13 +44,12 @@ sub XiaomiSmartHome_Device_Initialize($)
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
$hash->{ParseFn} = "XiaomiSmartHome_Device_Parse";
$hash->{AttrList} = "IODev follow-on-for-timer:1,0 follow-on-timer ".
$hash->{AttrList} = "follow-on-for-timer:1,0 follow-on-timer ".
"do_not_notify:1,0 ignore:1,0 dummy:1,0 showtime:1,0 valueFn:textField-long ".
"rnd_tmp:1,2,3 ".
"rnd_hum:1,2,3 ".
"rnd_bat:1,2,3 ".
"rnd_tmp:0,1,2,3 ".
"rnd_hum:0,1,2,3 ".
"rnd_bat:0,1,2,3 ".
"rnd_pres:0,1,2,3 ".
$readingFnAttributes ;
}
#####################################
@@ -202,6 +201,7 @@ sub XiaomiSmartHome_Device_Read($$$){
my $XMIround_tmp = AttrVal( $hash->{NAME}, "rnd_tmp", "2" );
my $XMIround_hum = AttrVal( $hash->{NAME}, "rnd_hum", "2" );
my $XMIround_bat = AttrVal( $hash->{NAME}, "rnd_bat", "1" );
my $XMIround_pres = AttrVal( $hash->{NAME}, "rnd_pres", "2" );
my $decoded = eval{decode_json($msg)};
if ($@) {
@@ -247,7 +247,7 @@ sub XiaomiSmartHome_Device_Read($$$){
readingsBulkUpdate($hash, "battery", "ok", 1 )
}
$bat = XiaomiSmartHome_round($bat, $XMIround_bat, $name );
readingsBulkUpdate($hash, "battery_level", $bat, 1 );
readingsBulkUpdate($hash, "batteryLevel", $bat, 1 );
}
if (defined $data->{temperature}){
if ($data->{temperature} ne "10000"){
@@ -271,7 +271,8 @@ sub XiaomiSmartHome_Device_Read($$$){
if ($data->{pressure} ne "0"){
my $pres = $data->{pressure};
$pres =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Pressure: " . $pres;
$pres = XiaomiSmartHome_round($pres, $XMIround_pres, $name );
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Pressure: " . $pres . " Round: " . $XMIround_pres;
readingsBulkUpdate($hash, "pressure", "$pres", 1 );
}
}
@@ -419,6 +420,7 @@ sub XiaomiSmartHome_Device_update($){
CommandDeleteReading( undef, "$name voltage" ) if(defined(ReadingsVal($name,"voltage",undef)));
CommandDeleteReading( undef, "$name batterystate" ) if(defined(ReadingsVal($name,"batterystate",undef)));
CommandDeleteReading( undef, "$name round" ) if(defined(ReadingsVal($name,"round",undef)));
CommandDeleteReading( undef, "$name battery_level" ) if(defined(ReadingsVal($name,"battery_level",undef)));
}
#####################################

View File

@@ -1,2 +1,2 @@
UPD 2017-12-15_09:45:00 37305 FHEM/71_XiaomiSmartHome.pm
UPD 2017-12-15_09:46:40 28101 FHEM/71_XiaomiSmartHome_Device.pm
UPD 2017-12-18_13:56:43 38751 FHEM/71_XiaomiSmartHome.pm
UPD 2017-12-18_10:00:55 29125 FHEM/71_XiaomiSmartHome_Device.pm