Support for new Sensors vibration

-add support for sensor vibration
-fix some fixes for multigw support.
This commit is contained in:
2018-09-09 12:52:58 +02:00
parent 631c54d0d9
commit d3d96436a2
3 changed files with 46 additions and 22 deletions

View File

@@ -51,7 +51,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.31";
my $version = "1.33";
my %XiaomiSmartHome_gets = (
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
@@ -107,7 +107,8 @@ sub XiaomiSmartHome_Initialize($) {
"17:XiaomiSmartHome_Device" => "^.+smoke",
"18:XiaomiSmartHome_Device" => "^.+weather.v1",
"19:XiaomiSmartHome_Device" => "^.+sensor_motion.aq2",
"20:XiaomiSmartHome_Device" => "^.+sensor_wleak.aq1"};
"20:XiaomiSmartHome_Device" => "^.+sensor_wleak.aq1",
"21:XiaomiSmartHome_Device" => "^.+vibration"};
FHEM_colorpickerInit();
}
#####################################
@@ -145,6 +146,7 @@ sub XiaomiSmartHome_Read($) {
Log3 $name, 5, "$name: Read> [PLAIN] " . $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') {
# devices does not exist yet
if (!$modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME}){
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device unknown trying autocreate" ;
my $def=$modules{XiaomiSmartHome}{defptr};
@@ -158,31 +160,44 @@ sub XiaomiSmartHome_Read($) {
}
}
}
if ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} eq $hash->{NAME}) {
# devices available with proper gw
elsif ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} eq $hash->{NAME}) {
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device known! " . "SID: " . $rsid . " " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " " . $hash->{NAME};
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
Dispatch($hash, $buf, undef);
}
# Senosoren check
elsif ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} ne $hash->{NAME}) {
Log3 $name, 5, "$name: Read> Wrong Modul HASH Trying to find the right one " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " <> " . $hash->{NAME} ;
$hash = $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{IODev};
Log3 $name, 5, "$name: Read> Using this GW " . $hash->{NAME} . " no Dispatching!";
Log3 $name, 5, "$name: Read> Using this GW " . $hash->{NAME} ;
}
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
Dispatch($hash, $buf, undef);
}
# gateway sensor list
elsif ($decoded->{'cmd'} eq 'get_id_list_ack'){
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
Log3 $name, 5, "$name: Read> Reading Sensorlist with $self->{NAME}" ;
XiaomiSmartHome_Reading ($self, $buf);
return;
}
# gateway not definded
elsif (!$modules{XiaomiSmartHome}{defptr}{$rsid}){
Log3 $name, 1, "$name: Read> GW not defined " . $buf;
return;
}
# gateway defined but not the right modul instance - change
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
Log3 $name, 5, "$name: Read> Change HASH Ref to $self->{NAME}";
XiaomiSmartHome_Reading ($self, $buf);
Log3 $name, 5, "$name: Read> Wrong Modul HASH skipping $self->{NAME}";
#XiaomiSmartHome_Reading ($self, $buf);
return;
}
else
{
#gateway defined and the right modul instance - nothing to change
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} eq $hash->{SID} ){
Log3 $name, 5, "$name: Read> HASH correctly";
XiaomiSmartHome_Reading ($hash, $buf);
return;
}
}
}

View File

@@ -27,7 +27,7 @@ use warnings;
my $version = "1.30";
my $version = "1.33";
sub XiaomiSmartHome_Device_updateSReading($);
@@ -38,7 +38,7 @@ sub XiaomiSmartHome_Device_Initialize($)
{
my ($hash) = @_;
$hash->{Match} = ".*magnet.*|.*motion.*|sensor_ht|.*switch.*|plug|.*cube.*|86sw1|86sw2|ctrl_neutral1|ctrl_neutral2|rgbw_light|curtain|ctrl_ln1|ctrl_ln2|86plug|natgas|smoke|weather.v1|sensor_wleak.aq1";
$hash->{Match} = ".*magnet.*|.*motion.*|sensor_ht|.*switch.*|plug|.*cube.*|86sw1|86sw2|ctrl_neutral1|ctrl_neutral2|rgbw_light|curtain|ctrl_ln1|ctrl_ln2|86plug|natgas|smoke|weather.v1|sensor_wleak.aq1|vibration";
$hash->{DefFn} = "XiaomiSmartHome_Device_Define";
$hash->{SetFn} = "XiaomiSmartHome_Device_Set";
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
@@ -362,11 +362,20 @@ sub XiaomiSmartHome_Device_Read($$$){
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
}
#curtain end
#vibration Start
if (defined $data->{'coordination'}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Coordination: " . $data->{coordination};
readingsBulkUpdate($hash, "coordination", "$data->{coordination}", 1 );
}
if (defined $data->{'final_tilt_angle'}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Final tilt angle: " . $data->{final_tilt_angle};
readingsBulkUpdate($hash, "final_tilt_angle", "$data->{final_tilt_angle}", 1 );
}
#vibration end
if ($decoded->{'cmd'} eq 'heartbeat'){
readingsBulkUpdate($hash, 'heartbeat', $decoded->{'sid'} , 1 );
}
readingsEndUpdate( $hash, 1 );
XiaomiSmartHome_Device_update($hash);
return $hash->{NAME};

View File

@@ -1,2 +1,2 @@
UPD 2018-07-02_21:06:31 38896 FHEM/71_XiaomiSmartHome.pm
UPD 2018-06-22_12:45:46 29142 FHEM/71_XiaomiSmartHome_Device.pm
UPD 2018-09-09 12:43:14 39606 FHEM/71_XiaomiSmartHome.pm
UPD 2018-09-09 12:43:16 29789 FHEM/71_XiaomiSmartHome_Device.pm