Skip to content

feat: add DayTripInfoEntity for per-trip sensor data#1698

Open
janfrederik wants to merge 1 commit into
Hyundai-Kia-Connect:masterfrom
flaksit:feat/day-trip-info
Open

feat: add DayTripInfoEntity for per-trip sensor data#1698
janfrederik wants to merge 1 commit into
Hyundai-Kia-Connect:masterfrom
flaksit:feat/day-trip-info

Conversation

@janfrederik

@janfrederik janfrederik commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Adds a new DayTripInfoEntity sensor exposing per-trip data for today, plus the coordinator wiring to populate it. The library (hyundai_kia_connect_api) already implements update_day_trip_info(), but the upstream coordinator never calls it, so the data is unreachable from HA. This PR closes that gap.

What it adds

A single new sensor per vehicle (translation key day_trip_info, e.g. sensor.<car>_day_trip_info):

  • State — integer trip count for today (0 if no trips yet or endpoint unsupported, never unavailable).
  • Attributes:
    • date — ISO YYYY-MM-DD for the day represented.
    • summary — day totals: drive_time, idle_time, distance, avg_speed, max_speed (or null before the first successful fetch).
    • trip_list — per-trip dicts with start_time / end_time (naive ISO 8601 local), drive_time, idle_time, distance, avg_speed, max_speed.

How it works

coordinator.py — in the cached-state branch of _async_update_data(), after the existing update_all_vehicles_with_cached_state() call:

  • Compute today_str = dt_util.now().strftime("%Y%m%d") once.
  • Loop over self.vehicle_manager.vehicles and call vehicle_manager.update_day_trip_info(vehicle_id, today_str) for each.
  • The library call is synchronous → wrapped in async_add_executor_job.
  • The full call is wrapped in try/except Exception with a DEBUG log so a NoDataFound, an unsupported region/firmware, or any transient backend error becomes a debug line, not an UpdateFailed. Integration availability is preserved on vehicles/regions where the endpoint isn't supported.

sensor.py — adds DayTripInfoEntity(SensorEntity, HyundaiKiaConnectEntity):

  • Registered unconditionally in async_setup_entry (one per vehicle). The entity is created at startup even when vehicle.day_trip_info is still None — otherwise users wouldn't see the sensor until the first successful fetch.
  • state returns len(trip_list) when populated, else 0.
  • state_attributes returns {} when day_trip_info is None; otherwise the structure above.
  • Times are emitted as naive ISO 8601 (YYYY-MM-DDTHH:MM:SS) — friendlier than the raw YYYYMMDD/HHMMSS strings the library returns.
  • Icon: mdi:calendar.

strings.json / translations/en.json — adds the day_trip_info translation entry.

Testing

Verified on a real Hyundai Kona Electric (EU):

  • Integration reloads cleanly; no UpdateFailed in HA logs.
  • sensor.<car>_day_trip_info registered in the HA entity registry; state goes from 0 → positive integer as trips happen during the day.
  • start_time / end_time render correctly in HA cards (the ISO-8601 conversion was necessary — the raw library strings were unfriendly).
  • Tested both the empty-state path (car parked, NoDataFound from the endpoint → DEBUG line, sensor stays at 0) and the populated path (after drives, attributes carry the full trip list and day summary).

No new dependencies; all changes use existing library APIs.

Wires the library's existing `update_day_trip_info()` call into the
coordinator and surfaces the result as a new sensor per vehicle.

Coordinator (cached-state branch of `_async_update_data`):

- Compute `today_str` once per cycle from `dt_util.now()`.
- For each vehicle, call `vehicle_manager.update_day_trip_info` via
  `async_add_executor_job` (library call is synchronous).
- Wrap in `try/except Exception` with a DEBUG log so a `NoDataFound`,
  an unsupported region/firmware, or a transient backend error becomes
  a debug line — never `UpdateFailed`.

Sensor (`DayTripInfoEntity`):

- Registered unconditionally in `async_setup_entry` (one per vehicle),
  so the entity exists at startup even when `vehicle.day_trip_info` is
  still `None`.
- `state` returns `len(trip_list)` when populated, else `0` — never
  `unavailable`.
- `state_attributes` exposes:
  - `date` — ISO `YYYY-MM-DD`
  - `summary` — day totals (drive_time, idle_time, distance, avg/max speed)
  - `trip_list` — per-trip dicts with ISO 8601 `start_time` / `end_time`,
    drive/idle time, distance, avg/max speed
- Helpers convert the library's packed `YYYYMMDD` / `HHMMSS` strings to
  naive ISO 8601 local timestamps — friendlier in HA cards than the raw
  strings.
- Translation entry added to `strings.json` and `translations/en.json`.

Tested on a real Hyundai Kona Electric (EU):

- Integration reloads cleanly; no `UpdateFailed` in HA logs.
- Sensor registers; state goes 0 -> positive integer as trips happen.
- `start_time` / `end_time` render correctly in HA cards.
- Empty-state path (car parked, `NoDataFound`) -> DEBUG line, sensor
  stays at `0`; populated path -> full trip list + day summary.
janfrederik added a commit to flaksit/kia_uvo that referenced this pull request Jun 3, 2026
Tags the fork install as 3.3.0-trip so HACS picks it up as newer than
upstream's 3.3.0. The codebase is upstream 3.3.0 plus the per-trip
sensor changes from PR Hyundai-Kia-Connect#1698 — no other deltas. Tag has no -trip.N
iteration suffix; future revisions can bump to -trip.1, -trip.2, etc.
if needed before the PR merges.

@cdnninja cdnninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few initial thoughts. Thank you for doing this!

# Per-trip data. The library implements update_day_trip_info() but the
# upstream coordinator never calls it. Trip data must not fail the
# coordinator update — wrap in try/except so a NoDataFound, an
# unsupported region/firmware, or a transient backend error becomes a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Based on this I wonder if we should have setting to turn this on and off? As well do we want to be polling this every time using API calls?

VehicleEntity(coordinator, coordinator.vehicle_manager.vehicles[vehicle_id])
)
# day_trip_info starts None and is populated by the coordinator's
# first update — register unconditionally so the entity exists even

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Doesn't this mean it will show up for people with cars that don't support it?

@saue0

saue0 commented Jun 4, 2026

Copy link
Copy Markdown

I have a Gas Kona 2024, and this endpoint work event if not EV (tested with postman)
https://mybluelink.ca/tods/api/alerts/maintenance/evTripDetails
will this change add the fonctionnality for us as well ?

@cdnninja

cdnninja commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

I have a Gas Kona 2024, and this endpoint work event if not EV (tested with postman) mybluelink.ca/tods/api/alerts/maintenance/evTripDetails will this change add the fonctionnality for us as well ?

It should as trip details are implemented here: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/master/hyundai_kia_connect_api/KiaUvoApiCA.py

It normalizes to the data model for the regions that implement it. Are you able to install this patch and test it out?

@Merwases

Copy link
Copy Markdown

No, its already available a long time at HA, see Screens:
Screenshot_20260613_200949_Home Assistant
Screenshot_20260613_201025_Home Assistant
Screenshot_20260613_201049_Home Assistant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants