Added timer support for auto update
This commit is contained in:
parent
5ffb942374
commit
e19d66953b
@ -32,7 +32,9 @@ my %EaseeWallbox_sets = (
|
|||||||
enableSmartCharging => "true,false",
|
enableSmartCharging => "true,false",
|
||||||
overrideChargingSchedule => "",
|
overrideChargingSchedule => "",
|
||||||
pairRfidTag => "",
|
pairRfidTag => "",
|
||||||
pricePerKWH => ""
|
pricePerKWH => "",
|
||||||
|
activateTimer => "",
|
||||||
|
deactivateTimer => "",
|
||||||
);
|
);
|
||||||
|
|
||||||
my %url = (
|
my %url = (
|
||||||
@ -247,16 +249,13 @@ sub EaseeWallbox_Define($$) {
|
|||||||
readingsSingleUpdate( $hash, 'state', 'Undefined', 0 );
|
readingsSingleUpdate( $hash, 'state', 'Undefined', 0 );
|
||||||
|
|
||||||
#Initial load of data
|
#Initial load of data
|
||||||
|
EaseeWallbox_UpdateBaseData($hash);
|
||||||
EaseeWallbox_RefreshData($hash);
|
EaseeWallbox_RefreshData($hash);
|
||||||
|
|
||||||
##RemoveInternalTimer($hash);
|
InternalTimer(gettimeofday()+15, "EaseeWallbox_GetZones", $hash) if (defined $hash);
|
||||||
|
|
||||||
#Call getZones with delay of 15 seconds, as all devices need to be loaded before timer triggers.
|
Log3 $name, 1, sprintf("EaseeWallbox_Define %s: Starting timer with interval %s", $name, InternalVal($name,'INTERVAL', undef));
|
||||||
#Otherwise some error messages are generated due to auto created devices...
|
InternalTimer(gettimeofday()+ InternalVal($name,'INTERVAL', undef), "EaseeWallbox_UpdateDueToTimer", $hash) if (defined $hash);
|
||||||
##InternalTimer(gettimeofday()+15, "EaseeWallbox_GetZones", $hash) if (defined $hash);
|
|
||||||
|
|
||||||
##Log3 $name, 1, sprintf("EaseeWallbox_Define %s: Starting timer with interval %s", $name, InternalVal($name,'INTERVAL', undef));
|
|
||||||
##InternalTimer(gettimeofday()+ InternalVal($name,'INTERVAL', undef), "EaseeWallbox_UpdateDueToTimer", $hash) if (defined $hash);
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,28 +278,14 @@ sub EaseeWallbox_Get($@) {
|
|||||||
my $cmdTemp = EaseeWallbox_getCmdList( $hash, $opt, \%EaseeWallbox_gets );
|
my $cmdTemp = EaseeWallbox_getCmdList( $hash, $opt, \%EaseeWallbox_gets );
|
||||||
return $cmdTemp if ( defined($cmdTemp) );
|
return $cmdTemp if ( defined($cmdTemp) );
|
||||||
|
|
||||||
my $cmd = $args[0];
|
$hash->{LOCAL} = 1;
|
||||||
my $arg = $args[1];
|
EaseeWallbox_GetChargers($hash) if $opt eq "chargers";
|
||||||
|
EaseeWallbox_GetChargerConfig($hash) if $opt eq "config";
|
||||||
if ($opt eq 'baseData') {
|
EaseeWallbox_GetChargerSite($hash) if $opt eq "sites";
|
||||||
EaseeWallbox_GetChargers($hash);
|
EaseeWallbox_RefreshData($hash) if $opt eq "update";
|
||||||
EaseeWallbox_GetChargerConfig($hash);
|
EaseeWallbox_UpdateBaseData($hash) if $opt eq 'baseData';
|
||||||
EaseeWallbox_GetChargerSite($hash);
|
delete $hash->{LOCAL};
|
||||||
EaseeWallbox_RefreshData($hash);
|
return undef;
|
||||||
|
|
||||||
} elsif ( $opt eq "update" ) {
|
|
||||||
Log3 $name, 3, "EaseeWallbox_Get $name: Updating all data";
|
|
||||||
$hash->{LOCAL} = 1;
|
|
||||||
EaseeWallbox_RequestChargerState($hash);
|
|
||||||
EaseeWallbox_RequestCurrentSession($hash);
|
|
||||||
delete $hash->{LOCAL};
|
|
||||||
return undef;
|
|
||||||
} else {
|
|
||||||
return EaseeWallbox_GetChargers($hash) if $opt eq "chargers";
|
|
||||||
return EaseeWallbox_RefreshData($hash) if $opt eq "profile";
|
|
||||||
return EaseeWallbox_GetChargerConfig($hash) if $opt eq "config";
|
|
||||||
return EaseeWallbox_GetChargerSite($hash) if $opt eq "sites";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub EaseeWallbox_Set($@) {
|
sub EaseeWallbox_Set($@) {
|
||||||
@ -315,12 +300,22 @@ sub EaseeWallbox_Set($@) {
|
|||||||
my $cmdTemp = EaseeWallbox_getCmdList( $hash, $opt, \%EaseeWallbox_sets );
|
my $cmdTemp = EaseeWallbox_getCmdList( $hash, $opt, \%EaseeWallbox_sets );
|
||||||
return $cmdTemp if ( defined($cmdTemp) );
|
return $cmdTemp if ( defined($cmdTemp) );
|
||||||
|
|
||||||
if ( $opt eq "stop" ) {
|
if ( $opt eq "deactivateTimer" ) {
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
Log3 $name, 1,
|
Log3 $name, 1,
|
||||||
"EaseeWallbox_Set $name: Stopped the timer to automatically update readings";
|
"EaseeWallbox_Set $name: Stopped the timer to automatically update readings";
|
||||||
readingsSingleUpdate( $hash, 'state', 'Initialized', 0 );
|
readingsSingleUpdate( $hash, 'state', 'Initialized', 0 );
|
||||||
return undef;
|
return undef;
|
||||||
|
}
|
||||||
|
elsif ( $opt eq "activateTimer" ) {
|
||||||
|
#Update once manually and then start the timer
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
$hash->{LOCAL} = 1;
|
||||||
|
EaseeWallbox_RefreshData($hash);
|
||||||
|
delete $hash->{LOCAL};
|
||||||
|
InternalTimer(gettimeofday()+ InternalVal($name,'INTERVAL', undef), "EaseeWallbox_UpdateDueToTimer", $hash);
|
||||||
|
readingsSingleUpdate($hash,'state','Started',0);
|
||||||
|
Log3 $name, 1, sprintf("EaseeWallbox_Set %s: Updated readings and started timer to automatically update readings with interval %s", $name, InternalVal($name,'INTERVAL', undef));
|
||||||
}
|
}
|
||||||
elsif ( $opt eq "interval" ) {
|
elsif ( $opt eq "interval" ) {
|
||||||
my $interval = shift @param;
|
my $interval = shift @param;
|
||||||
@ -352,6 +347,20 @@ sub EaseeWallbox_Set($@) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub EaseeWallbox_RefreshData($){
|
||||||
|
my $hash = shift;
|
||||||
|
EaseeWallbox_GetChargerSite($hash);
|
||||||
|
EaseeWallbox_RequestChargerState($hash);
|
||||||
|
EaseeWallbox_RequestCurrentSession($hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub EaseeWallbox_UpdateBaseData($){
|
||||||
|
my $hash = shift;
|
||||||
|
EaseeWallbox_GetChargers($hash);
|
||||||
|
EaseeWallbox_GetChargerConfig($hash);
|
||||||
|
EaseeWallbox_RefreshData($hash);
|
||||||
|
}
|
||||||
|
|
||||||
sub EaseeWallbox_LoadToken {
|
sub EaseeWallbox_LoadToken {
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -1001,14 +1010,7 @@ sub EaseeWallbox_UpdateDueToTimer($) {
|
|||||||
"EaseeWallbox_UpdateDueToTimer", $hash );
|
"EaseeWallbox_UpdateDueToTimer", $hash );
|
||||||
readingsSingleUpdate( $hash, 'state', 'Polling', 0 );
|
readingsSingleUpdate( $hash, 'state', 'Polling', 0 );
|
||||||
}
|
}
|
||||||
|
EaseeWallbox_RefreshData($hash);
|
||||||
#EaseeWallbox_RequestZoneUpdate($hash);
|
|
||||||
#EaseeWallbox_RequestAirComfortUpdate($hash);
|
|
||||||
#EaseeWallbox_RequestMobileDeviceUpdate($hash);
|
|
||||||
#EaseeWallbox_RequestWeatherUpdate($hash);
|
|
||||||
|
|
||||||
#EaseeWallbox_RequestDeviceUpdate($hash);
|
|
||||||
#EaseeWallbox_RequestPresenceUpdate($hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub EaseeWallbox_RequestCurrentSession($) {
|
sub EaseeWallbox_RequestCurrentSession($) {
|
||||||
|
Loading…
Reference in New Issue
Block a user