Skip to content

Update zone.home from router GPS (#28) - #32

Merged
crbn60 merged 7 commits into
devfrom
fix/issue-28-home-location-editable-zone
Apr 19, 2026
Merged

Update zone.home from router GPS (#28)#32
crbn60 merged 7 commits into
devfrom
fix/issue-28-home-location-editable-zone

Conversation

@crbn60

@crbn60 crbn60 commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #28. With "Update Home Assistant home location from GPS" enabled, zone.home never moved to the router's reported GPS position.

Root cause

Discovered by wiring diagnostic logging through _async_apply_home_location and watching it run against a live HA 2026.4.2 instance: the RutOS ubus /gps/position/status endpoint returns latitude, longitude, and altitude as strings (e.g. "44.817068", "156.4"). The integration was passing them straight into homeassistant.set_location, where int(round(altitude)) raised TypeError: type str doesn't define __round__ method. The exception was raised inside a coroutine scheduled via hass.async_create_task and never surfaced under the custom_components.rutos logger, so users (and earlier diagnostic passes) saw only the symptom — zone.home frozen at its last persisted value.

This bug predates PR #32; the same uncast-altitude code exists on dev. Two earlier theories were investigated and ruled out:

  • Editable zone.home skips core_config_updated — wrong for modern HA. homeassistant.set_location propagates to editable zones on 2026.4+; verified by direct service calls.
  • elevation must be an int — true but not the whole story. Even after casting to int, the cast itself raised on string input before reaching the service call.

Fix

custom_components/rutos/__init__.py: inside _update_home_location, coerce latitude, longitude, and altitude to float before scheduling _async_apply_home_location. If lat/lon fail to parse the listener returns silently; if altitude fails, elevation is omitted from the service call. _async_apply_home_location then stays simple: it does int(round(altitude)) knowing the input is numeric.

The belt-and-suspenders storage-collection update path (_async_update_stored_home_zone) is kept — it is a no-op on HA 2026.4+ but guards older releases where stored zones may not follow core_config_updated.

Changes

  • custom_components/rutos/__init__.py: float-coerce router GPS strings at the listener boundary before the service call.
  • tests/test_home_location.py: add test_string_valued_router_gps_is_coerced — mocks the router returning all-string GPS fields and asserts set_location is called with float latitude/longitude and int elevation.
  • Earlier commits on this branch (editable-zone repair issue, stored-zone update) are preserved as defensive coverage for older HA releases.

Verification on live HA

  • Before fix: zone.home stuck at manually set test coordinates; integration listener fires every ~30 s but service call never runs.
  • After fix: zone.home attributes are latitude: 44.817068, longitude: -76.23063 — matches the router; zero rutos log entries at any level; person entities correctly resolve to home because the zone is now where the router is.

Test plan

  • .venv/bin/python -m pytest tests/ — 187 passed
  • .venv/bin/ruff check custom_components/rutos/
  • Manual verification on HA 2026.4.2 against a RUTX50: zone.home tracks router GPS across coordinator refreshes.

🤖 Generated with Claude Code

crbn60 and others added 3 commits April 18, 2026 16:08
When a user has customized zone.home in Settings > Areas & Zones, HA
persists the zone with editable=True and skips wiring its
core_config_updated listener. The homeassistant.set_location service
then updates hass.config but never propagates to the zone.home entity,
so the integration silently fails to update the home location.

Detect editable=True on zone.home and log a one-time WARNING instructing
the user to remove the custom home zone. Resume updates if they do.
In addition to the log warning, create a Home Assistant Repair issue when
zone.home is detected as user-customized, and delete it automatically
once the condition clears or the config entry unloads. Adds the
corresponding translation strings for title and description.
Users cannot delete zone.home, so the prior warn-and-skip approach left
customized home zones permanently stuck. Instead, when zone.home is
editable, update the stored entry directly via the zone storage
collection so the entity moves while preserving the user's radius,
icon, and passive settings.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
crbn60 and others added 4 commits April 18, 2026 20:03
homeassistant.set_location's schema requires elevation to be an int, but
the integration was passing the router's float altitude (e.g. 156.2).
The resulting voluptuous MultipleInvalid was swallowed by async_create_task
and never surfaced under the rutos logger, so the home-location update
silently failed every coordinator refresh.

This was the real root cause of #28 — the editable-zone theory behind the
earlier commits on this branch turned out to be wrong on modern HA
releases, where set_location does propagate to editable home zones.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Temporary diagnostic commit for #28. To be reverted after investigation.
Diagnostic commit only. Listener fires every ~30s with correct GPS
coords but zone.home never moves on the live HA — manual set_location
calls with the same payload move the zone fine, so something between
the warning log and the actual service call is failing silently.

Log types + values on entry, catch the int-cast, and wrap the
set_location call in try/except with .__name__ logging to expose
whatever's being swallowed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The RutOS ubus /gps/position/status endpoint returns latitude,
longitude, and altitude as strings (e.g. "44.817068", "156.4"). The
integration was passing them straight into homeassistant.set_location,
where `int(round(altitude))` raised a TypeError ("type str doesn't
define __round__ method"). The exception was swallowed by the
async_create_task scheduler, so set_location never ran and zone.home
never moved — the visible symptom of issue #28.

Coerce all three fields to floats inside the listener before scheduling
the apply task, so _async_apply_home_location can rely on numeric
inputs. Drop the debug breadcrumbs now that the failure mode is
understood.

Add a regression test that mocks the router's all-strings GPS response
and asserts the dispatched service_data contains float lat/lon and int
elevation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@crbn60 crbn60 changed the title Warn when zone.home is editable and skip no-op set_location (#28) Update zone.home from router GPS (#28) Apr 19, 2026
@crbn60
crbn60 merged commit 6652a49 into dev Apr 19, 2026
3 checks passed
@crbn60
crbn60 deleted the fix/issue-28-home-location-editable-zone branch April 19, 2026 01:33
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.

HA Home location doesn't appear to be updating.

1 participant