mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 16:46:35 +00:00
73_NUKIBridge: 74_NUKIDevice add NUKIDevice Readings rssi paired
git-svn-id: https://svn.fhem.de/fhem/trunk@13116 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
665d73bb26
commit
03b253403f
@ -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.
|
||||||
|
- feature: 73_NUKIBridge,74_NUKIDevice: add NUKIDevice Readings rssi paired
|
||||||
- feature: 73_PRESENCE:
|
- feature: 73_PRESENCE:
|
||||||
- new mode "event" to determine presence state based on events of
|
- new mode "event" to determine presence state based on events of
|
||||||
other FHEM definitions.
|
other FHEM definitions.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2016 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
# (c) 2016-2017 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
|
||||||
@ -46,7 +46,7 @@ use JSON;
|
|||||||
|
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
|
|
||||||
my $version = "0.4.5";
|
my $version = "0.4.7";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -59,6 +59,29 @@ my %lockActions = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
# Declare functions
|
||||||
|
sub NUKIBridge_Initialize ($);
|
||||||
|
sub NUKIBridge_Define ($$);
|
||||||
|
sub NUKIBridge_Undef ($$);
|
||||||
|
sub NUKIBridge_Read($@);
|
||||||
|
sub NUKIBridge_Attr(@);
|
||||||
|
sub NUKIBridge_Set($@);
|
||||||
|
sub NUKIBridge_Get($@);
|
||||||
|
sub NUKIBridge_GetCheckBridgeAlive($);
|
||||||
|
sub NUKIBridge_firstRun($);
|
||||||
|
sub NUKIBridge_Call($$$$$);
|
||||||
|
sub NUKIBridge_Distribution($$$);
|
||||||
|
sub NUKIBridge_ResponseProcessing($$$);
|
||||||
|
sub NUKIBridge_Autocreate($$;$);
|
||||||
|
sub NUKIBridge_InfoProcessing($$);
|
||||||
|
sub NUKIBridge_getLogfile($);
|
||||||
|
sub NUKIBridge_getCallbackList($);
|
||||||
|
sub NUKIBridge_CallBlocking($$$);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub NUKIBridge_Initialize($) {
|
sub NUKIBridge_Initialize($) {
|
||||||
|
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
@ -164,7 +187,6 @@ sub NUKIBridge_Attr(@) {
|
|||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
|
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +199,6 @@ sub NUKIBridge_Attr(@) {
|
|||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
|
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
|
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,9 +299,12 @@ sub NUKIBridge_GetCheckBridgeAlive($) {
|
|||||||
|
|
||||||
NUKIBridge_Call($hash,$hash,'info',undef,undef);
|
NUKIBridge_Call($hash,$hash,'info',undef,undef);
|
||||||
|
|
||||||
InternalTimer( gettimeofday()+15+int(rand(15)), 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
|
Log3 $name, 4, "NUKIBridge ($name) - run NUKIBridge_Call";
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - Call InternalTimer for NUKIBridge_GetCheckBridgeAlive";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InternalTimer( gettimeofday()+15+int(rand(15)), 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
|
||||||
|
|
||||||
|
Log3 $name, 4, "NUKIBridge ($name) - Call InternalTimer for NUKIBridge_GetCheckBridgeAlive";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIBridge_firstRun($) {
|
sub NUKIBridge_firstRun($) {
|
||||||
@ -361,6 +385,13 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( $json eq "" and exists( $param->{code} ) and $param->{code} ne 200 ) {
|
if( $json eq "" and exists( $param->{code} ) and $param->{code} ne 200 ) {
|
||||||
|
|
||||||
|
if( $param->{code} eq 503 ) {
|
||||||
|
NUKIDevice_Parse($param->{chash},$param->{code}) if( $hash != $param->{chash} );
|
||||||
|
Log3 $name, 4, "NUKIBridge ($name) - smartlock is offline";
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
return "received http code ".$param->{code}.": smartlock is offline";
|
||||||
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastError", "Internal error, " .$param->{code} );
|
readingsBulkUpdate( $hash, "lastError", "Internal error, " .$param->{code} );
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - received http code " .$param->{code}." without any data after requesting";
|
Log3 $name, 4, "NUKIBridge ($name) - received http code " .$param->{code}." without any data after requesting";
|
||||||
@ -377,7 +408,8 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
|
|
||||||
###### Fehler bei Antwort auf Anfrage eines logischen Devices ######
|
###### Fehler bei Antwort auf Anfrage eines logischen Devices ######
|
||||||
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 404 );
|
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 404 );
|
||||||
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 400 and $hash != $param->{chash} );
|
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 400 and $hash != $param->{chash} );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - invalid API token" if( $param->{code} eq 401 );
|
Log3 $name, 4, "NUKIBridge ($name) - invalid API token" if( $param->{code} eq 401 );
|
||||||
@ -403,8 +435,11 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( $hash == $param->{chash} ) {
|
if( $hash == $param->{chash} ) {
|
||||||
|
|
||||||
#$json = '[{"nukiId": 1,"name": "Home","lastKnownState": {"state": 1,"stateName": "locked","batteryCritical": false,"timestamp": "2016-10-03T06:49:00+00:00"}},{"nukiId": 2,"name": "Grandma","lastKnownState": {"state": 3,"stateName": "unlocked","batteryCritical": false,"timestamp": "2016-10-03T06:49:00+00:00"}}]' if( $param->{endpoint} eq "list" ); # zum testen da ich kein Nuki Smartlock habe
|
# zum testen da ich kein Nuki Smartlock habe
|
||||||
|
#$json = '[{"nukiId": 1,"name": "Home","lastKnownState": {"state": 1,"stateName": "locked","batteryCritical": false,"timestamp": "2016-10-03T06:49:00+00:00"}},{"nukiId": 2,"name": "Grandma","lastKnownState": {"state": 3,"stateName": "unlocked","batteryCritical": false,"timestamp": "2016-10-03T06:49:00+00:00"}}]' if( $param->{endpoint} eq "list" );
|
||||||
|
|
||||||
|
#$json= '{"bridgeType":2,"ids":{"serverId":142667440},"versions":{"appVersion":"0.2.14"},"uptime":1527,"currentTime":"2017-01-17T04:55:58Z","serverConnected":true,"scanResults":[{"nukiId": 1,"name": "Home","rssi": -87,"paired": true},{"nukiId": 2,"name": "Grandma","rssi": -93,"paired": false}]}';
|
||||||
|
|
||||||
NUKIBridge_ResponseProcessing($hash,$json,$param->{endpoint});
|
NUKIBridge_ResponseProcessing($hash,$json,$param->{endpoint});
|
||||||
|
|
||||||
@ -531,6 +566,12 @@ sub NUKIBridge_InfoProcessing($$) {
|
|||||||
my ($hash,$decode_json) = @_;
|
my ($hash,$decode_json) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $nukiId;
|
||||||
|
my $scanResults;
|
||||||
|
my %response_hash;
|
||||||
|
my $dname;
|
||||||
|
my $dhash;
|
||||||
|
|
||||||
my %bridgeType = (
|
my %bridgeType = (
|
||||||
'1' => 'Hardware',
|
'1' => 'Hardware',
|
||||||
'2' => 'Software'
|
'2' => 'Software'
|
||||||
@ -548,6 +589,27 @@ sub NUKIBridge_InfoProcessing($$) {
|
|||||||
readingsBulkUpdate($hash,"currentTime",$decode_json->{currentTime});
|
readingsBulkUpdate($hash,"currentTime",$decode_json->{currentTime});
|
||||||
readingsBulkUpdate($hash,"serverConnected",$decode_json->{serverConnected});
|
readingsBulkUpdate($hash,"serverConnected",$decode_json->{serverConnected});
|
||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
|
|
||||||
|
|
||||||
|
foreach $scanResults (@{$decode_json->{scanResults}}) {
|
||||||
|
if( ref($scanResults) eq "HASH" ) {
|
||||||
|
if ( defined( $modules{NUKIDevice}{defptr} ) ) {
|
||||||
|
while ( my ( $key, $value ) = each %{ $modules{NUKIDevice}{defptr} } ) {
|
||||||
|
|
||||||
|
$dhash = $modules{NUKIDevice}{defptr}{$key};
|
||||||
|
$dname = $dhash->{NAME};
|
||||||
|
$nukiId = InternalVal( $dname, "NUKIID", undef );
|
||||||
|
next if ( !$nukiId or $nukiId ne $scanResults->{nukiId} );
|
||||||
|
|
||||||
|
Log3 $name, 4, "NUKIDevice ($dname) - Received scanResults for matching NukiID $nukiId at device $dname";
|
||||||
|
|
||||||
|
%response_hash = ('name'=>$scanResults->{name}, 'rssi'=>$scanResults->{rssi},'paired'=>$scanResults->{paired});
|
||||||
|
|
||||||
|
NUKIDevice_Parse($dhash,encode_json \%response_hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIBridge_getLogfile($) {
|
sub NUKIBridge_getLogfile($) {
|
||||||
@ -688,6 +750,9 @@ sub NUKIBridge_CallBlocking($$$) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2016 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
# (c) 2016-2017 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
|
||||||
@ -33,7 +33,25 @@ use warnings;
|
|||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
|
||||||
my $version = "0.4.5";
|
my $version = "0.4.7";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Declare functions
|
||||||
|
sub NUKIDevice_Initialize($);
|
||||||
|
sub NUKIDevice_Define($$);
|
||||||
|
sub NUKIDevice_Undef($$);
|
||||||
|
sub NUKIDevice_Attr(@);
|
||||||
|
sub NUKIDevice_addExtension($$$);
|
||||||
|
sub NUKIDevice_removeExtension($);
|
||||||
|
sub NUKIDevice_Set($$@);
|
||||||
|
sub NUKIDevice_GetUpdate($);
|
||||||
|
sub NUKIDevice_ReadFromNUKIBridge($@);
|
||||||
|
sub NUKIDevice_Parse($$);
|
||||||
|
sub NUKIDevice_WriteReadings($$);
|
||||||
|
sub NUKIDevice_CGI();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -96,10 +114,10 @@ sub NUKIDevice_Define($$) {
|
|||||||
|
|
||||||
if(defined($hash->{IODev}->{NAME})) {
|
if(defined($hash->{IODev}->{NAME})) {
|
||||||
|
|
||||||
Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME};
|
Log3 $name, 3, "NUKIDevice ($name) - I/O device is " . $hash->{IODev}->{NAME};
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Log3 $name, 1, "$name: no I/O device";
|
Log3 $name, 1, "NUKIDevice ($name) - no I/O device";
|
||||||
}
|
}
|
||||||
|
|
||||||
$iodev = $hash->{IODev}->{NAME};
|
$iodev = $hash->{IODev}->{NAME};
|
||||||
@ -338,7 +356,7 @@ sub NUKIDevice_ReadFromNUKIBridge($@) {
|
|||||||
!$iohash->{TYPE} ||
|
!$iohash->{TYPE} ||
|
||||||
!$modules{$iohash->{TYPE}} ||
|
!$modules{$iohash->{TYPE}} ||
|
||||||
!$modules{$iohash->{TYPE}}{ReadFn}) {
|
!$modules{$iohash->{TYPE}}{ReadFn}) {
|
||||||
Log3 $name, 3, "No I/O device or ReadFn found for $name";
|
Log3 $name, 3, "NUKIDevice ($name) - No I/O device or ReadFn found for $name";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,6 +399,12 @@ sub NUKIDevice_Parse($$) {
|
|||||||
Log3 $name, 3, "NUKIDevice ($name) - nukiId is not known";
|
Log3 $name, 3, "NUKIDevice ($name) - nukiId is not known";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $result eq 503 ) {
|
||||||
|
readingsSingleUpdate( $hash, "state", "smartlock is offline", 1 );
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - smartlock is offline";
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -455,6 +479,10 @@ sub NUKIDevice_WriteReadings($$) {
|
|||||||
readingsBulkUpdate( $hash, "state", $decode_json->{stateName} );
|
readingsBulkUpdate( $hash, "state", $decode_json->{stateName} );
|
||||||
readingsBulkUpdate( $hash, "battery", $battery );
|
readingsBulkUpdate( $hash, "battery", $battery );
|
||||||
readingsBulkUpdate( $hash, "success", $decode_json->{success} );
|
readingsBulkUpdate( $hash, "success", $decode_json->{success} );
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "name", $decode_json->{name} );
|
||||||
|
readingsBulkUpdate( $hash, "rssi", $decode_json->{rssi} );
|
||||||
|
readingsBulkUpdate( $hash, "paired", $decode_json->{paired} );
|
||||||
|
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - readings set for $name";
|
Log3 $name, 5, "NUKIDevice ($name) - readings set for $name";
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,7 @@ FHEM/74_NUKIBridge.pm CoolTux http://forum.fhem.de Sonstige
|
|||||||
FHEM/74_AMAD.pm CoolTux http://forum.fhem.de Unterstuetzende Dienste
|
FHEM/74_AMAD.pm CoolTux http://forum.fhem.de Unterstuetzende Dienste
|
||||||
FHEM/74_HOMBOT.pm CoolTux http://forum.fhem.de Unterstuetzende Dienste
|
FHEM/74_HOMBOT.pm CoolTux http://forum.fhem.de Unterstuetzende Dienste
|
||||||
FHEM/74_NUKIDevice.pm CoolTux http://forum.fhem.de Sonstige Systeme
|
FHEM/74_NUKIDevice.pm CoolTux http://forum.fhem.de Sonstige Systeme
|
||||||
|
FHEM/74_XiaomiFlowerSens CoolTux http://forum.fhem.de Sonstige Systeme
|
||||||
FHEM/74_THINKINGCLEANER.pm loredo http://forum.fhem.de Unterstuetzende Dienste
|
FHEM/74_THINKINGCLEANER.pm loredo http://forum.fhem.de Unterstuetzende Dienste
|
||||||
FHEM/74_Unifi.pm rapster http://forum.fhem.de Automatisierung
|
FHEM/74_Unifi.pm rapster http://forum.fhem.de Automatisierung
|
||||||
FHEM/75_MSG.pm loredo http://forum.fhem.de Automatisierung
|
FHEM/75_MSG.pm loredo http://forum.fhem.de Automatisierung
|
||||||
|
Loading…
x
Reference in New Issue
Block a user