Skip to content

Refactor Places integration internals#413

Merged
Snuffy2 merged 30 commits into
custom-components:masterfrom
Snuffy2:architecture-cleanup-design
May 20, 2026
Merged

Refactor Places integration internals#413
Snuffy2 merged 30 commits into
custom-components:masterfrom
Snuffy2:architecture-cleanup-design

Conversation

@Snuffy2

@Snuffy2 Snuffy2 commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Refactors the Places integration internals into focused helper modules while preserving the existing entity behavior. The change separates attribute storage, tracker snapshots, location math, OSM requests, config schemas, and update orchestration so the main sensor/updater code is easier to reason about and test.

What Changed

  • Added PlacesAttributes as the mutable attribute store and delegated sensor attribute helpers through it.
  • Added tracker and location primitives for coordinate validation, distance calculations, direction-of-travel classification, and GPS metadata handling.
  • Added an OSMClient for URL construction, throttled/cached JSON fetches, non-2xx response handling, service-error detection, and stale-cache cleanup.
  • Added PlacesUpdatePipeline to keep update phase ordering explicit, including rollback/finalization behavior when a phase fails.
  • Extracted config-flow schema construction and display-option helper logic into smaller modules.
  • Updated OSM parsing to prefer explicit payloads over stale sensor attributes.
  • Added architecture design/implementation docs under docs/superpowers/.

Reviewer Notes

  • The intent is structural cleanup, not a feature rewrite. Existing behavior is covered by characterization tests where the refactor moved logic behind new helper classes.
  • Tracker state objects with unknown/unavailable states still proceed when valid coordinates are present; this preserves the current characterized behavior.
  • OSM request handling now avoids caching error responses and keeps list/mapping cache semantics explicit.

Validation

  • ./.venv/bin/python -m pytest (411 passed)
  • ./.venv/bin/python -m prek run -a

Snuffy2 added 30 commits May 15, 2026 21:47
Move the missing tracker ID check ahead of hass.states.get() so malformed entries skip cleanly without querying Home Assistant states. Add regression coverage for both None and empty tracker IDs through the updater gate.
Reject non-2xx OSM responses before parsing so error payloads are not cached, and add regression coverage for 429/500/503 responses. Ensure the update pipeline rolls back partial state and always finalizes bookkeeping when a phase raises. Clean up synchronous URL-builder tests, intentionally unused test callback parameters, and tracker-dependent tests that now require an explicit configured tracker ID.
Follow the existing is_float validation contract when storing tracker latitude, longitude, and GPS accuracy so Decimal-like values are not dropped after passing validation. Add regression coverage through the updater coordinate path.
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  custom_components/places
  advanced_options.py
  attributes.py
  basic_options.py
  config_flow.py
  config_schema.py
  location.py 55, 62, 69, 86
  osm_client.py 122, 193
  parse_osm.py 69, 73-76
  pipeline.py 60-64
  sensor.py 453
  tracker.py
  update_sensor.py 897
Project Total  

This report was generated by python-coverage-comment-action

@Snuffy2
Snuffy2 merged commit f9bbb98 into custom-components:master May 20, 2026
6 of 7 checks passed
@Snuffy2
Snuffy2 deleted the architecture-cleanup-design branch May 20, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant