mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-24 15:19:21 +00:00
30_HUEBridge.pm, 31_HUEDevice.pm: better button event handling
git-svn-id: https://svn.fhem.de/fhem/trunk@25591 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1693173b04
commit
2ed59dadc5
@ -50,7 +50,7 @@ HUEBridge_Initialize($)
|
||||
$hash->{GetFn} = "HUEBridge_Get";
|
||||
$hash->{AttrFn} = "HUEBridge_Attr";
|
||||
$hash->{UndefFn} = "HUEBridge_Undefine";
|
||||
$hash->{AttrList} = "key disable:1 disabledForIntervals createEventTimestampReading:1,0 eventstreamTimeout createGroupReadings:1,0 httpUtils:1,0 forceAutocreate:1,0 ignoreUnknown:1,0 noshutdown:1,0 pollDevices:1,2,0 queryAfterSet:1,0 $readingFnAttributes";
|
||||
$hash->{AttrList} = "key disable:1 disabledForIntervals createEventTimestampReading:1,0 eventstreamTimeout createGroupReadings:1,0 httpUtils:1,0 forceAutocreate:1,0 ignoreUnknown:1,0 noshutdown:1,0 pollDevices:1,2,0 queryAfterEvent:1,0 queryAfterSet:1,0 $readingFnAttributes";
|
||||
|
||||
#$hash->{isDiscoverable} = { ssdp => {'hue-bridgeid' => '/.*/'}, upnp => {} };
|
||||
|
||||
@ -2525,6 +2525,8 @@ HUEBridge_dispatch($$$;$)
|
||||
$obj->{state}{presence} = $data->{motion}{motion} if( defined($data->{motion}) );
|
||||
|
||||
} elsif( $data->{type} eq 'button' ) {
|
||||
RemoveInternalTimer($chash, 'updateFinalButtonState' );
|
||||
|
||||
my $input = $service->{metadata}{control_id};
|
||||
my $eventtype = $data->{button}{last_event};
|
||||
#Log 1, "input: $input";
|
||||
@ -2638,6 +2640,8 @@ HUEBridge_dispatch($$$;$)
|
||||
}
|
||||
|
||||
delete $hash->{helper}{ignored}{$code};
|
||||
InternalTimer(gettimeofday()+1, "updateFinalButtonState", $chash, 0) if( $data->{type} eq 'button'
|
||||
&& AttrVal( $name,'queryAfterEvent', 0 ) );
|
||||
}
|
||||
|
||||
} elsif( !$hash->{helper}{ignored}{$code} && !AttrVal($name, 'ignoreUnknown', undef) ) {
|
||||
@ -3151,6 +3155,8 @@ __END__
|
||||
try to create devices even if autocreate is disabled.</li>
|
||||
<li>ignoreUnknown<br>
|
||||
don't try to create devices after data or events with unknown references are received.</li>
|
||||
<li>queryAfterEvent<br>
|
||||
the bridge will request the real button state 1 sec after the final event in a quick series. default is 0.</li>
|
||||
<li>queryAfterSet<br>
|
||||
the bridge will request the real device state after a set command. default is 1.</li>
|
||||
<li>noshutdown<br>
|
||||
|
@ -502,6 +502,7 @@ HUEDevice_Define($$) {
|
||||
$interval = 60 if( defined($interval) && $interval < 1 );
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
$hash->{helper}{state} = '';
|
||||
}
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
@ -1414,6 +1415,13 @@ HUEDevice_ReadFromServer($@)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub
|
||||
updateFinalButtonState($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{helper}{forceUpdate} = 1;
|
||||
HUEDevice_GetUpdate($hash);
|
||||
}
|
||||
sub
|
||||
HUEDevice_GetUpdate($)
|
||||
{
|
||||
@ -1693,6 +1701,7 @@ HUEDevice_Parse($$)
|
||||
$hash->{helper}{events}[$i] = {};
|
||||
foreach my $event (@{$input->{events}}) {
|
||||
$hash->{helper}{events}[$i]{$event->{eventtype}} = $event->{buttonevent};
|
||||
$hash->{helper}{events}[$i]{$event->{buttonevent}} = $event->{eventtype};
|
||||
}
|
||||
|
||||
++$i;
|
||||
@ -1837,6 +1846,41 @@ HUEDevice_Parse($$)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( $hash->{helper}{forceUpdate}
|
||||
&& defined($state->{buttonevent}) ) {
|
||||
if( $hash->{helper}{state} eq $readings{state} ) {
|
||||
delete $hash->{helper}{forceUpdate};
|
||||
|
||||
} else {
|
||||
my $input = substr($state->{buttonevent}, 0, 1);
|
||||
$readings{input} = substr($state->{buttonevent}, 0, 1);
|
||||
if( $input
|
||||
&& defined($hash->{helper}{events})
|
||||
&& defined($hash->{helper}{events}[$input-1])
|
||||
&& defined($hash->{helper}{events}[$input-1]{$state->{buttonevent}}) ) {
|
||||
$readings{eventtype} = $hash->{helper}{events}[$input-1]{$state->{buttonevent}};
|
||||
|
||||
} elsif( my $type = substr($state->{buttonevent}, 2, 2) ) {
|
||||
if( $type eq 00 ) {
|
||||
$readings{eventtype} = 'initial_press';
|
||||
|
||||
} elsif( $type eq 00 ) {
|
||||
$readings{eventtype} = 'repeat';
|
||||
|
||||
} elsif( $type eq 00 ) {
|
||||
$readings{eventtype} = 'short_release';
|
||||
|
||||
} elsif( $type eq 00 ) {
|
||||
$readings{eventtype} = 'long_release';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$hash->{helper}{state} = $readings{state} if( defined($readings{state}) );
|
||||
|
||||
}
|
||||
|
||||
CommandDeleteReading( undef, "$name .lastupdated" );
|
||||
@ -1850,7 +1894,8 @@ HUEDevice_Parse($$)
|
||||
if( defined($readings{$key}) ) {
|
||||
if( $lastupdated ) {
|
||||
my $rut = ReadingsTimestamp($name,$key,undef);
|
||||
if( (!defined($result->{v2_service}) || !defined($result->{t}))
|
||||
if( !$hash->{helper}{forceUpdate}
|
||||
&& !defined($result->{v2_service}) && !defined($result->{t})
|
||||
&& $ts && defined($rut) && $ts <= time_str2num($rut) ) {
|
||||
Log3 $name, 4, "$name: ignoring reading $key with timestamp $lastupdated, current reading timestamp is $rut";
|
||||
next;
|
||||
@ -1867,6 +1912,8 @@ HUEDevice_Parse($$)
|
||||
|
||||
readingsEndUpdate($hash,1);
|
||||
delete $hash->{CHANGETIME};
|
||||
|
||||
delete $hash->{helper}{forceUpdate};
|
||||
}
|
||||
|
||||
return undef;
|
||||
|
Loading…
x
Reference in New Issue
Block a user