2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2024-11-22 02:59:49 +00:00

96_RenaultZE:Support for RenaultZE cars

git-svn-id: https://svn.fhem.de/fhem/trunk@28119 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
plin 2023-11-01 08:20:17 +00:00
parent 443dfe805f
commit 4d33b0ce2a

View File

@ -38,6 +38,7 @@
############################################################################################################################
# Version History
# v 1.14 changed code for automatic update of readings distance/home during
# v 1.13 recalculation of varius readings distance/home during update
# v 1.12 implemented new Attribute ze_homeRadius
# v 1.11 implemented new function GET checkAPIkeys
@ -106,7 +107,7 @@ use Time::Piece;
#use JSON qw(decode_json);
use JSON;
my $RenaultZE_version ="V1.13 / 31.10.2023";
my $RenaultZE_version ="V1.14 / 1.11.2023";
my %RenaultZE_sets = (
"AC:on,cancel" => "",
@ -516,10 +517,6 @@ sub RenaultZE_Main3($) {
$res = RenaultZE_gData_Step1($hash,'charge-mode') if ($model ne "SPRING");
Log3 $name, 5, "RenaultZE_gData_Step1 - charge-mode - RC=".$res if ($model ne "SPRING");
}, undef);
# recalc distance from home an update home info & status
my $gpsLatitude = ReadingsVal($name,"gpsLatitude","empty");
my $gpsLongitude = ReadingsVal($name,"gpsLongitude","empty");
RenaultZE_distanceFromHome($hash,$gpsLatitude,$gpsLongitude);
}
if ($key eq "GET_vehicles")
@ -606,7 +603,7 @@ sub RenaultZE_Attr(@) {
$_[3] = $attrVal;
$hash->{".reset"} = 1 if defined($hash->{LPID});
}
elsif (($attrName eq "disabled") && ($attrVal == 1))
if (($attrName eq "disabled") && ($attrVal == 1))
{
readingsSingleUpdate($hash,"state","disabled",1);
readingsSingleUpdate($hash,"ze_Step","RenaultZE ($name) is disabled",1);
@ -644,6 +641,16 @@ sub RenaultZE_Attr(@) {
InternalTimer($firstTrigger, "RenaultZE_UpdateTimer", $hash, 0);
}
}
if ($attrName eq "ze_homeRadius")
{
my $gpsLatitude = ReadingsVal($name,"gpsLatitude","empty");
my $gpsLongitude = ReadingsVal($name,"gpsLongitude","empty");
my $homeRadius = 20; # defule radius
$homeRadius = $attrVal if ( $cmd eq "set" );
$homeRadius = 20 if ( $homeRadius eq "" ); # just in case
#Log3 $name, 5, "pre RenaultZE_distanceFromHome - In ".$cmd."/".$gpsLatitude." ".$gpsLongitude."/".$homeRadius;
RenaultZE_distanceFromHome($hash,$gpsLatitude,$gpsLongitude,$homeRadius);
}
return undef;
}
@ -1062,7 +1069,7 @@ sub RenaultZE_gData_Step2($)
my $link = "<html><a href=\"https://www.google.com/maps/place/".$gpsLatitude.",".$gpsLongitude."\" target=\”_blank\”>Google Maps</a></html>";
if ( $oldlat != $gpsLatitude or $oldlong != $gpsLongitude ) {
Log3 $name, 5, "RenaultZE_gData_Step2 - GPS ".$oldlat."/".$gpsLatitude." ".$oldlong."/".$gpsLongitude;
RenaultZE_distanceFromHome($hash,$gpsLatitude,$gpsLongitude);
RenaultZE_distanceFromHome($hash,$gpsLatitude,$gpsLongitude,"auto");
}
readingsBeginUpdate($hash);
readingsBulkUpdate($hash,"gpsLatitude",$gpsLatitude);
@ -1644,10 +1651,11 @@ sub RenaultZE_pp_err($$)
}
return $output;
}
sub RenaultZE_distanceFromHome($$$)
sub RenaultZE_distanceFromHome($$$$)
{
my ($hash, $lat, $long) = @_;
my ($hash, $lat, $long, $homeRadius) = @_;
my $name = $hash->{NAME};
Log3 $name, 5, "RenaultZE_distanceFromHome - In ".$hash."/".$lat." ".$long."/".$homeRadius;
my $hlong = AttrVal( $name, "ze_longitude", AttrVal( "global", "longitude", 0.0 ) );
my $hlat = AttrVal( $name, "ze_latitude", AttrVal( "global", "latitude", 0.0 ) );
@ -1669,7 +1677,8 @@ sub RenaultZE_distanceFromHome($$$)
my $dim = "km";
my $homeinfo = "";
my $homestate = "away";
my $homeRadius = AttrVal( $name, "ze_homeRadius", 20 );
$homeRadius = AttrVal( $name, "ze_homeRadius", 20 ) if ( $homeRadius eq "auto");
Log3 $name, 5, "RenaultZE_distanceFromHome - Check ".$hash."/".$lat." ".$long."/".$homeRadius;
if ($distance < $homeRadius) {
$distance = $distance * 1000;