Skip to content

Support unit-aware target coordinate evaluation - #38

Open
kernelpanic85 wants to merge 1 commit into
ApolloAutomation:Mainfrom
kernelpanic85:Main
Open

kernelpanic85 wants to merge 1 commit into
ApolloAutomation:Mainfrom
kernelpanic85:Main

Conversation

@kernelpanic85

@kernelpanic85 kernelpanic85 commented Sep 18, 2026 •

Copy link
Copy Markdown

Support unit-aware target coordinate evaluation

Description

Convert tracked X/Y coordinates to millimetres before evaluating zone presence.

The integration now:

  • Uses each entity's unit_of_measurement when available.
  • Falls back to the card-configured input_units.
  • Persists and restores input_units with coordinate sensor state.
  • Preserves millimetre behavior for legacy unitless entities.

Related Issue

I ran into this issue where the target entities reporting in inches were not triggering the binary presence sensors as they were stored in mm.

Related PR: ApolloAutomation/zone-mapper-card#23

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (feature or fix that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvements

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the code style of this project (run scripts/lint)
  • [] I have updated the documentation accordingly
  • [] I have updated the translations if needed

Testing

  • Python AST syntax validation passed.
  • Service YAML validation passed.
  • Verified inch-based coordinates are converted before zone evaluation.

Screenshots (if applicable)

Not applicable.

Summary by CodeRabbit

  • New Features
    • Added support for tracking coordinates provided in millimetres, centimetres, metres, inches, or feet.
    • Coordinate values are converted automatically for accurate zone evaluation.
    • Unit settings are displayed with location sensors and restored after restart.
    • Added validation for supported units when updating tracked locations.

… presence

- Uses each entity's `unit_of_measurement` when available.
- Falls back to the card-configured `input_units`.
- Persists and restores `input_units` with coordinate sensor state.
- Preserves millimetre behavior for legacy unitless entities.
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: acd77cdd-1e5e-4eb9-b6c7-185f82731b5a

📥 Commits

Reviewing files that changed from the base of the PR and between e5665f2 and a5b17ca.

📒 Files selected for processing (5)
  • custom_components/zone_mapper/__init__.py
  • custom_components/zone_mapper/binary_sensor.py
  • custom_components/zone_mapper/const.py
  • custom_components/zone_mapper/sensor.py
  • custom_components/zone_mapper/services.yaml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The integration adds supported input-unit configuration, persistence, state restoration, service validation, and unit-aware coordinate conversion for zone evaluation.

Changes

Unit-aware coordinate handling

Layer / File(s) Summary
Unit contract and storage
custom_components/zone_mapper/const.py, custom_components/zone_mapper/__init__.py
Defines supported input units. The update service validates them and stores valid values.
Coordinate conversion
custom_components/zone_mapper/binary_sensor.py
Normalizes unit aliases and converts coordinate values to millimetres. State units take precedence over configured input units.
State exposure and restore
custom_components/zone_mapper/sensor.py, custom_components/zone_mapper/services.yaml
Exposes supported input units in sensor attributes, restores them from prior state, and documents the optional service field.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant UpdateService
  participant LocationStore
  participant BinarySensor
  participant CoordinateStates
  UpdateService->>LocationStore: store supported input_units
  BinarySensor->>LocationStore: resolve zone definition
  LocationStore-->>BinarySensor: return input_units
  BinarySensor->>CoordinateStates: read coordinate states
  CoordinateStates-->>BinarySensor: return values and unit metadata
  BinarySensor->>BinarySensor: convert coordinates to millimetres
Loading

Merge Risk: ⚪ Minimal · up to a5b17

Configured and entity-provided coordinate units are validated and converted consistently before zone evaluation. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: evaluating target coordinates with unit-aware conversion.
Description check ✅ Passed The description includes all required sections, explains the change and related issue, identifies the change type, records testing, and addresses screenshots. Documentation and translation checklist i…
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@kernelpanic85 kernelpanic85 changed the title Convert tracked X/Y coordinates to millimetres before evaluating zone… Support unit-aware target coordinate evaluation Sep 18, 2026
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.

1 participant