agittins / agittins/bermuda

Duplicate scanner names collapse per-scanner RSSI offset fields

Aberta
#822 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
2k
Forks
70
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

## Configuration

- Home Assistant Core: 2026.8.3
- Bermuda: 0.8.7
- 15 active scanners in the observed installation
- Multiple scanners intentionally share a Home Assistant friendly name but are assigned to different HA areas (for example, two `Appliances 2` scanners). The same installation also has three scanners with another shared friendly name.

Related context:

- Originating discussion: https://github.com/agittins/bermuda/discussions/821
- #716 (show proxy area in the configuration page)
- #758 (sort scanners in the RSSI-offset UI)

## Describe the bug

In **Configure Bermuda → Calibration 2: Scanner RSSI Offsets**, scanners are keyed only by `BermudaDevice.name` (the friendly name).

When two scanners have the same friendly name:

1. The `rssi_offset_dict` entry for the first scanner is overwritten by the second, so the object selector shows only one input for that name.
2. On refresh and save, Bermuda looks up both scanner addresses using the same submitted name key.
3. Both scanners therefore receive the same offset and cannot be calibrated independently.

This is more than a display ambiguity: duplicate friendly names collapse distinct scanners into one transient form field.

Current code path on `main`:

- `custom_components/bermuda/config_flow.py`, `async_step_calibration2_scanners`
- Form construction uses `rssi_offset_dict[scanner_name]` (currently around lines 501–506).
- Refresh/results and save perform the same name-based lookup (currently around lines 474–482 and 527–545).

## Reproduction

1. Add two Bluetooth proxies/scanners with the same HA friendly name.
2. Assign them to different Home Assistant areas.
3. Open Bermuda's **Calibration 2: Scanner RSSI Offsets** step.
4. Try to enter a different RSSI offset for each proxy.

### Actual

Only one field/label exists for the shared name, and saving applies its value to both scanner addresses.

### Expected

Every scanner has a distinct, stable field and can retain an independent RSSI offset. The UI should also make clear which HA area each scanner belongs to.

## Suggested solution

Build one transient `display_label → scanner_address` mapping for the form and use it consistently for initial values, refresh/results, and save. Keep the persisted `CONF_RSSI_OFFSETS` format unchanged (address-keyed), so no options migration is required.

Suggested label behavior:

- Include the HA area in the normal label, for example `Appliances 2 — Study` and `Appliances 2 — Workshop`.
- If `name + area` is still duplicated, or no area is assigned, append a short address suffix only where required to guarantee uniqueness.
- Sort the editable labels case-insensitively by display label, which would also address the edit-list portion of #758.

An opt-in toggle does not appear necessary: the area is contextual display data, does not alter stored options, and solves the ambiguity by default. If preserving the existing compact display is preferred, the area could instead be added only when duplicate names are detected, but the internal label/address mapping must still guarantee unique keys.

## Acceptance criteria

- Two scanners with the same friendly name in different areas appear as two fields.
- They can be assigned different offsets, refreshed, and saved independently.
- Same-name/same-area and same-name/no-area scanners remain uniquely addressable via a short suffix fallback.
- Existing address-keyed RSSI offset options load without migration.
- The distance-results table uses the same disambiguated labels as the edit form.

## Diagnostics

A full diagnostics upload is omitted because it contains unrelated household BLE inventory. The behavior is deterministic from the name-keyed dictionaries above and was reproduced against a live 15-scanner Bermuda installation.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.