change reading create in Nukidevice, change online state work

This commit is contained in:
Marko Oldenburg 2020-01-10 11:47:49 +01:00
parent 2b9989d491
commit 870f27b0ac
2 changed files with 115 additions and 61 deletions

View File

@ -113,9 +113,14 @@ if ($@) {
}
}
my $version = '0.7.15';
my $version = '0.7.22';
my $bridgeapi = '1.9';
my %bridgeType = (
'1' => 'Hardware',
'2' => 'Software'
);
my %lockActionsSmartLock = (
'unlock' => 1,
'lock' => 2,
@ -312,14 +317,16 @@ sub NUKIBridge_Attr(@) {
if ( $attrName =~ /^webhook.*/ ) {
my $webhookHttpHostname =
( $attrName eq 'webhookHttpHostname'
my $webhookHttpHostname = (
$attrName eq 'webhookHttpHostname'
? $attrVal
: AttrVal( $name, 'webhookHttpHostname', '' ) );
my $webhookFWinstance =
( $attrName eq 'webhookFWinstance'
: AttrVal( $name, 'webhookHttpHostname', '' )
);
my $webhookFWinstance = (
$attrName eq 'webhookFWinstance'
? $attrVal
: AttrVal( $name, 'webhookFWinstance', '' ) );
: AttrVal( $name, 'webhookFWinstance', '' )
);
$hash->{WEBHOOK_URI} = '/'
. AttrVal( $webhookFWinstance, 'webname', 'fhem' )
@ -760,16 +767,13 @@ sub NUKIBridge_ResponseProcessing($$$) {
}
}
if ( $path eq 'info' ) {
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, 'state', 'connected' );
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist online" );
NUKIBridge_InfoProcessing( $hash, $decode_json )
if ( $path eq 'info' );
readingsEndUpdate( $hash, 1 );
$hash->{helper}{aliveCount} = 0;
readingsSingleUpdate( $hash, 'state', 'connected', 1 );
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist online" );
NUKIBridge_InfoProcessing( $hash, $decode_json );
}
$hash->{helper}{aliveCount} = 0;
}
else {
Log3(
@ -848,11 +852,6 @@ sub NUKIBridge_InfoProcessing($$) {
my $dname;
my $dhash;
my %bridgeType = (
'1' => 'Hardware',
'2' => 'Software'
);
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, 'appVersion',
$decode_json->{versions}->{appVersion} );

View File

@ -101,7 +101,7 @@ if ($@) {
}
}
my $version = '0.7.15';
my $version = '0.7.27';
# Declare functions
sub NUKIDevice_Initialize($);
@ -118,6 +118,64 @@ my %deviceTypes = (
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($) {
@ -416,36 +474,17 @@ sub NUKIDevice_WriteReadings($$) {
############################
#### Status des Smartlock
my $battery;
if ( defined( $decode_json->{batteryCritical} ) ) {
if ( $decode_json->{batteryCritical} eq 'false'
or $decode_json->{batteryCritical} == 0 )
{
$battery = 'ok';
}
elsif ($decode_json->{batteryCritical} eq 'true'
or $decode_json->{batteryCritical} == 1 )
{
$battery = "low";
}
}
readingsBeginUpdate($hash);
my $state;
if ( defined( $hash->{helper}{lockAction} ) ) {
my ( $state, $lockState );
if (
defined( $decode_json->{success} )
and ( $decode_json->{success} eq 'true'
or $decode_json->{success} == 1 )
)
{
$state = $hash->{helper}{lockAction};
$lockState = $hash->{helper}{lockAction};
IOWrite( $hash, "lockState", undef, $hash->{NUKIID} )
$state = $hash->{helper}{lockAction};
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID} )
if (
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
eq 'Software' );
@ -463,32 +502,48 @@ sub NUKIDevice_WriteReadings($$) {
$hash->{DEVICETYPE} );
}
readingsBulkUpdate( $hash, 'state', $state );
readingsBulkUpdate( $hash, 'lockState', $lockState );
readingsBulkUpdate( $hash, 'success', $decode_json->{success} );
delete $hash->{helper}{lockAction};
Log3( $name, 5,
"NUKIDevice ($name) - lockAction readings set for $name" );
}
else {
readingsBulkUpdate( $hash, 'batteryCritical',
$decode_json->{batteryCritical} );
readingsBulkUpdate( $hash, 'lockState', $decode_json->{stateName} );
readingsBulkUpdate( $hash, 'state', $decode_json->{stateName} );
readingsBulkUpdate( $hash, 'batteryState', $battery );
readingsBulkUpdate( $hash, 'success', $decode_json->{success} );
readingsBulkUpdate( $hash, 'name', $decode_json->{name} );
readingsBulkUpdate( $hash, 'rssi', $decode_json->{rssi} );
readingsBulkUpdate( $hash, 'paired', $decode_json->{paired} );
readingsBeginUpdate($hash);
Log3( $name, 5, "NUKIDevice ($name) - readings set for $name" );
my $t;
my $v;
if ( defined( $decode_json->{lastKnownState} )
and ref( $decode_json->{lastKnownState} ) eq 'HASH' )
{
while ( ( $t, $v ) = each %{ $decode_json->{lastKnownState} } ) {
$decode_json->{$t} = $v;
}
delete $decode_json->{lastKnownState};
}
while ( ( $t, $v ) = each %{$decode_json} ) {
readingsBulkUpdate( $hash, $t, $v )
unless ( $t eq 'state'
or $t eq 'mode'
or $t eq 'deviceType'
or $t eq 'paired'
or $t eq 'batteryCritical' );
readingsBulkUpdate( $hash, $t, $lockStates{$v}{ $hash->{DEVICETYPE} } )
if ( $t eq 'state' );
readingsBulkUpdate( $hash, $t, $modes{$v}{ $hash->{DEVICETYPE} } )
if ( $t eq 'mode' );
readingsBulkUpdate( $hash, $t, $deviceTypes{$v} )
if ( $t eq 'deviceType' );
readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) )
if ( $t eq 'paired' );
readingsBulkUpdate( $hash, 'batteryState',
( ( $v eq 'true' or $v == 1 ) ? 'low' : 'ok' ) )
if ( $t eq 'batteryCritical' );
}
readingsEndUpdate( $hash, 1 );
Log3( $name, 5, "NUKIDevice ($name) - lockAction readings set for $name" );
return undef;
}