2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

31_Aurora.pm: new update handling, additional internals

git-svn-id: https://svn.fhem.de/fhem/trunk@15915 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2018-01-17 16:44:46 +00:00
parent e3483c310b
commit 03db3784ff

View File

@ -43,6 +43,7 @@ Aurora_Initialize($)
#Consumer
$hash->{DefFn} = "Aurora_Define";
$hash->{NotifyFn} = "Aurora_Notify";
$hash->{UndefFn} = "Aurora_Undefine";
$hash->{SetFn} = "Aurora_Set";
$hash->{GetFn} = "Aurora_Get";
@ -127,6 +128,8 @@ Aurora_Define($$)
$interval = 60 if( defined($interval) && $interval < 10 );
$hash->{INTERVAL} = $interval;
$hash->{helper}{last_config_timestamp} = 0;
$hash->{helper}{on} = -1;
$hash->{helper}{colormode} = '';
$hash->{helper}{ct} = -1;
@ -143,16 +146,37 @@ Aurora_Define($$)
my $icon_path = AttrVal("WEB", "iconPath", "default:fhemSVG:openautomation" );
$attr{$name}{'color-icons'} = 2 if( !defined( $attr{$name}{'color-icons'} ) && $icon_path =~ m/openautomation/ );
$hash->{NOTIFYDEV} = "global";
RemoveInternalTimer($hash);
if( $init_done ) {
Aurora_OpenDev($hash);
} else {
#InternalTimer(gettimeofday()+10, "Aurora_GetUpdate", $hash, 0);
Aurora_OpenDev($hash) if( !IsDisabled($name) );
}
return undef;
}
sub
Aurora_Notify($$)
{
my ($hash,$dev) = @_;
my $name = $hash->{NAME};
my $type = $hash->{TYPE};
return if($dev->{NAME} ne "global");
return if(!grep(m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}}));
if( IsDisabled($name) > 0 ) {
readingsSingleUpdate($hash, 'state', 'inactive', 1 ) if( ReadingsVal($name,'inactive','' ) ne 'disabled' );
return undef;
}
Aurora_OpenDev($hash);
return undef;
}
sub
Aurora_Undefine($$)
{
@ -282,12 +306,6 @@ Aurora_dispatch($$$;$)
RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+1, "Aurora_GetUpdate", $hash, 0);
}
} elsif( $param->{type} eq 'effects' ) {
$hash->{helper}{effects} = $json->{effectsList};
if( my $effect = $json->{select} ) {
if( $effect ne $hash->{helper}{effect} ) { readingsSingleUpdate($hash, 'effect', $effect, 1 ) };
$hash->{helper}{effect} = $effect;
}
}
}
@ -703,6 +721,21 @@ Aurora_GetUpdate($)
return undef if(IsDisabled($name));
my ($now) = gettimeofday();
if( $hash->{LOCAL} || $now - $hash->{helper}{last_config_timestamp} > 300 ) {
my($err,$data) = HttpUtils_NonblockingGet({
url => "http://$hash->{IP}:16021/api/v1/$attr{$name}{token}",
timeout => 2,
method => 'GET',
noshutdown => $hash->{noshutdown},
hash => $hash,
type => 'state',
callback => \&Aurora_dispatch,
});
$hash->{helper}{last_config_timestamp} = $now;
} else {
my($err,$data) = HttpUtils_NonblockingGet({
url => "http://$hash->{IP}:16021/api/v1/$attr{$name}{token}/state",
timeout => 2,
@ -713,16 +746,7 @@ Aurora_GetUpdate($)
callback => \&Aurora_dispatch,
});
($err,$data) = HttpUtils_NonblockingGet({
url => "http://$hash->{IP}:16021/api/v1/$attr{$name}{token}/effects",
timeout => 2,
method => 'GET',
noshutdown => $hash->{noshutdown},
hash => $hash,
type => 'effects',
callback => \&Aurora_dispatch,
});
}
return undef;
}
@ -757,18 +781,19 @@ Aurora_Parse($$)
Log3 $name, 5, Dumper $result if($Aurora_hasDataDumper);
$hash->{name} = $result->{name} if( defined($result->{name}) );
$hash->{type} = $result->{type} if( defined($result->{type}) );
$hash->{class} = $result->{class} if( defined($result->{class}) );
$hash->{uniqueid} = $result->{uniqueid} if( defined($result->{uniqueid}) );
$hash->{serialNo} = $result->{serialNo} if( defined($result->{serialNo}) );
$hash->{manufacturer} = $result->{manufacturer} if( defined($result->{manufacturer}) );
$hash->{model} = $result->{model} if( defined($result->{model}) );
$hash->{firmwareVersion} = $result->{firmwareVersion} if( defined($result->{firmwareVersion}) );
$hash->{modelid} = $result->{modelid} if( defined($result->{modelid}) );
$hash->{productid} = $result->{productid} if( defined($result->{productid}) );
$hash->{swversion} = $result->{swversion} if( defined($result->{swversion}) );
$hash->{swconfigid} = $result->{swconfigid} if( defined($result->{swconfigid}) );
$hash->{manufacturername} = $result->{manufacturername} if( defined($result->{manufacturername}) );
$hash->{luminaireuniqueid} = $result->{luminaireuniqueid} if( defined($result->{luminaireuniqueid}) );
if( my $effects = $result->{effects} ) {
$hash->{helper}{effects} = $effects->{effectsList} if( defined($effects->{effectsList}) );
$attr{$name}{model} = $result->{modelid} if( !defined($attr{$name}{model}) && $result->{modelid} );
if( my $effect = $effects->{select} ) {
if( $effect ne $hash->{helper}{effect} ) { readingsSingleUpdate($hash, 'effect', $effect, 1 ) };
$hash->{helper}{effect} = $effect;
}
}
$attr{$name}{devStateIcon} = '{(Aurora_devStateIcon($name),"toggle")}' if( !defined( $attr{$name}{devStateIcon} ) );
@ -783,6 +808,7 @@ Aurora_Parse($$)
readingsBeginUpdate($hash);
my $state = $result;
$state = $state->{'state'} if( defined($state->{'state'}) );
my $on = $state->{on}{value};
$on = $hash->{helper}{on} if( !defined($on) );