set Befehle für lockAction hinzugefügt
This commit is contained in:
parent
05d202018c
commit
be870d67c4
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2015-2016 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
# (c) 2016 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
|
||||||
@ -34,7 +34,7 @@ use JSON;
|
|||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
|
|
||||||
my $version = "0.1.27";
|
my $version = "0.1.35";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ my %lockActions = (
|
|||||||
'unlock' => 1,
|
'unlock' => 1,
|
||||||
'lock' => 2,
|
'lock' => 2,
|
||||||
'unlatch' => 3,
|
'unlatch' => 3,
|
||||||
'lockngo' => 4,
|
'locknGo' => 4,
|
||||||
'lockngowithunlatch' => 5
|
'locknGoWithUnlatch' => 5
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -75,9 +75,9 @@ sub NUKIBridge_Initialize($) {
|
|||||||
|
|
||||||
sub NUKIBridge_Read($@) {
|
sub NUKIBridge_Read($@) {
|
||||||
|
|
||||||
my ($hash,$chash,$name,$path, $nukiId)= @_;
|
my ($hash,$chash,$name,$path,$lockAction,$nukiId)= @_;
|
||||||
|
|
||||||
return NUKIBridge_Call($hash, $chash, $path, $nukiId );
|
return NUKIBridge_Call($hash,$chash,$path,$lockAction,$nukiId );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIBridge_Define($$) {
|
sub NUKIBridge_Define($$) {
|
||||||
@ -95,7 +95,7 @@ sub NUKIBridge_Define($$) {
|
|||||||
my $host = $a[2];
|
my $host = $a[2];
|
||||||
my $token = $a[3];
|
my $token = $a[3];
|
||||||
my $port = 8080;
|
my $port = 8080;
|
||||||
my $interval = 60;
|
my $interval = 180;
|
||||||
|
|
||||||
$hash->{HOST} = $host;
|
$hash->{HOST} = $host;
|
||||||
$hash->{PORT} = $port;
|
$hash->{PORT} = $port;
|
||||||
@ -108,12 +108,17 @@ sub NUKIBridge_Define($$) {
|
|||||||
Log3 $name, 3, "NUKIBridge ($name) - defined with host $host on port $port, Token $token";
|
Log3 $name, 3, "NUKIBridge ($name) - defined with host $host on port $port, Token $token";
|
||||||
|
|
||||||
$attr{$name}{room} = "NUKI" if( !defined( $attr{$name}{room} ) );
|
$attr{$name}{room} = "NUKI" if( !defined( $attr{$name}{room} ) );
|
||||||
readingsSingleUpdate($hash, 'state', 'initialized', 1 );
|
readingsSingleUpdate($hash, 'state', 'Initialized', 1 );
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer( gettimeofday()+15, "NUKIBridge_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) and ($hash->{TOKEN}) and !IsDisabled($name) );
|
|
||||||
|
|
||||||
$modules{AMAD}{defptr}{$hash->{HOST}} = $hash;
|
if( $init_done ) {
|
||||||
|
NUKIDevice_GetUpdate($hash);
|
||||||
|
} else {
|
||||||
|
InternalTimer( gettimeofday()+15, "NUKIBridge_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) and ($hash->{TOKEN}) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$modules{NUKIBridge}{defptr}{$hash->{HOST}} = $hash;
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -127,7 +132,7 @@ sub NUKIBridge_Undef($$) {
|
|||||||
|
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
|
|
||||||
delete $modules{NUKI}{defptr}{$hash->{HOST}};
|
delete $modules{NUKIBridge}{defptr}{$hash->{HOST}};
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -144,15 +149,18 @@ sub NUKIBridge_Attr(@) {
|
|||||||
if( $attrVal eq "0" ) {
|
if( $attrVal eq "0" ) {
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
InternalTimer( gettimeofday()+2, "NUKIBridge_GetUpdate", $hash, 0 );
|
InternalTimer( gettimeofday()+2, "NUKIBridge_GetUpdate", $hash, 0 );
|
||||||
|
readingsSingleUpdate($hash, 'state', 'Initialized', 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
||||||
} else {
|
} else {
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
|
readingsSingleUpdate($hash, 'state', 'disabled', 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - disabled";
|
Log3 $name, 3, "NUKIBridge ($name) - disabled";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
InternalTimer( gettimeofday()+2, "NUKIBridge_GetUpdate", $hash, 0 );
|
InternalTimer( gettimeofday()+2, "NUKIBridge_GetUpdate", $hash, 0 );
|
||||||
|
readingsSingleUpdate($hash, 'state', 'Initialized', 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +220,7 @@ sub NUKIBridge_Get($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
NUKIBridge_Call($hash,$hash,"list",undef) if( !IsDisabled($name) );
|
NUKIBridge_Call($hash,$hash,"list",undef,undef) if( !IsDisabled($name) );
|
||||||
|
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - Call NUKIBridge_Get" if( !IsDisabled($name) );
|
Log3 $name, 3, "NUKIBridge ($name) - Call NUKIBridge_Get" if( !IsDisabled($name) );
|
||||||
|
|
||||||
@ -227,17 +235,17 @@ sub NUKIBridge_GetUpdate($) {
|
|||||||
|
|
||||||
if( !IsDisabled($name) ) {
|
if( !IsDisabled($name) ) {
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
#RemoveInternalTimer($hash);
|
||||||
NUKIBridge_Call($hash,$hash,"list",undef);
|
NUKIBridge_Call($hash,$hash,"list",undef,undef);
|
||||||
#InternalTimer( gettimeofday()+$hash->{INTERVAL}, "NUKIBridge_GetUpdate", $hash, 1 );
|
#InternalTimer( gettimeofday()+$hash->{INTERVAL}, "NUKIBridge_GetUpdate", $hash, 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - Call NUKIBridge_GetUpdate";
|
Log3 $name, 3, "NUKIBridge ($name) - Call NUKIBridge_GetUpdate";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIBridge_Call($$$$;$) {
|
sub NUKIBridge_Call($$$$$;$) {
|
||||||
|
|
||||||
my ($hash,$chash,$path,$nukiId,$method) = @_;
|
my ($hash,$chash,$path,$lockAction,$nukiId,$method) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $host = $hash->{HOST};
|
my $host = $hash->{HOST};
|
||||||
@ -247,7 +255,8 @@ sub NUKIBridge_Call($$$$;$) {
|
|||||||
my $uri = "http://" . $hash->{HOST} . ":" . $port;
|
my $uri = "http://" . $hash->{HOST} . ":" . $port;
|
||||||
$uri .= "/" . $path if( defined $path);
|
$uri .= "/" . $path if( defined $path);
|
||||||
$uri .= "?token=" . $token if( defined($token) );
|
$uri .= "?token=" . $token if( defined($token) );
|
||||||
$uri .= "&nukiId" . $nukiId if( $path ne "list" and defined($nukiId) );
|
$uri .= "&action=" . $lockActions{$lockAction} if( defined($lockAction) );
|
||||||
|
$uri .= "&nukiId=" . $nukiId if( $path ne "list" and defined($nukiId) );
|
||||||
|
|
||||||
$method = 'GET' if( !$method );
|
$method = 'GET' if( !$method );
|
||||||
|
|
||||||
@ -306,7 +315,8 @@ sub NUKIBridge_dispatch($$$) {
|
|||||||
|
|
||||||
|
|
||||||
######### Zum testen da ich kein Nuki Smartkey habe ############
|
######### Zum testen da ich kein Nuki Smartkey habe ############
|
||||||
#if ( $param->{code} eq 400 ) {
|
#if ( $param->{code} eq 404 ) {
|
||||||
|
# Log3 $name, 3, "NUKIBridge ($name) - Test JSON String";
|
||||||
# $json = '{"state": 1, "stateName": "locked", "batteryCritical": false, "success": "true"}';
|
# $json = '{"state": 1, "stateName": "locked", "batteryCritical": false, "success": "true"}';
|
||||||
# NUKIDevice_Parse($param->{chash},$json);
|
# NUKIDevice_Parse($param->{chash},$json);
|
||||||
#}
|
#}
|
||||||
@ -395,9 +405,10 @@ sub NUKIBridge_Autocreate($$;$) {
|
|||||||
|
|
||||||
readingsBulkUpdate( $hash, "${autocreated}_nukiId", $nukiId );
|
readingsBulkUpdate( $hash, "${autocreated}_nukiId", $nukiId );
|
||||||
readingsBulkUpdate( $hash, "${autocreated}_name", $nukiName );
|
readingsBulkUpdate( $hash, "${autocreated}_name", $nukiName );
|
||||||
readingsBulkUpdate( $hash, "smartlockCount", $autocreated );
|
|
||||||
|
|
||||||
$autocreated++;
|
$autocreated++;
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "smartlockCount", $autocreated );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
114
74_NUKIDevice.pm
114
74_NUKIDevice.pm
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2015-2016 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
# (c) 2016 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
|
||||||
@ -31,8 +31,9 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
my $version = "0.1.28";
|
my $version = "0.1.37";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ sub NUKIDevice_Define($$) {
|
|||||||
$hash->{NUKIID} = $nukiId;
|
$hash->{NUKIID} = $nukiId;
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
$hash->{STATE} = 'Initialized';
|
$hash->{STATE} = 'Initialized';
|
||||||
|
$hash->{INTERVAL} = 30;
|
||||||
|
|
||||||
|
|
||||||
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
|
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
|
||||||
@ -114,6 +116,15 @@ sub NUKIDevice_Define($$) {
|
|||||||
|
|
||||||
$attr{$name}{room} = "NUKI" if( !defined( $attr{$name}{room} ) );
|
$attr{$name}{room} = "NUKI" if( !defined( $attr{$name}{room} ) );
|
||||||
|
|
||||||
|
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
|
||||||
|
if( $init_done ) {
|
||||||
|
NUKIDevice_GetUpdateInternalTimer($hash);
|
||||||
|
} else {
|
||||||
|
InternalTimer(gettimeofday()+20, "NUKIDevice_GetUpdateInternalTimer", $hash, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,29 +154,39 @@ sub NUKIDevice_Attr(@) {
|
|||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq "disable" ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" ) {
|
||||||
if( $attrVal eq "0" ) {
|
if( $attrVal eq "0" ) {
|
||||||
#RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
#InternalTimer( gettimeofday()+2, "NUKIDevice_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
InternalTimer( gettimeofday()+2, "NUKIDevice_GetUpdate", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
||||||
#readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "initialized", 1 );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
||||||
} else {
|
} else {
|
||||||
#readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||||
#RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - disabled";
|
Log3 $name, 3, "NUKIDevice ($name) - disabled";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
elsif( $cmd eq "del" ) {
|
|
||||||
#RemoveInternalTimer( $hash );
|
|
||||||
#InternalTimer( gettimeofday()+2, "NUKIDevice_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
|
||||||
#readingsSingleUpdate ( $hash, "state", "active", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if($cmd eq "set") {
|
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
RemoveInternalTimer( $hash );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - $attrName : $attrVal";
|
InternalTimer( gettimeofday()+2, "NUKIDevice_GetUpdate", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
||||||
|
readingsSingleUpdate ( $hash, "state", "initialized", 1 );
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
||||||
}
|
}
|
||||||
elsif( $cmd eq "del" ) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $attrName eq "interval" ) {
|
||||||
|
if( $cmd eq "set" ) {
|
||||||
|
if( $attrVal < 10 ) {
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - interval too small, please use something > 10 (sec), default is 30 (sec)";
|
||||||
|
return "interval too small, please use something > 10 (sec), default is 60 (sec)";
|
||||||
|
} else {
|
||||||
|
$hash->{INTERVAL} = $attrVal;
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - set interval to $attrVal";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$hash->{INTERVAL} = 30;
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - set interval to default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,23 +198,49 @@ sub NUKIDevice_Set($$@) {
|
|||||||
my ($hash, $name, @aa) = @_;
|
my ($hash, $name, @aa) = @_;
|
||||||
my ($cmd, @args) = @aa;
|
my ($cmd, @args) = @aa;
|
||||||
|
|
||||||
my %obj;
|
my $lockAction;
|
||||||
|
|
||||||
|
|
||||||
if($cmd eq 'statusRequest') {
|
if( $cmd eq 'statusRequest' ) {
|
||||||
return "usage: statusRequest" if( @args != 0 );
|
return "usage: statusRequest" if( @args != 0 );
|
||||||
|
|
||||||
NUKIDevice_GetUpdate($hash);
|
NUKIDevice_GetUpdate($hash);
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
} elsif($cmd eq 'other') {
|
} elsif( $cmd eq 'lock' ) {
|
||||||
|
$lockAction = $cmd;
|
||||||
|
|
||||||
|
} elsif( $cmd eq 'unlock' ) {
|
||||||
|
$lockAction = $cmd;
|
||||||
|
|
||||||
|
} elsif( $cmd eq 'unlatch' ) {
|
||||||
|
$lockAction = $cmd;
|
||||||
|
|
||||||
|
} elsif( $cmd eq 'locknGo' ) {
|
||||||
|
$lockAction = $cmd;
|
||||||
|
|
||||||
|
} elsif( $cmd eq 'locknGoWithUnlatch' ) {
|
||||||
|
$lockAction = $cmd;
|
||||||
|
|
||||||
} elsif($cmd eq 'other2') {
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $list = "statusRequest:noArg";
|
my $list = "statusRequest:noArg unlock:noArg lock:noArg unlatch:noArg locknGo:noArg locknGoWithUnlatch:noArg";
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
return "Unknown argument $cmd, choose one of $list";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $result = NUKIDevice_ReadFromNUKIBridge($hash,"lockAction",$lockAction,$hash->{NUKIID} );
|
||||||
|
|
||||||
|
if( !defined($result) ) {
|
||||||
|
|
||||||
|
$hash->{STATE} = "unknown";
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - unknown result to ReadFromNUKIBridge";
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
NUKIDevice_Parse($hash,$result);
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - Call NUKIDevice_Parse";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_GetUpdate($) {
|
sub NUKIDevice_GetUpdate($) {
|
||||||
@ -202,20 +249,35 @@ sub NUKIDevice_GetUpdate($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
#RemoveInternalTimer($hash);
|
Log3 $name, 3, "NUKIBridge ($name) - Call NUKIBridge_GetUpdate";
|
||||||
my $result = NUKIDevice_ReadFromNUKIBridge($hash, "lockState", $hash->{NUKIID} );
|
|
||||||
|
my $result = NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} );
|
||||||
|
|
||||||
if( !defined($result) ) {
|
if( !defined($result) ) {
|
||||||
|
|
||||||
$hash->{STATE} = "unknown";
|
$hash->{STATE} = "unknown";
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - unknown result to ReadFromNUKIBridge";
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
NUKIDevice_Parse($hash,$result);
|
NUKIDevice_Parse($hash,$result);
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - Call NUKIDevice_Parse";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#InternalTimer(gettimeofday()+$hash->{INTERVAL}, "NUKIDevice_GetUpdate", $hash, 0) if( $hash->{INTERVAL} );
|
sub NUKIDevice_GetUpdateInternalTimer($) {
|
||||||
|
|
||||||
return undef;
|
my ($hash) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
|
NUKIDevice_GetUpdate($hash);
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - Call NUKIDevice_GetUpdate";
|
||||||
|
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "NUKIDevice_GetUpdateInternalTimer", $hash, 0) if( $hash->{INTERVAL} );
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - Call InternalTimer";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_ReadFromNUKIBridge($@) {
|
sub NUKIDevice_ReadFromNUKIBridge($@) {
|
||||||
|
Loading…
Reference in New Issue
Block a user