Merge pull request 'fix little model bugs' (#12) from patch-discoveryAuthorization into devel
Reviewed-on: #12
This commit is contained in:
commit
1b001e942a
@ -64,8 +64,7 @@ sub Initialize {
|
||||
$hash->{NotifyFn} = \&FHEM::Devices::Nuki::Bridge::Notify;
|
||||
$hash->{AttrFn} = \&FHEM::Devices::Nuki::Bridge::Attr;
|
||||
$hash->{AttrList} =
|
||||
'disable:1 '
|
||||
. 'port '
|
||||
'disable:1 ' . 'port '
|
||||
. 'webhookFWinstance:'
|
||||
. $webhookFWinstance . ' '
|
||||
. 'webhookHttpHostname '
|
||||
|
@ -1,4 +1,4 @@
|
||||
UPD 2021-11-27_21:26:06 9224 FHEM/73_NUKIBridge.pm
|
||||
UPD 2021-11-27_21:30:28 7569 FHEM/74_NUKIDevice.pm
|
||||
UPD 2021-11-27_21:26:06 40444 lib/FHEM/Devices/Nuki/Bridge.pm
|
||||
UPD 2021-11-27_21:32:02 15123 lib/FHEM/Devices/Nuki/Device.pm
|
||||
UPD 2021-11-27_22:52:03 9217 FHEM/73_NUKIBridge.pm
|
||||
UPD 2021-11-27_21:36:27 7569 FHEM/74_NUKIDevice.pm
|
||||
UPD 2021-11-27_22:52:20 40367 lib/FHEM/Devices/Nuki/Bridge.pm
|
||||
UPD 2021-11-27_22:56:00 15826 lib/FHEM/Devices/Nuki/Device.pm
|
||||
|
@ -145,6 +145,7 @@ sub Define {
|
||||
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
||||
|
||||
my ( $name, undef, $host, $token ) = split( m{\s+}xms, $def );
|
||||
|
||||
# return ('too few parameters: define <name> NUKIBridge <HOST> <TOKEN>')
|
||||
# if ( !defined($host)
|
||||
# || !defined($token) );
|
||||
@ -236,7 +237,8 @@ sub Attr {
|
||||
}
|
||||
elsif ( $cmd eq 'del' ) {
|
||||
$hash->{PORT} = 8080;
|
||||
::Log3( $name, 3, "NUKIBridge ($name) - set bridge port to default" );
|
||||
::Log3( $name, 3,
|
||||
"NUKIBridge ($name) - set bridge port to default" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,9 +397,7 @@ sub removeExtension {
|
||||
|
||||
::Log3( $name, 2,
|
||||
"NUKIBridge ($name) - Unregistering NUKIBridge for webhook URL $url..."
|
||||
)
|
||||
if ( defined($name) );
|
||||
|
||||
) if ( defined($name) );
|
||||
|
||||
delete $::data{FWEXT}{$url};
|
||||
|
||||
@ -501,7 +501,14 @@ sub GetCheckBridgeAlive {
|
||||
if ( !::IsDisabled($name)
|
||||
&& $hash->{helper}->{iowrite} == 0 )
|
||||
{
|
||||
if ( $hash->{helper}->{runInfo} == 0 ) {
|
||||
Write( $hash, 'info', undef );
|
||||
$hash->{helper}->{runInfo} = 1;
|
||||
}
|
||||
else {
|
||||
Write( $hash, 'list', undef );
|
||||
$hash->{helper}->{runInfo} = 0;
|
||||
}
|
||||
|
||||
::Log3( $name, 4, "NUKIBridge ($name) - run Write" );
|
||||
}
|
||||
@ -521,6 +528,7 @@ sub FirstRun {
|
||||
Write( $hash, 'list', undef )
|
||||
if ( !::IsDisabled($name) );
|
||||
|
||||
$hash->{helper}->{runInfo} = 0;
|
||||
return ::InternalTimer( ::gettimeofday() + 5,
|
||||
\&FHEM::Devices::Nuki::Bridge::GetCheckBridgeAlive, $hash );
|
||||
}
|
||||
@ -656,6 +664,7 @@ sub Distribution {
|
||||
my $json = shift;
|
||||
|
||||
my $hash = $param->{hash};
|
||||
|
||||
# my $doTrigger = $param->{doTrigger};
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{HOST};
|
||||
@ -1110,8 +1119,8 @@ sub getCallbackList {
|
||||
|
||||
if ( scalar( @{ $decode_json->{callbacks} } ) > 0 ) {
|
||||
for my $cb ( @{ $decode_json->{callbacks} } ) {
|
||||
$aHref =
|
||||
"<a href=\""
|
||||
$aHref = "<a href=\""
|
||||
|
||||
# . $::FW_httpheader->{host}
|
||||
. "/fhem?cmd=set+"
|
||||
. $name
|
||||
@ -1276,17 +1285,20 @@ sub BridgeDiscover {
|
||||
my $endpoint = shift;
|
||||
my $bridge = shift;
|
||||
my $name = $hash->{NAME};
|
||||
my $url = ( $endpoint eq 'discover' && !defined($bridge)
|
||||
my $url = (
|
||||
$endpoint eq 'discover' && !defined($bridge)
|
||||
? 'https://api.nuki.io/discover/bridges'
|
||||
: 'http://' . $bridge->{'ip'} . ':' . $bridge->{'port'} . '/auth' );
|
||||
my $timeout = ( $endpoint eq 'discover' && !defined($bridge)
|
||||
: 'http://' . $bridge->{'ip'} . ':' . $bridge->{'port'} . '/auth'
|
||||
);
|
||||
my $timeout = (
|
||||
$endpoint eq 'discover' && !defined($bridge)
|
||||
? 5
|
||||
: 35 );
|
||||
: 35
|
||||
);
|
||||
|
||||
if ( $endpoint eq 'discover' ) {
|
||||
::Log3( $name, 3,
|
||||
"NUKIBridge ($name) - Bridge device defined. run discover mode"
|
||||
);
|
||||
"NUKIBridge ($name) - Bridge device defined. run discover mode" );
|
||||
|
||||
::readingsSingleUpdate( $hash, 'state', 'run discovery', 1 );
|
||||
}
|
||||
@ -1297,7 +1309,6 @@ sub BridgeDiscover {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
::HttpUtils_NonblockingGet(
|
||||
{
|
||||
url => $url,
|
||||
@ -1316,8 +1327,7 @@ sub BridgeDiscover {
|
||||
"NUKIBridge ($name) - Send Discover request to Nuki Cloud" )
|
||||
if ( $endpoint eq 'discover' );
|
||||
|
||||
::Log3( $name, 3,
|
||||
"NUKIBridge ($name) - get API Token from the Bridge" )
|
||||
::Log3( $name, 3, "NUKIBridge ($name) - get API Token from the Bridge" )
|
||||
if ( $endpoint eq 'getApiToken' );
|
||||
|
||||
return;
|
||||
@ -1331,18 +1341,17 @@ sub BridgeDiscoverRequest {
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
|
||||
if ( defined($err)
|
||||
&& $err ne '' )
|
||||
{
|
||||
return ::Log3( $name, 3,
|
||||
"NUKIBridge ($name) - Error: $err");
|
||||
return ::Log3( $name, 3, "NUKIBridge ($name) - Error: $err" );
|
||||
}
|
||||
elsif ( exists( $param->{code} )
|
||||
&& $param->{code} != 200 )
|
||||
{
|
||||
return ::Log3( $name, 3,
|
||||
"NUKIBridge ($name) - HTTP error Code present. Code: $param->{code}");
|
||||
"NUKIBridge ($name) - HTTP error Code present. Code: $param->{code}"
|
||||
);
|
||||
}
|
||||
|
||||
my $decode_json;
|
||||
@ -1354,14 +1363,16 @@ sub BridgeDiscoverRequest {
|
||||
|
||||
if ( $param->{endpoint} eq 'discover' ) {
|
||||
|
||||
return ::readingsSingleUpdate($hash, 'state', 'no bridges discovered', 1)
|
||||
return ::readingsSingleUpdate( $hash, 'state', 'no bridges discovered',
|
||||
1 )
|
||||
if ( scalar( @{ $decode_json->{bridges} } ) == 0
|
||||
&& $decode_json->{errorCode} == 0 );
|
||||
|
||||
return BridgeDiscover_getAPIToken( $hash, $decode_json );
|
||||
}
|
||||
elsif ( $param->{endpoint} eq 'getApiToken' ) {
|
||||
::readingsSingleUpdate($hash, 'state', 'modefined bridge device in progress', 1);
|
||||
::readingsSingleUpdate( $hash, 'state',
|
||||
'modefined bridge device in progress', 1 );
|
||||
|
||||
$decode_json->{host} = $param->{host};
|
||||
$decode_json->{port} = $param->{port};
|
||||
@ -1369,7 +1380,8 @@ sub BridgeDiscoverRequest {
|
||||
return ModefinedBridgeDevices( $hash, $decode_json )
|
||||
if ( $decode_json->{success} == 1 );
|
||||
|
||||
return ::readingsSingleUpdate($hash, 'state', 'get api token failed', 1);
|
||||
return ::readingsSingleUpdate( $hash, 'state', 'get api token failed',
|
||||
1 );
|
||||
}
|
||||
|
||||
return;
|
||||
@ -1380,7 +1392,8 @@ sub BridgeDiscover_getAPIToken {
|
||||
my $decode_json = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $pullApiKeyMessage = 'When issuing this API-call the bridge turns on its LED for 30 seconds.
|
||||
my $pullApiKeyMessage =
|
||||
'When issuing this API-call the bridge turns on its LED for 30 seconds.
|
||||
The button of the bridge has to be pressed within this timeframe. Otherwise the bridge returns a negative success and no token.';
|
||||
|
||||
::readingsSingleUpdate( $hash, 'state', $pullApiKeyMessage, 1 );
|
||||
@ -1398,7 +1411,6 @@ sub ModefinedBridgeDevices {
|
||||
my $decode_json = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
|
||||
::CommandAttr( undef, $name . ' port ' . $decode_json->{port} )
|
||||
if ( $decode_json->{port} != 8080 );
|
||||
::CommandDefMod( undef,
|
||||
@ -1410,5 +1422,4 @@ sub ModefinedBridgeDevices {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
@ -111,6 +111,9 @@ my %deviceTypes = (
|
||||
4 => 'smartlock3'
|
||||
);
|
||||
|
||||
my %deviceTypeIds = reverse(%deviceTypes);
|
||||
|
||||
|
||||
my %modes = (
|
||||
2 => {
|
||||
0 => 'door mode',
|
||||
@ -180,7 +183,14 @@ my %lockStates = (
|
||||
}
|
||||
);
|
||||
|
||||
my %deviceTypeIds = reverse(%deviceTypes);
|
||||
my %doorsensorStates = (
|
||||
1 => 'deactivated',
|
||||
2 => 'door closed',
|
||||
3 => 'door opened',
|
||||
4 => 'door state unknown',
|
||||
5 => 'calibrating'
|
||||
);
|
||||
|
||||
|
||||
sub Define {
|
||||
my $hash = shift;
|
||||
@ -205,6 +215,7 @@ sub Define {
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NOTIFYDEV} = 'global,autocreate,' . $name;
|
||||
|
||||
|
||||
my $iodev = ::AttrVal( $name, 'IODev', 'none' );
|
||||
|
||||
::AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} );
|
||||
@ -541,11 +552,21 @@ sub WriteReadings {
|
||||
&& $t ne 'deviceType'
|
||||
&& $t ne 'paired'
|
||||
&& $t ne 'batteryCritical'
|
||||
&& $t ne 'timestamp' );
|
||||
&& $t ne 'batteryChargeState'
|
||||
&& $t ne 'batteryCharging'
|
||||
&& $t ne 'timestamp'
|
||||
&& $t ne 'doorsensorState'
|
||||
&& $t ne 'doorsensorStateName' );
|
||||
|
||||
::readingsBulkUpdate( $hash, $t,
|
||||
( $v =~ m/^[0-9]$/ ? $lockStates{$v}{ $hash->{DEVICETYPEID} } : $v ) )
|
||||
if ( $t eq 'state' );
|
||||
|
||||
::readingsBulkUpdate(
|
||||
$hash, $t,
|
||||
(
|
||||
$v =~ m/^[0-9]$/
|
||||
? $lockStates{$v}{ $hash->{DEVICETYPEID} }
|
||||
: $v
|
||||
)
|
||||
) if ( $t eq 'state' );
|
||||
|
||||
::readingsBulkUpdate( $hash, $t, $modes{$v}{ $hash->{DEVICETYPEID} } )
|
||||
if ( $t eq 'mode' );
|
||||
@ -553,12 +574,21 @@ sub WriteReadings {
|
||||
::readingsBulkUpdate( $hash, $t, $deviceTypes{$v} )
|
||||
if ( $t eq 'deviceType' );
|
||||
|
||||
::readingsBulkUpdate( $hash, $t, $doorsensorStates{$v} )
|
||||
if ( $t eq 'doorsensorState' );
|
||||
|
||||
::readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) )
|
||||
if ( $t eq 'paired' );
|
||||
|
||||
::readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) )
|
||||
if ( $t eq 'batteryCharging' );
|
||||
|
||||
::readingsBulkUpdate( $hash, 'batteryState',
|
||||
( ( $v eq 'true' or $v == 1 ) ? 'low' : 'ok' ) )
|
||||
( $v == 1 ? 'low' : 'ok' ) )
|
||||
if ( $t eq 'batteryCritical' );
|
||||
|
||||
::readingsBulkUpdate( $hash, 'batteryPercent', $v )
|
||||
if ( $t eq 'batteryChargeState' );
|
||||
}
|
||||
|
||||
::readingsEndUpdate( $hash, 1 );
|
||||
|
Loading…
Reference in New Issue
Block a user