some changes and fixes
close #16 close #15 close #14 close #13 -change: the sensors now align themselves with their real gateway (iodev) -change: the ne aqara cube is supportet but the firmware has an bug -change batteryreadings changed to FHEM standard
This commit is contained in:
@@ -42,7 +42,6 @@ eval "use Net::Ping";
|
|||||||
return "\nERROR: Please install Net::Ping" if($@);
|
return "\nERROR: Please install Net::Ping" if($@);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use Color;
|
use Color;
|
||||||
use SetExtensions;
|
use SetExtensions;
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ sub XiaomiSmartHome_Notify($$);
|
|||||||
sub XiaomiSmartHome_updateSingleReading($$);
|
sub XiaomiSmartHome_updateSingleReading($$);
|
||||||
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
|
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
|
||||||
|
|
||||||
my $version = "1.21";
|
my $version = "1.30";
|
||||||
|
|
||||||
my %XiaomiSmartHome_gets = (
|
my %XiaomiSmartHome_gets = (
|
||||||
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
||||||
@@ -93,7 +92,7 @@ sub XiaomiSmartHome_Initialize($) {
|
|||||||
"2:XiaomiSmartHome_Device" => ".*motion.*",
|
"2:XiaomiSmartHome_Device" => ".*motion.*",
|
||||||
"3:XiaomiSmartHome_Device" => "^.+sensor_ht",
|
"3:XiaomiSmartHome_Device" => "^.+sensor_ht",
|
||||||
"4:XiaomiSmartHome_Device" => ".*switch.*",
|
"4:XiaomiSmartHome_Device" => ".*switch.*",
|
||||||
"5:XiaomiSmartHome_Device" => "^.+cube",
|
"5:XiaomiSmartHome_Device" => ".*cube.*",
|
||||||
"6:XiaomiSmartHome_Device" => "^.+plug",
|
"6:XiaomiSmartHome_Device" => "^.+plug",
|
||||||
"7:XiaomiSmartHome_Device" => "^.+86sw1",
|
"7:XiaomiSmartHome_Device" => "^.+86sw1",
|
||||||
"8:XiaomiSmartHome_Device" => "^.+86sw2",
|
"8:XiaomiSmartHome_Device" => "^.+86sw2",
|
||||||
@@ -143,19 +142,36 @@ sub XiaomiSmartHome_Read($) {
|
|||||||
}
|
}
|
||||||
if ($json)
|
if ($json)
|
||||||
{
|
{
|
||||||
Log3 $name, 5, "$name: Read> " . $buf;
|
Log3 $name, 5, "$name: Read> [PLAIN] " . $buf;
|
||||||
my $rsid = $decoded->{'sid'};
|
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 ($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 ){
|
if (!$modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME}){
|
||||||
Log3 $name, 5, "$name: Read> Dispatch " . $buf;
|
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device unknown trying autocreate" ;
|
||||||
my $devhash = $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{IODev};
|
my $def=$modules{XiaomiSmartHome}{defptr};
|
||||||
Dispatch($devhash, $buf, undef);
|
while(my ($key, $value) =each(%$def)){
|
||||||
|
XiaomiSmartHome_Write($value, 'get_id_list');
|
||||||
|
Log3 $value->{NAME}, 5, "$value->{NAME}: Push to get all Sensors for Gateway $value->{NAME} " . $key;
|
||||||
|
if ($value->{helper}{sensors} =~ m/$rsid/ ) {
|
||||||
|
Log3 $value->{NAME}, 5, "$value->{NAME}: $rsid is sensor from $value->{NAME}";
|
||||||
|
Dispatch($value, $buf, undef);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
Log3 $name, 5, "$name: Read> Dispatch " . $buf;
|
}
|
||||||
|
if ($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};
|
||||||
|
}
|
||||||
|
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};
|
||||||
|
}
|
||||||
|
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
|
||||||
Dispatch($hash, $buf, undef);
|
Dispatch($hash, $buf, undef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
elsif (!$modules{XiaomiSmartHome}{defptr}{$rsid}){
|
||||||
|
Log3 $name, 1, "$name: Read> GW not defined " . $buf;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
|
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
|
||||||
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
|
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
|
||||||
@@ -216,7 +232,7 @@ sub XiaomiSmartHome_Reading ($@) {
|
|||||||
#$hash->{SID} = $decoded->{'sid'};
|
#$hash->{SID} = $decoded->{'sid'};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3 $name, 4, "$name: Reading> IP-Heartbeat Data didnt match! $data->{ip} " . $hash->{GATEWAY_IP} ;
|
Log3 $name, 5, "$name: Reading> IP-Heartbeat Data didnt match! $data->{ip} " . $hash->{GATEWAY_IP} ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,14 +322,14 @@ sub XiaomiSmartHome_getGatewaySID($){
|
|||||||
}
|
}
|
||||||
if ($json) {
|
if ($json) {
|
||||||
if ($decoded->{'ip'} eq $ip){
|
if ($decoded->{'ip'} eq $ip){
|
||||||
Log3 $name, 4, "$name: getGatewaySID> Find SID for Gateway: $decoded->{sid}";
|
Log3 $name, 3, "$name: getGatewaySID> Find SID for Gateway: $decoded->{sid}";
|
||||||
$sidsock->close();
|
$sidsock->close();
|
||||||
$hash->{SID} = $decoded->{sid};
|
$hash->{SID} = $decoded->{sid};
|
||||||
$modules{XiaomiSmartHome}{defptr}{$decoded->{sid}} = $hash;
|
$modules{XiaomiSmartHome}{defptr}{$decoded->{sid}} = $hash;
|
||||||
return $decoded->{sid};
|
return $decoded->{sid};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3 $name, 4, "$name: getGatewaySID> whois Data didnt match! $decoded->{sid} $decoded->{'ip'} ". $ip ;
|
Log3 $name, 5, "$name: getGatewaySID> whois Data didnt match! $decoded->{sid} $decoded->{'ip'} ". $ip ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -346,7 +362,7 @@ sub XiaomiSmartHome_Define($$) {
|
|||||||
if ( ! $p->ping($param[2])){
|
if ( ! $p->ping($param[2])){
|
||||||
$hash->{STATE} = "Disconnected";
|
$hash->{STATE} = "Disconnected";
|
||||||
XiaomiSmartHome_disconnect($hash);
|
XiaomiSmartHome_disconnect($hash);
|
||||||
Log3 $name, 5, "$name: Define> Ping ERROR Gateway disconnecting";
|
Log3 $name, 1, "$name: Define> Ping ERROR Gateway disconnecting";
|
||||||
$p->close();
|
$p->close();
|
||||||
}
|
}
|
||||||
my $GATEWAY_IP = $param[2];
|
my $GATEWAY_IP = $param[2];
|
||||||
@@ -374,7 +390,7 @@ sub XiaomiSmartHome_Define($$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$hash->{GATEWAY_IP} = $GATEWAY_IP;
|
$hash->{GATEWAY_IP} = $GATEWAY_IP;
|
||||||
$modules{XiaomiSmartHome}{defptr}{$GATEWAY_IP} = $hash;
|
#$modules{XiaomiSmartHome}{defptr}{$GATEWAY_IP} = $hash;
|
||||||
#$hash->{SID} = XiaomiSmartHome_getGatewaySID($hash);
|
#$hash->{SID} = XiaomiSmartHome_getGatewaySID($hash);
|
||||||
|
|
||||||
Log3 $name, 5, "$name: Define> $definition";
|
Log3 $name, 5, "$name: Define> $definition";
|
||||||
@@ -507,7 +523,7 @@ sub XiaomiSmartHome_Write($@)
|
|||||||
my $sock = $hash->{CD};
|
my $sock = $hash->{CD};
|
||||||
my $MAXLEN = 1024;
|
my $MAXLEN = 1024;
|
||||||
$sock->mcast_send($msg,$GATEWAY .':9898') or die "send: $!";
|
$sock->mcast_send($msg,$GATEWAY .':9898') or die "send: $!";
|
||||||
Log3 $name, 5, "$name: Write> End " . $GATEWAY;
|
Log3 $name, 4, "$name: Write> End " . $GATEWAY;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
@@ -538,12 +554,14 @@ sub XiaomiSmartHome_Get($@)
|
|||||||
if ($opt eq "UpdateAll")
|
if ($opt eq "UpdateAll")
|
||||||
{
|
{
|
||||||
XiaomiSmartHome_updateAllReadings($hash);
|
XiaomiSmartHome_updateAllReadings($hash);
|
||||||
Log3 $name, 5, "$name: Get> UpdateALLReadings Started";
|
Log3 $name, 3, "$name: Get> UpdateALLReadings Started";
|
||||||
|
return "UpdateALLReadings Started";
|
||||||
}
|
}
|
||||||
elsif($opt eq "UpdateSingle")
|
elsif($opt eq "UpdateSingle")
|
||||||
{
|
{
|
||||||
XiaomiSmartHome_updateSingleReading($hash,$args);
|
XiaomiSmartHome_updateSingleReading($hash,$args);
|
||||||
Log3 $name, 5, "$name: Get> UpdateSingel Started";
|
Log3 $name, 3, "$name: Get> UpdateSingel Started";
|
||||||
|
return "UpdateSingel " . $args . " Started";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -710,8 +728,6 @@ sub XiaomiSmartHome_connect($)
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $GATEWAY_IP;
|
my $GATEWAY_IP;
|
||||||
Log3 $name, 5, "$name: connect> ConnectStart";
|
Log3 $name, 5, "$name: connect> ConnectStart";
|
||||||
|
|
||||||
Log3 $name, 4, "$name: connecting";
|
|
||||||
my $p = Net::Ping->new();
|
my $p = Net::Ping->new();
|
||||||
if ( ! $p->ping($hash->{GATEWAY})){
|
if ( ! $p->ping($hash->{GATEWAY})){
|
||||||
Log3 $name, 1, "$name: connect> Ping to $hash->{helper}{host} failed";
|
Log3 $name, 1, "$name: connect> Ping to $hash->{helper}{host} failed";
|
||||||
@@ -724,7 +740,7 @@ sub XiaomiSmartHome_connect($)
|
|||||||
eval {
|
eval {
|
||||||
$GATEWAY_IP = inet_ntoa(inet_aton($hash->{GATEWAY})) ;
|
$GATEWAY_IP = inet_ntoa(inet_aton($hash->{GATEWAY})) ;
|
||||||
$hash->{GATEWAY_IP} = $GATEWAY_IP;
|
$hash->{GATEWAY_IP} = $GATEWAY_IP;
|
||||||
Log3 $name, 4, "$name: Connect> Set GATEWAYs IP: " . $GATEWAY_IP;
|
Log3 $name, 5, "$name: Connect> Set GATEWAYs IP: " . $GATEWAY_IP;
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3 $name, 1, "$name: Connect> Error $@\n";
|
Log3 $name, 1, "$name: Connect> Error $@\n";
|
||||||
@@ -735,12 +751,12 @@ sub XiaomiSmartHome_connect($)
|
|||||||
}
|
}
|
||||||
XiaomiSmartHome_getGatewaySID($hash);
|
XiaomiSmartHome_getGatewaySID($hash);
|
||||||
my $timeout = $hash->{TIMEOUT} ? $hash->{TIMEOUT} : 3;
|
my $timeout = $hash->{TIMEOUT} ? $hash->{TIMEOUT} : 3;
|
||||||
my $sock = IO::Socket::Multicast->new( Proto => 'udp', LocalPort =>'9898', ReuseAddr => 1, Timeout => $timeout) or die "Creating socket: $!\n";
|
my $sock = IO::Socket::Multicast->new( Proto => 'udp', LocalPort =>'9898', ReusePort => 1, ReuseAddr => 1, Timeout => $timeout) or die "Creating socket: $!\n";
|
||||||
$sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, pack('l!l!', 30, 0)) or die "setsockopt: $!";
|
$sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, pack('l!l!', 30, 0)) or die "setsockopt: $!";
|
||||||
if ($sock)
|
if ($sock)
|
||||||
{
|
{
|
||||||
Log3 $name, 4, "$name: connect> Connected";
|
Log3 $name, 3, "$name: connect> Connected";
|
||||||
$sock->mcast_add('224.0.0.50', $hash->{fhemIP} ) || die "Couldn't set group: $!\n"; #$hash->{fhemIP}
|
$sock->mcast_add('224.0.0.50', $hash->{FHEMIP} ) || die "Couldn't set group: $!\n"; #$hash->{FHEMIP}
|
||||||
$sock->mcast_ttl(32);
|
$sock->mcast_ttl(32);
|
||||||
$sock->mcast_loopback(1);
|
$sock->mcast_loopback(1);
|
||||||
$hash->{helper}{ConnectionState} = "Connected";
|
$hash->{helper}{ConnectionState} = "Connected";
|
||||||
@@ -811,7 +827,7 @@ sub XiaomiSmartHome_updateAllReadings($)
|
|||||||
my $GATEWAY;
|
my $GATEWAY;
|
||||||
my $p = Net::Ping->new();
|
my $p = Net::Ping->new();
|
||||||
if ( ! $p->ping($hash->{GATEWAY})){
|
if ( ! $p->ping($hash->{GATEWAY})){
|
||||||
Log3 $name, 4, "$name: updateAllReadings> Ping to $hash->{helper}{host} failed";
|
Log3 $name, 1, "$name: updateAllReadings> Ping to $hash->{helper}{host} failed";
|
||||||
$hash->{STATE} = "Disconnected";
|
$hash->{STATE} = "Disconnected";
|
||||||
XiaomiSmartHome_disconnect($hash);
|
XiaomiSmartHome_disconnect($hash);
|
||||||
$p->close();
|
$p->close();
|
||||||
@@ -1058,6 +1074,3 @@ sub XiaomiSmartHome_updateAllReadings($)
|
|||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use warnings;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $version = "1.21";
|
my $version = "1.30";
|
||||||
|
|
||||||
sub XiaomiSmartHome_Device_updateSReading($);
|
sub XiaomiSmartHome_Device_updateSReading($);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ sub XiaomiSmartHome_Device_Initialize($)
|
|||||||
{
|
{
|
||||||
my ($hash) = @_;
|
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";
|
||||||
$hash->{DefFn} = "XiaomiSmartHome_Device_Define";
|
$hash->{DefFn} = "XiaomiSmartHome_Device_Define";
|
||||||
$hash->{SetFn} = "XiaomiSmartHome_Device_Set";
|
$hash->{SetFn} = "XiaomiSmartHome_Device_Set";
|
||||||
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
|
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
|
||||||
@@ -241,13 +241,13 @@ sub XiaomiSmartHome_Device_Read($$$){
|
|||||||
my $bat = ($data->{voltage}/1000);
|
my $bat = ($data->{voltage}/1000);
|
||||||
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Voltage: " . $data->{voltage};
|
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Voltage: " . $data->{voltage};
|
||||||
if ($bat < 2.2) {
|
if ($bat < 2.2) {
|
||||||
readingsBulkUpdate($hash, "battery", "low", 1 );
|
readingsBulkUpdate($hash, "batteryState", "low", 1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate($hash, "battery", "ok", 1 )
|
readingsBulkUpdate($hash, "batteryState", "ok", 1 )
|
||||||
}
|
}
|
||||||
$bat = XiaomiSmartHome_round($bat, $XMIround_bat, $name );
|
$bat = XiaomiSmartHome_round($bat, $XMIround_bat, $name );
|
||||||
readingsBulkUpdate($hash, "batteryLevel", $bat, 1 );
|
readingsBulkUpdate($hash, "batteryVoltage", $bat, 1 );
|
||||||
}
|
}
|
||||||
if (defined $data->{temperature}){
|
if (defined $data->{temperature}){
|
||||||
if ($data->{temperature} ne "10000"){
|
if ($data->{temperature} ne "10000"){
|
||||||
@@ -384,15 +384,17 @@ sub XiaomiSmartHome_Device_Parse($$) {
|
|||||||
}
|
}
|
||||||
my $sid = $decoded->{'sid'};
|
my $sid = $decoded->{'sid'};
|
||||||
my $model = $decoded->{'model'};
|
my $model = $decoded->{'model'};
|
||||||
if (my $hash = $modules{XiaomiSmartHome_Device}{defptr}{$sid})
|
if ($modules{XiaomiSmartHome_Device}{defptr}{$sid}{IODev}->{NAME})
|
||||||
{
|
{
|
||||||
Log3 $name, 4, "$name: DEV_Parse> IS DEFINED " . $model . " : " .$sid;
|
my $hash = $modules{XiaomiSmartHome_Device}{defptr}{$sid}->{IODev};
|
||||||
|
Log3 $name, 5, "$name: DEV_Parse> IS DEFINED " . $model . " : " . $sid . " " . $modules{XiaomiSmartHome_Device}{defptr}{$sid}->{IODev};
|
||||||
|
$hash = $modules{XiaomiSmartHome_Device}{defptr}{$sid};
|
||||||
XiaomiSmartHome_Device_Read($hash, $msg, $name);
|
XiaomiSmartHome_Device_Read($hash, $msg, $name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
Log3 $name, 4, "$name: DEV_Parse> UNDEFINED " . $model . " : " .$sid;
|
Log3 $name, 1, "$name: DEV_Parse> UNDEFINED " . $model . " : " .$sid;
|
||||||
return "UNDEFINED XMI_$sid XiaomiSmartHome_Device $sid $model $name";
|
return "UNDEFINED XMI_$sid XiaomiSmartHome_Device $sid $model $name";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,6 +423,8 @@ sub XiaomiSmartHome_Device_update($){
|
|||||||
CommandDeleteReading( undef, "$name batterystate" ) if(defined(ReadingsVal($name,"batterystate",undef)));
|
CommandDeleteReading( undef, "$name batterystate" ) if(defined(ReadingsVal($name,"batterystate",undef)));
|
||||||
CommandDeleteReading( undef, "$name round" ) if(defined(ReadingsVal($name,"round",undef)));
|
CommandDeleteReading( undef, "$name round" ) if(defined(ReadingsVal($name,"round",undef)));
|
||||||
CommandDeleteReading( undef, "$name battery_level" ) if(defined(ReadingsVal($name,"battery_level",undef)));
|
CommandDeleteReading( undef, "$name battery_level" ) if(defined(ReadingsVal($name,"battery_level",undef)));
|
||||||
|
CommandDeleteReading( undef, "$name battery" ) if(defined(ReadingsVal($name,"battery",undef)));
|
||||||
|
CommandDeleteReading( undef, "$name batteryLevel" ) if(defined(ReadingsVal($name,"batteryLevel",undef)));
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
@@ -446,14 +450,16 @@ sub XiaomiSmartHome_Device_Define($$) {
|
|||||||
}
|
}
|
||||||
$iodev = $hash->{IODev}->{NAME};
|
$iodev = $hash->{IODev}->{NAME};
|
||||||
|
|
||||||
my $d = $modules{XiaomiSmartHome_Device}{defptr}{$name};
|
my $d = $modules{XiaomiSmartHome_Device}{defptr}{$sid};
|
||||||
|
|
||||||
return "XiaomiSmartHome device $hash->{SID} on XiaomiSmartHome $iodev already defined as $d->{NAME}." if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{NAME} ne $name );
|
return "XiaomiSmartHome device $hash->{SID} on XiaomiSmartHome $iodev already defined as $d->{SID}." if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{SID} ne $sid );
|
||||||
|
|
||||||
Log3 $name, 4, $iodev . ": DEV_Define> " . $name . ": defined as ". $hash->{MODEL};
|
Log3 $name, 4, $iodev . ": DEV_Define> " . $name . ": defined as ". $hash->{MODEL};
|
||||||
$attr{$name}{room} = $room if( !defined( $attr{$name}{room} ) );
|
$attr{$name}{room} = $room if( !defined( $attr{$name}{room} ) );
|
||||||
if( $type =~ /motion/) {
|
if( $type =~ /motion/) {
|
||||||
|
readingsSingleUpdate($hash, "state", "motion", 1 ) if( !defined( $attr{$name}{devStateIcon} ));
|
||||||
$attr{$name}{devStateIcon} = 'motion:motion_detector@red off:motion_detector@green no_motion:motion_detector@green' if( !defined( $attr{$name}{devStateIcon} ) );
|
$attr{$name}{devStateIcon} = 'motion:motion_detector@red off:motion_detector@green no_motion:motion_detector@green' if( !defined( $attr{$name}{devStateIcon} ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif ( $type =~ /magnet/) {
|
elsif ( $type =~ /magnet/) {
|
||||||
$attr{$name}{devStateIcon} = 'open:fts_door_open@red close:fts_door@green' if( !defined( $attr{$name}{devStateIcon} ) );
|
$attr{$name}{devStateIcon} = 'open:fts_door_open@red close:fts_door@green' if( !defined( $attr{$name}{devStateIcon} ) );
|
||||||
@@ -488,9 +494,11 @@ sub XiaomiSmartHome_Device_Undef($)
|
|||||||
my ($hash, $arg) = @_;
|
my ($hash, $arg) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $iodev = $hash->{IODev}->{NAME};
|
my $iodev = $hash->{IODev}->{NAME};
|
||||||
|
my $sid = $hash->{SID};
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
delete($modules{XiaomiSmartHome_Device}{defptr}{$hash->{SID}});
|
Log3 $name, 1, "$iodev: DEV_Undef> ". $hash->{SID} . " > " . $modules{XiaomiSmartHome_Device}{defptr}{$hash->{SID}} . " > " . $sid ." > " . $modules{XiaomiSmartHome_Device}{defptr}{$sid};
|
||||||
Log3 $name, 4, "$iodev: DEV_Undef> $name - device deleted";
|
my $error = delete ($modules{XiaomiSmartHome_Device}{defptr}{$sid});
|
||||||
|
Log3 $name, 1, "$iodev: DEV_Undef> $name - device deleted " . $error;
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -504,8 +512,9 @@ sub XiaomiSmartHome_round {
|
|||||||
$p ||= 0;
|
$p ||= 0;
|
||||||
$n *= 10 ** $p;
|
$n *= 10 ** $p;
|
||||||
$n = int($n + .5 * $sign);
|
$n = int($n + .5 * $sign);
|
||||||
Log3 $name, 5, "$name: DEV_Round>" . " Result_value: " . $n / 10**$p;
|
my $res = sprintf( "%." . $p . "f", $n / 10**$p);
|
||||||
return $n / 10**$p;
|
Log3 $name, 5, "$name: DEV_Round>" . " Result_value: " . $res;
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
UPD 2017-12-18_13:56:43 37688 FHEM/71_XiaomiSmartHome.pm
|
UPD 2018-06-22_13:29:31 38872 FHEM/71_XiaomiSmartHome.pm
|
||||||
UPD 2017-12-18_10:00:55 28395 FHEM/71_XiaomiSmartHome_Device.pm
|
UPD 2018-06-22_12:45:46 29142 FHEM/71_XiaomiSmartHome_Device.pm
|
||||||
|
|||||||
Reference in New Issue
Block a user