change reading create in Nukidevice, change online state work
This commit is contained in:
parent
2b9989d491
commit
870f27b0ac
@ -113,9 +113,14 @@ if ($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $version = '0.7.15';
|
my $version = '0.7.22';
|
||||||
my $bridgeapi = '1.9';
|
my $bridgeapi = '1.9';
|
||||||
|
|
||||||
|
my %bridgeType = (
|
||||||
|
'1' => 'Hardware',
|
||||||
|
'2' => 'Software'
|
||||||
|
);
|
||||||
|
|
||||||
my %lockActionsSmartLock = (
|
my %lockActionsSmartLock = (
|
||||||
'unlock' => 1,
|
'unlock' => 1,
|
||||||
'lock' => 2,
|
'lock' => 2,
|
||||||
@ -312,14 +317,16 @@ sub NUKIBridge_Attr(@) {
|
|||||||
|
|
||||||
if ( $attrName =~ /^webhook.*/ ) {
|
if ( $attrName =~ /^webhook.*/ ) {
|
||||||
|
|
||||||
my $webhookHttpHostname =
|
my $webhookHttpHostname = (
|
||||||
( $attrName eq 'webhookHttpHostname'
|
$attrName eq 'webhookHttpHostname'
|
||||||
? $attrVal
|
? $attrVal
|
||||||
: AttrVal( $name, 'webhookHttpHostname', '' ) );
|
: AttrVal( $name, 'webhookHttpHostname', '' )
|
||||||
my $webhookFWinstance =
|
);
|
||||||
( $attrName eq 'webhookFWinstance'
|
my $webhookFWinstance = (
|
||||||
|
$attrName eq 'webhookFWinstance'
|
||||||
? $attrVal
|
? $attrVal
|
||||||
: AttrVal( $name, 'webhookFWinstance', '' ) );
|
: AttrVal( $name, 'webhookFWinstance', '' )
|
||||||
|
);
|
||||||
|
|
||||||
$hash->{WEBHOOK_URI} = '/'
|
$hash->{WEBHOOK_URI} = '/'
|
||||||
. AttrVal( $webhookFWinstance, 'webname', 'fhem' )
|
. AttrVal( $webhookFWinstance, 'webname', 'fhem' )
|
||||||
@ -760,16 +767,13 @@ sub NUKIBridge_ResponseProcessing($$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $path eq 'info' ) {
|
NUKIBridge_InfoProcessing( $hash, $decode_json )
|
||||||
readingsBeginUpdate($hash);
|
if ( $path eq 'info' );
|
||||||
readingsBulkUpdate( $hash, 'state', 'connected' );
|
|
||||||
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist online" );
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsSingleUpdate( $hash, 'state', 'connected', 1 );
|
||||||
$hash->{helper}{aliveCount} = 0;
|
Log3( $name, 5, "NUKIBridge ($name) - Bridge ist online" );
|
||||||
|
|
||||||
NUKIBridge_InfoProcessing( $hash, $decode_json );
|
$hash->{helper}{aliveCount} = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3(
|
Log3(
|
||||||
@ -848,11 +852,6 @@ sub NUKIBridge_InfoProcessing($$) {
|
|||||||
my $dname;
|
my $dname;
|
||||||
my $dhash;
|
my $dhash;
|
||||||
|
|
||||||
my %bridgeType = (
|
|
||||||
'1' => 'Hardware',
|
|
||||||
'2' => 'Software'
|
|
||||||
);
|
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate( $hash, 'appVersion',
|
readingsBulkUpdate( $hash, 'appVersion',
|
||||||
$decode_json->{versions}->{appVersion} );
|
$decode_json->{versions}->{appVersion} );
|
||||||
|
137
74_NUKIDevice.pm
137
74_NUKIDevice.pm
@ -101,7 +101,7 @@ if ($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $version = '0.7.15';
|
my $version = '0.7.27';
|
||||||
|
|
||||||
# Declare functions
|
# Declare functions
|
||||||
sub NUKIDevice_Initialize($);
|
sub NUKIDevice_Initialize($);
|
||||||
@ -118,6 +118,64 @@ my %deviceTypes = (
|
|||||||
2 => 'opener'
|
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);
|
my %deviceTypeIds = reverse(%deviceTypes);
|
||||||
|
|
||||||
sub NUKIDevice_Initialize($) {
|
sub NUKIDevice_Initialize($) {
|
||||||
@ -416,36 +474,17 @@ sub NUKIDevice_WriteReadings($$) {
|
|||||||
############################
|
############################
|
||||||
#### Status des Smartlock
|
#### Status des Smartlock
|
||||||
|
|
||||||
my $battery;
|
my $state;
|
||||||
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);
|
|
||||||
|
|
||||||
if ( defined( $hash->{helper}{lockAction} ) ) {
|
if ( defined( $hash->{helper}{lockAction} ) ) {
|
||||||
my ( $state, $lockState );
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
defined( $decode_json->{success} )
|
defined( $decode_json->{success} )
|
||||||
and ( $decode_json->{success} eq 'true'
|
and ( $decode_json->{success} eq 'true'
|
||||||
or $decode_json->{success} == 1 )
|
or $decode_json->{success} == 1 )
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$state = $hash->{helper}{lockAction};
|
$state = $hash->{helper}{lockAction};
|
||||||
$lockState = $hash->{helper}{lockAction};
|
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID} )
|
||||||
|
|
||||||
IOWrite( $hash, "lockState", undef, $hash->{NUKIID} )
|
|
||||||
if (
|
if (
|
||||||
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
|
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
|
||||||
eq 'Software' );
|
eq 'Software' );
|
||||||
@ -463,32 +502,48 @@ sub NUKIDevice_WriteReadings($$) {
|
|||||||
$hash->{DEVICETYPE} );
|
$hash->{DEVICETYPE} );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, 'state', $state );
|
|
||||||
readingsBulkUpdate( $hash, 'lockState', $lockState );
|
|
||||||
readingsBulkUpdate( $hash, 'success', $decode_json->{success} );
|
|
||||||
|
|
||||||
delete $hash->{helper}{lockAction};
|
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} );
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate( $hash, 'rssi', $decode_json->{rssi} );
|
|
||||||
readingsBulkUpdate( $hash, 'paired', $decode_json->{paired} );
|
|
||||||
|
|
||||||
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 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3( $name, 5, "NUKIDevice ($name) - lockAction readings set for $name" );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user