Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location topic #3729

Merged
merged 2 commits into from
Mar 18, 2024
Merged

Add location topic #3729

merged 2 commits into from
Mar 18, 2024

Conversation

brianmay
Copy link
Collaborator

Fixes #3660.

Copy link

netlify bot commented Mar 11, 2024

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit 00f3620
🔍 Latest deploy log https://app.netlify.com/sites/teslamate/deploys/65f7ee2c80400700087eee41
😎 Deploy Preview https://deploy-preview-3729--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@brianmay
Copy link
Collaborator Author

Not tested yet :-)

@brianmay brianmay force-pushed the location_mqtt_topic branch 4 times, most recently from b0e4f15 to 6834fd5 Compare March 11, 2024 03:09
@brianmay
Copy link
Collaborator Author

Not sure I understand why this test is failing:

 1) test publishes vehicle data (TeslaMate.Mqtt.PubSub.VehicleSubscriberTest)
Error:      test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs:27
     Unexpectedly received message {VehiclesMock, {:subscribe_to_summary, 0}} (which matched _)
     code: refute_receive _
     stacktrace:
       test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs:103: (test)

The test already has at the top:

    assert_receive {VehiclesMock, {:subscribe_to_summary, 0}}

@brianmay brianmay force-pushed the location_mqtt_topic branch from 6834fd5 to 609deff Compare March 11, 2024 04:02
@brianmay
Copy link
Collaborator Author

Test now works, but I don't understand why. Seems dodgy.

@brianmay brianmay force-pushed the location_mqtt_topic branch from 609deff to 9338e3e Compare March 11, 2024 05:39
@brianmay
Copy link
Collaborator Author

Not sure how the tests were even passing before. All fixed now.

@brianmay
Copy link
Collaborator Author

Problem with this is that there are times when we have the latitude, longitude, but not the elevation. So as a result nothing gets published. Arrgh.

Think I will remove elevation. I think the Tesla API treats elevation is very different from latitude and longitude anyway.

@brianmay brianmay force-pushed the location_mqtt_topic branch 3 times, most recently from 68576b9 to c958404 Compare March 11, 2024 07:17
@brianmay
Copy link
Collaborator Author

brianmay commented Mar 11, 2024

Seems to be working so far.

latitude/longitude are being encoded as quoted string values, not floats. Which is a bit unexpected.

I might try to get them as floats.

@brianmay
Copy link
Collaborator Author

teslamate uses Decimal type everywhere for latitude/longitude.

Suspect this is a misunderstanding here. Decimal is required for applications that keep track of numbers - like $ and cents, where it is vital that we represent values like 0.01 exactly.

But this is not one of those applications. It doesn't matter really if a latitude of 0.01 gets converted to 0.0099999997 (https://hexdocs.pm/elixir/1.13.4/Float.html). In fact it is likely the values came out of floating point numbers in Tesla's code anyway.

But will keep it as is for now.

Values are now coming out as floats. And tests appear to be passing.

Early on one of the tests passed, which I hadn't even updated. That was weird. Fixed now.

@JakobLichterfeld
Copy link
Collaborator

Thanks for your deditcation!

@JakobLichterfeld JakobLichterfeld added enhancement New feature or request area:teslamate Related to TeslaMate core labels Mar 11, 2024
@brianmay
Copy link
Collaborator Author

brianmay commented Mar 11, 2024

Arggh. Looks like some parts of the code use the Decimal type, and other parts use the floating point type.

I like having compile time type checking...

I think I might get rid of all the Decimal values. For latitude/longitude. Just use floats everywhere.

