skodaconnect/homeassistant-myskoda

Handle vehicle in motion

Closed this issue · 4 comments

Describe the solution you'd like
Add support for detecting vehicle in motion

Describe alternatives you've considered
This is present in skodaconnect, but switching back is undesired

Additional context
We can detect a vehicle in motion from this API response:

GET https://mysmob.api.connect.skoda-auto.cz/api/v1/maps/positio - response: 200 (93 bytes) {"positions":[],"errors":[{"type":"VEHICLE_IN_MOTION","description":"Vehicle is in motion"}]}

Can you describe the current and desired behavior of the integration while the API reports the vehicle is in motion?

Current
When the car is in motion, the device_tracker returns Unknown because we set lat/lon to None, due to the "positions" list from API reply above being empty

Desired
When the car is in motion, do not update the device_tracker, instead turn on a new boolean sensor indicating the device is in motion.
When a new position update is received, turn off the motion indicator and update the device_tracker as normal

The boolean in_motion sensor makes sense to me.

I'm not sure about not updating the device tracker though. We know it's no longer at the 'last known' position, so None for the coordinates, resulting in HA reporting Unknown seems correct?

I don't know if we can maybe set location_name (see https://developers.home-assistant.io/docs/core/entity/device-tracker/#trackerentity)? Like, what happens if we set that to In Motion?

The location_name is defined at https://github.com/home-assistant/core/blob/2bd5039f28e639439dfd6da216f51921072395f3/homeassistant/components/device_tracker/config_entry.py#L245 as:

"Return a location name for the current location of the device."

and if it is not set to None, it is reported as the state of the tracker. Looks like a cool solution, as long as we clear it when the device is no longer in motion