mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
73_NUKIBridge: 74_NUKIDevice change Code to 2 step modul and Dispatch Fn
git-svn-id: https://svn.fhem.de/fhem/trunk@20938 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
36804e5aea
commit
016b9f7c68
@ -1,5 +1,7 @@
|
|||||||
# 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 change Code to 2 step modul
|
||||||
|
and Dispatch Fn, make Bridge robust
|
||||||
- bugfix: 74_XiaomiBTLESens: fix thermoHydroSens loop bug
|
- bugfix: 74_XiaomiBTLESens: fix thermoHydroSens loop bug
|
||||||
- bugfix: 73_AutoShuttersControl: fix little Resident home bug
|
- bugfix: 73_AutoShuttersControl: fix little Resident home bug
|
||||||
- feature: 70_VIERA: new commands, direct access to apps, commands had
|
- feature: 70_VIERA: new commands, direct access to apps, commands had
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2016-2017 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
|
# (c) 2016-2020 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
|
||||||
@ -25,55 +25,175 @@
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use JSON;
|
|
||||||
|
|
||||||
|
# try to use JSON::MaybeXS wrapper
|
||||||
|
# for chance of better performance + open code
|
||||||
|
eval {
|
||||||
|
require JSON::MaybeXS;
|
||||||
|
import JSON::MaybeXS qw( decode_json encode_json );
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
my $version = "0.6.4";
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# try to use JSON wrapper
|
||||||
|
# for chance of better performance
|
||||||
|
eval {
|
||||||
|
|
||||||
|
# JSON preference order
|
||||||
|
local $ENV{PERL_JSON_BACKEND} =
|
||||||
|
'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP'
|
||||||
|
unless ( defined( $ENV{PERL_JSON_BACKEND} ) );
|
||||||
|
|
||||||
|
require JSON;
|
||||||
|
import JSON qw( decode_json encode_json );
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# In rare cases, Cpanel::JSON::XS may
|
||||||
|
# be installed but JSON|JSON::MaybeXS not ...
|
||||||
|
eval {
|
||||||
|
require Cpanel::JSON::XS;
|
||||||
|
import Cpanel::JSON::XS qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# In rare cases, JSON::XS may
|
||||||
|
# be installed but JSON not ...
|
||||||
|
eval {
|
||||||
|
require JSON::XS;
|
||||||
|
import JSON::XS qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# Fallback to built-in JSON which SHOULD
|
||||||
|
# be available since 5.014 ...
|
||||||
|
eval {
|
||||||
|
require JSON::PP;
|
||||||
|
import JSON::PP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# Fallback to JSON::backportPP in really rare cases
|
||||||
|
require JSON::backportPP;
|
||||||
|
import JSON::backportPP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $version = '1.8.0';
|
||||||
|
|
||||||
# Declare functions
|
# Declare functions
|
||||||
sub NUKIDevice_Initialize($);
|
sub NUKIDevice_Initialize($);
|
||||||
sub NUKIDevice_Define($$);
|
sub NUKIDevice_Define($$);
|
||||||
sub NUKIDevice_Undef($$);
|
sub NUKIDevice_Undef($$);
|
||||||
sub NUKIDevice_Attr(@);
|
sub NUKIDevice_Attr(@);
|
||||||
sub NUKIDevice_addExtension($$$);
|
|
||||||
sub NUKIDevice_removeExtension($);
|
|
||||||
sub NUKIDevice_Set($$@);
|
sub NUKIDevice_Set($$@);
|
||||||
sub NUKIDevice_GetUpdate($);
|
sub NUKIDevice_GetUpdate($);
|
||||||
sub NUKIDevice_ReadFromNUKIBridge($@);
|
|
||||||
sub NUKIDevice_Parse($$);
|
sub NUKIDevice_Parse($$);
|
||||||
sub NUKIDevice_WriteReadings($$);
|
sub NUKIDevice_WriteReadings($$);
|
||||||
sub NUKIDevice_CGI();
|
|
||||||
|
|
||||||
|
my %deviceTypes = (
|
||||||
|
0 => 'smartlock',
|
||||||
|
2 => 'opener'
|
||||||
|
);
|
||||||
|
|
||||||
|
my %modes = (
|
||||||
|
2 => {
|
||||||
|
0 => 'door mode',
|
||||||
|
2 => 'door mode'
|
||||||
|
},
|
||||||
|
3 => {
|
||||||
|
0 => '-',
|
||||||
|
2 => ' continuous mode'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my %lockStates = (
|
||||||
|
0 => {
|
||||||
|
0 => 'uncalibrated',
|
||||||
|
2 => 'untrained'
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
0 => 'locked',
|
||||||
|
2 => 'online'
|
||||||
|
},
|
||||||
|
2 => {
|
||||||
|
0 => 'unlocking',
|
||||||
|
2 => '-'
|
||||||
|
},
|
||||||
|
3 => {
|
||||||
|
0 => 'unlocked',
|
||||||
|
2 => 'rto active'
|
||||||
|
},
|
||||||
|
4 => {
|
||||||
|
0 => 'locking',
|
||||||
|
2 => '-'
|
||||||
|
},
|
||||||
|
5 => {
|
||||||
|
0 => 'unlatched',
|
||||||
|
2 => 'open'
|
||||||
|
},
|
||||||
|
6 => {
|
||||||
|
0 => 'unlocked (lock ‘n’ go)',
|
||||||
|
2 => '-'
|
||||||
|
},
|
||||||
|
7 => {
|
||||||
|
0 => 'unlatching',
|
||||||
|
2 => 'opening'
|
||||||
|
},
|
||||||
|
253 => {
|
||||||
|
0 => '-',
|
||||||
|
2 => 'boot run'
|
||||||
|
},
|
||||||
|
254 => {
|
||||||
|
0 => 'motor blocked',
|
||||||
|
2 => '-'
|
||||||
|
},
|
||||||
|
255 => {
|
||||||
|
0 => 'undefined',
|
||||||
|
2 => 'undefined'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my %deviceTypeIds = reverse(%deviceTypes);
|
||||||
|
|
||||||
sub NUKIDevice_Initialize($) {
|
sub NUKIDevice_Initialize($) {
|
||||||
|
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{SetFn} = "NUKIDevice_Set";
|
$hash->{Match} = '^{.*}$';
|
||||||
$hash->{DefFn} = "NUKIDevice_Define";
|
|
||||||
$hash->{UndefFn} = "NUKIDevice_Undef";
|
|
||||||
$hash->{AttrFn} = "NUKIDevice_Attr";
|
|
||||||
|
|
||||||
my $webhookFWinstance = join( ",", devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') );
|
|
||||||
|
|
||||||
$hash->{AttrList} = "IODev ".
|
|
||||||
"disable:1 ".
|
|
||||||
"webhookFWinstance:$webhookFWinstance ".
|
|
||||||
"webhookHttpHostname ".
|
|
||||||
$readingFnAttributes;
|
|
||||||
|
|
||||||
|
$hash->{SetFn} = 'NUKIDevice_Set';
|
||||||
|
$hash->{DefFn} = 'NUKIDevice_Define';
|
||||||
|
$hash->{UndefFn} = 'NUKIDevice_Undef';
|
||||||
|
$hash->{AttrFn} = 'NUKIDevice_Attr';
|
||||||
|
$hash->{ParseFn} = 'NUKIDevice_Parse';
|
||||||
|
|
||||||
|
$hash->{AttrList} =
|
||||||
|
'IODev '
|
||||||
|
. 'model:opener,smartlock '
|
||||||
|
. 'disable:1 '
|
||||||
|
. $readingFnAttributes;
|
||||||
|
|
||||||
foreach my $d ( sort keys %{ $modules{NUKIDevice}{defptr} } ) {
|
foreach my $d ( sort keys %{ $modules{NUKIDevice}{defptr} } ) {
|
||||||
my $hash = $modules{NUKIDevice}{defptr}{$d};
|
my $hash = $modules{NUKIDevice}{defptr}{$d};
|
||||||
@ -82,501 +202,344 @@ sub NUKIDevice_Initialize($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_Define($$) {
|
sub NUKIDevice_Define($$) {
|
||||||
|
|
||||||
my ( $hash, $def ) = @_;
|
my ( $hash, $def ) = @_;
|
||||||
|
my @a = split( '[ \t][ \t]*', $def );
|
||||||
|
|
||||||
my @a = split( "[ \t]+", $def );
|
return 'too few parameters: define <name> NUKIDevice <nukiId> <deviceType>'
|
||||||
splice( @a, 1, 1 );
|
if ( @a != 4 );
|
||||||
my $iodev;
|
|
||||||
my $i = 0;
|
|
||||||
|
|
||||||
foreach my $param ( @a ) {
|
my $name = $a[0];
|
||||||
if( $param =~ m/IODev=([^\s]*)/ ) {
|
my $nukiId = $a[2];
|
||||||
$iodev = $1;
|
my $deviceType = ( defined $a[3] ) ? $a[3] : 0;
|
||||||
splice( @a, $i, 3 );
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "too few parameters: define <name> NUKIDevice <nukiId>" if( @a < 2 );
|
|
||||||
|
|
||||||
my ($name,$nukiId) = @a;
|
|
||||||
|
|
||||||
$hash->{NUKIID} = $nukiId;
|
$hash->{NUKIID} = $nukiId;
|
||||||
|
$hash->{DEVICETYPE} = ( defined $deviceType ) ? $deviceType : 0;
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
$hash->{STATE} = 'Initialized';
|
$hash->{STATE} = 'Initialized';
|
||||||
my $infix = "NUKIDevice";
|
|
||||||
|
|
||||||
|
my $iodev = AttrVal( $name, 'IODev', 'none' );
|
||||||
|
|
||||||
AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} );
|
AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} );
|
||||||
|
|
||||||
if ( defined( $hash->{IODev}->{NAME} ) ) {
|
if ( defined( $hash->{IODev}->{NAME} ) ) {
|
||||||
|
Log3( $name, 3,
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - I/O device is " . $hash->{IODev}->{NAME};
|
"NUKIDevice ($name) - I/O device is " . $hash->{IODev}->{NAME} );
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Log3 $name, 1, "NUKIDevice ($name) - no I/O device";
|
Log3( $name, 1, "NUKIDevice ($name) - no I/O device" );
|
||||||
}
|
}
|
||||||
|
|
||||||
$iodev = $hash->{IODev}->{NAME};
|
$iodev = $hash->{IODev}->{NAME};
|
||||||
|
|
||||||
|
my $d = $modules{NUKIDevice}{defptr}{$nukiId};
|
||||||
|
|
||||||
my $code = $hash->{NUKIID};
|
return
|
||||||
$code = $iodev ."-". $code if( defined($iodev) );
|
'NUKIDevice device '
|
||||||
my $d = $modules{NUKIDevice}{defptr}{$code};
|
. $name
|
||||||
return "NUKIDevice device $hash->{NUKIID} on NUKIBridge $iodev already defined as $d->{NAME}."
|
. ' on NUKIBridge '
|
||||||
|
. $iodev
|
||||||
|
. ' already defined.'
|
||||||
if ( defined($d)
|
if ( defined($d)
|
||||||
&& $d->{IODev} == $hash->{IODev}
|
and $d->{IODev} == $hash->{IODev}
|
||||||
&& $d->{NAME} ne $name );
|
and $d->{NAME} ne $name );
|
||||||
|
|
||||||
$modules{NUKIDevice}{defptr}{$code} = $hash;
|
|
||||||
|
|
||||||
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - defined with Code: $code";
|
|
||||||
Log3 $name, 1, "NUKIDevice ($name) - reading battery a deprecated and will be remove in future";
|
|
||||||
|
|
||||||
$attr{$name}{room} = "NUKI" if( !defined( $attr{$name}{room} ) );
|
|
||||||
|
|
||||||
if ( NUKIDevice_addExtension( $name, "NUKIDevice_CGI", $infix ) ) {
|
|
||||||
$hash->{fhem}{infix} = $infix;
|
|
||||||
}
|
|
||||||
|
|
||||||
$hash->{WEBHOOK_REGISTER} = "unregistered";
|
|
||||||
|
|
||||||
|
Log3( $name, 3, "NUKIDevice ($name) - defined with NukiId: $nukiId" );
|
||||||
|
|
||||||
|
CommandAttr( undef, $name . ' room NUKI' )
|
||||||
|
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
|
||||||
|
CommandAttr( undef, $name . ' model ' . $deviceTypes{$deviceType} )
|
||||||
|
if ( AttrVal( $name, 'model', 'none' ) eq 'none' );
|
||||||
|
|
||||||
if ($init_done) {
|
if ($init_done) {
|
||||||
InternalTimer( gettimeofday()+int(rand(10)), "NUKIDevice_GetUpdate", $hash, 0 );
|
InternalTimer( gettimeofday() + int( rand(10) ),
|
||||||
} else {
|
"NUKIDevice_GetUpdate", $hash );
|
||||||
InternalTimer( gettimeofday()+15+int(rand(5)), "NUKIDevice_GetUpdate", $hash, 0 );
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
InternalTimer( gettimeofday() + 15 + int( rand(5) ),
|
||||||
|
"NUKIDevice_GetUpdate", $hash );
|
||||||
|
}
|
||||||
|
|
||||||
|
$modules{NUKIDevice}{defptr}{$nukiId} = $hash;
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_Undef($$) {
|
sub NUKIDevice_Undef($$) {
|
||||||
|
|
||||||
my ( $hash, $arg ) = @_;
|
my ( $hash, $arg ) = @_;
|
||||||
|
|
||||||
my $nukiId = $hash->{NUKIID};
|
my $nukiId = $hash->{NUKIID};
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
if ( defined( $hash->{fhem}{infix} ) ) {
|
|
||||||
NUKIDevice_removeExtension( $hash->{fhem}{infix} );
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
|
|
||||||
my $code = $hash->{NUKIID};
|
Log3( $name, 3, "NUKIDevice ($name) - undefined with NukiId: $nukiId" );
|
||||||
$code = $hash->{IODev}->{NAME} ."-". $code if( defined($hash->{IODev}->{NAME}) );
|
delete( $modules{NUKIDevice}{defptr}{$nukiId} );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - undefined with Code: $code";
|
|
||||||
delete($modules{NUKIDevice}{defptr}{$code});
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_Attr(@) {
|
sub NUKIDevice_Attr(@) {
|
||||||
|
|
||||||
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
||||||
|
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $token = $hash->{IODev}->{TOKEN};
|
my $token = $hash->{IODev}->{TOKEN};
|
||||||
|
|
||||||
if( $attrName eq "disable" ) {
|
if ( $attrName eq 'disable' ) {
|
||||||
if( $cmd eq "set" and $attrVal eq "1" ) {
|
if ( $cmd eq 'set' and $attrVal == 1 ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
readingsSingleUpdate( $hash, 'state', 'disabled', 1 );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - disabled";
|
Log3( $name, 3, "NUKIDevice ($name) - disabled" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif ( $cmd eq 'del' ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate( $hash, 'state', 'active', 1 );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
Log3( $name, 3, "NUKIDevice ($name) - enabled" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elsif ( $attrName eq 'disabledForIntervals' ) {
|
||||||
if( $attrName eq "disabledForIntervals" ) {
|
if ( $cmd eq 'set' ) {
|
||||||
if( $cmd eq "set" ) {
|
Log3( $name, 3,
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enable disabledForIntervals";
|
"NUKIDevice ($name) - enable disabledForIntervals" );
|
||||||
readingsSingleUpdate ( $hash, "state", "Unknown", 1 );
|
readingsSingleUpdate( $hash, 'state', 'Unknown', 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif ( $cmd eq 'del' ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate( $hash, 'state', 'active', 1 );
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - delete disabledForIntervals";
|
Log3( $name, 3,
|
||||||
|
"NUKIDevice ($name) - delete disabledForIntervals" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elsif ( $attrName eq 'model' ) {
|
||||||
######################
|
if ( $cmd eq 'set' ) {
|
||||||
#### webhook #########
|
Log3( $name, 3, "NUKIDevice ($name) - change model" );
|
||||||
|
$hash->{DEVICETYPE} = $deviceTypeIds{$attrVal};
|
||||||
return "Invalid value for attribute $attrName: can only by FQDN or IPv4 or IPv6 address" if ( $attrVal && $attrName eq "webhookHttpHostname" && $attrVal !~ /^([A-Za-z_.0-9]+\.[A-Za-z_.0-9]+)|[0-9:]+$/ );
|
|
||||||
|
|
||||||
return "Invalid value for attribute $attrName: FHEMWEB instance $attrVal not existing" if ( $attrVal && $attrName eq "webhookFWinstance" && ( !defined( $defs{$attrVal} ) || $defs{$attrVal}{TYPE} ne "FHEMWEB" ) );
|
|
||||||
|
|
||||||
return "Invalid value for attribute $attrName: needs to be an integer value" if ( $attrVal && $attrName eq "webhookPort" && $attrVal !~ /^\d+$/ );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( $attrName =~ /^webhook.*/ ) {
|
|
||||||
|
|
||||||
my $webhookHttpHostname = ( $attrName eq "webhookHttpHostname" ? $attrVal : AttrVal( $name, "webhookHttpHostname", "" ) );
|
|
||||||
my $webhookFWinstance = ( $attrName eq "webhookFWinstance" ? $attrVal : AttrVal( $name, "webhookFWinstance", "" ) );
|
|
||||||
|
|
||||||
$hash->{WEBHOOK_URI} = "/" . AttrVal( $webhookFWinstance, "webname", "fhem" ) . "/NUKIDevice";
|
|
||||||
$hash->{WEBHOOK_PORT} = ( $attrName eq "webhookPort" ? $attrVal : AttrVal( $name, "webhookPort", InternalVal( $webhookFWinstance, "PORT", "" )) );
|
|
||||||
|
|
||||||
$hash->{WEBHOOK_URL} = "";
|
|
||||||
$hash->{WEBHOOK_COUNTER} = "0";
|
|
||||||
|
|
||||||
if ( $webhookHttpHostname ne "" && $hash->{WEBHOOK_PORT} ne "" ) {
|
|
||||||
|
|
||||||
$hash->{WEBHOOK_URL} = "http://" . $webhookHttpHostname . ":" . $hash->{WEBHOOK_PORT} . $hash->{WEBHOOK_URI} . "-" . $hash->{NUKIID};
|
|
||||||
my $url = "http://$webhookHttpHostname" . ":" . $hash->{WEBHOOK_PORT} . $hash->{WEBHOOK_URI} . "-" . $hash->{NUKIID};
|
|
||||||
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - URL ist: $url";
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash,"callback/add",$url,undef ) if( $init_done );
|
|
||||||
$hash->{WEBHOOK_REGISTER} = "sent";
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$hash->{WEBHOOK_REGISTER} = "incomplete_attributes";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_addExtension($$$) {
|
|
||||||
|
|
||||||
my ( $name, $func, $link ) = @_;
|
|
||||||
my $url = "/$link";
|
|
||||||
|
|
||||||
|
|
||||||
return 0 if ( defined( $data{FWEXT}{$url} ) && $data{FWEXT}{$url}{deviceName} ne $name );
|
|
||||||
|
|
||||||
Log3 $name, 2, "NUKIDevice ($name) - Registering NUKIDevice for webhook URI $url ...";
|
|
||||||
|
|
||||||
$data{FWEXT}{$url}{deviceName} = $name;
|
|
||||||
$data{FWEXT}{$url}{FUNC} = $func;
|
|
||||||
$data{FWEXT}{$url}{LINK} = $link;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub NUKIDevice_removeExtension($) {
|
|
||||||
|
|
||||||
my ($link) = @_;
|
|
||||||
|
|
||||||
my $url = "/$link";
|
|
||||||
my $name = $data{FWEXT}{$url}{deviceName};
|
|
||||||
|
|
||||||
Log3 $name, 2, "NUKIDevice ($name) - Unregistering NUKIDevice for webhook URL $url...";
|
|
||||||
delete $data{FWEXT}{$url};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub NUKIDevice_Set($$@) {
|
sub NUKIDevice_Set($$@) {
|
||||||
|
|
||||||
my ( $hash, $name, @aa ) = @_;
|
my ( $hash, $name, @aa ) = @_;
|
||||||
my ($cmd, @args) = @aa;
|
|
||||||
|
|
||||||
|
my ( $cmd, @args ) = @aa;
|
||||||
my $lockAction;
|
my $lockAction;
|
||||||
|
|
||||||
|
if ( lc($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 'lock' ) {
|
elsif ($cmd eq 'lock'
|
||||||
|
or lc($cmd) eq 'deactivaterto'
|
||||||
|
or $cmd eq 'unlock'
|
||||||
|
or lc($cmd) eq 'activaterto'
|
||||||
|
or $cmd eq 'unlatch'
|
||||||
|
or lc($cmd) eq 'electricstrikeactuation'
|
||||||
|
or lc($cmd) eq 'lockngo'
|
||||||
|
or lc($cmd) eq 'activatecontinuousmode'
|
||||||
|
or lc($cmd) eq 'lockngowithunlatch'
|
||||||
|
or lc($cmd) eq 'deactivatecontinuousmode'
|
||||||
|
or $cmd eq 'unpair' )
|
||||||
|
{
|
||||||
|
return ( 'usage: ' . $cmd )
|
||||||
|
if ( @args != 0 );
|
||||||
$lockAction = $cmd;
|
$lockAction = $cmd;
|
||||||
|
|
||||||
} elsif( $cmd eq 'unlock' ) {
|
}
|
||||||
$lockAction = $cmd;
|
else {
|
||||||
|
my $list = '';
|
||||||
|
$list =
|
||||||
|
'statusRequest:noArg unlock:noArg lock:noArg unlatch:noArg locknGo:noArg locknGoWithUnlatch:noArg unpair:noArg'
|
||||||
|
if ( $hash->{DEVICETYPE} == 0 );
|
||||||
|
$list =
|
||||||
|
'statusRequest:noArg activateRto:noArg deactivateRto:noArg electricStrikeActuation:noArg activateContinuousMode:noArg deactivateContinuousMode:noArg unpair:noArg'
|
||||||
|
if ( $hash->{DEVICETYPE} == 2 );
|
||||||
|
|
||||||
} elsif( $cmd eq 'unlatch' ) {
|
return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list );
|
||||||
$lockAction = $cmd;
|
|
||||||
|
|
||||||
} elsif( $cmd eq 'locknGo' ) {
|
|
||||||
$lockAction = $cmd;
|
|
||||||
|
|
||||||
} elsif( $cmd eq 'locknGoWithUnlatch' ) {
|
|
||||||
$lockAction = $cmd;
|
|
||||||
|
|
||||||
} elsif( $cmd eq 'unpair' ) {
|
|
||||||
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash,"$cmd",undef,$hash->{NUKIID} ) if( !IsDisabled($name) );
|
|
||||||
return undef;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
my $list = "statusRequest:noArg unlock:noArg lock:noArg unlatch:noArg locknGo:noArg locknGoWithUnlatch:noArg unpair:noArg";
|
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash->{helper}{lockAction} = $lockAction;
|
$hash->{helper}{lockAction} = $lockAction;
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash,"lockAction",$lockAction,$hash->{NUKIID} ) if( !IsDisabled($name) );
|
|
||||||
|
IOWrite( $hash, 'lockAction', $lockAction, $hash->{NUKIID},
|
||||||
|
$hash->{DEVICETYPE} );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_GetUpdate($) {
|
sub NUKIDevice_GetUpdate($) {
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
my ($hash) = @_;
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} ) if( !IsDisabled($name) );
|
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID}, $hash->{DEVICETYPE} )
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - NUKIDevice_GetUpdate Call NUKIDevice_ReadFromNUKIBridge" if( !IsDisabled($name) );
|
if ( !IsDisabled($name) );
|
||||||
|
Log3( $name, 5, "NUKIDevice ($name) - NUKIDevice_GetUpdate Call IOWrite" )
|
||||||
|
if ( !IsDisabled($name) );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_ReadFromNUKIBridge($@) {
|
|
||||||
|
|
||||||
my ($hash,@a) = @_;
|
|
||||||
my $name = $hash->{NAME};
|
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIDevice ($name) - NUKIDevice_ReadFromNUKIBridge check Bridge connected";
|
|
||||||
return "IODev $hash->{IODev} is not connected" if( ReadingsVal($hash->{IODev}->{NAME},"state","not connected") eq "not connected" );
|
|
||||||
|
|
||||||
|
|
||||||
no strict "refs";
|
|
||||||
my $ret;
|
|
||||||
unshift(@a,$name);
|
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIDevice ($name) - NUKIDevice_ReadFromNUKIBridge Bridge is connected call IOWrite";
|
|
||||||
|
|
||||||
$ret = IOWrite($hash,$hash,@a);
|
|
||||||
use strict "refs";
|
|
||||||
return $ret;
|
|
||||||
return if(IsDummy($name) || IsIgnored($name));
|
|
||||||
my $iohash = $hash->{IODev};
|
|
||||||
|
|
||||||
if(!$iohash ||
|
|
||||||
!$iohash->{TYPE} ||
|
|
||||||
!$modules{$iohash->{TYPE}} ||
|
|
||||||
!$modules{$iohash->{TYPE}}{ReadFn}) {
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - No I/O device or ReadFn found for $name";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
no strict "refs";
|
|
||||||
unshift(@a,$name);
|
|
||||||
$ret = &{$modules{$iohash->{TYPE}}{ReadFn}}($iohash, @a);
|
|
||||||
use strict "refs";
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub NUKIDevice_Parse($$) {
|
sub NUKIDevice_Parse($$) {
|
||||||
|
my ( $hash, $json ) = @_;
|
||||||
|
|
||||||
my($hash,$result) = @_;
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - Parse with result: $result";
|
Log3( $name, 5, "NUKIDevice ($name) - Parse with result: $json" );
|
||||||
#########################################
|
#########################################
|
||||||
####### Errorhandling #############
|
####### Errorhandling #############
|
||||||
|
|
||||||
if( !$result ) {
|
if ( $json !~ m/^[\[{].*[}\]]$/ ) {
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - empty answer received";
|
Log3( $name, 3, "NUKIDevice ($name) - invalid json detected: $json" );
|
||||||
return undef;
|
return "NUKIDevice ($name) - invalid json detected: $json";
|
||||||
} elsif( $result =~ m'HTTP/1.1 200 OK' ) {
|
|
||||||
Log3 $name, 4, "NUKIDevice ($name) - empty answer received";
|
|
||||||
return undef;
|
|
||||||
} elsif( $result !~ m/^[\[{].*[}\]]$/ ) {
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - invalid json detected: $result";
|
|
||||||
return "NUKIDevice ($name) - invalid json detected: $result";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $result =~ /\d{3}/ ) {
|
|
||||||
if( $result eq 400 ) {
|
|
||||||
readingsSingleUpdate( $hash, "state", "action is undefined", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - action is undefined";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $result eq 404 ) {
|
|
||||||
readingsSingleUpdate( $hash, "state", "nukiId is not known", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - nukiId is not known";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $result eq 503 ) {
|
|
||||||
readingsSingleUpdate( $hash, "state", "smartlock is offline", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - smartlock is offline";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
#### verarbeiten des JSON Strings #######
|
#### verarbeiten des JSON Strings #######
|
||||||
my $decode_json = eval{decode_json($result)};
|
my $decode_json = eval { decode_json($json) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - JSON error while request: $@";
|
Log3( $name, 3, "NUKIDevice ($name) - JSON error while request: $@" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ref($decode_json) ne 'HASH' ) {
|
||||||
if( ref($decode_json) ne "HASH" ) {
|
Log3( $name, 2,
|
||||||
Log3 $name, 2, "NUKIDevice ($name) - got wrong status message for $name: $decode_json";
|
"NUKIDevice ($name) - got wrong status message for $name: $decode_json"
|
||||||
|
);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - parse status message for $name";
|
my $nukiId = $decode_json->{nukiId};
|
||||||
|
|
||||||
|
if ( my $hash = $modules{NUKIDevice}{defptr}{$nukiId} ) {
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
NUKIDevice_WriteReadings( $hash, $decode_json );
|
||||||
|
Log3( $name, 4,
|
||||||
|
"NUKIDevice ($name) - find logical device: $hash->{NAME}" );
|
||||||
|
|
||||||
|
##################
|
||||||
|
## Zwischenlösung so für die Umstellung, kann später gelöscht werden
|
||||||
|
if ( AttrVal( $name, 'model', '' ) eq '' ) {
|
||||||
|
CommandDefMod( undef,
|
||||||
|
$name
|
||||||
|
. ' NUKIDevice '
|
||||||
|
. $hash->{NUKIID} . ' '
|
||||||
|
. $decode_json->{deviceType} );
|
||||||
|
CommandAttr( undef,
|
||||||
|
$name
|
||||||
|
. ' model '
|
||||||
|
. $deviceTypes{ $decode_json->{deviceType} } );
|
||||||
|
Log3( $name, 2, "NUKIDevice ($name) - redefined Defmod" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hash->{NAME};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log3( $name, 3,
|
||||||
|
"NUKIDevice ($name) - autocreate new device "
|
||||||
|
. makeDeviceName( $decode_json->{name} )
|
||||||
|
. " with nukiId $decode_json->{nukiId}, model $decode_json->{deviceType}"
|
||||||
|
);
|
||||||
|
return
|
||||||
|
'UNDEFINED '
|
||||||
|
. makeDeviceName( $decode_json->{name} )
|
||||||
|
. " NUKIDevice $decode_json->{nukiId} $decode_json->{deviceType}";
|
||||||
|
}
|
||||||
|
|
||||||
|
Log3( $name, 5, "NUKIDevice ($name) - parse status message for $name" );
|
||||||
|
|
||||||
NUKIDevice_WriteReadings( $hash, $decode_json );
|
NUKIDevice_WriteReadings( $hash, $decode_json );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_WriteReadings($$) {
|
sub NUKIDevice_WriteReadings($$) {
|
||||||
|
|
||||||
my ( $hash, $decode_json ) = @_;
|
my ( $hash, $decode_json ) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
#### Status des Smartlock
|
#### Status des Smartlock
|
||||||
|
|
||||||
my $battery;
|
if ( defined( $hash->{helper}{lockAction} ) ) {
|
||||||
if( defined($decode_json->{batteryCritical}) ) {
|
my $state;
|
||||||
if( $decode_json->{batteryCritical} eq "false" or $decode_json->{batteryCritical} == 0 ) {
|
|
||||||
$battery = "ok";
|
if (
|
||||||
} elsif ( $decode_json->{batteryCritical} eq "true" or $decode_json->{batteryCritical} == 1 ) {
|
defined( $decode_json->{success} )
|
||||||
$battery = "low";
|
and ( $decode_json->{success} eq 'true'
|
||||||
|
or $decode_json->{success} == 1 )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$state = $hash->{helper}{lockAction};
|
||||||
|
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID} )
|
||||||
|
if (
|
||||||
|
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
|
||||||
|
eq 'Software' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
elsif (
|
||||||
|
defined( $decode_json->{success} )
|
||||||
|
and ( $decode_json->{success} eq 'false'
|
||||||
|
or $decode_json->{success} == 0 )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
$state = $deviceTypes{ $hash->{DEVICETYPE} } . ' response error';
|
||||||
|
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID},
|
||||||
|
$hash->{DEVICETYPE} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$decode_json->{'state'} = $state;
|
||||||
|
delete $hash->{helper}{lockAction};
|
||||||
|
}
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
if( defined($hash->{helper}{lockAction}) ) {
|
my $t;
|
||||||
|
my $v;
|
||||||
|
|
||||||
my ($state,$lockState);
|
if ( defined( $decode_json->{lastKnownState} )
|
||||||
|
and ref( $decode_json->{lastKnownState} ) eq 'HASH' )
|
||||||
|
{
|
||||||
if( defined($decode_json->{success}) and ($decode_json->{success} eq "true" or $decode_json->{success} eq "1") ) {
|
while ( ( $t, $v ) = each %{ $decode_json->{lastKnownState} } ) {
|
||||||
|
$decode_json->{$t} = $v;
|
||||||
$state = $hash->{helper}{lockAction};
|
|
||||||
$lockState = $hash->{helper}{lockAction};
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} ) if( ReadingsVal($hash->{IODev}->{NAME},'bridgeType','Software') eq 'Software' );
|
|
||||||
|
|
||||||
} elsif ( defined($decode_json->{success}) and ($decode_json->{success} eq "false" or $decode_json->{success} eq "0") ) {
|
|
||||||
|
|
||||||
$state = "error";
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "state", $state );
|
delete $decode_json->{lastKnownState};
|
||||||
readingsBulkUpdate( $hash, "lockState", $lockState );
|
}
|
||||||
readingsBulkUpdate( $hash, "success", $decode_json->{success} );
|
|
||||||
|
|
||||||
|
while ( ( $t, $v ) = each %{$decode_json} ) {
|
||||||
delete $hash->{helper}{lockAction};
|
readingsBulkUpdate( $hash, $t, $v )
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - lockAction readings set for $name";
|
unless ( $t eq 'state'
|
||||||
|
or $t eq 'mode'
|
||||||
} else {
|
or $t eq 'deviceType'
|
||||||
|
or $t eq 'paired'
|
||||||
readingsBulkUpdate( $hash, "batteryCritical", $decode_json->{batteryCritical} );
|
or $t eq 'batteryCritical'
|
||||||
readingsBulkUpdate( $hash, "lockState", $decode_json->{stateName} );
|
or $t eq 'timestamp' );
|
||||||
readingsBulkUpdate( $hash, "state", $decode_json->{stateName} );
|
readingsBulkUpdate( $hash, $t,
|
||||||
readingsBulkUpdate( $hash, "battery", $battery );
|
( $v =~ m/^[0-9]$/ ? $lockStates{$v}{ $hash->{DEVICETYPE} } : $v ) )
|
||||||
readingsBulkUpdate( $hash, "batteryState", $battery );
|
if ( $t eq 'state' );
|
||||||
readingsBulkUpdate( $hash, "success", $decode_json->{success} );
|
readingsBulkUpdate( $hash, $t, $modes{$v}{ $hash->{DEVICETYPE} } )
|
||||||
|
if ( $t eq 'mode' );
|
||||||
readingsBulkUpdate( $hash, "name", $decode_json->{name} );
|
readingsBulkUpdate( $hash, $t, $deviceTypes{$v} )
|
||||||
readingsBulkUpdate( $hash, "rssi", $decode_json->{rssi} );
|
if ( $t eq 'deviceType' );
|
||||||
readingsBulkUpdate( $hash, "paired", $decode_json->{paired} );
|
readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) )
|
||||||
|
if ( $t eq 'paired' );
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - readings set for $name";
|
readingsBulkUpdate( $hash, 'batteryState',
|
||||||
|
( ( $v eq 'true' or $v == 1 ) ? 'low' : 'ok' ) )
|
||||||
|
if ( $t eq 'batteryCritical' );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3( $name, 5, "NUKIDevice ($name) - lockAction readings set for $name" );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_CGI() {
|
|
||||||
|
|
||||||
my ($request) = @_;
|
|
||||||
|
|
||||||
my $hash;
|
|
||||||
my $name;
|
|
||||||
my $nukiId;
|
|
||||||
|
|
||||||
|
|
||||||
# data received
|
|
||||||
# Testaufruf:
|
|
||||||
# curl --data '{"nukiId": 123456, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-123456
|
|
||||||
# wget --post-data '{"nukiId": 123456, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-123456
|
|
||||||
|
|
||||||
|
|
||||||
my $header = join("\n", @FW_httpheader);
|
|
||||||
|
|
||||||
my ($first,$json) = split("&",$request,2);
|
|
||||||
|
|
||||||
if( !$json ) {
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - empty answer received";
|
|
||||||
return undef;
|
|
||||||
} elsif( $json =~ m'HTTP/1.1 200 OK' ) {
|
|
||||||
Log3 $name, 4, "NUKIDevice ($name) - empty answer received";
|
|
||||||
return undef;
|
|
||||||
} elsif( $json !~ m/^[\[{].*[}\]]$/ ) {
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - invalid json detected: $json";
|
|
||||||
return "NUKIDevice ($name) - invalid json detected: $json";
|
|
||||||
}
|
|
||||||
|
|
||||||
my $decode_json = eval{decode_json($json)};
|
|
||||||
if($@){
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - JSON error while request: $@";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( ref($decode_json) eq "HASH" ) {
|
|
||||||
if ( defined( $modules{NUKIDevice}{defptr} ) ) {
|
|
||||||
while ( my ( $key, $value ) = each %{ $modules{NUKIDevice}{defptr} } ) {
|
|
||||||
|
|
||||||
$hash = $modules{NUKIDevice}{defptr}{$key};
|
|
||||||
$name = $hash->{NAME};
|
|
||||||
$nukiId = InternalVal( $name, "NUKIID", undef );
|
|
||||||
next if ( !$nukiId or $nukiId ne $decode_json->{nukiId} );
|
|
||||||
|
|
||||||
$hash->{WEBHOOK_COUNTER}++;
|
|
||||||
$hash->{WEBHOOK_LAST} = TimeNow();
|
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIDevice ($name) - Received webhook for matching NukiId at device $name";
|
|
||||||
|
|
||||||
NUKIDevice_Parse($hash,$json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( undef, undef );
|
|
||||||
}
|
|
||||||
|
|
||||||
# no data received
|
|
||||||
else {
|
|
||||||
|
|
||||||
Log3 undef, 4, "NUKIDevice - received malformed request\n$request";
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( "text/plain; charset=utf-8", "Call failure: " . $request );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
=item device
|
=item device
|
||||||
=item summary Modul to control the Nuki Smartlock's
|
=item summary Modul to control the Nuki Smartlock's
|
||||||
@ -589,17 +552,19 @@ sub NUKIDevice_CGI() {
|
|||||||
<ul>
|
<ul>
|
||||||
<u><b>NUKIDevice - Controls the Nuki Smartlock</b></u>
|
<u><b>NUKIDevice - Controls the Nuki Smartlock</b></u>
|
||||||
<br>
|
<br>
|
||||||
The Nuki module connects FHEM over the Nuki Bridge with a Nuki Smartlock. After that, it´s possible to lock and unlock the Smartlock.<br>
|
The Nuki module connects FHEM over the Nuki Bridge with a Nuki Smartlock or Nuki Opener. After that, it´s possible to lock and unlock the Smartlock.<br>
|
||||||
Normally the Nuki devices are automatically created by the bridge module.
|
Normally the Nuki devices are automatically created by the bridge module.
|
||||||
<br><br>
|
<br><br>
|
||||||
<a name="NUKIDevicedefine"></a>
|
<a name="NUKIDevicedefine"></a>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul><br>
|
<ul><br>
|
||||||
<code>define <name> NUKIDevice <Nuki-Id> <IODev-Device></code>
|
<code>define <name> NUKIDevice <Nuki-Id> <IODev-Device> <Device-Type></code>
|
||||||
|
<br><br>
|
||||||
|
Device-Type is 0 for the Smartlock and 2 for the Opener.
|
||||||
<br><br>
|
<br><br>
|
||||||
Example:
|
Example:
|
||||||
<ul><br>
|
<ul><br>
|
||||||
<code>define Frontdoor NUKIDevice 1 NBridge1</code><br>
|
<code>define Frontdoor NUKIDevice 1 NBridge1 0</code><br>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
This statement creates a NUKIDevice with the name Frontdoor, the NukiId 1 and the IODev device NBridge1.<br>
|
This statement creates a NUKIDevice with the name Frontdoor, the NukiId 1 and the IODev device NBridge1.<br>
|
||||||
@ -636,8 +601,6 @@ sub NUKIDevice_CGI() {
|
|||||||
<b>Attributes</b>
|
<b>Attributes</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>disable - disables the Nuki device</li>
|
<li>disable - disables the Nuki device</li>
|
||||||
<li>webhookFWinstance - Webinstanz of the Callback</li>
|
|
||||||
<li>webhookHttpHostname - IP or FQDN of the FHEM Server Callback</li>
|
|
||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
@ -650,17 +613,19 @@ sub NUKIDevice_CGI() {
|
|||||||
<ul>
|
<ul>
|
||||||
<u><b>NUKIDevice - Steuert das Nuki Smartlock</b></u>
|
<u><b>NUKIDevice - Steuert das Nuki Smartlock</b></u>
|
||||||
<br>
|
<br>
|
||||||
Das Nuki Modul verbindet FHEM über die Nuki Bridge mit einem Nuki Smartlock. Es ist dann möglich das Schloss zu ver- und entriegeln.<br>
|
Das Nuki Modul verbindet FHEM über die Nuki Bridge mit einem Nuki Smartlock oder Nuki Opener. Es ist dann möglich das Schloss zu ver- und entriegeln.<br>
|
||||||
In der Regel werden die Nuki Devices automatisch durch das Bridgemodul angelegt.
|
In der Regel werden die Nuki Devices automatisch durch das Bridgemodul angelegt.
|
||||||
<br><br>
|
<br><br>
|
||||||
<a name="NUKIDevicedefine"></a>
|
<a name="NUKIDevicedefine"></a>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul><br>
|
<ul><br>
|
||||||
<code>define <name> NUKIDevice <Nuki-Id> <IODev-Device></code>
|
<code>define <name> NUKIDevice <Nuki-Id> <IODev-Device> <Device-Type></code>
|
||||||
|
<br><br>
|
||||||
|
Device-Type ist 0 für das Smartlock und 2 f&üuml;r den Opener.
|
||||||
<br><br>
|
<br><br>
|
||||||
Beispiel:
|
Beispiel:
|
||||||
<ul><br>
|
<ul><br>
|
||||||
<code>define Haustür NUKIDevice 1 NBridge1</code><br>
|
<code>define Haustür NUKIDevice 1 NBridge1 0</code><br>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
Diese Anweisung erstellt ein NUKIDevice mit Namen Haustür, der NukiId 1 sowie dem IODev Device NBridge1.<br>
|
Diese Anweisung erstellt ein NUKIDevice mit Namen Haustür, der NukiId 1 sowie dem IODev Device NBridge1.<br>
|
||||||
@ -697,8 +662,6 @@ sub NUKIDevice_CGI() {
|
|||||||
<b>Attribute</b>
|
<b>Attribute</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>disable - deaktiviert das Nuki Device</li>
|
<li>disable - deaktiviert das Nuki Device</li>
|
||||||
<li>webhookFWinstance - zu verwendene Webinstanz für den Callbackaufruf</li>
|
|
||||||
<li>webhookHttpHostname - IP oder FQDN vom FHEM Server für den Callbackaufruf</li>
|
|
||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user