Skip to content

Commit

Permalink
Cast latitude/longitude values as floats in location mqtt topic
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmay committed Mar 11, 2024
1 parent c958404 commit f186445
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/teslamate/mqtt/pubsub/vehicle_subscriber.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriber do
if summary.latitude != nil and summary.longitude != nil do
location =
%{
latitude: summary.latitude,
longitude: summary.longitude
# latitude/longitude are Decimal type and without conversion would come out as string type.
latitude: Decimal.to_float(summary.latitude),
longitude: Decimal.to_float(summary.longitude)
}
|> Jason.encode!()

Expand Down
4 changes: 2 additions & 2 deletions test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do
shift_state: "D",
state: :online,
since: DateTime.utc_now(),
latitude: 37.889602,
longitude: 41.129182,
latitude: Decimal.from_float(37.889602),
longitude: Decimal.from_float(41.129182),
power: -9,
speed: 40,
heading: 340,
Expand Down
4 changes: 2 additions & 2 deletions test/teslamate/vehicles/vehicle_sync_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ defmodule TeslaMate.Vehicles.VehicleSyncTest do
assert_receive {MqttPublisherMock, {:publish, ^topic, data, [retain: true, qos: 1]}}

assert Jason.decode!(data) == %{
"latitude" => "37.889544",
"longitude" => "41.128817"
"latitude" => 37.889544,
"longitude" => 41.128817
}

refute_receive _
Expand Down

0 comments on commit f186445

Please sign in to comment.