mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +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:
parent
e3483c310b
commit
03db3784ff
@ -43,6 +43,7 @@ Aurora_Initialize($)
|
|||||||
|
|
||||||
#Consumer
|
#Consumer
|
||||||
$hash->{DefFn} = "Aurora_Define";
|
$hash->{DefFn} = "Aurora_Define";
|
||||||
|
$hash->{NotifyFn} = "Aurora_Notify";
|
||||||
$hash->{UndefFn} = "Aurora_Undefine";
|
$hash->{UndefFn} = "Aurora_Undefine";
|
||||||
$hash->{SetFn} = "Aurora_Set";
|
$hash->{SetFn} = "Aurora_Set";
|
||||||
$hash->{GetFn} = "Aurora_Get";
|
$hash->{GetFn} = "Aurora_Get";
|
||||||
@ -127,6 +128,8 @@ Aurora_Define($$)
|
|||||||
$interval = 60 if( defined($interval) && $interval < 10 );
|
$interval = 60 if( defined($interval) && $interval < 10 );
|
||||||
$hash->{INTERVAL} = $interval;
|
$hash->{INTERVAL} = $interval;
|
||||||
|
|
||||||
|
$hash->{helper}{last_config_timestamp} = 0;
|
||||||
|
|
||||||
$hash->{helper}{on} = -1;
|
$hash->{helper}{on} = -1;
|
||||||
$hash->{helper}{colormode} = '';
|
$hash->{helper}{colormode} = '';
|
||||||
$hash->{helper}{ct} = -1;
|
$hash->{helper}{ct} = -1;
|
||||||
@ -143,16 +146,37 @@ Aurora_Define($$)
|
|||||||
my $icon_path = AttrVal("WEB", "iconPath", "default:fhemSVG:openautomation" );
|
my $icon_path = AttrVal("WEB", "iconPath", "default:fhemSVG:openautomation" );
|
||||||
$attr{$name}{'color-icons'} = 2 if( !defined( $attr{$name}{'color-icons'} ) && $icon_path =~ m/openautomation/ );
|
$attr{$name}{'color-icons'} = 2 if( !defined( $attr{$name}{'color-icons'} ) && $icon_path =~ m/openautomation/ );
|
||||||
|
|
||||||
|
$hash->{NOTIFYDEV} = "global";
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
if( $init_done ) {
|
if( $init_done ) {
|
||||||
Aurora_OpenDev($hash);
|
Aurora_OpenDev($hash) if( !IsDisabled($name) );
|
||||||
} else {
|
|
||||||
#InternalTimer(gettimeofday()+10, "Aurora_GetUpdate", $hash, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
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
|
sub
|
||||||
Aurora_Undefine($$)
|
Aurora_Undefine($$)
|
||||||
{
|
{
|
||||||
@ -282,12 +306,6 @@ Aurora_dispatch($$$;$)
|
|||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday()+1, "Aurora_GetUpdate", $hash, 0);
|
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));
|
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({
|
my($err,$data) = HttpUtils_NonblockingGet({
|
||||||
url => "http://$hash->{IP}:16021/api/v1/$attr{$name}{token}/state",
|
url => "http://$hash->{IP}:16021/api/v1/$attr{$name}{token}/state",
|
||||||
timeout => 2,
|
timeout => 2,
|
||||||
@ -713,16 +746,7 @@ Aurora_GetUpdate($)
|
|||||||
callback => \&Aurora_dispatch,
|
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;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -757,18 +781,19 @@ Aurora_Parse($$)
|
|||||||
Log3 $name, 5, Dumper $result if($Aurora_hasDataDumper);
|
Log3 $name, 5, Dumper $result if($Aurora_hasDataDumper);
|
||||||
|
|
||||||
$hash->{name} = $result->{name} if( defined($result->{name}) );
|
$hash->{name} = $result->{name} if( defined($result->{name}) );
|
||||||
$hash->{type} = $result->{type} if( defined($result->{type}) );
|
$hash->{serialNo} = $result->{serialNo} if( defined($result->{serialNo}) );
|
||||||
$hash->{class} = $result->{class} if( defined($result->{class}) );
|
$hash->{manufacturer} = $result->{manufacturer} if( defined($result->{manufacturer}) );
|
||||||
$hash->{uniqueid} = $result->{uniqueid} if( defined($result->{uniqueid}) );
|
$hash->{model} = $result->{model} if( defined($result->{model}) );
|
||||||
|
$hash->{firmwareVersion} = $result->{firmwareVersion} if( defined($result->{firmwareVersion}) );
|
||||||
|
|
||||||
$hash->{modelid} = $result->{modelid} if( defined($result->{modelid}) );
|
if( my $effects = $result->{effects} ) {
|
||||||
$hash->{productid} = $result->{productid} if( defined($result->{productid}) );
|
$hash->{helper}{effects} = $effects->{effectsList} if( defined($effects->{effectsList}) );
|
||||||
$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}) );
|
|
||||||
|
|
||||||
$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} ) );
|
$attr{$name}{devStateIcon} = '{(Aurora_devStateIcon($name),"toggle")}' if( !defined( $attr{$name}{devStateIcon} ) );
|
||||||
|
|
||||||
@ -783,6 +808,7 @@ Aurora_Parse($$)
|
|||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
my $state = $result;
|
my $state = $result;
|
||||||
|
$state = $state->{'state'} if( defined($state->{'state'}) );
|
||||||
|
|
||||||
my $on = $state->{on}{value};
|
my $on = $state->{on}{value};
|
||||||
$on = $hash->{helper}{on} if( !defined($on) );
|
$on = $hash->{helper}{on} if( !defined($on) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user