From 8a6a17b767882d8ce3adc256119e583d59d2f385 Mon Sep 17 00:00:00 2001 From: Richard Mann Date: Sat, 11 Apr 2026 17:25:33 +1000 Subject: [PATCH] fix: try the shade with the strongest signal first for the key --- custom_components/hunterdouglas_powerview_ble/config_flow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/hunterdouglas_powerview_ble/config_flow.py b/custom_components/hunterdouglas_powerview_ble/config_flow.py index c217f61..e26881b 100644 --- a/custom_components/hunterdouglas_powerview_ble/config_flow.py +++ b/custom_components/hunterdouglas_powerview_ble/config_flow.py @@ -111,7 +111,10 @@ async def _fetch_key_from_hub( if not shades: raise ValueError("No shades found on the hub") - ble_names = [s.get("bleName", "") for s in shades if s.get("bleName")] + # Sort by signal strength (strongest first) — a stronger signal means the + # hub is more likely to have an active BLE connection to that shade. + shades.sort(key=lambda s: s.get("signalStrength", -100), reverse=True) + ble_names = [s["bleName"] for s in shades if s.get("bleName")] if not ble_names: raise ValueError("No BLE-capable shades found on the hub")