mod-NUKI/73_NUKIBridge.pm

1272 lines
37 KiB
Perl
Raw Normal View History

2016-09-27 11:37:19 +00:00
###############################################################################
2020-01-09 21:02:41 +00:00
#
2016-09-27 11:37:19 +00:00
# Developed with Kate
#
2020-01-08 12:26:22 +00:00
# (c) 2016-2020 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
2016-09-27 11:37:19 +00:00
# All rights reserved
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# The GNU General Public License can be found at
# http://www.gnu.org/copyleft/gpl.html.
# A copy is found in the textfile GPL.txt and important notices to the license
# from the author is found in LICENSE.txt distributed with these scripts.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# $Id$
#
###############################################################################
2016-10-30 12:45:03 +00:00
#################################
######### Wichtige Hinweise und Links #################
## Beispiel für Logausgabe
# https://forum.fhem.de/index.php/topic,55756.msg508412.html#msg508412
##
#
################################
2016-09-27 11:37:19 +00:00
package main;
use strict;
use warnings;
use HttpUtils;
# 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;
};
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;
}
}
}
}
}
2020-01-11 11:08:35 +00:00
my $version = '0.7.31';
2020-01-09 21:02:41 +00:00
my $bridgeapi = '1.9';
2016-09-27 11:37:19 +00:00
my %bridgeType = (
'1' => 'Hardware',
'2' => 'Software'
);
2019-12-21 20:52:18 +00:00
my %lockActionsSmartLock = (
2020-01-09 21:02:41 +00:00
'unlock' => 1,
'lock' => 2,
'unlatch' => 3,
'locknGo' => 4,
'locknGoWithUnlatch' => 5
2019-12-21 20:52:18 +00:00
);
my %lockActionsOpener = (
'activateRto' => 1,
'deactivateRto' => 2,
'electricStrikeActuation' => 3,
'activateContinuousMode' => 4,
'deactivateContinuousMode' => 5
2016-09-27 11:37:19 +00:00
);
2017-01-17 05:18:25 +00:00
# Declare functions
sub NUKIBridge_Initialize ($);
sub NUKIBridge_Define ($$);
sub NUKIBridge_Undef ($$);
sub NUKIBridge_Read($@);
sub NUKIBridge_Attr(@);
sub NUKIBridge_addExtension($$$);
sub NUKIBridge_removeExtension($);
2017-01-17 05:18:25 +00:00
sub NUKIBridge_Set($@);
sub NUKIBridge_Get($@);
sub NUKIBridge_GetCheckBridgeAlive($);
sub NUKIBridge_firstRun($);
2020-01-08 15:30:42 +00:00
sub NUKIBridge_Write($@);
2020-01-11 11:08:35 +00:00
sub NUKIBridge_Call($);
2017-01-17 05:18:25 +00:00
sub NUKIBridge_Distribution($$$);
sub NUKIBridge_ResponseProcessing($$$);
sub NUKIBridge_CGI();
2017-01-17 05:18:25 +00:00
sub NUKIBridge_Autocreate($$;$);
sub NUKIBridge_InfoProcessing($$);
sub NUKIBridge_getLogfile($);
sub NUKIBridge_getCallbackList($);
2020-01-08 22:24:01 +00:00
sub NUKIBridge_CallBlocking($@);
2017-01-17 05:18:25 +00:00
2016-09-27 11:37:19 +00:00
sub NUKIBridge_Initialize($) {
my ($hash) = @_;
2020-01-08 12:26:22 +00:00
2016-09-27 11:37:19 +00:00
# Provider
2020-01-09 21:02:41 +00:00
$hash->{WriteFn} = 'NUKIBridge_Write';
$hash->{Clients} = ':NUKIDevice:';
$hash->{MatchList} = { '1:NUKIDevice' => '^{.*}$' };
my $webhookFWinstance =
2020-01-10 18:46:30 +00:00
join( ",", devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') );
2016-09-27 11:37:19 +00:00
# Consumer
2020-01-09 21:02:41 +00:00
$hash->{SetFn} = 'NUKIBridge_Set';
$hash->{GetFn} = 'NUKIBridge_Get';
$hash->{DefFn} = 'NUKIBridge_Define';
$hash->{UndefFn} = 'NUKIBridge_Undef';
$hash->{AttrFn} = 'NUKIBridge_Attr';
$hash->{AttrList} =
'disable:1 '
. 'webhookFWinstance:'
. $webhookFWinstance . ' '
. 'webhookHttpHostname '
. $readingFnAttributes;
foreach my $d ( sort keys %{ $modules{NUKIBridge}{defptr} } ) {
my $hash = $modules{NUKIBridge}{defptr}{$d};
$hash->{VERSION} = $version;
2016-09-27 11:37:19 +00:00
}
}
sub NUKIBridge_Define($$) {
my ( $hash, $def ) = @_;
2020-01-09 21:02:41 +00:00
2016-09-27 11:37:19 +00:00
my @a = split( "[ \t][ \t]*", $def );
2020-01-09 21:02:41 +00:00
return ('too few parameters: define <name> NUKIBridge <HOST> <TOKEN>')
if ( @a != 4 );
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
my $name = $a[0];
my $host = $a[2];
my $token = $a[3];
my $port = 8080;
2020-01-11 11:08:35 +00:00
$hash->{HOST} = $host;
$hash->{PORT} = $port;
$hash->{TOKEN} = $token;
$hash->{VERSION} = $version;
$hash->{BRIDGEAPI} = $bridgeapi;
$hash->{helper}->{aliveCount} = 0;
$hash->{helper}->{actionQueue} = [];
2020-01-09 21:02:41 +00:00
my $infix = 'NUKIBridge';
Log3( $name, 3,
"NUKIBridge ($name) - defined with host $host on port $port, Token $token"
);
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
CommandAttr( undef, $name . ' room NUKI' )
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
if (
NUKIBridge_addExtension(
$name, 'NUKIBridge_CGI', $infix . "-" . $host
)
)
{
$hash->{fhem}{infix} = $infix;
}
$hash->{WEBHOOK_REGISTER} = "unregistered";
2020-01-09 21:02:41 +00:00
readingsSingleUpdate( $hash, 'state', 'Initialized', 1 );
2016-09-27 11:37:19 +00:00
RemoveInternalTimer($hash);
2020-01-09 21:02:41 +00:00
if ($init_done) {
NUKIBridge_firstRun($hash)
if ( ( $hash->{HOST} ) and ( $hash->{TOKEN} ) );
}
else {
InternalTimer( gettimeofday() + 15, 'NUKIBridge_firstRun', $hash )
if ( ( $hash->{HOST} ) and ( $hash->{TOKEN} ) );
2016-11-13 09:44:02 +00:00
}
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
$modules{NUKIBridge}{defptr}{ $hash->{HOST} } = $hash;
2016-09-27 11:37:19 +00:00
return undef;
}
sub NUKIBridge_Undef($$) {
my ( $hash, $arg ) = @_;
2016-09-27 11:37:19 +00:00
my $host = $hash->{HOST};
my $name = $hash->{NAME};
if ( defined( $hash->{fhem}{infix} ) ) {
NUKIBridge_removeExtension( $hash->{fhem}{infix} );
}
2020-01-09 21:02:41 +00:00
RemoveInternalTimer($hash);
delete $modules{NUKIBridge}{defptr}{ $hash->{HOST} };
2016-09-27 11:37:19 +00:00
return undef;
}
sub NUKIBridge_Attr(@) {
my ( $cmd, $name, $attrName, $attrVal ) = @_;
2016-09-27 11:37:19 +00:00
my $hash = $defs{$name};
my $orig = $attrVal;
2020-01-09 21:02:41 +00:00
if ( $attrName eq 'disable' ) {
if ( $cmd eq 'set' and $attrVal == 1 ) {
2020-01-09 21:02:41 +00:00
readingsSingleUpdate( $hash, 'state', 'disabled', 1 );
Log3( $name, 3, "NUKIBridge ($name) - disabled" );
}
elsif ( $cmd eq 'del' ) {
2020-01-09 21:02:41 +00:00
readingsSingleUpdate( $hash, 'state', 'active', 1 );
Log3( $name, 3, "NUKIBridge ($name) - enabled" );
2016-09-27 11:37:19 +00:00
}
}
if ( $attrName eq 'disabledForIntervals' ) {
if ( $cmd eq 'set' ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3,
"NUKIBridge ($name) - enable disabledForIntervals" );
readingsSingleUpdate( $hash, 'state', 'Unknown', 1 );
}
elsif ( $cmd eq 'del' ) {
2020-01-09 21:02:41 +00:00
readingsSingleUpdate( $hash, 'state', 'active', 1 );
Log3( $name, 3,
"NUKIBridge ($name) - delete disabledForIntervals" );
2016-11-03 16:58:01 +00:00
}
}
######################
#### webhook #########
2020-01-09 21:02:41 +00:00
return (
"Invalid value for attribute $attrName: can only by FQDN or IPv4 or IPv6 address"
)
if ( $attrVal
and $attrName eq 'webhookHttpHostname'
and $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
and $attrName eq 'webhookFWinstance'
and
( !defined( $defs{$attrVal} ) or $defs{$attrVal}{TYPE} ne 'FHEMWEB' ) );
2020-01-09 21:02:41 +00:00
return (
"Invalid value for attribute $attrName: needs to be an integer value")
if ( $attrVal and $attrName eq 'webhookPort' and $attrVal !~ /^\d+$/ );
if ( $attrName =~ /^webhook.*/ ) {
2020-01-09 21:02:41 +00:00
my $webhookHttpHostname = (
$attrName eq 'webhookHttpHostname'
2020-01-09 21:02:41 +00:00
? $attrVal
: AttrVal( $name, 'webhookHttpHostname', '' )
);
my $webhookFWinstance = (
$attrName eq 'webhookFWinstance'
2020-01-09 21:02:41 +00:00
? $attrVal
: AttrVal( $name, 'webhookFWinstance', '' )
);
2020-01-09 21:02:41 +00:00
$hash->{WEBHOOK_URI} = '/'
. AttrVal( $webhookFWinstance, 'webname', 'fhem' )
. '/NUKIBridge' . '-'
. $hash->{HOST};
$hash->{WEBHOOK_PORT} = (
$attrName eq 'webhookPort' ? $attrVal : AttrVal(
$name, 'webhookPort',
InternalVal( $webhookFWinstance, 'PORT', '' )
)
);
$hash->{WEBHOOK_URL} = '';
$hash->{WEBHOOK_COUNTER} = 0;
2020-01-09 21:02:41 +00:00
if ( $webhookHttpHostname ne '' and $hash->{WEBHOOK_PORT} ne '' ) {
2020-01-09 21:02:41 +00:00
$hash->{WEBHOOK_URL} =
'http://'
. $webhookHttpHostname . ':'
. $hash->{WEBHOOK_PORT}
. $hash->{WEBHOOK_URI};
my $url =
'http://'
. $webhookHttpHostname . ':'
. $hash->{WEBHOOK_PORT}
. $hash->{WEBHOOK_URI};
Log3( $name, 3, "NUKIBridge ($name) - URL ist: $url" );
NUKIBridge_Write( $hash, 'callback/add', $url, undef, undef )
if ($init_done);
$hash->{WEBHOOK_REGISTER} = 'sent';
}
else {
$hash->{WEBHOOK_REGISTER} = 'incomplete_attributes';
}
}
2016-09-27 11:37:19 +00:00
return undef;
}
sub NUKIBridge_addExtension($$$) {
my ( $name, $func, $link ) = @_;
my $url = '/' . $link;
2020-01-09 21:02:41 +00:00
Log3( $name, 2,
"NUKIBridge ($name) - Registering NUKIBridge for webhook URI $url ..."
);
$data{FWEXT}{$url}{deviceName} = $name;
$data{FWEXT}{$url}{FUNC} = $func;
$data{FWEXT}{$url}{LINK} = $link;
return 1;
}
sub NUKIBridge_removeExtension($) {
my ($link) = @_;
my $url = '/' . $link;
my $name = $data{FWEXT}{$url}{deviceName};
2020-01-09 21:02:41 +00:00
Log3( $name, 2,
"NUKIBridge ($name) - Unregistering NUKIBridge for webhook URL $url..."
);
delete $data{FWEXT}{$url};
}
2016-09-27 11:37:19 +00:00
sub NUKIBridge_Set($@) {
2020-01-09 21:02:41 +00:00
my ( $hash, $name, $cmd, @args ) = @_;
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
my ( $arg, @params ) = @args;
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
if ( lc($cmd) eq 'getdevicelist' ) {
return 'usage: getDeviceList' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_Write( $hash, "list", undef, undef, undef )
if ( !IsDisabled($name) );
2016-09-27 11:37:19 +00:00
return undef;
}
2020-01-09 21:02:41 +00:00
elsif ( $cmd eq 'info' ) {
return 'usage: statusRequest' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_Write( $hash, "info", undef, undef, undef )
if ( !IsDisabled($name) );
return undef;
}
2020-01-09 21:02:41 +00:00
elsif ( lc($cmd) eq 'fwupdate' ) {
return 'usage: fwUpdate' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_CallBlocking( $hash, "fwupdate", undef )
if ( !IsDisabled($name) );
2016-11-03 16:58:01 +00:00
return undef;
}
2020-01-09 21:02:41 +00:00
elsif ( $cmd eq 'reboot' ) {
return 'usage: reboot' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_CallBlocking( $hash, "reboot", undef )
if ( !IsDisabled($name) );
2016-11-03 16:58:01 +00:00
return undef;
}
2020-01-09 21:02:41 +00:00
elsif ( lc($cmd) eq 'clearlog' ) {
return 'usage: clearLog' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_CallBlocking( $hash, "clearlog", undef )
if ( !IsDisabled($name) );
}
2020-01-09 21:02:41 +00:00
elsif ( lc($cmd) eq 'factoryreset' ) {
return 'usage: clearLog' if ( @args != 0 );
2020-01-09 21:02:41 +00:00
NUKIBridge_CallBlocking( $hash, "factoryReset", undef )
if ( !IsDisabled($name) );
}
2020-01-09 21:02:41 +00:00
elsif ( lc($cmd) eq 'callbackremove' ) {
return 'usage: callbackRemove' if ( @args > 1 );
2016-09-27 11:37:19 +00:00
2020-01-09 21:02:41 +00:00
my $id = "id=" . ( @args > 0 ? join( ' ', @args ) : 0 );
my $resp = NUKIBridge_CallBlocking( $hash, 'callback/remove', $id )
if ( !IsDisabled($name) );
2020-01-09 21:02:41 +00:00
if (
(
$resp->{success} eq 'true'
or $resp->{success} == 1
)
and !IsDisabled($name)
)
{
2020-01-09 21:02:41 +00:00
return ( 'Success Callback ' . $id . ' removed' );
}
else {
2020-01-09 21:02:41 +00:00
return ('remove Callback failed');
}
}
else {
2020-01-09 21:02:41 +00:00
my $list = '';
$list .= 'info:noArg getDeviceList:noArg callbackRemove:noArg ';
$list .= 'clearLog:noArg fwUpdate:noArg reboot:noArg factoryReset:noArg'
2020-01-09 21:02:41 +00:00
if ( ReadingsVal( $name, 'bridgeType', 'Software' ) eq 'Hardware' );
return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list );
2016-09-27 11:37:19 +00:00
}
}
2016-10-30 21:24:52 +00:00
sub NUKIBridge_Get($@) {
2020-01-09 21:02:41 +00:00
my ( $hash, $name, $cmd, @args ) = @_;
my ( $arg, @params ) = @args;
2020-01-09 21:02:41 +00:00
if ( lc($cmd) eq 'logfile' ) {
return 'usage: logFile' if ( @args != 0 );
2016-10-30 21:24:52 +00:00
NUKIBridge_getLogfile($hash) if ( !IsDisabled($name) );
}
2020-01-09 21:02:41 +00:00
elsif ( lc($cmd) eq 'callbacklist' ) {
return 'usage: callbackList' if ( @args != 0 );
NUKIBridge_getCallbackList($hash) if ( !IsDisabled($name) );
}
else {
my $list = '';
$list .= 'callbackList:noArg ';
$list .= 'logFile:noArg'
2020-01-09 21:02:41 +00:00
if ( ReadingsVal( $name, 'bridgeType', 'Software' ) eq 'Hardware' );
return 'Unknown argument ' . $cmd . ', choose one of ' . $list;
2016-10-30 21:24:52 +00:00
}
}
sub NUKIBridge_GetCheckBridgeAlive($) {
2016-09-27 11:37:19 +00:00
my ($hash) = @_;
2016-09-27 11:37:19 +00:00
my $name = $hash->{NAME};
2020-01-09 21:02:41 +00:00
2017-01-10 20:02:39 +00:00
RemoveInternalTimer($hash);
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge ($name) - NUKIBridge_GetCheckBridgeAlive" );
2020-01-11 11:08:35 +00:00
if ( !IsDisabled($name) ) {
2020-01-09 21:02:41 +00:00
NUKIBridge_Write( $hash, 'info', undef, undef, undef );
Log3( $name, 4, "NUKIBridge ($name) - run NUKIBridge_Write" );
}
2020-01-09 21:02:41 +00:00
InternalTimer( gettimeofday() + 15 + int( rand(15) ),
'NUKIBridge_GetCheckBridgeAlive', $hash );
Log3( $name, 4,
"NUKIBridge ($name) - Call InternalTimer for NUKIBridge_GetCheckBridgeAlive"
);
}
sub NUKIBridge_firstRun($) {
my ($hash) = @_;
2020-01-09 21:02:41 +00:00
my $name = $hash->{NAME};
2017-01-10 20:02:39 +00:00
RemoveInternalTimer($hash);
2020-01-09 21:02:41 +00:00
NUKIBridge_Write( $hash, 'list', undef, undef, undef )
if ( !IsDisabled($name) );
InternalTimer( gettimeofday() + 15,
'NUKIBridge_GetCheckBridgeAlive', $hash );
return undef;
2016-09-27 11:37:19 +00:00
}
2020-01-08 15:30:42 +00:00
sub NUKIBridge_Write($@) {
2020-01-11 11:08:35 +00:00
my ( $hash, $endpoint, $param, $nukiId, $deviceType ) = @_;
2016-09-27 11:37:19 +00:00
2020-01-11 11:08:35 +00:00
my $obj = {
endpoint => $endpoint,
param => $param,
nukiId => $nukiId,
deviceType => $deviceType
};
$hash->{helper}->{lastDeviceAction} = $obj
if ( defined($param)
and $param );
unshift( @{ $hash->{helper}->{actionQueue} }, $obj );
NUKIBridge_Call($hash);
}
sub NUKIBridge_CreateUri($$) {
my ( $hash, $obj ) = @_;
2016-09-27 11:37:19 +00:00
2020-01-11 11:08:35 +00:00
my $host = $hash->{HOST};
my $port = $hash->{PORT};
my $token = $hash->{TOKEN};
my $endpoint = $obj->{endpoint};
my $param = $obj->{param};
my $nukiId = $obj->{nukiId};
my $deviceType = $obj->{deviceType};
my $uri = 'http://' . $host . ':' . $port;
$uri .= '/' . $endpoint if ( defined $endpoint );
$uri .= '?token=' . $token if ( defined($token) );
2020-01-11 11:08:35 +00:00
$uri .= '&action=' . $lockActionsSmartLock{$param}
if ( defined($param)
and $param ne 'callback/add'
and $deviceType == 0 );
2020-01-11 11:08:35 +00:00
$uri .= '&action=' . $lockActionsOpener{$param}
if ( defined($param)
and $param ne 'callback/add'
and $deviceType == 2 );
2020-01-11 11:08:35 +00:00
$uri .= '&url=' . $param
if ( defined($param)
and $param eq 'callback/add' );
$uri .= '&nukiId=' . $nukiId
if ( defined($nukiId) );
$uri .= '&deviceType=' . $deviceType
if ( defined($deviceType) );
2020-01-11 11:08:35 +00:00
return $uri;
}
sub NUKIBridge_Call($) {
my $hash = shift;
my $name = $hash->{NAME};
my $obj = pop( @{ $hash->{helper}->{actionQueue} } );
my $endpoint = $obj->{endpoint};
my $nukiId = $obj->{nukiId};
my $uri = NUKIBridge_CreateUri( $hash, $obj );
2016-09-27 11:37:19 +00:00
HttpUtils_NonblockingGet(
{
2020-01-09 21:02:41 +00:00
url => $uri,
timeout => 60,
hash => $hash,
nukiId => $nukiId,
2020-01-11 11:08:35 +00:00
endpoint => $endpoint,
2020-01-09 21:02:41 +00:00
header => 'Accept: application/json',
method => 'GET',
callback => \&NUKIBridge_Distribution,
}
2016-09-27 11:37:19 +00:00
);
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge ($name) - Send HTTP POST with URL $uri" );
2016-09-27 11:37:19 +00:00
}
2016-11-01 12:39:13 +00:00
sub NUKIBridge_Distribution($$$) {
2016-09-27 11:37:19 +00:00
my ( $param, $err, $json ) = @_;
2020-01-09 21:02:41 +00:00
my $hash = $param->{hash};
my $doTrigger = $param->{doTrigger};
my $name = $hash->{NAME};
my $host = $hash->{HOST};
2020-01-08 15:30:42 +00:00
my $dhash = $hash;
$dhash = $modules{NUKIDevice}{defptr}{ $param->{'nukiId'} }
unless ( not defined( $param->{'nukiId'} ) );
my $dname = $dhash->{NAME};
2020-01-09 21:02:41 +00:00
Log3( $name, 5, "NUKIBridge ($name) - Response JSON: $json" );
Log3( $name, 5, "NUKIBridge ($name) - Response ERROR: $err" );
Log3( $name, 5, "NUKIBridge ($name) - Response CODE: $param->{code}" )
if ( defined( $param->{code} ) and ( $param->{code} ) );
readingsBeginUpdate($hash);
2020-01-09 21:02:41 +00:00
if ( defined($err) ) {
if ( $err ne '' ) {
2020-01-09 21:02:41 +00:00
if ( $param->{endpoint} eq 'info' ) {
readingsBulkUpdate( $hash, 'state', 'not connected' )
if ( $hash->{helper}{aliveCount} > 1 );
2020-01-09 21:02:41 +00:00
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist offline" );
$hash->{helper}{aliveCount} = $hash->{helper}{aliveCount} + 1;
}
readingsBulkUpdate( $hash, 'lastError', $err )
2020-01-09 21:02:41 +00:00
if ( ReadingsVal( $name, 'state', 'not connected' ) eq
'not connected' );
2020-01-09 21:02:41 +00:00
Log3( $name, 4,
"NUKIBridge ($name) - error while requesting: $err" );
readingsEndUpdate( $hash, 1 );
return $err;
}
2016-09-27 11:37:19 +00:00
}
2020-01-09 21:02:41 +00:00
if ( ( $json eq '' or $json =~ /Unavailable/i )
and exists( $param->{code} )
and $param->{code} != 200 )
{
if ( $param->{code} == 503 and $json eq 'HTTP 503 Unavailable' ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 4,
"NUKIBridge ($name) - Response from Bridge: $param->{code}, $json"
);
2017-01-17 05:18:25 +00:00
readingsEndUpdate( $hash, 1 );
2020-01-11 11:08:35 +00:00
if ( defined( $hash->{helper}->{lastDeviceAction} )
and $hash->{helper}->{lastDeviceAction} )
{
push(
@{ $hash->{helper}->{actionQueue} },
$hash->{helper}->{lastDeviceAction}
);
delete $hash->{helper}->{lastDeviceAction};
InternalTimer( gettimeofday() + 1, 'NUKIBridge_Call', $hash );
}
return;
2017-01-17 05:18:25 +00:00
}
2020-01-09 21:02:41 +00:00
readingsBulkUpdate( $hash, 'lastError',
'Internal error, ' . $param->{code} );
Log3( $name, 4,
"NUKIBridge ($name) - received http code "
. $param->{code}
. " without any data after requesting" );
2016-09-27 11:37:19 +00:00
readingsEndUpdate( $hash, 1 );
2020-01-09 21:02:41 +00:00
return ('received http code '
. $param->{code}
. ' without any data after requesting' );
2016-09-27 11:37:19 +00:00
}
2020-01-09 21:02:41 +00:00
if ( ( $json =~ /Error/i ) and exists( $param->{code} ) ) {
readingsBulkUpdate( $hash, 'lastError', 'invalid API token' )
if ( $param->{code} == 401 );
readingsBulkUpdate( $hash, 'lastError', 'action is undefined' )
if ( $param->{code} == 400 and $hash == $dhash );
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge ($name) - invalid API token" )
if ( $param->{code} == 401 );
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge ($name) - nukiId is not known" )
if ( $param->{code} == 404 );
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge ($name) - action is undefined" )
if ( $param->{code} == 400 and $hash == $dhash );
readingsEndUpdate( $hash, 1 );
return $param->{code};
}
2020-01-09 21:02:41 +00:00
2020-01-11 11:08:35 +00:00
delete $hash->{helper}->{lastDeviceAction}
if ( defined( $hash->{helper}->{lastDeviceAction} )
and $hash->{helper}->{lastDeviceAction} );
2020-01-08 15:30:42 +00:00
readingsEndUpdate( $hash, 1 );
2020-01-09 21:02:41 +00:00
if ( $hash == $dhash ) {
2020-01-09 21:02:41 +00:00
NUKIBridge_ResponseProcessing( $hash, $json, $param->{endpoint} );
}
else {
2020-01-09 21:02:41 +00:00
my $decode_json = eval { decode_json($json) };
if ($@) {
Log3( $name, 3,
"NUKIBridge ($name) - JSON error while request: $@" );
2020-01-08 22:24:01 +00:00
return;
}
2020-01-08 22:24:01 +00:00
$decode_json->{nukiId} = $param->{nukiId};
$json = encode_json($decode_json);
2020-01-09 21:02:41 +00:00
Dispatch( $hash, $json, undef );
2016-09-27 11:37:19 +00:00
}
2020-01-11 11:08:35 +00:00
InternalTimer( gettimeofday() + 1, 'NUKIBridge_Call', $hash )
if ( defined( $hash->{helper}->{actionQueue} )
and scalar( @{ $hash->{helper}->{actionQueue} } ) > 0 );
return undef;
2016-09-27 11:37:19 +00:00
}
2016-11-03 16:58:01 +00:00
sub NUKIBridge_ResponseProcessing($$$) {
2020-01-11 11:08:35 +00:00
my ( $hash, $json, $endpoint ) = @_;
2016-09-27 11:37:19 +00:00
my $name = $hash->{NAME};
my $decode_json;
if ( !$json ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3, "NUKIBridge ($name) - empty answer received" );
return undef;
2020-01-09 21:02:41 +00:00
}
elsif ( $json =~ m'HTTP/1.1 200 OK' ) {
Log3( $name, 4, "NUKIBridge ($name) - empty answer received" );
return undef;
2020-01-09 21:02:41 +00:00
}
elsif ( $json !~ m/^[\[{].*[}\]]$/ ) {
Log3( $name, 3, "NUKIBridge ($name) - invalid json detected: $json" );
return ("NUKIBridge ($name) - invalid json detected: $json");
}
2020-01-09 21:02:41 +00:00
$decode_json = eval { decode_json($json) };
if ($@) {
Log3( $name, 3, "NUKIBridge ($name) - JSON error while request: $@" );
return;
}
2020-01-09 21:02:41 +00:00
2020-01-11 11:08:35 +00:00
if ( $endpoint eq 'list'
or $endpoint eq 'info' )
{
2020-01-09 21:02:41 +00:00
if (
(
ref($decode_json) eq 'ARRAY'
and scalar( @{$decode_json} ) > 0
2020-01-11 11:08:35 +00:00
and $endpoint eq 'list'
2020-01-09 21:02:41 +00:00
)
or ( ref( $decode_json->{scanResults} ) eq 'ARRAY'
and scalar( @{ $decode_json->{scanResults} } ) > 0
2020-01-11 11:08:35 +00:00
and $endpoint eq 'info' )
2020-01-09 21:02:41 +00:00
)
{
my @buffer;
@buffer = split( '\[', $json )
2020-01-11 11:08:35 +00:00
if ( $endpoint eq 'list' );
2020-01-09 21:02:41 +00:00
@buffer = split( '"scanResults": \[', $json )
2020-01-11 11:08:35 +00:00
if ( $endpoint eq 'info' );
2020-01-09 21:02:41 +00:00
my ( $json, $tail ) = NUKIBridge_ParseJSON( $hash, $buffer[1] );
while ($json) {
Log3( $name, 5,
"NUKIBridge ($name) - Decoding JSON message. Length: "
. length($json)
. " Content: "
. $json );
Log3( $name, 5,
"NUKIBridge ($name) - Vor Sub: Laenge JSON: "
. length($json)
. " Content: "
. $json
. " Tail: "
. $tail );
Dispatch( $hash, $json, undef )
unless ( not defined($tail) and not($tail) );
( $json, $tail ) = NUKIBridge_ParseJSON( $hash, $tail );
Log3( $name, 5,
"NUKIBridge ($name) - Nach Sub: Laenge JSON: "
. length($json)
. " Content: "
. $json
. " Tail: "
. $tail );
}
}
NUKIBridge_InfoProcessing( $hash, $decode_json )
2020-01-11 11:08:35 +00:00
if ( $endpoint eq 'info' );
2020-01-09 21:02:41 +00:00
readingsSingleUpdate( $hash, 'state', 'connected', 1 );
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist online" );
2020-01-09 21:02:41 +00:00
$hash->{helper}{aliveCount} = 0;
}
else {
2020-01-09 21:02:41 +00:00
Log3(
$name, 5, "NUKIBridge ($name) - Rückgabe Path nicht korrekt:
$json"
);
2016-11-03 16:58:01 +00:00
return;
2016-09-27 11:37:19 +00:00
}
return undef;
2016-09-27 11:37:19 +00:00
}
sub NUKIBridge_CGI() {
my ($request) = @_;
2020-01-08 22:24:01 +00:00
my $hash;
my $name;
2020-01-08 22:24:01 +00:00
while ( my ( $key, $value ) = each %{ $modules{NUKIBridge}{defptr} } ) {
$hash = $modules{NUKIBridge}{defptr}{$key};
$name = $hash->{NAME};
}
2020-01-09 21:02:41 +00:00
return ('NUKIBridge WEBHOOK - No IODev found')
unless ( defined($hash) and defined($name) );
2020-01-08 22:24:01 +00:00
2020-01-09 21:02:41 +00:00
my $json = ( split( '&', $request, 2 ) )[1];
if ( !$json ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3, "NUKIBridge WEBHOOK ($name) - empty message received" );
return undef;
}
elsif ( $json =~ m'HTTP/1.1 200 OK' ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIBridge WEBHOOK ($name) - empty answer received" );
return undef;
}
elsif ( $json !~ m/^[\[{].*[}\]]$/ ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3,
"NUKIBridge WEBHOOK ($name) - invalid json detected: $json" );
return ("NUKIBridge WEBHOOK ($name) - invalid json detected: $json");
}
2020-01-08 22:24:01 +00:00
2020-01-09 21:02:41 +00:00
Log3( $name, 5,
"NUKIBridge WEBHOOK ($name) - Webhook received with JSON: $json" );
2020-01-08 22:24:01 +00:00
if ( $json =~ m/^\{.*\}$/ ) {
2019-12-21 20:52:18 +00:00
$hash->{WEBHOOK_COUNTER}++;
$hash->{WEBHOOK_LAST} = TimeNow();
2020-01-09 21:02:41 +00:00
Log3(
$name, 4, "NUKIBridge WEBHOOK ($name) - Received webhook for
matching NukiId at device $name"
);
Dispatch( $hash, $json, undef );
2020-01-08 22:24:01 +00:00
return ( undef, undef );
}
# no data received
else {
2020-01-09 21:02:41 +00:00
Log3( $name, 4,
"NUKIBridge WEBHOOK - received malformed request\n$request" );
}
2020-01-09 21:02:41 +00:00
return ( 'text/plain; charset=utf-8', 'Call failure: ' . $request );
2016-09-27 11:37:19 +00:00
}
2016-11-03 16:58:01 +00:00
sub NUKIBridge_InfoProcessing($$) {
2020-01-09 21:02:41 +00:00
my ( $hash, $decode_json ) = @_;
my $name = $hash->{NAME};
2017-01-17 05:18:25 +00:00
my $nukiId;
my $scanResults;
my %response_hash;
my $dname;
my $dhash;
2020-01-09 21:02:41 +00:00
2016-11-03 16:58:01 +00:00
readingsBeginUpdate($hash);
2020-01-09 21:02:41 +00:00
readingsBulkUpdate( $hash, 'appVersion',
$decode_json->{versions}->{appVersion} );
readingsBulkUpdate( $hash, 'firmwareVersion',
$decode_json->{versions}->{firmwareVersion} );
readingsBulkUpdate( $hash, 'wifiFirmwareVersion',
$decode_json->{versions}->{wifiFirmwareVersion} );
readingsBulkUpdate( $hash, 'bridgeType',
$bridgeType{ $decode_json->{bridgeType} } );
readingsBulkUpdate( $hash, 'hardwareId', $decode_json->{ids}{hardwareId} );
readingsBulkUpdate( $hash, 'serverId', $decode_json->{ids}{serverId} );
readingsBulkUpdate( $hash, 'uptime', $decode_json->{uptime} );
readingsBulkUpdate( $hash, 'currentTime', $decode_json->{currentTime} );
readingsBulkUpdate( $hash, 'serverConnected',
$decode_json->{serverConnected} );
readingsEndUpdate( $hash, 1 );
2016-11-03 16:58:01 +00:00
}
2016-10-30 21:24:52 +00:00
sub NUKIBridge_getLogfile($) {
2020-01-09 21:02:41 +00:00
my ($hash) = @_;
2016-10-30 21:24:52 +00:00
2020-01-09 21:02:41 +00:00
my $name = $hash->{NAME};
my $decode_json = NUKIBridge_CallBlocking( $hash, 'log', undef );
Log3( $name, 4,
"NUKIBridge ($name) - Log data are collected and processed" );
if ( ref($decode_json) eq 'ARRAY' and scalar( @{$decode_json} ) > 0 ) {
Log3( $name, 4, "NUKIBridge ($name) - created Table with log file" );
2016-10-30 21:24:52 +00:00
my $ret = '<html><table width=100%><tr><td>';
$ret .= '<table class="block wide">';
2020-01-09 21:02:41 +00:00
foreach my $logs ( @{$decode_json} ) {
$ret .= '<tr class="odd">';
2020-01-09 21:02:41 +00:00
if ( $logs->{timestamp} ) {
$ret .= '<td><b>timestamp:</b> </td>';
$ret .= '<td>' . $logs->{timestamp} . '</td>';
2016-12-18 20:05:14 +00:00
$ret .= '<td> </td>';
}
2020-01-09 21:02:41 +00:00
if ( $logs->{type} ) {
$ret .= '<td><b>type:</b> </td>';
$ret .= '<td>' . $logs->{type} . '</td>';
2016-12-18 20:05:14 +00:00
$ret .= '<td> </td>';
}
2020-01-09 21:02:41 +00:00
foreach my $d ( reverse sort keys %{$logs} ) {
next if ( $d eq 'type' );
next if ( $d eq 'timestamp' );
2020-01-09 21:02:41 +00:00
$ret .= '<td><b>' . $d . ':</b> </td>';
$ret .= '<td>' . $logs->{$d} . '</td>';
$ret .= '<td> </td>';
}
2020-01-09 21:02:41 +00:00
2016-10-30 21:24:52 +00:00
$ret .= '</tr>';
}
2020-01-09 21:02:41 +00:00
2016-10-30 21:24:52 +00:00
$ret .= '</table></td></tr>';
$ret .= '</table></html>';
2020-01-09 21:02:41 +00:00
2016-10-30 21:24:52 +00:00
return $ret;
}
}
sub NUKIBridge_getCallbackList($) {
2020-01-09 21:02:41 +00:00
my ($hash) = @_;
2020-01-09 21:02:41 +00:00
my $name = $hash->{NAME};
my $decode_json = NUKIBridge_CallBlocking( $hash, 'callback/list', undef );
2019-02-12 18:45:16 +00:00
return
unless ( ref($decode_json) eq 'HASH' );
2020-01-09 21:02:41 +00:00
Log3(
$name, 4, "NUKIBridge ($name) - Callback data is collected and
processed"
);
if ( ref( $decode_json->{callbacks} ) eq 'ARRAY'
and scalar( @{ $decode_json->{callbacks} } ) > 0 )
{
Log3( $name, 4, "NUKIBridge ($name) - created Table with log file" );
my $ret = '<html><table width=100%><tr><td>';
$ret .= '<table class="block wide">';
2020-01-09 21:02:41 +00:00
$ret .= '<tr class="odd">';
$ret .= '<td><b>Callback-ID</b></td>';
$ret .= '<td> </td>';
$ret .= '<td><b>Callback-URL</b></td>';
$ret .= '</tr>';
foreach my $cb ( @{ $decode_json->{callbacks} } ) {
$ret .= '<td>' . $cb->{id} . '</td>';
$ret .= '<td> </td>';
$ret .= '<td>' . $cb->{url} . '</td>';
$ret .= '</tr>';
}
2020-01-09 21:02:41 +00:00
$ret .= '</table></td></tr>';
$ret .= '</table></html>';
return $ret;
}
2020-01-09 21:02:41 +00:00
2017-01-10 20:02:39 +00:00
return "No callback data available or error during processing";
}
2020-01-08 22:24:01 +00:00
sub NUKIBridge_CallBlocking($@) {
2020-01-11 11:08:35 +00:00
my ( $hash, $endpoint, $obj ) = @_;
2020-01-09 21:02:41 +00:00
my $name = $hash->{NAME};
my $host = $hash->{HOST};
my $port = $hash->{PORT};
my $token = $hash->{TOKEN};
my $url = 'http://' . $hash->{HOST} . ':' . $port;
2020-01-11 11:08:35 +00:00
$url .= '/' . $endpoint
if ( defined $endpoint );
$url .= '?token=' . $token
if ( defined($token) );
$url .= '&' . $obj
if ( defined($obj) );
2020-01-09 21:02:41 +00:00
my ( $err, $data ) = HttpUtils_BlockingGet(
{
url => $url,
timeout => 3,
method => "GET",
header => "Content-Type: application/json",
}
);
2016-10-30 21:24:52 +00:00
if ( !$data ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3, "NUKIDevice ($name) - empty answer received for $url" );
return undef;
}
elsif ( $data =~ m'HTTP/1.1 200 OK' ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 4, "NUKIDevice ($name) - empty answer received for $url" );
return undef;
2016-10-30 21:24:52 +00:00
}
2020-01-11 11:08:35 +00:00
elsif ( $data !~ m/^[\[{].*[}\]]$/ and $endpoint ne "log" ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 3,
"NUKIDevice ($name) - invalid json detected for $url: $data" );
return ("NUKIDevice ($name) - invalid json detected for $url: $data");
}
2020-01-09 21:02:41 +00:00
my $decode_json = eval { decode_json($data) };
if ($@) {
Log3( $name, 3, "NUKIBridge ($name) - JSON error while request: $@" );
return;
}
return undef if ( !$decode_json );
2020-01-09 21:02:41 +00:00
Log3( $name, 5, "NUKIBridge ($name) - Data: $data" );
Log3( $name, 4, "NUKIBridge ($name) - Blocking HTTP Query finished" );
2016-10-30 21:24:52 +00:00
return ($decode_json);
}
2020-01-08 12:26:22 +00:00
sub NUKIBridge_ParseJSON($$) {
my ( $hash, $buffer ) = @_;
my $name = $hash->{NAME};
my $open = 0;
my $close = 0;
my $msg = '';
my $tail = '';
if ($buffer) {
foreach my $c ( split //, $buffer ) {
if ( $open == $close and $open > 0 ) {
$tail .= $c;
2020-01-09 21:02:41 +00:00
Log3( $name, 5,
"NUKIBridge ($name) - $open == $close and $open > 0" );
2020-01-08 12:26:22 +00:00
}
elsif ( ( $open == $close ) and ( $c ne '{' ) ) {
2020-01-09 21:02:41 +00:00
Log3( $name, 5,
"NUKIBridge ($name) - Garbage character before message: "
. $c );
2020-01-08 12:26:22 +00:00
}
else {
if ( $c eq '{' ) {
$open++;
}
elsif ( $c eq '}' ) {
$close++;
}
$msg .= $c;
}
}
if ( $open != $close ) {
$tail = $msg;
$msg = '';
}
}
2020-01-09 21:02:41 +00:00
Log3( $name, 5, "NUKIBridge ($name) - return msg: $msg and tail: $tail" );
2020-01-08 12:26:22 +00:00
return ( $msg, $tail );
}
2016-09-27 11:37:19 +00:00
1;
=pod
2016-10-10 10:14:16 +00:00
=item device
2016-10-22 15:00:29 +00:00
=item summary Modul to control the Nuki Smartlock's over the Nuki Bridge.
2016-10-10 10:14:16 +00:00
=item summary_DE Modul zur Steuerung des Nuki Smartlock über die Nuki Bridge.
2016-09-27 11:37:19 +00:00
=begin html
2016-12-18 20:17:33 +00:00
2016-10-10 10:14:16 +00:00
<a name="NUKIBridge"></a>
<h3>NUKIBridge</h3>
2016-09-27 11:37:19 +00:00
<ul>
2016-10-11 07:11:43 +00:00
<u><b>NUKIBridge - controls the Nuki Smartlock over the Nuki Bridge</b></u>
<br>
The Nuki Bridge module connects FHEM to the Nuki Bridge and then reads all the smartlocks available on the bridge. Furthermore, the detected Smartlocks are automatically created as independent devices.
<br><br>
<a name="NUKIBridgedefine"></a>
<b>Define</b>
<ul><br>
<code>define &lt;name&gt; NUKIBridge &lt;HOST&gt; &lt;API-TOKEN&gt;</code>
<br><br>
Example:
<ul><br>
<code>define NBridge1 NUKIBridge 192.168.0.23 F34HK6</code><br>
</ul>
<br>
This statement creates a NUKIBridge device with the name NBridge1 and the IP 192.168.0.23 as well as the token F34HK6.<br>
After the bridge device is created, all available Smartlocks are automatically placed in FHEM.
</ul>
<br><br>
<a name="NUKIBridgereadings"></a>
<b>Readings</b>
<ul>
<li>bridgeAPI - API Version of bridge</li>
<li>bridgeType - Hardware bridge / Software bridge</li>
<li>currentTime - Current timestamp</li>
<li>firmwareVersion - Version of the bridge firmware</li>
<li>hardwareId - Hardware ID</li>
<li>lastError - Last connected error</li>
<li>serverConnected - Flag indicating whether or not the bridge is connected to the Nuki server</li>
<li>serverId - Server ID</li>
<li>uptime - Uptime of the bridge in seconds</li>
<li>wifiFirmwareVersion- Version of the WiFi modules firmware</li>
2016-10-11 07:11:43 +00:00
<br>
The preceding number is continuous, starts with 0 und returns the properties of <b>one</b> Smartlock.
</ul>
<br><br>
<a name="NUKIBridgeset"></a>
<b>Set</b>
<ul>
<li>getDeviceList - Prompts to re-read all devices from the bridge and if not already present in FHEM, create the automatically.</li>
<li>callbackRemove - Removes a previously added callback</li>
<li>clearLog - Clears the log of the Bridge (only hardwarebridge)</li>
<li>factoryReset - Performs a factory reset (only hardwarebridge)</li>
<li>fwUpdate - Immediately checks for a new firmware update and installs it (only hardwarebridge)</li>
<li>info - Returns all Smart Locks in range and some device information of the bridge itself</li>
<li>reboot - reboots the bridge (only hardwarebridge)</li>
<br>
</ul>
<br><br>
<a name="NUKIBridgeget"></a>
<b>Get</b>
<ul>
<li>callbackList - List of register url callbacks.</li>
<li>logFile - Retrieves the log of the Bridge</li>
2016-10-11 07:11:43 +00:00
<br>
</ul>
<br><br>
<a name="NUKIBridgeattribut"></a>
<b>Attributes</b>
<ul>
<li>disable - disables the Nuki Bridge</li>
<li>webhookFWinstance - Webinstanz of the Callback</li>
<li>webhookHttpHostname - IP or FQDN of the FHEM Server Callback</li>
2016-10-11 07:11:43 +00:00
<br>
</ul>
2016-09-27 11:37:19 +00:00
</ul>
=end html
=begin html_DE
2016-10-10 10:14:16 +00:00
<a name="NUKIBridge"></a>
<h3>NUKIBridge</h3>
2016-09-27 11:37:19 +00:00
<ul>
2016-10-10 10:14:16 +00:00
<u><b>NUKIBridge - Steuert das Nuki Smartlock über die Nuki Bridge</b></u>
<br>
Das Nuki Bridge Modul verbindet FHEM mit der Nuki Bridge und liest dann alle auf der Bridge verf&uuml;gbaren Smartlocks ein. Desweiteren werden automatisch die erkannten Smartlocks als eigenst&auml;ndige Devices an gelegt.
2016-10-10 10:14:16 +00:00
<br><br>
<a name="NUKIBridgedefine"></a>
<b>Define</b>
<ul><br>
<code>define &lt;name&gt; NUKIBridge &lt;HOST&gt; &lt;API-TOKEN&gt;</code>
<br><br>
Beispiel:
<ul><br>
<code>define NBridge1 NUKIBridge 192.168.0.23 F34HK6</code><br>
</ul>
<br>
Diese Anweisung erstellt ein NUKIBridge Device mit Namen NBridge1 und der IP 192.168.0.23 sowie dem Token F34HK6.<br>
Nach dem anlegen des Bridge Devices werden alle zur verf&uuml;gung stehende Smartlock automatisch in FHEM an gelegt.
</ul>
<br><br>
<a name="NUKIBridgereadings"></a>
<b>Readings</b>
<ul>
2016-10-11 07:11:43 +00:00
<li>bridgeAPI - API Version der Bridge</li>
<li>bridgeType - Hardware oder Software/App Bridge</li>
<li>currentTime - aktuelle Zeit auf der Bridge zum zeitpunkt des Info holens</li>
<li>firmwareVersion - aktuell auf der Bridge verwendete Firmwareversion</li>
<li>hardwareId - ID der Hardware Bridge</li>
<li>lastError - gibt die letzte HTTP Errormeldung wieder</li>
<li>serverConnected - true/false gibt an ob die Hardwarebridge Verbindung zur Nuki-Cloude hat.</li>
<li>serverId - gibt die ID des Cloudeservers wieder</li>
<li>uptime - Uptime der Bridge in Sekunden</li>
<li>wifiFirmwareVersion- Firmwareversion des Wifi Modules der Bridge</li>
2016-10-10 10:14:16 +00:00
<br>
Die vorangestellte Zahl ist forlaufend und gibt beginnend bei 0 die Eigenschaften <b>Eines</b> Smartlocks wieder.
</ul>
<br><br>
<a name="NUKIBridgeset"></a>
<b>Set</b>
<ul>
<li>getDeviceList - Veranlasst ein erneutes Einlesen aller Devices von der Bridge und falls noch nicht in FHEM vorhanden das automatische anlegen.</li>
<li>callbackRemove - L&ouml;schen der Callback Instanz auf der Bridge.</li>
<li>clearLog - l&ouml;scht das Logfile auf der Bridge</li>
<li>fwUpdate - schaut nach einer neueren Firmware und installiert diese sofern vorhanden</li>
<li>info - holt aktuellen Informationen &uuml;ber die Bridge</li>
<li>reboot - veranl&auml;sst ein reboot der Bridge</li>
<br>
</ul>
<br><br>
<a name="NUKIBridgeget"></a>
<b>Get</b>
<ul>
<li>callbackList - Gibt die Liste der eingetragenen Callback URL's wieder.</li>
<li>logFile - Zeigt das Logfile der Bridge an</li>
2016-10-10 10:14:16 +00:00
<br>
</ul>
<br><br>
<a name="NUKIBridgeattribut"></a>
<b>Attribute</b>
<ul>
<li>disable - deaktiviert die Nuki Bridge</li>
<li>webhookFWinstance - zu verwendene Webinstanz für den Callbackaufruf</li>
<li>webhookHttpHostname - IP oder FQDN vom FHEM Server für den Callbackaufruf</li>
2016-10-10 10:14:16 +00:00
<br>
</ul>
2016-09-27 11:37:19 +00:00
</ul>
=end html_DE
=cut