From fa6369534ff4e663d6baec66401b0e0ac3b97b74 Mon Sep 17 00:00:00 2001 From: zivillian Date: Fri, 9 Aug 2024 00:02:37 +0200 Subject: [PATCH] geo coordinates seem to be optional --- libgwmapi/DTO/Vehicle/VehicleStatus.cs | 4 ++-- ora2mqtt/RunCommand.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libgwmapi/DTO/Vehicle/VehicleStatus.cs b/libgwmapi/DTO/Vehicle/VehicleStatus.cs index ac633ef..b64fb18 100644 --- a/libgwmapi/DTO/Vehicle/VehicleStatus.cs +++ b/libgwmapi/DTO/Vehicle/VehicleStatus.cs @@ -29,10 +29,10 @@ public class VehicleStatus public VehicleStatusItems[] Items { get; set; } [JsonPropertyName("latitude")] - public double Latitude { get; set; } + public double? Latitude { get; set; } [JsonPropertyName("longitude")] - public double Longitude { get; set; } + public double? Longitude { get; set; } [JsonPropertyName("oilQty")] public object OilQty { get; set; } diff --git a/ora2mqtt/RunCommand.cs b/ora2mqtt/RunCommand.cs index 0d936ed..e661be5 100644 --- a/ora2mqtt/RunCommand.cs +++ b/ora2mqtt/RunCommand.cs @@ -117,8 +117,12 @@ private async Task PublishStatusAsync(IMqttClient mqtt, GwmApiClient gwm, Cancel var topicPrefix = $"GWM/{vehicle.Vin}/status"; await PublishMessageAsync(mqtt, $"{topicPrefix}/AcquisitionTime", status.AcquisitionTime, cancellationToken); await PublishMessageAsync(mqtt, $"{topicPrefix}/UpdateTime", status.UpdateTime, cancellationToken); - await PublishMessageAsync(mqtt, $"{topicPrefix}/Latitude", status.Latitude, cancellationToken); - await PublishMessageAsync(mqtt, $"{topicPrefix}/Longitude", status.Longitude, cancellationToken); + if (status.Latitude.HasValue && status.Longitude.HasValue) + { + await PublishMessageAsync(mqtt, $"{topicPrefix}/Latitude", status.Latitude.Value, cancellationToken); + await PublishMessageAsync(mqtt, $"{topicPrefix}/Longitude", status.Longitude.Value, cancellationToken); + } + foreach (var item in status.Items) { if (item.Value is null) continue;