chore: consistently use lat/lon

This commit is contained in:
andig 2025-09-22 13:21:20 +02:00
parent 7dfb36d71f
commit 2a74cbe13a
4 changed files with 22 additions and 24 deletions

View file

@ -16,9 +16,7 @@ type VehicleApi struct {
lp loadpoint.API
enabled bool
geofenceEnabled bool
latitude float64
longitude float64
radius float64
lat, lon, radius float64
cacheRefreshExpectedAt time.Time
}
@ -30,8 +28,8 @@ func init() {
func NewVehicleApiFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
GeofenceEnabled bool `mapstructure:"geofence_enabled"`
Latitude float64 `mapstructure:"latitude"`
Longitude float64 `mapstructure:"longitude"`
Lat float64 `mapstructure:"lat"`
Lon float64 `mapstructure:"lon"`
Radius float64 `mapstructure:"radius"`
}{
Radius: 100, // Default 100 meter radius
@ -43,8 +41,8 @@ func NewVehicleApiFromConfig(other map[string]interface{}) (api.Charger, error)
c := &VehicleApi{
geofenceEnabled: cc.GeofenceEnabled,
latitude: cc.Latitude,
longitude: cc.Longitude,
lat: cc.Lat,
lon: cc.Lon,
radius: cc.Radius,
}
@ -178,10 +176,10 @@ func (c *VehicleApi) LoadpointControl(lp loadpoint.API) {
// distance approximates Euclidean distance, good enough for geofencing
func (c *VehicleApi) distance(lat, lon float64) float64 {
const metersPerDegreeLat = 111000 // ~111km per degree latitude (constant)
const metersPerDegreeLat = 111000 // ~111km per degree lat (constant)
deltaLat := (c.latitude - lat) * metersPerDegreeLat
deltaLon := (c.longitude - lon) * metersPerDegreeLat * math.Cos(c.latitude*math.Pi/180) // varies by latitude
deltaLat := (c.lat - lat) * metersPerDegreeLat
deltaLon := (c.lon - lon) * metersPerDegreeLat * math.Cos(c.lat*math.Pi/180) // varies by lat
return math.Sqrt(deltaLat*deltaLat + deltaLon*deltaLon)
}

View file

@ -48,7 +48,7 @@ render: |
type: vehicle-api
{{- if .geofence_enabled }}
geofence_enabled: {{ .geofence_enabled }}
latitude: {{ .latitude }}
longitude: {{ .longitude }}
lat: {{ .lat }}
lon: {{ .lon }}
radius: {{ .radius }}
{{- end }}

View file

@ -441,6 +441,18 @@ params:
description:
de: Temperaturquelle
en: Temperature source
- name: lat
description:
en: Latitude
de: Breitengrad
type: float
example: 55.7351
- name: lon
description:
en: Longitude
de: Längengrad
type: float
example: 9.1275
presets:
vehicle-base:
@ -531,18 +543,8 @@ presets:
forecast-base:
params:
- name: lat
description:
en: Latitude
de: Breitengrad
type: float
example: 55.7351
required: true
- name: lon
description:
en: Longitude
de: Längengrad
type: float
example: 9.1275
required: true
- name: dec
description:

View file

@ -38,8 +38,6 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values
t.Parallel()
for _, tmpl := range ByClass(class, WithDeprecated()) {
tmpl := tmpl
// set default values for all params
values := tmpl.Defaults(RenderModeUnitTest)