Mar 12 08:01:51 iot2 teslamate[8982]: 2024-03-12 08:01:51.653 [error] GenServer #PID<0.176940.0> terminating
Mar 12 08:01:51 iot2 teslamate[8982]: ** (FunctionClauseError) no function clause matching in Decimal.to_float/1
Mar 12 08:01:51 iot2 teslamate[8982]:     (decimal 2.1.1) lib/decimal.ex:1498: Decimal.to_float(-37.906105)
Mar 12 08:01:51 iot2 teslamate[8982]:     (teslamate 1.28.4) lib/teslamate/mqtt/pubsub/vehicle_subscriber.ex:81: TeslaMate.Mqtt.PubSub.VehicleSubscriber.handle_info/2
Mar 12 08:01:51 iot2 teslamate[8982]:     (stdlib 5.2) gen_server.erl:1095: :gen_server.try_handle_info/3
Mar 12 08:01:51 iot2 teslamate[8982]:     (stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
Mar 12 08:01:51 iot2 teslamate[8982]:     (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Mar 12 08:01:51 iot2 teslamate[8982]: Last message: %TeslaMate.Vehicles.Vehicle.Summary{car: %TeslaMate.Log.Car{__meta__: #Ecto.Schema.Metadata<:loaded, "cars">, id: 1, name: nil, efficiency: 0.15006, model: "S", trim_badging: "90D", marketing_name: nil, exterior_color: "Red", wheel_type: "AeroTurbine19", spoiler_type: "None", eid: 1492931337154343, vid: 1318482982, vin: "5YJSB7E22GF153397", settings_id: 1, settings: %TeslaMate.Settings.CarSettings{__meta__: #Ecto.Schema.Metadata<:loaded, "car_settings">, id: 1, suspend_min: 21, suspend_after_idle_min: 15, req_not_unlocked: true, free_supercharging: true, use_streaming_api: true, car: #Ecto.Association.NotLoaded<association :car is not loaded>}, charging_processes: #Ecto.Association.NotLoaded<association :charging_processes is not loaded>, positions: #Ecto.Association.NotLoaded<association :positions is not loaded>, drives: #Ecto.Association.NotLoaded<association :drives is not loaded>, inserted_at: ~N[2021-01-07 00:28:25], updated_at: ~N[2024-02-09 21:57:09]}, display_name: nil, state: :online, since: ~U[2024-03-11 20:47:54.879000Z], healthy: true, latitude: -37.906105, longitude: 145.343587, heading: 19, battery_level: 69, charging_state: "Disconnected", usable_battery_level: 69, ideal_battery_range_km: 291.29, est_battery_range_km: 254.68, rated_battery_range_km: 363.15, charge_energy_added: 0.0, speed: 0, outside_temp: 24.5, inside_temp: 18.6, is_climate_on: true, is_preconditioning: false, locked: false, sentry_mode: nil, plugged_in: false, scheduled_charging_start_time: nil, charge_limit_soc: 90, charger_power: 0, windows_open: true, doors_open: false, odometer: 157541.71, shift_state: "P", charge_port_door_open: false, time_to_full_charge: 0.0, charger_phases: nil, charger_actual_current: 0, charger_voltage: 0, version: "2024.2.7", update_available: false, update_version: "", is_user_present: true, geofence: nil, model: "S", trim_badging: "90D", exterior_color: "Red", wheel_type: "AeroTurbine19", spoiler_type: "None", trunk_open: false, frunk_open: false, elevation: 228, power: 1, charge_current_request: 24, ...}

@brianmay
Copy link
Collaborator Author

Database values are stored in decimal, since 45d94d5. Supposedly this makes things more efficient.

Values from the TeslaApi are retrieved at floats.

I think I am will put all the Decimal types back and have this new code deal with both cases.

@brianmay brianmay force-pushed the location_mqtt_topic branch from f186445 to 5612ee7 Compare March 11, 2024 21:55
@brianmay
Copy link
Collaborator Author

We seem to have an unrelated intermittent test failure. https://github.com/teslamate-org/teslamate/actions/runs/8240221994/job/22535198738?pr=3729

@brianmay brianmay closed this Mar 11, 2024
@brianmay brianmay reopened this Mar 11, 2024
@brianmay
Copy link
Collaborator Author

Sorry, didn't mean to close, pushed the wrong thing.

@brianmay
Copy link
Collaborator Author

brianmay commented Mar 11, 2024

Testing again. But next drive not scheduled until this afternoon.

@brianmay
Copy link
Collaborator Author

Just noticed we always publish this every time. We should be checking if the value has changed since the last time. Will fix.

@brianmay brianmay force-pushed the location_mqtt_topic branch 2 times, most recently from 406f9c4 to 7b60382 Compare March 12, 2024 03:45
@brianmay
Copy link
Collaborator Author

See #3736 concerning the test failures,

All the tests passed on my box :-)

@brianmay
Copy link
Collaborator Author

This seems to be working correctly now.

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Mar 12, 2024

Test issue should be resolved by #3733. If you don't mind, update from master.

Edit: issue with async run still persist on master, "solved" by rerun action.

@brianmay brianmay force-pushed the location_mqtt_topic branch from 7b60382 to 4839e3d Compare March 12, 2024 22:20
@brianmay brianmay force-pushed the location_mqtt_topic branch from 4839e3d to b7bcdbe Compare March 17, 2024 06:00
@brianmay
Copy link
Collaborator Author

Rebased against latest master.

Not 100% comfortable adding 30 extra lines to the handle_info function call, but I think to early to refactor.

Refactoring probably should happen if we are going to output other stuff as json blobs however.

@brianmay
Copy link
Collaborator Author

Had to retry CI tests three times to get a pass :-(

I think they work OK from my box however.

@JakobLichterfeld
Copy link
Collaborator

Will merge as soon as I came up with a good changelog for this, as it will break some third party integrations

@brianmay
Copy link
Collaborator Author

Shouldn't cause any breakage, the current topics remain unchanged.

Unless I missed something here?

@JakobLichterfeld
Copy link
Collaborator

Shouldn't cause any breakage, the current topics remain unchanged.

Unless I missed something here?

You are absolutely right, and I did not look close enough. Will double-check and merge tomorrow.

Thanks for your dedication!

Copy link
Collaborator

@JakobLichterfeld JakobLichterfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I added the doc entry for the new topic

@JakobLichterfeld JakobLichterfeld merged commit b5285d2 into master Mar 18, 2024
14 checks passed
@JakobLichterfeld JakobLichterfeld deleted the location_mqtt_topic branch March 18, 2024 07:36
@WesSec
Copy link

WesSec commented Mar 18, 2024

What a hero, thanks for the efforts <3

@vbarrier
Copy link

@tobiasehlert I think this new topic, generate a lot of warning on teslamateapi

@tobiasehlert
Copy link
Collaborator

@tobiasehlert I think this new topic, generate a lot of warning on teslamateapi

@vbarrier, noticed some errors as well at home. Going to add a fix very soon 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:teslamate Related to TeslaMate core enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: bundle MQTT data in one json blob
5 participants